-
Notifications
You must be signed in to change notification settings - Fork 254
/
sign.go
54 lines (43 loc) · 1.53 KB
/
sign.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package testnode
import (
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var veryLargeGasLim uint64 = uint64(appconsts.DefaultSquareSizeUpperBound*appconsts.DefaultSquareSizeUpperBound) * appconsts.ShareSize * 10
// SignAndBroadcastTx signs a transaction using the provided account and keyring
// inside the client.Context, then broadcasts it synchronously.
func SignAndBroadcastTx(encCfg encoding.Config, c client.Context, account string, msg ...sdk.Msg) (res *sdk.TxResponse, err error) {
opts := []types.TxBuilderOption{
types.SetGasLimit(veryLargeGasLim),
types.SetFeeAmount(sdk.NewCoins(
sdk.NewCoin(app.BondDenom, sdk.NewInt(1)),
)),
}
// use the key for accounts[i] to create a signer used for a single PFB
signer := types.NewKeyringSigner(c.Keyring, account, c.ChainID)
signer.SetEncodingConfig(encCfg)
rec := signer.GetSignerInfo()
addr, err := rec.GetAddress()
if err != nil {
return nil, err
}
acc, seq, err := c.AccountRetriever.GetAccountNumberSequence(c, addr)
if err != nil {
return nil, err
}
signer.SetAccountNumber(acc)
signer.SetSequence(seq)
tx, err := signer.BuildSignedTx(signer.NewTxBuilder(opts...), msg...)
if err != nil {
return nil, err
}
rawTx, err := encCfg.TxConfig.TxEncoder()(tx)
if err != nil {
return nil, err
}
return c.BroadcastTxSync(rawTx)
}