From 3ce10cd55bee7c80050c587dc031532ecce33a5d Mon Sep 17 00:00:00 2001 From: denalimarsh Date: Fri, 24 Apr 2020 15:35:53 -0700 Subject: [PATCH 1/2] update deps to v0.38.3 --- README.md | 15 ++++++++++++--- client/client.go | 5 ++++- client/queries.go | 6 +++--- client/validate.go | 6 +++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8c5ffcc..bbf14d0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,16 @@ # Kava Go SDK -The Kava Go SDK provides unique types and functionality required by services that interact with Kava's core modules. It includes the following core components: +The Kava Go SDK provides unique types and functionality required by services that interact with Kava's core modules. -client - sends transactions and queries to Kava's blockchain +## Components -keys - management of private keys and account recovery from mnenomic phrase +Kava's Go SDK includes the following components: +- client: sends transactions and queries to Kava's blockchain +- keys: management of private keys and account recovery from mnenomic phrase + +## Version compatibility + +We recommend using the Go SDK with the following versions of relevant software: +- github.com/cosmos/cosmos-sdk v0.38.3 +- github.com/tendermint/tendermint v0.33.3 +- github.com/kava-labs/kava v0.7.1-0.20200424154444-e9a73b80ce91 diff --git a/client/client.go b/client/client.go index 5fe1bde..3ba4eb9 100644 --- a/client/client.go +++ b/client/client.go @@ -25,7 +25,10 @@ type KavaClient struct { // NewKavaClient creates a new KavaClient func NewKavaClient(cdc *amino.Codec, mnemonic string, coinID uint32, rpcAddr string, networkType ChainNetwork) *KavaClient { // Set up HTTP client - http := client.NewHTTP(rpcAddr, "/websocket") + http, err := client.NewHTTP(rpcAddr, "/websocket") + if err != nil { + panic(err) + } http.Logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)) // Set up key manager diff --git a/client/queries.go b/client/queries.go index 7a7527c..0f90fd8 100644 --- a/client/queries.go +++ b/client/queries.go @@ -7,11 +7,11 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bep3 "github.com/kava-labs/kava/x/bep3/types" - cmn "github.com/tendermint/tendermint/libs/common" + tmbytes "github.com/tendermint/tendermint/libs/bytes" ) // GetSwapByID gets an atomic swap on Kava by ID -func (kc *KavaClient) GetSwapByID(swapID cmn.HexBytes) (swap bep3.AtomicSwap, err error) { +func (kc *KavaClient) GetSwapByID(swapID tmbytes.HexBytes) (swap bep3.AtomicSwap, err error) { params := bep3.NewQueryAtomicSwapByID(swapID) bz, err := kc.Keybase.GetCodec().MarshalJSON(params) if err != nil { @@ -56,7 +56,7 @@ func (kc *KavaClient) GetAccount(addr sdk.AccAddress) (acc authtypes.BaseAccount } // ABCIQuery sends a query to Kava -func (kc *KavaClient) ABCIQuery(path string, data cmn.HexBytes) ([]byte, error) { +func (kc *KavaClient) ABCIQuery(path string, data tmbytes.HexBytes) ([]byte, error) { if err := ValidateABCIQuery(path, data); err != nil { return []byte{}, err } diff --git a/client/validate.go b/client/validate.go index 7d8ed69..f8dddc7 100644 --- a/client/validate.go +++ b/client/validate.go @@ -3,7 +3,7 @@ package client import ( "fmt" - cmn "github.com/tendermint/tendermint/libs/common" + tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" ) @@ -29,7 +29,7 @@ func ValidateTx(tx tmtypes.Tx) error { } // ValidateABCIQuery validates an ABCI query -func ValidateABCIQuery(path string, data cmn.HexBytes) error { +func ValidateABCIQuery(path string, data tmbytes.HexBytes) error { if err := ValidateABCIPath(path); err != nil { return err } @@ -48,7 +48,7 @@ func ValidateABCIPath(path string) error { } // ValidateABCIData validates an ABCI query's data -func ValidateABCIData(data cmn.HexBytes) error { +func ValidateABCIData(data tmbytes.HexBytes) error { if len(data) > maxABCIDataLength { return ExceedABCIPathLengthError } From eb8edfff46726886d273e4191ed04cca22719bce Mon Sep 17 00:00:00 2001 From: denalimarsh Date: Fri, 24 Apr 2020 15:36:15 -0700 Subject: [PATCH 2/2] update readme with code examples --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index bbf14d0..78f98bc 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,52 @@ Kava's Go SDK includes the following components: - client: sends transactions and queries to Kava's blockchain - keys: management of private keys and account recovery from mnenomic phrase +### Client + +To initialize a new client we'll need to set up the codec and pass it into the constructor + +```go +// Initialize codec with Kava's prefixes and coin type +config := sdk.GetConfig() +app.SetBech32AddressPrefixes(config) +app.SetBip44CoinType(config) +cdc := app.MakeCodec() + +// Initialize new Kava client and set codec +kavaClient := client.NewKavaClient(cdc, mnemonic, app.Bip44CoinType, rpcAddr, networkTestnet) +kavaClient.Keybase.SetCodec(cdc) +``` + +Let's use our new client to query the Kava blockchain for information about an account + +```go +kavaAddress := "kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny" +addr, err := sdk.AccAddressFromBech32(kavaAddress) +if err != nil { + panic(err) +} + +acc, err := kavaClient.GetAccount(addr) +if err != nil { + panic(err) +} + +fmt.Println("Account:", acc) +``` + +### Keys + +Client uses the keys package for signing transactions, but keys can also be used standalone. The following example shows how to create a new key manager from a mnemonic phrase + +```go +// Create a new mnemonic key manager +mnemonic := "secret words that unlock your address" +keybase, err := keys.NewMnemonicKeyManager(mnemonic, app.Bip44CoinType) +if err != nil { + fmt.Println(err) +} +``` + ## Version compatibility We recommend using the Go SDK with the following versions of relevant software: