Skip to content

Commit

Permalink
Add option to pay fees (#23)
Browse files Browse the repository at this point in the history
* add BroadcastWithFee method

* update kava depency
  • Loading branch information
rhuairahrighairidh authored Nov 5, 2020
1 parent b8dfbd3 commit 593d5cb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
17 changes: 12 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

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

"github.com/kava-labs/go-sdk/keys"
)
Expand Down Expand Up @@ -44,9 +44,16 @@ func NewKavaClient(cdc *amino.Codec, mnemonic string, coinID uint32, rpcAddr str
}
}

// Broadcast sends a message to the Kava blockchain as a transaction
// Broadcast sends a message to the Kava blockchain as a transaction.
// This pays no transaction fees.
func (kc *KavaClient) Broadcast(m sdk.Msg, syncType SyncType) (*ctypes.ResultBroadcastTx, error) {
signBz, err := kc.sign(m)
fee := authtypes.NewStdFee(250000, nil)
return kc.BroadcastWithFee(m, fee, syncType)
}

// BroadcastWithFee sends a message to the Kava blockchain as a transaction, paying the specified transaction fee.
func (kc *KavaClient) BroadcastWithFee(m sdk.Msg, fee authtypes.StdFee, syncType SyncType) (*ctypes.ResultBroadcastTx, error) {
signBz, err := kc.sign(m, fee)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -79,7 +86,7 @@ func (kc *KavaClient) Broadcast(m sdk.Msg, syncType SyncType) (*ctypes.ResultBro
}
}

func (kc *KavaClient) sign(m sdk.Msg) ([]byte, error) {
func (kc *KavaClient) sign(m sdk.Msg, fee authtypes.StdFee) ([]byte, error) {
if kc.Keybase == nil {
return nil, fmt.Errorf("Keys are missing, must to set key")
}
Expand All @@ -93,7 +100,7 @@ func (kc *KavaClient) sign(m sdk.Msg) ([]byte, error) {
ChainID: chainID,
AccountNumber: 0,
Sequence: 0,
Fee: authtypes.NewStdFee(250000, nil),
Fee: fee,
Msgs: []sdk.Msg{m},
Memo: "",
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/btcsuite/btcd v0.20.1-beta
github.com/cosmos/cosmos-sdk v0.39.1
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d
github.com/kava-labs/kava v0.11.0-rc1
github.com/kava-labs/kava v0.12.0
github.com/stretchr/testify v1.6.1
github.com/tendermint/go-amino v0.15.1
github.com/tendermint/tendermint v0.33.7
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
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/kava v0.11.0-alpha.1.0.20200922214458-087b10d15ff2 h1:D2RyPYygQ7cr08ax3D03qC+c6gep7TTHf+NNucNKSu0=
github.com/kava-labs/kava v0.11.0-alpha.1.0.20200922214458-087b10d15ff2/go.mod h1:1AYBNxuelDdwzZzWFsgPUMVwZ9qfKSjgT6UEEhTe/ys=
github.com/kava-labs/kava v0.11.0-rc1 h1:2qV0SYgtzPxZ+oLJV5dzLweLNa0AXxM7X+n1zrnDOS0=
github.com/kava-labs/kava v0.11.0-rc1/go.mod h1:1AYBNxuelDdwzZzWFsgPUMVwZ9qfKSjgT6UEEhTe/ys=
github.com/kava-labs/kava v0.12.0 h1:ix/Ooq5HV9pIvUd2nbHjnDheGx65+x3Da5pecI0OXpQ=
github.com/kava-labs/kava v0.12.0/go.mod h1:1AYBNxuelDdwzZzWFsgPUMVwZ9qfKSjgT6UEEhTe/ys=
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
4 changes: 2 additions & 2 deletions keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"strings"

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

"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/go-amino"
)

const (
Expand Down

0 comments on commit 593d5cb

Please sign in to comment.