Skip to content

Commit

Permalink
Merge pull request #17 from Kava-Labs/develop
Browse files Browse the repository at this point in the history
Merge develop -> master
  • Loading branch information
denalimarsh authored Jun 11, 2020
2 parents 78512c4 + 02c7e8a commit 37d6047
Show file tree
Hide file tree
Showing 49 changed files with 5,244 additions and 36 deletions.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ The Kava Go SDK provides unique types and functionality required by services tha
## Components

Kava's Go SDK includes the following components:
- client: sends transactions and queries to Kava's blockchain
- client: sends transactions and queries to the Kava blockchain
- kava: msgs and types from the Kava blockchain required for complete codec registration
- 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
// Required imports
import (
"github.com/kava-labs/go-sdk/client"
"github.com/kava-labs/go-sdk/kava"
)

// Set up Kava prefixes and codec
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)
app.SetBip44CoinType(config)
cdc := app.MakeCodec()
kava.SetBech32AddressPrefixes(config)
cdc := kava.MakeCodec()

// Initialize new Kava client and set codec
kavaClient := client.NewKavaClient(cdc, mnemonic, app.Bip44CoinType, rpcAddr, networkTestnet)
kavaClient := client.NewKavaClient(cdc, mnemonic, kava.Bip44CoinType, rpcAddr, networkTestnet)
kavaClient.Keybase.SetCodec(cdc)
```

Expand All @@ -46,6 +52,12 @@ fmt.Println("Account:", acc)
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
// Required imports
import (
"github.com/kava-labs/kava/app"
"github.com/kava-labs/go-sdk/keys"
)

// Create a new mnemonic key manager
mnemonic := "secret words that unlock your address"
keybase, err := keys.NewMnemonicKeyManager(mnemonic, app.Bip44CoinType)
Expand All @@ -56,7 +68,6 @@ if err != nil {

## 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
The go-sdk is compatible with other libraries that use different versions of Tendermint and the Cosmos SDK. To ensure compatibility, Kava's go-sdk uses stable forks of tendermint v0.33.3 and the cosmos-sdk v0.38.3. The go-sdk has the equivalent dependencies:
- github.com/kava-labs/cosmos-sdk v0.34.4-0.20200506043356-5d772797f9a3
- github.com/kava-labs/tendermint v0.33.4-0.20200506042050-c611c5308a53
26 changes: 16 additions & 10 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import (
"fmt"
"os"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
sdk "github.com/kava-labs/cosmos-sdk/types"
authtypes "github.com/kava-labs/cosmos-sdk/x/auth/types"
"github.com/kava-labs/tendermint/libs/log"
rpcclient "github.com/kava-labs/tendermint/rpc/client"
ctypes "github.com/kava-labs/tendermint/rpc/core/types"
tmtypes "github.com/kava-labs/tendermint/types"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/kava-labs/go-sdk/keys"
)

// KavaClient facilitates interaction with the Kava blockchain
type KavaClient struct {
Network ChainNetwork
HTTP *client.HTTP
HTTP *rpcclient.HTTP
Keybase keys.KeyManager
}

// NewKavaClient creates a new KavaClient
func NewKavaClient(cdc *amino.Codec, mnemonic string, coinID uint32, rpcAddr string, networkType ChainNetwork) *KavaClient {
// Set up HTTP client
http, err := client.NewHTTP(rpcAddr, "/websocket")
http, err := rpcclient.NewHTTP(rpcAddr, "/websocket")
if err != nil {
panic(err)
}
Expand All @@ -44,6 +44,7 @@ func NewKavaClient(cdc *amino.Codec, mnemonic string, coinID uint32, rpcAddr str
}
}

// Broadcast sends a message to the Kava blockchain as a transaction
func (kc *KavaClient) Broadcast(m sdk.Msg, syncType SyncType) (*ctypes.ResultBroadcastTx, error) {
signBz, err := kc.sign(m)
if err != nil {
Expand Down Expand Up @@ -83,9 +84,14 @@ func (kc *KavaClient) sign(m sdk.Msg) ([]byte, error) {
return nil, fmt.Errorf("Keys are missing, must to set key")
}

chainID := ProdChainID
if kc.Network != ProdNetwork {
var chainID string
switch kc.Network {
case LocalNetwork:
chainID = LocalChainID
case TestNetwork:
chainID = TestChainID
case ProdNetwork:
chainID = ProdChainID
}

signMsg := &authtypes.StdSignMsg{
Expand Down
9 changes: 5 additions & 4 deletions client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"errors"
"fmt"

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"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
sdk "github.com/kava-labs/cosmos-sdk/types"
authtypes "github.com/kava-labs/cosmos-sdk/x/auth/types"
tmbytes "github.com/kava-labs/tendermint/libs/bytes"

"github.com/kava-labs/go-sdk/kava/bep3"
)

// GetSwapByID gets an atomic swap on Kava by ID
Expand Down
12 changes: 8 additions & 4 deletions client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ const (
type ChainNetwork uint8

const (
TestNetwork ChainNetwork = iota
LocalNetwork ChainNetwork = iota
TestNetwork
ProdNetwork
)

const (
TestChainID = "testing"
// ProdChainID is currently set to testnet-5000
ProdChainID = "kava-testnet-5000"
// LocalChainID is for local development
LocalChainID = "testing"
// TestChainID is Kava's latest testnet
TestChainID = "kava-testnet-6000"
// ProdChainID is Kava's mainnet
ProdChainID = "kava-3"
)
8 changes: 4 additions & 4 deletions client/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package client
import (
"fmt"

tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmtypes "github.com/tendermint/tendermint/types"
tmbytes "github.com/kava-labs/tendermint/libs/bytes"
tmtypes "github.com/kava-labs/tendermint/types"
)

const (
Expand All @@ -13,8 +13,8 @@ const (
)

var (
ExceedABCIPathLengthError = fmt.Errorf("the abci path exceed max length %d ", maxABCIPathLength)
ExceedABCIDataLengthError = fmt.Errorf("the abci data exceed max length %d ", maxABCIDataLength)
ExceedABCIPathLengthError = fmt.Errorf("the abci path exceeds max length %d ", maxABCIPathLength)
ExceedABCIDataLengthError = fmt.Errorf("the abci data exceeds max length %d ", maxABCIDataLength)
)

// ValidateTx validates a Tendermint transaction
Expand Down
28 changes: 28 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module github.com/kava-labs/go-sdk

go 1.13

require (
github.com/btcsuite/btcd v0.20.1-beta
github.com/btcsuite/btcutil v1.0.2
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d
github.com/kava-labs/cosmos-sdk v0.38.3-release
github.com/kava-labs/tendermint v0.33.3-release
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.5.1
github.com/stumble/gorocksdb v0.0.3 // indirect
github.com/tendermint/go-amino v0.15.1
github.com/zondax/ledger-go v0.11.0 // indirect
gopkg.in/yaml.v2 v2.2.8
)

replace github.com/zondax/ledger-go => github.com/binance-chain/ledger-go v0.9.1

replace github.com/tendermint/tm-db => github.com/kava-labs/tm-db v0.4.1-release

replace github.com/tendermint/tendermint => github.com/kava-labs/tendermint v0.33.3-release

replace github.com/tendermint/iavl => github.com/kava-labs/iavl v0.13.3-release

replace github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.38.3-release
Loading

0 comments on commit 37d6047

Please sign in to comment.