Skip to content

Commit

Permalink
Merge pull request #18 from Kava-Labs/dm-refactor-codec
Browse files Browse the repository at this point in the history
Dm refactor codec
  • Loading branch information
denalimarsh authored Jul 2, 2020
2 parents 37d6047 + 62ee2a5 commit e1c2ad5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 34 deletions.
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type KavaClient struct {
Network ChainNetwork
HTTP *rpcclient.HTTP
Keybase keys.KeyManager
Cdc *amino.Codec
}

// NewKavaClient creates a new KavaClient
Expand All @@ -41,6 +42,7 @@ func NewKavaClient(cdc *amino.Codec, mnemonic string, coinID uint32, rpcAddr str
Network: networkType,
HTTP: http,
Keybase: keyManager,
Cdc: cdc,
}
}

Expand Down Expand Up @@ -124,7 +126,7 @@ func (kc *KavaClient) sign(m sdk.Msg) ([]byte, error) {
}
}

signedMsg, err := kc.Keybase.Sign(*signMsg)
signedMsg, err := kc.Keybase.Sign(*signMsg, kc.Cdc)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// GetSwapByID gets an atomic swap on Kava by ID
func (kc *KavaClient) GetSwapByID(swapID tmbytes.HexBytes) (swap bep3.AtomicSwap, err error) {
params := bep3.NewQueryAtomicSwapByID(swapID)
bz, err := kc.Keybase.GetCodec().MarshalJSON(params)
bz, err := kc.Cdc.MarshalJSON(params)
if err != nil {
return bep3.AtomicSwap{}, err
}
Expand All @@ -26,7 +26,7 @@ func (kc *KavaClient) GetSwapByID(swapID tmbytes.HexBytes) (swap bep3.AtomicSwap
return bep3.AtomicSwap{}, err
}

err = kc.Keybase.GetCodec().UnmarshalJSON(result, &swap)
err = kc.Cdc.UnmarshalJSON(result, &swap)
if err != nil {
return bep3.AtomicSwap{}, err
}
Expand All @@ -36,7 +36,7 @@ func (kc *KavaClient) GetSwapByID(swapID tmbytes.HexBytes) (swap bep3.AtomicSwap
// GetAccount gets the account associated with an address on Kava
func (kc *KavaClient) GetAccount(addr sdk.AccAddress) (acc authtypes.BaseAccount, err error) {
params := authtypes.NewQueryAccountParams(addr)
bz, err := kc.Keybase.GetCodec().MarshalJSON(params)
bz, err := kc.Cdc.MarshalJSON(params)
if err != nil {
return authtypes.BaseAccount{}, err
}
Expand All @@ -48,7 +48,7 @@ func (kc *KavaClient) GetAccount(addr sdk.AccAddress) (acc authtypes.BaseAccount
return authtypes.BaseAccount{}, err
}

err = kc.Keybase.GetCodec().UnmarshalJSON(result, &acc)
err = kc.Cdc.UnmarshalJSON(result, &acc)
if err != nil {
return authtypes.BaseAccount{}, err
}
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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/kava-labs/cosmos-sdk v0.38.3-stable.0.20200520223313-bfbe25d175da
github.com/kava-labs/tendermint v0.33.4-0.20200520221629-77480532c622
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.5.1
Expand All @@ -19,10 +19,10 @@ require (

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/tm-db => github.com/kava-labs/tm-db v0.4.1-stable

replace github.com/tendermint/tendermint => github.com/kava-labs/tendermint v0.33.3-release
replace github.com/tendermint/tendermint => github.com/kava-labs/tendermint v0.33.4-0.20200520221629-77480532c622

replace github.com/tendermint/iavl => github.com/kava-labs/iavl v0.13.3-release
replace github.com/tendermint/iavl => github.com/kava-labs/iavl v0.13.4-0.20200520164545-88a15b563d3d

replace github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.38.3-release
replace github.com/cosmos/cosmos-sdk => github.com/kava-labs/cosmos-sdk v0.38.3-stable.0.20200520223313-bfbe25d175da
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kava-labs/cosmos-sdk v0.38.3-release h1:/+8MUaP0UzcHmxfWTj19QcdgsUwNtLjfbjQwL3eAFeE=
github.com/kava-labs/cosmos-sdk v0.38.3-release/go.mod h1:7vX9GHxzw5TsrHMOXaVri2fyOk/B++7Q3ic8zl8UNPw=
github.com/kava-labs/iavl v0.13.3-release h1:hHa3/xE/4CXcCWf3DtpWMzkXUPfrVkkKjELGxNewX4s=
github.com/kava-labs/iavl v0.13.3-release/go.mod h1:+u2pgyVlUGuAKEixtjzo5mY+7jbDtdG79o37hYvzfJo=
github.com/kava-labs/tendermint v0.33.3-release h1:5VGpieDxAU7vu52EtlUOpO7+Lz0pASLAR09lqE67kOQ=
github.com/kava-labs/tendermint v0.33.3-release/go.mod h1:+YBcrznWqtj6NkBMll7Dayzxz5JiDT6gG2UKajX6Kc8=
github.com/kava-labs/tm-db v0.4.1-release h1:M2QbX8nBl3iK0MoPd7o8FKusY/AaJVhVp7jLTdJ14OM=
github.com/kava-labs/tm-db v0.4.1-release/go.mod h1:dRComvpd8Xj0cJun86vy2bc1i5b8gm15dQlRm1+BiMs=
github.com/kava-labs/cosmos-sdk v0.38.3-stable.0.20200520223313-bfbe25d175da h1:helK0wcW3LN1KXif+ca/U/n7x7/1jcmBQOXSPXQTRs0=
github.com/kava-labs/cosmos-sdk v0.38.3-stable.0.20200520223313-bfbe25d175da/go.mod h1:75qc1x7nKTGNQsu1GRL0TehEW9jrfQSGw4+ook4FdbE=
github.com/kava-labs/iavl v0.13.4-0.20200520222038-6fa4fba8921e h1:MZZqo9oxf/c69fNje3K9Bd0rjBca76qmycYcnNphWzk=
github.com/kava-labs/iavl v0.13.4-0.20200520222038-6fa4fba8921e/go.mod h1:MhuTGVny8uFF0Fe7sTbC8pj/5sncuSRBSOc1G2mrrJo=
github.com/kava-labs/tendermint v0.33.4-0.20200520221629-77480532c622 h1:uqsJITDXMP5Lm4ZHhDWP7QuI1XvoNn9zptTbp7/wrFg=
github.com/kava-labs/tendermint v0.33.4-0.20200520221629-77480532c622/go.mod h1:y7GZOfZgPhiOeIWjfHo6MWA/+n1NHYM/CCbdkc1ZiCI=
github.com/kava-labs/tm-db v0.4.2-0.20200506040135-3f7b09feebcd h1:2ez2kbAN34BjuS9Op8CJ2GJo8DrpmicOiY3BY3bagKo=
github.com/kava-labs/tm-db v0.4.2-0.20200506040135-3f7b09feebcd/go.mod h1:hV2Nix8Ndt0UMAuGceyBKxKvfuRnWQDaBAJNGDeVbBs=
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d h1:Z+RDyXzjKE0i2sTjZ/b1uxiGtPhFy34Ou/Tk0qwN0kM=
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down
19 changes: 4 additions & 15 deletions keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"strings"

"github.com/btcsuite/btcd/btcec"
"github.com/cosmos/go-bip39"
sdk "github.com/kava-labs/cosmos-sdk/types"
authtypes "github.com/kava-labs/cosmos-sdk/x/auth/types"
"github.com/cosmos/go-bip39"

"github.com/kava-labs/tendermint/crypto"
"github.com/kava-labs/tendermint/crypto/secp256k1"
Expand All @@ -31,9 +31,7 @@ const (
type KeyManager interface {
GetPrivKey() crypto.PrivKey
GetAddr() sdk.AccAddress
GetCodec() *amino.Codec
SetCodec(*amino.Codec)
Sign(authtypes.StdSignMsg) ([]byte, error)
Sign(authtypes.StdSignMsg, *amino.Codec) ([]byte, error)
}

// NewMnemonicKeyManager creates a new KeyManager from a mnenomic
Expand All @@ -54,7 +52,6 @@ func NewPrivateKeyManager(priKey string) (KeyManager, error) {
}

type keyManager struct {
cdc *amino.Codec
privKey crypto.PrivKey
addr sdk.AccAddress
mnemonic string
Expand All @@ -68,24 +65,16 @@ func (m *keyManager) GetAddr() sdk.AccAddress {
return m.addr
}

func (m *keyManager) GetCodec() *amino.Codec {
return m.cdc
}

func (m *keyManager) SetCodec(codec *amino.Codec) {
m.cdc = codec
}

// Sign signs a standard msg and marshals the result to bytes
func (m *keyManager) Sign(stdMsg authtypes.StdSignMsg) ([]byte, error) {
func (m *keyManager) Sign(stdMsg authtypes.StdSignMsg, cdc *amino.Codec) ([]byte, error) {
sig, err := m.makeSignature(stdMsg)
if err != nil {
return nil, err
}

newTx := authtypes.NewStdTx(stdMsg.Msgs, stdMsg.Fee, []authtypes.StdSignature{sig}, stdMsg.Memo)

bz, err := m.cdc.MarshalBinaryLengthPrefixed(&newTx)
bz, err := cdc.MarshalBinaryLengthPrefixed(&newTx)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e1c2ad5

Please sign in to comment.