Skip to content

Commit

Permalink
Merge pull request #6 from Kava-Labs/dm-bump-v0.38
Browse files Browse the repository at this point in the history
[R4R] Update to v0.38.3
  • Loading branch information
denalimarsh authored Apr 24, 2020
2 parents f0c010b + eb8edff commit 78512c4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 10 deletions.
61 changes: 58 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,62 @@
# 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

### 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:
- 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
5 changes: 4 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions client/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 78512c4

Please sign in to comment.