From 8794fcb683f3a686dec8d35253d5667108e397a0 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Wed, 2 Mar 2022 05:35:58 -0300 Subject: [PATCH] feat(pkg/cosmosclient): request more tokens from faucet as needed (#2125) * ask token from faucet if don't have enough balance * fix import sort --- starport/pkg/cosmosclient/cosmosclient.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/starport/pkg/cosmosclient/cosmosclient.go b/starport/pkg/cosmosclient/cosmosclient.go index c20eb017c2..248c353f1f 100644 --- a/starport/pkg/cosmosclient/cosmosclient.go +++ b/starport/pkg/cosmosclient/cosmosclient.go @@ -20,12 +20,13 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdktypes "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx/signing" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" staking "github.com/cosmos/cosmos-sdk/x/staking/types" - proto "github.com/gogo/protobuf/proto" + "github.com/gogo/protobuf/proto" prototypes "github.com/gogo/protobuf/types" "github.com/pkg/errors" rpchttp "github.com/tendermint/tendermint/rpc/client/http" @@ -305,6 +306,14 @@ func (c Client) BroadcastTxWithProvision(accountName string, msgs ...sdktypes.Ms } resp, err := ctx.BroadcastTx(txBytes) + if err == sdkerrors.ErrInsufficientFunds { + err = c.makeSureAccountHasTokens(context.Background(), accountAddress.String()) + if err != nil { + return Response{}, err + } + resp, err = ctx.BroadcastTx(txBytes) + } + return Response{ codec: ctx.Codec, TxResponse: resp,