Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cli for tips transactions #10311

Merged
merged 230 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 201 commits
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
48da6e2
Replace abci calls with txHandler
amaury1093 Aug 12, 2021
3e4d7b6
still WIP
amaury1093 Aug 12, 2021
096d103
Use inner
amaury1093 Aug 12, 2021
11bd37f
runTx middleware
amaury1093 Aug 13, 2021
c666dc9
Fix some tests
amaury1093 Aug 13, 2021
664f8d7
Simplify runMsgs
amaury1093 Aug 13, 2021
25a643e
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/m…
amaury1093 Aug 13, 2021
ac74030
Fix ante event emitting
amaury1093 Aug 13, 2021
0b8f940
Use context.Context
amaury1093 Aug 16, 2021
080c6af
Small refactor
amaury1093 Aug 16, 2021
c3911f8
Fix antehandler events
amaury1093 Aug 16, 2021
6582496
Add Simulate
amaury1093 Aug 16, 2021
a900541
Fix gasInfo
amaury1093 Aug 16, 2021
6b1f9d7
Add gas tx middleware
amaury1093 Aug 16, 2021
bbf2872
Fix baseapp_test
amaury1093 Aug 16, 2021
dd32108
Fix tests
amaury1093 Aug 17, 2021
60d43dc
Fix grpc SimulateTx test
amaury1093 Aug 18, 2021
4451a4b
Fix slashing test
amaury1093 Aug 18, 2021
7f071da
Merge branch 'master' into am/middleware
amaury1093 Aug 18, 2021
c5c0247
Fix mock tests
amaury1093 Aug 18, 2021
67a2cd5
Fix antehandlers test
amaury1093 Aug 19, 2021
788d7a0
Merge branch 'master' into am/middleware
alexanderbez Aug 20, 2021
8fee5b9
Address reviews
amaury1093 Aug 23, 2021
43c4de0
Merge branch 'am/middleware' of ssh://github.com/cosmos/cosmos-sdk in…
amaury1093 Aug 23, 2021
00fce8c
More reviews
amaury1093 Aug 23, 2021
e5a076f
Fix tests
amaury1093 Aug 23, 2021
dd70e91
Merge branch 'master' into am/middleware
alexanderbez Aug 23, 2021
61d1013
Switch ComposeMiddlewares order
amaury1093 Aug 24, 2021
74167e9
Fix test
amaury1093 Aug 24, 2021
0bb9c48
Merge branch 'master' into am/middleware
amaury1093 Aug 24, 2021
bcba471
migrate RejectExtensionOptions
amaury1093 Aug 25, 2021
8d763ba
migrate mempool to middleware
atheeshp Aug 25, 2021
2595b27
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Aug 30, 2021
16caed2
remove WithContext
atheeshp Aug 30, 2021
967b3a3
migrate `ValidateBasicDecorator` to middleware
atheeshp Aug 30, 2021
011b793
migrate `TxTimeoutHeightDecorator` to middleware
atheeshp Aug 30, 2021
5b15fd8
migrate `ValidateMemoDecorator` to middleware
atheeshp Aug 30, 2021
6d1f27c
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 1, 2021
ef64904
migrate `ConsumeGasForTxSize` to middleware
atheeshp Sep 1, 2021
3d4ee4a
migrate `DeductFee` ante to middleware
atheeshp Sep 1, 2021
ba7379d
migrate signature ante to middlewares
atheeshp Sep 3, 2021
49f6539
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 7, 2021
a92ba52
fix failing tests
atheeshp Sep 7, 2021
7f1e831
fix tests
atheeshp Sep 7, 2021
a04988d
fix tests
atheeshp Sep 7, 2021
39dab39
migrate ante tests
atheeshp Sep 8, 2021
57a0796
migrate tests
atheeshp Sep 8, 2021
4850b04
migrate tests
atheeshp Sep 8, 2021
a77202a
fix tests
atheeshp Sep 8, 2021
acb784f
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 8, 2021
8ff193a
refactor
atheeshp Sep 8, 2021
4864fd2
fix tests
atheeshp Sep 9, 2021
748501e
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 9, 2021
404be63
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 13, 2021
ae35f45
fix lint
atheeshp Sep 13, 2021
83a1174
split baseapp_test.go
atheeshp Sep 14, 2021
e77f9b1
remove unused
atheeshp Sep 14, 2021
8a25fa7
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 14, 2021
ce31800
update docs
atheeshp Sep 16, 2021
d47dd19
fix error
atheeshp Sep 16, 2021
b0409e7
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 16, 2021
06ca566
update docs
atheeshp Sep 16, 2021
f6b0d66
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 16, 2021
0adee13
reivew suggestions
atheeshp Sep 16, 2021
6aee9bb
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 16, 2021
99e3155
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 16, 2021
9212400
fix tests
atheeshp Sep 17, 2021
0516575
remove alias
atheeshp Sep 17, 2021
bd3a861
fix tests
atheeshp Sep 18, 2021
8d72020
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 18, 2021
4066eef
fix tests
atheeshp Sep 18, 2021
8fc3c06
fix tests
atheeshp Sep 18, 2021
785a697
refactor
atheeshp Sep 18, 2021
adec5ff
refactor
atheeshp Sep 18, 2021
cf680e2
fix tests
atheeshp Sep 20, 2021
c01b79f
Merge branch 'atheesh/refactor-mw' of github.com:cosmos/cosmos-sdk in…
atheeshp Sep 20, 2021
13b9988
refactor
atheeshp Sep 20, 2021
2277aa9
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 20, 2021
d51d294
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 20, 2021
daf658d
fix test
atheeshp Sep 20, 2021
ff12cc3
fix tests
atheeshp Sep 21, 2021
0482ae0
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 21, 2021
e289188
fix msg service router
atheeshp Sep 21, 2021
9d5aead
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 21, 2021
9737db3
refactor msg service router tests
atheeshp Sep 21, 2021
f4a3040
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 22, 2021
0995d4a
fix rosetta
atheeshp Sep 22, 2021
f6c2e53
review changes
atheeshp Sep 22, 2021
24832b4
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 22, 2021
9b2c116
review changes
atheeshp Sep 22, 2021
0cf38e1
Use NewDefaultTxHandler where possible
amaury1093 Sep 23, 2021
7740e97
review changes
atheeshp Sep 23, 2021
9c554cf
Merge branch 'am/ah-to-mw-2' of github.com:cosmos/cosmos-sdk into ath…
atheeshp Sep 23, 2021
2a55b8b
review changes
atheeshp Sep 23, 2021
a3bf0b3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 23, 2021
1ba2327
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 27, 2021
e5a30a5
refactor
atheeshp Sep 28, 2021
174a345
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 28, 2021
2ac74d5
merge middleware_test.go & baseapp_test.go
atheeshp Sep 28, 2021
31633eb
refactor some tests
amaury1093 Sep 28, 2021
04c4e6c
Refactor some more tests
amaury1093 Sep 28, 2021
d9613b0
address review changes
atheeshp Sep 29, 2021
8fd1631
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 29, 2021
3380782
Merge branch 'atheesh/ah-to-mw' of github.com:cosmos/cosmos-sdk into …
atheeshp Sep 29, 2021
bf037a8
revert baseapp_test
atheeshp Sep 29, 2021
c519525
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 29, 2021
736694b
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 30, 2021
03f27a9
address review changes
atheeshp Sep 30, 2021
cebf66f
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Sep 30, 2021
0027087
feat: Add Tips middleware
amaury1093 Sep 21, 2021
ff84618
Add test file
amaury1093 Sep 30, 2021
bb5e25f
add SetTip
amaury1093 Sep 30, 2021
aaa956d
Add test
amaury1093 Sep 30, 2021
2f3e7d5
Add sign modes test
amaury1093 Sep 30, 2021
129408e
Merge branch 'master' into atheesh/ah-to-mw
alexanderbez Sep 30, 2021
f5e1104
address review changes
atheeshp Oct 1, 2021
9e51928
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ah…
atheeshp Oct 1, 2021
8039aef
Merge branch 'atheesh/ah-to-mw' of github.com:cosmos/cosmos-sdk into …
atheeshp Oct 1, 2021
1396896
Fix SignMode middleware
amaury1093 Oct 1, 2021
94fe995
Make tests pass
amaury1093 Oct 1, 2021
b4bb5ae
fix test
amaury1093 Oct 1, 2021
d3833f0
Merge branch 'atheesh/ah-to-mw' of ssh://github.com/cosmos/cosmos-sdk…
amaury1093 Oct 1, 2021
1a5c73e
Fix setup test
amaury1093 Oct 1, 2021
d1ea4c0
Add changelog
amaury1093 Oct 1, 2021
6019244
Rename to tips
amaury1093 Oct 1, 2021
5e95c7e
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/9…
amaury1093 Oct 1, 2021
118c0e6
Factor out reusable function
amaury1093 Oct 4, 2021
1be0a53
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/9…
amaury1093 Oct 4, 2021
15023f4
Add SIGN_MODE_AMINO_AUX
amaury1093 Oct 4, 2021
2058b0c
Add comment
amaury1093 Oct 4, 2021
7734e77
WIP: add tips cli
atheeshp Oct 6, 2021
43f344d
revert tx.go
atheeshp Oct 6, 2021
8860f53
add cli command `tips-to-fee`
atheeshp Oct 7, 2021
3680800
add cli tests
atheeshp Oct 8, 2021
6ec5722
Add IsTipper
amaury1093 Oct 7, 2021
6eb5a10
Use addr in signer data
amaury1093 Oct 7, 2021
72a56cb
Always populate addr in signer data
amaury1093 Oct 7, 2021
c0bd505
fi error messages
amaury1093 Oct 7, 2021
551f5f4
make proto gen
amaury1093 Oct 12, 2021
49987e7
Merge branch 'master' into am/0fee0gas
amaury1093 Oct 12, 2021
76b8dff
fix build
amaury1093 Oct 12, 2021
e285150
Add fields to sign docs and sign mode handler
amaury1093 Oct 12, 2021
910f2da
fix tests
atheeshp Oct 12, 2021
8bff529
fix tests
atheeshp Oct 12, 2021
3f04021
Remove getSequence
amaury1093 Oct 12, 2021
031b987
Merge branch 'am/0fee0gas' of ssh://github.com/cosmos/cosmos-sdk into…
amaury1093 Oct 12, 2021
a33a5cd
Update x/auth/migrations/legacytx/stdtx.go
amaury1093 Oct 12, 2021
a5d11b3
Update x/auth/migrations/legacytx/stdsign.go
amaury1093 Oct 12, 2021
894a7ce
Use addressCodec
amaury1093 Oct 12, 2021
6c66bfb
NewTxConfig with addrCdc
amaury1093 Oct 12, 2021
debee8d
REmove simapp.NewBech32
amaury1093 Oct 12, 2021
674a8cd
revert sign
atheeshp Oct 13, 2021
e3a7c35
Move bech32 stuff to x/auth/address
amaury1093 Oct 13, 2021
dfd1d82
Add changelog
amaury1093 Oct 13, 2021
7092ee8
Move address.Codec to x/auth
amaury1093 Oct 13, 2021
bac6349
Fix test
amaury1093 Oct 13, 2021
b5a18ea
Merge branch 'am/0fee0gas' of ssh://github.com/cosmos/cosmos-sdk into…
amaury1093 Oct 13, 2021
80b0637
Merge branch 'am/amino-tipper' of ssh://github.com/cosmos/cosmos-sdk …
amaury1093 Oct 13, 2021
ab495df
Add tests for tipper and feepayer
amaury1093 Oct 13, 2021
892bff4
Rename tests
amaury1093 Oct 13, 2021
2dd883c
Add more tests
amaury1093 Oct 13, 2021
07ef3e2
Empty tip test
amaury1093 Oct 13, 2021
b7a1fc1
feat: Add Tips middleware
amaury1093 Oct 14, 2021
4a83a3f
Add changelog
amaury1093 Oct 14, 2021
2e8254c
fixed conflicts
atheeshp Oct 18, 2021
34a4a89
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Oct 18, 2021
d5feed5
Revert unwanted files
amaury1093 Oct 18, 2021
0071f3c
Less line diff
amaury1093 Oct 18, 2021
908db03
fix errors
atheeshp Oct 18, 2021
df19e58
fix test
amaury1093 Oct 18, 2021
2e7e75b
fix tests
atheeshp Oct 18, 2021
6c069d5
fix another test
amaury1093 Oct 18, 2021
3a37cfe
fix tests
atheeshp Oct 18, 2021
7216370
Fix test
amaury1093 Oct 18, 2021
8f1367d
Merge branch 'am/amino-tipper' of ssh://github.com/cosmos/cosmos-sdk …
amaury1093 Oct 18, 2021
cb749c2
removed logs
atheeshp Oct 18, 2021
6a59fa4
Merge branch 'am/9912-tips-middleware' of github.com:cosmos/cosmos-sd…
atheeshp Oct 18, 2021
0fa4bc0
Update x/auth/migrations/legacytx/stdtx_test.go
amaury1093 Oct 19, 2021
6058b7d
Fix tests
amaury1093 Oct 19, 2021
a606970
Add more gas
amaury1093 Oct 19, 2021
e3f8d91
Merge branch 'am/amino-tipper' of ssh://github.com/cosmos/cosmos-sdk …
amaury1093 Oct 19, 2021
8e181c4
Merge branch 'am/9912-tips-middleware' of github.com:cosmos/cosmos-sd…
atheeshp Oct 20, 2021
9c0c498
fix test
atheeshp Oct 20, 2021
6722477
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Nov 18, 2021
dbdeaa3
fix conflicts
atheeshp Nov 18, 2021
3468648
remove unecessary imports
atheeshp Nov 18, 2021
c2326db
update cli test
atheeshp Nov 22, 2021
e349121
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Nov 22, 2021
cb2a697
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Nov 25, 2021
be83c1c
add `makeAuxSignerData`
atheeshp Nov 25, 2021
f41b7bb
update settip
atheeshp Nov 25, 2021
21fc0de
update tips.go cli
atheeshp Nov 25, 2021
eaf284c
comment `checkMultipleSigners`
atheeshp Nov 25, 2021
b2c0605
fix tests
atheeshp Nov 26, 2021
790345c
add missing norace build tag
atheeshp Nov 26, 2021
5e9753e
Fix multipler signers
amaury1093 Nov 30, 2021
99ae823
review changes
atheeshp Nov 30, 2021
3d99381
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Nov 30, 2021
b07dcb3
review changes
atheeshp Nov 30, 2021
a8c2f8f
review changes
atheeshp Dec 2, 2021
71355d1
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Dec 2, 2021
dfe8ebf
add tipper flag
atheeshp Dec 2, 2021
96020a2
review changes
atheeshp Dec 2, 2021
0ca4c17
add back `checkMultipleSigners`
atheeshp Dec 2, 2021
87ff1d5
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Dec 3, 2021
7200552
add more tests
atheeshp Dec 3, 2021
7079b08
fix tests
atheeshp Dec 3, 2021
2627bb2
fix tests
atheeshp Dec 3, 2021
05d1be1
remove console
atheeshp Dec 3, 2021
c60adc5
fix test
atheeshp Dec 3, 2021
5557922
fix tests
atheeshp Dec 3, 2021
4aabde0
fix test
atheeshp Dec 3, 2021
9a76456
Update x/auth/client/testutil/suite.go
atheeshp Dec 4, 2021
903f498
fix test
atheeshp Dec 6, 2021
091835a
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Dec 6, 2021
5c05d4d
Merge branch 'master' into atheesh/tips-cli
amaury1093 Dec 6, 2021
c217410
fix test
atheeshp Dec 6, 2021
9e6481a
Merge branch 'atheesh/tips-cli' of github.com:cosmos/cosmos-sdk into …
atheeshp Dec 6, 2021
c6dad76
fix tests
atheeshp Dec 6, 2021
4d611a6
Merge branch 'atheesh/tips-cli' of github.com:cosmos/cosmos-sdk into …
atheeshp Dec 6, 2021
66e8e93
fix test
atheeshp Dec 6, 2021
8d6385e
fix tests
atheeshp Dec 6, 2021
aa9744d
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Dec 7, 2021
0197e81
Merge branch 'atheesh/tips-cli' of github.com:cosmos/cosmos-sdk into …
atheeshp Dec 7, 2021
28e6deb
fix tests
atheeshp Dec 7, 2021
ecaf012
review changes
atheeshp Dec 7, 2021
7747f53
add changelog
atheeshp Dec 7, 2021
771870d
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/ti…
atheeshp Dec 7, 2021
39c20d4
Update CHANGELOG.md
atheeshp Dec 7, 2021
9b3faa9
Merge branch 'master' into atheesh/tips-cli
amaury1093 Dec 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
}
}

