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 all 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#10208](https://github.com/cosmos/cosmos-sdk/pull/10208) Add `TipsTxMiddleware` for transferring tips.
* [\#10379](https://github.com/cosmos/cosmos-sdk/pull/10379) Add validation to `x/upgrade` CLI `software-upgrade` command `--plan-info` value.
* [\#10561](https://github.com/cosmos/cosmos-sdk/pull/10561) Add configurable IAVL cache size to app.toml
* [\10507](https://github.com/cosmos/cosmos-sdk/pull/10507) Add middleware for tx priority.
* [\#10507](https://github.com/cosmos/cosmos-sdk/pull/10507) Add middleware for tx priority.
* [\#10311](https://github.com/cosmos/cosmos-sdk/pull/10311) Adds cli to use tips transactions. It adds an `--aux` flag to all CLI tx commands to generate the aux signer data (with optional tip), and a new `tx aux-to-fee` subcommand to let the fee payer gather aux signer data and broadcast the tx

### Improvements

Expand Down
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
10 changes: 9 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,9 @@ const (
FlagFeePayer = "fee-payer"
FlagFeeGranter = "fee-granter"
FlagReverse = "reverse"
FlagTip = "tip"
FlagAux = "aux"
FlagTipper = "tipper"

// Tendermint logging flags
FlagLogLevel = "log_level"
Expand Down Expand Up @@ -111,10 +116,13 @@ 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().String(FlagTip, "", "Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux")
cmd.Flags().String(FlagTipper, "", "Tipper will pay for tips for executing the tx on the target chain. This flag is only valid when used with --aux")
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
26 changes: 24 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,10 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
feesStr, _ := flagSet.GetString(flags.FlagFees)
f = f.WithFees(feesStr)

tipsStr, _ := flagSet.GetString(flags.FlagTip)
tipper, _ := flagSet.GetString(flags.FlagTipper)
f = f.WithTips(tipsStr, tipper)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down Expand Up @@ -130,6 +138,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 +276,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
83 changes: 83 additions & 0 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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 +41,16 @@ 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 @@ -335,3 +346,75 @@ type GasEstimateResponse struct {
func (gr GasEstimateResponse) String() string {
return fmt.Sprintf("gas estimate: %d", gr.GasEstimate)
}

// makeAuxSignerData generates an AuxSignerData from the client inputs.
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 {
if f.tip.Tipper == "" {
return tx.AuxSignerData{}, sdkerrors.Wrap(errors.New("tipper flag required"), "tipper")
} else {
atheeshp marked this conversation as resolved.
Show resolved Hide resolved
if _, err := sdk.AccAddressFromBech32(f.tip.Tipper); err != nil {
return tx.AuxSignerData{}, sdkerrors.ErrInvalidAddress.Wrap("tipper must be a bech32 address")
}
b.SetTip(f.tip)
}
}

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()
}
1 change: 1 addition & 0 deletions client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func TestSign(t *testing.T) {
{"direct: should overwrite multi-signers tx with DIRECT sig",
txfDirect, txb2, from1, true, []cryptotypes.PubKey{pubKey1}, nil},
}

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
85 changes: 85 additions & 0 deletions x/auth/client/cli/tips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package cli

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/tx"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
)

func GetAuxToFeeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "aux-to-fee <aux_signed_tx.json>",
Short: "includes the aux signer data in the tx, broadcast the tx, and sends the tip amount to the broadcaster",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

auxSignerData := tx.AuxSignerData{}
err = readAuxSignerData(clientCtx.Codec, &auxSignerData, args[0])
if err != nil {
return err
}

f := clienttx.NewFactoryCLI(clientCtx, cmd.Flags())

txBuilder := clientCtx.TxConfig.NewTxBuilder()
err = txBuilder.AddAuxSignerData(auxSignerData)
if err != nil {
return err
}

txBuilder.SetFeePayer(clientCtx.FromAddress)
txBuilder.SetFeeAmount(f.Fees())
txBuilder.SetGasLimit(f.Gas())

if clientCtx.GenerateOnly {
json, err := clientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx())
if err != nil {
return err
}
return clientCtx.PrintString(fmt.Sprintf("%s\n", json))
}

err = authclient.SignTx(f, clientCtx, clientCtx.FromName, txBuilder, clientCtx.Offline, false)
if err != nil {
return err
}

txBytes, err := clientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
if err != nil {
return err
}

// broadcast to a Tendermint node
res, err := clientCtx.BroadcastTx(txBytes)
if err != nil {
return err
}
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved

return clientCtx.PrintProto(res)
},
}

flags.AddTxFlagsToCmd(cmd)
return cmd
}

func readAuxSignerData(cdc codec.Codec, auxSignerData *tx.AuxSignerData, filename string) error {
bytes, err := os.ReadFile(filename)
if err != nil {
return err
}

return cdc.UnmarshalJSON(bytes, auxSignerData)
}
9 changes: 9 additions & 0 deletions x/auth/client/testutil/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,13 @@ func TxMultiSignBatchExec(clientCtx client.Context, filename string, from string
return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignBatchCmd(), args)
}

// TxAuxToFeeExec executes `GetAuxToFeeCommand` cli command with given args.
func TxAuxToFeeExec(clientCtx client.Context, filename string, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{
filename,
}

return clitestutil.ExecTestCLICmd(clientCtx, cli.GetAuxToFeeCommand(), append(args, extraArgs...))
}

// DONTCOVER
Loading