-
Notifications
You must be signed in to change notification settings - Fork 276
/
builder_options.go
99 lines (82 loc) · 2.54 KB
/
builder_options.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package types
import (
sdkclient "github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
)
type TxBuilderOption func(builder sdkclient.TxBuilder) sdkclient.TxBuilder
func SetGasLimit(limit uint64) TxBuilderOption {
return func(builder sdkclient.TxBuilder) sdkclient.TxBuilder {
builder.SetGasLimit(limit)
return builder
}
}
func SetFeeAmount(fees sdk.Coins) TxBuilderOption {
return func(builder sdkclient.TxBuilder) sdkclient.TxBuilder {
builder.SetFeeAmount(fees)
return builder
}
}
func SetMemo(memo string) TxBuilderOption {
return func(builder sdkclient.TxBuilder) sdkclient.TxBuilder {
builder.SetMemo(memo)
return builder
}
}
func SetFeePayer(feePayer sdk.AccAddress) TxBuilderOption {
return func(builder sdkclient.TxBuilder) sdkclient.TxBuilder {
builder.SetFeePayer(feePayer)
return builder
}
}
func SetTip(tip *tx.Tip) TxBuilderOption {
return func(builder sdkclient.TxBuilder) sdkclient.TxBuilder {
builder.SetTip(tip)
return builder
}
}
func SetTimeoutHeight(height uint64) TxBuilderOption {
return func(builder sdkclient.TxBuilder) sdkclient.TxBuilder {
builder.SetTimeoutHeight(height)
return builder
}
}
func SetFeeGranter(feeGranter sdk.AccAddress) TxBuilderOption {
return func(builder sdkclient.TxBuilder) sdkclient.TxBuilder {
builder.SetFeeGranter(feeGranter)
return builder
}
}
// InheritTxConfig sets all of the accessible configurations from a given tx
// into a a give client.TxBuilder
func InheritTxConfig(builder sdkclient.TxBuilder, tx authsigning.Tx) sdkclient.TxBuilder {
if gas := tx.GetGas(); gas != 0 {
builder.SetGasLimit(gas)
}
if feeAmmount := tx.GetFee(); !feeAmmount.AmountOf("utia").Equal(sdk.NewInt(0)) {
builder.SetFeeAmount(tx.GetFee())
}
if memo := tx.GetMemo(); memo != "" {
builder.SetMemo(tx.GetMemo())
}
if tip := tx.GetTip(); tip != nil {
builder.SetTip(tip)
}
if timeoutHeight := tx.GetTimeoutHeight(); timeoutHeight != 0 {
builder.SetTimeoutHeight(timeoutHeight)
}
signers := tx.GetSigners()
// Note: if there are multiple signers in a PFB, then this could create an
// invalid signature. This is not an issue at this time because we currently
// ignore pfbs with multiple signers
if len(signers) == 1 {
if feePayer := tx.FeeGranter(); !feePayer.Equals(signers[0]) {
builder.SetFeeGranter(tx.FeeGranter())
}
}
if feeGranter := tx.FeeGranter(); !feeGranter.Empty() {
builder.SetFeeGranter(tx.FeeGranter())
}
return builder
}