if !clientCtx.IsAux || flagSet.Changed(flags.FlagAux) {
isAux, _ := flagSet.GetBool(flags.FlagAux)
clientCtx = clientCtx.WithAux(isAux)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
if isAux {
// If the user didn't explicity set an --output flag, use JSON by
// default.
if clientCtx.OutputFormat == "" || !flagSet.Changed(cli.OutputFlag) {
clientCtx = clientCtx.WithOutputFormat("json")
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}

// If the user didn't explicity set a --sign-mode flag, use
// DIRECT_AUX by default.
if clientCtx.SignModeStr == "" || !flagSet.Changed(flags.FlagSignMode) {
clientCtx = clientCtx.WithSignModeStr(flags.SignModeDirectAux)
}
}
}

return clientCtx, nil
}

Expand Down
9 changes: 9 additions & 0 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type Context struct {
FeePayer sdk.AccAddress
FeeGranter sdk.AccAddress
Viper *viper.Viper

// IsAux is true when the signer is an auxiliary signer (e.g. the tipper).
IsAux bool
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Deprecated (remove).
LegacyAmino *codec.LegacyAmino
Expand Down Expand Up @@ -245,6 +248,12 @@ func (ctx Context) WithViper(prefix string) Context {
return ctx
}

// WithAux returns a copy of the context with an updated IsAux value.
func (ctx Context) WithAux(isAux bool) Context {
ctx.IsAux = isAux
return ctx
}

// PrintString prints the raw string to ctx.Output if it's defined, otherwise to os.Stdout
func (ctx Context) PrintString(str string) error {
return ctx.PrintBytes([]byte(str))
Expand Down
7 changes: 6 additions & 1 deletion client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
SignModeDirect = "direct"
// SignModeLegacyAminoJSON is the value of the --sign-mode flag for SIGN_MODE_LEGACY_AMINO_JSON
SignModeLegacyAminoJSON = "amino-json"
// SignModeDirectAux is the value of the --sign-mode flag for SIGN_MODE_DIRECT_AUX
SignModeDirectAux = "direct-aux"
)

// List of CLI flags
Expand Down Expand Up @@ -73,6 +75,8 @@ const (
FlagFeePayer = "fee-payer"
FlagFeeGranter = "fee-granter"
FlagReverse = "reverse"
FlagTip = "tip"
FlagAux = "aux"

// Tendermint logging flags
FlagLogLevel = "log_level"
Expand Down Expand Up @@ -111,10 +115,11 @@ func AddTxFlagsToCmd(cmd *cobra.Command) {
cmd.Flags().Bool(FlagOffline, false, "Offline mode (does not allow any online functionality)")
cmd.Flags().BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation")
cmd.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test|memory)")
cmd.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json), this is an advanced feature")
cmd.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json|direct-aux), this is an advanced feature")
cmd.Flags().Uint64(FlagTimeoutHeight, 0, "Set a block timeout height to prevent the tx from being committed past a certain height")
cmd.Flags().String(FlagFeePayer, "", "Fee payer pays fees for the transaction instead of deducting from the signer")
cmd.Flags().String(FlagFeeGranter, "", "Fee granter grants fees for the transaction")
cmd.Flags().Bool(FlagAux, false, "Generate aux signer data instead of sending a tx")
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

