Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 35a837b

Browse files
committedJun 6, 2023
support broadcasting multiple txns
1 parent be4f83f commit 35a837b

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed
 

‎CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes will be documented here.
44

5+
## [v0.4.1] - TBD
6+
- support broadcasting multiple transactions
7+
- accept configs dynamically set by the user
8+
59
## [v0.3.1] - 2023-05-17
610
- add support for configuring fee granter for transactions
711
## [v0.3.0] - 2023-03-14

‎README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
A gitopia client library and cosmos sdk wrapper
44

5-
## Environment configs
6-
// TODO: accept config via parameters
7-
configure the below environment variables
5+
## configs
6+
configure the below config variables
87
```
98
GITOPIA_ADDR
109
TM_ADDR

‎client.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
rtypes "github.com/gitopia/gitopia/v2/x/rewards/types"
1919
"github.com/pkg/errors"
2020
"github.com/sirupsen/logrus"
21-
"github.com/spf13/viper"
2221
rpcclient "github.com/tendermint/tendermint/rpc/client"
2322
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
2423
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@@ -51,14 +50,14 @@ func NewClient(ctx context.Context, cc client.Context, txf tx.Factory) (Client,
5150
w := logger.FromContext(ctx).WriterLevel(logrus.DebugLevel)
5251
cc = cc.WithOutput(w)
5352

54-
txf = txf.WithGasPrices(viper.GetString("GAS_PRICES")).WithGasAdjustment(GAS_ADJUSTMENT)
53+
txf = txf.WithGasPrices(GAS_PRICES).WithGasAdjustment(GAS_ADJUSTMENT)
5554

5655
rc, err := rpchttp.New(cc.NodeURI, TM_WS_ENDPOINT)
5756
if err != nil {
5857
return Client{}, errors.Wrap(err, "error creating rpc client")
5958
}
6059

61-
q, err := GetQueryClient(viper.GetString("GITOPIA_ADDR"))
60+
q, err := GetQueryClient(GITOPIA_ADDR)
6261
if err != nil {
6362
return Client{}, errors.Wrap(err, "error creating query client")
6463
}
@@ -117,9 +116,9 @@ func (c Client) AuthorizedBroadcastTx(ctx context.Context, msg sdk.Msg) error {
117116
return nil
118117
}
119118

120-
func (c Client) BroadcastTxAndWait(ctx context.Context, msg sdk.Msg) error {
119+
func (c Client) BroadcastTxAndWait(ctx context.Context, msg ...sdk.Msg) error {
121120
// !!HACK!! set sequence to 0 to force refresh account sequence for every txn
122-
txHash, err := BroadcastTx(c.cc, c.txf.WithSequence(0).WithFeePayer(c.Address()), msg)
121+
txHash, err := BroadcastTx(c.cc, c.txf.WithSequence(0).WithFeePayer(c.Address()), msg...)
123122
if err != nil {
124123
return err
125124
}

‎cmd.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
otypes "github.com/gitopia/gitopia/v2/x/offchain/types"
1919
"github.com/pkg/errors"
2020
"github.com/spf13/cobra"
21-
"github.com/spf13/viper"
2221
)
2322

2423
func initClientConfig() {
@@ -55,8 +54,8 @@ func CommandInit(cmd *cobra.Command, appName string) error {
5554

5655
func GetClientContext(cmd *cobra.Command) (client.Context, error) {
5756
clientCtx := client.GetClientContextFromCmd(cmd)
58-
clientCtx = clientCtx.WithChainID(viper.GetString("CHAIN_ID"))
59-
clientCtx = clientCtx.WithNodeURI(viper.GetString("TM_ADDR"))
57+
clientCtx = clientCtx.WithChainID(CHAIN_ID)
58+
clientCtx = clientCtx.WithNodeURI(TM_ADDR)
6059
c, err := client.NewClientFromNode(clientCtx.NodeURI)
6160
if err != nil {
6261
return clientCtx, errors.Wrap(err, "error creatig tm client")
@@ -74,7 +73,7 @@ func GetClientContext(cmd *cobra.Command) (client.Context, error) {
7473
return clientCtx, errors.Wrap(err, "error creating keyring backend")
7574
}
7675
clientCtx = clientCtx.WithKeyring(kr)
77-
clientCtx = clientCtx.WithKeyringDir(viper.GetString("WORKING_DIR"))
76+
clientCtx = clientCtx.WithKeyringDir(WORKING_DIR)
7877

7978
from, err := cmd.Flags().GetString(flags.FlagFrom)
8079
if err != nil {
@@ -87,7 +86,7 @@ func GetClientContext(cmd *cobra.Command) (client.Context, error) {
8786

8887
clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName)
8988

90-
feeGranterAddr := sdk.MustAccAddressFromBech32(viper.GetString("FEE_GRANTER_ADDR"))
89+
feeGranterAddr := sdk.MustAccAddressFromBech32(FEE_GRANTER_ADDR)
9190
clientCtx = clientCtx.WithFeeGranterAddress(feeGranterAddr)
9291
return clientCtx, nil
9392
}

‎config.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package gitopia
2+
3+
var APP_NAME string
4+
var GAS_PRICES string
5+
var GITOPIA_ADDR string
6+
var CHAIN_ID string
7+
var TM_ADDR string
8+
var WORKING_DIR string
9+
var FEE_GRANTER_ADDR string
10+
11+
func WithAppName(a string) {
12+
APP_NAME = a
13+
}
14+
15+
func WithGasPrices(g string) {
16+
GAS_PRICES = g
17+
}
18+
func WithGitopiaAddr(a string) {
19+
GITOPIA_ADDR = a
20+
}
21+
22+
func WithChainId(c string) {
23+
CHAIN_ID = c
24+
}
25+
func WithTmAddr(a string) {
26+
TM_ADDR = a
27+
}
28+
func WithWorkingDir(w string) {
29+
WORKING_DIR = w
30+
}
31+
func WithFeeGranter(a string) {
32+
FEE_GRANTER_ADDR = a
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.