// --gas can accept integers and "auto"
cmd.Flags().String(FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", GasFlagAuto, DefaultGasLimit))
Expand Down
25 changes: 23 additions & 2 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)

Expand All @@ -29,6 +30,7 @@ type Factory struct {
chainID string
memo string
fees sdk.Coins
tip *tx.Tip
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
gasPrices sdk.DecCoins
signMode signing.SignMode
simulateAndExecute bool
Expand All @@ -44,6 +46,8 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
signMode = signing.SignMode_SIGN_MODE_DIRECT
case flags.SignModeLegacyAminoJSON:
signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON
case flags.SignModeDirectAux:
signMode = signing.SignMode_SIGN_MODE_DIRECT_AUX
}

accNum, _ := flagSet.GetUint64(flags.FlagAccountNumber)
Expand Down Expand Up @@ -73,6 +77,9 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
feesStr, _ := flagSet.GetString(flags.FlagFees)
f = f.WithFees(feesStr)

tipsStr, _ := flagSet.GetString(flags.FlagTip)
f = f.WithTips(tipsStr, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is tipper address being set if it is empty here? Do we need a --tipper CLI flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are handling it here, ref

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually do need a --tipper flag, because the tipper needs to use his address on the target chain. See #10311 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to take it as mandatory flag or optional one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tips are always optional. But if --tip is set, then --tipper must be set too, and vice versa.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the --tipper flag didn't set, should I use the fromAddress? (from address will have different prefix right in this case)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from address will have different prefix

Yes exactly, this won't work in general. I think we need to make --tipper be a user input (if --tip is set too)


gasPricesStr, _ := flagSet.GetString(flags.FlagGasPrices)
f = f.WithGasPrices(gasPricesStr)

Expand Down Expand Up @@ -130,6 +137,20 @@ func (f Factory) WithFees(fees string) Factory {
return f
}

// WithTips returns a copy of the Factory with an updated tip.
func (f Factory) WithTips(tip string, tipper string) Factory {
parsedTips, err := sdk.ParseCoinsNormalized(tip)
if err != nil {
panic(err)
}
Comment on lines +143 to +146
Copy link
Contributor

@amaury1093 amaury1093 Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atheeshp if you can find a way to:

  • move this logic together with the "check tipper not empty" logic
  • not panic in the CLI

then that would be ideal! If not, then it's okay like this too.


f.tip = &tx.Tip{
Tipper: tipper,
Amount: parsedTips,
}
return f
}

// WithGasPrices returns a copy of the Factory with updated gas prices.
func (f Factory) WithGasPrices(gasPrices string) Factory {
parsedGasPrices, err := sdk.ParseDecCoins(gasPrices)
Expand Down Expand Up @@ -254,12 +275,12 @@ func (f Factory) PrintUnsignedTx(clientCtx client.Context, msgs ...sdk.Msg) erro
_, _ = fmt.Fprintf(os.Stderr, "%s\n", GasEstimateResponse{GasEstimate: f.Gas()})
}

tx, err := f.BuildUnsignedTx(msgs...)
unsignedTx, err := f.BuildUnsignedTx(msgs...)
if err != nil {
return err
}

json, err := clientCtx.TxConfig.TxJSONEncoder()(tx.GetTx())
json, err := clientCtx.TxConfig.TxJSONEncoder()(unsignedTx.GetTx())
if err != nil {
return err
}
Expand Down
97 changes: 84 additions & 13 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/input"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
Expand All @@ -24,6 +23,7 @@ import (
// or sign it and broadcast it returning an error upon failure.
func GenerateOrBroadcastTxCLI(clientCtx client.Context, flagSet *pflag.FlagSet, msgs ...sdk.Msg) error {
txf := NewFactoryCLI(clientCtx, flagSet)

return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
}

Expand All @@ -40,6 +40,15 @@ func GenerateOrBroadcastTxWithFactory(clientCtx client.Context, txf Factory, msg
}
}

// If the --aux flag is set, we simply generate and print the AuxSignerData.
if clientCtx.IsAux {
auxSignerData, err := makeAuxSignerData(clientCtx, txf, msgs...)
if err != nil {
return err
}
return clientCtx.PrintProto(&auxSignerData)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}

if clientCtx.GenerateOnly {
return txf.PrintUnsignedTx(clientCtx, msgs...)
}
Expand Down Expand Up @@ -170,14 +179,6 @@ func SignWithPrivKey(
return sigV2, nil
}

func checkMultipleSigners(mode signing.SignMode, tx authsigning.Tx) error {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
if mode == signing.SignMode_SIGN_MODE_DIRECT &&
len(tx.GetSigners()) > 1 {
return sdkerrors.Wrap(sdkerrors.ErrNotSupported, "Signing in DIRECT mode is only supported for transactions with one signer only")
}
return nil
}

// Sign signs a given tx with a named key. The bytes signed over are canconical.
// The resulting signature will be added to the transaction builder overwriting the previous
// ones if overwrite=true (otherwise, the signature will be appended).
Expand All @@ -194,9 +195,6 @@ func Sign(txf Factory, name string, txBuilder client.TxBuilder, overwriteSig boo
// use the SignModeHandler's default mode if unspecified
signMode = txf.txConfig.SignModeHandler().DefaultMode()
}
if err := checkMultipleSigners(signMode, txBuilder.GetTx()); err != nil {
Copy link
Contributor

@i-norden i-norden Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to checkMultipleSigners after adding the signatures with SetSignatures below on line 270? Or is this constraint being enforced elsewhere/is unnecessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkMultipleSigners was added to avoid using the CLI for signing multi-signers Msgs with DIRECT, it's a bad UX: you need a 1st step where all signers choose their SIGN_MODE and put inside AuthInfo, gather all that, and then a 2nd step where all signers sign over that AuthInfo.

So you're probably right, we probably should keep checkMultipleSigners. However it must be modified, because with tips, we want to allow the fee payer to use DIRECT in a multi-signer tx (the other signer being the tipper).

Maybe we can add a check that with multiple signers, only the last signer can be DIRECT. That way we still avoid the multi-DIRECT bad UX, but allow tipping.

return err
}

k, err := txf.keybase.Key(name)
if err != nil {
Expand Down Expand Up @@ -246,14 +244,24 @@ func Sign(txf Factory, name string, txBuilder client.TxBuilder, overwriteSig boo
Data: &sigData,
Sequence: txf.Sequence(),
}

var prevSignatures []signing.SignatureV2
if !overwriteSig {
prevSignatures, err = txBuilder.GetTx().GetSignaturesV2()
if err != nil {
return err
}
}
if err := txBuilder.SetSignatures(sig); err != nil {

// Overwrite or append signer infos.
var sigs []signing.SignatureV2
if overwriteSig {
sigs = []signing.SignatureV2{sig}
} else {
sigs = append(prevSignatures, sig)
}

if err := txBuilder.SetSignatures(sigs...); err != nil {
return err
}

Expand Down Expand Up @@ -295,3 +303,66 @@ type GasEstimateResponse struct {
func (gr GasEstimateResponse) String() string {
return fmt.Sprintf("gas estimate: %d", gr.GasEstimate)
}

func makeAuxSignerData(clientCtx client.Context, f Factory, msgs ...sdk.Msg) (tx.AuxSignerData, error) {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
b := NewAuxTxBuilder()
fromAddress, name, _, err := client.GetFromFields(clientCtx.Keyring, clientCtx.From, false)
if err != nil {
return tx.AuxSignerData{}, err
}
b.SetAddress(fromAddress.String())
if clientCtx.Offline {
b.SetAccountNumber(f.accountNumber)
b.SetSequence(f.sequence)
} else {
accNum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, fromAddress)
if err != nil {
return tx.AuxSignerData{}, err
}
b.SetAccountNumber(accNum)
b.SetSequence(seq)
}

err = b.SetMsgs(msgs...)
if err != nil {
return tx.AuxSignerData{}, err
}

if f.tip != nil {
b.SetTip(&tx.Tip{Amount: f.tip.Amount, Tipper: fromAddress.String()})
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}

err = b.SetSignMode(f.SignMode())
if err != nil {
return tx.AuxSignerData{}, err
}

key, err := clientCtx.Keyring.Key(name)
if err != nil {
return tx.AuxSignerData{}, err
}

pub, err := key.GetPubKey()
if err != nil {
return tx.AuxSignerData{}, err
}

err = b.SetPubKey(pub)
if err != nil {
return tx.AuxSignerData{}, err
}

b.SetChainID(clientCtx.ChainID)
signBz, err := b.GetSignBytes()
if err != nil {
return tx.AuxSignerData{}, err
}

sig, _, err := clientCtx.Keyring.Sign(name, signBz)
if err != nil {
return tx.AuxSignerData{}, err
}
b.SetSignature(sig)

return b.GetAuxSignerData()
}
12 changes: 1 addition & 11 deletions client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ func TestSign(t *testing.T) {
msg2 := banktypes.NewMsgSend(addr2, sdk.AccAddress("to"), nil)
txb, err := txfNoKeybase.BuildUnsignedTx(msg1, msg2)
requireT.NoError(err)
txb2, err := txfNoKeybase.BuildUnsignedTx(msg1, msg2)
requireT.NoError(err)
txbSimple, err := txfNoKeybase.BuildUnsignedTx(msg2)
requireT.NoError(err)

Expand Down Expand Up @@ -208,16 +206,8 @@ func TestSign(t *testing.T) {
txfAmino, txb, from2, false, []cryptotypes.PubKey{pubKey1, pubKey2}, []int{0, 0}},
{"amino: should overwrite a signature",
txfAmino, txb, from2, true, []cryptotypes.PubKey{pubKey2}, []int{1, 0}},

/**** test double sign Direct mode
signing transaction with more than 2 signers should fail in DIRECT mode ****/
{"direct: should fail to append a signature with different mode",
txfDirect, txb, from1, false, []cryptotypes.PubKey{}, nil},
{"direct: should fail to sign multi-signers tx",
txfDirect, txb2, from1, false, []cryptotypes.PubKey{}, nil},
{"direct: should fail to overwrite multi-signers tx",
txfDirect, txb2, from1, true, []cryptotypes.PubKey{}, nil},
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}

var prevSigs []signingtypes.SignatureV2
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion client/tx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type (
SetSignatures(signatures ...signingtypes.SignatureV2) error
SetMemo(memo string)
SetFeeAmount(amount sdk.Coins)
SetFeePayer(feePayer sdk.AccAddress)
SetGasLimit(limit uint64)
SetTip(tip *tx.Tip)
SetTimeoutHeight(height uint64)
SetFeePayer(feePayer sdk.AccAddress)
SetFeeGranter(feeGranter sdk.AccAddress)
AddAuxSignerData(tx.AuxSignerData) error
}
Expand Down
1 change: 1 addition & 0 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func txCommand() *cobra.Command {
authcmd.GetBroadcastCommand(),
authcmd.GetEncodeCommand(),
authcmd.GetDecodeCommand(),
authcmd.GetAuxToFeeCommand(),
)

simapp.ModuleBasics.AddTxCommands(cmd)
Expand Down
Loading