fix: change the behavior of offline mode correctly (#15123)
## Description Closes: #15109 Change to work only when `FlagAccountNumber` and `FlagSequence` are in offline mode. In other cases, use `AccountRetriever` to populate those values. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
+15
-12
@@ -47,7 +47,7 @@ type Factory struct {
|
||||
}
|
||||
|
||||
// NewFactoryCLI creates a new Factory.
|
||||
func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
|
||||
func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) (Factory, error) {
|
||||
signModeStr := clientCtx.SignModeStr
|
||||
|
||||
signMode := signing.SignMode_SIGN_MODE_UNSPECIFIED
|
||||
@@ -64,8 +64,16 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
|
||||
signMode = signing.SignMode_SIGN_MODE_EIP_191
|
||||
}
|
||||
|
||||
accNum, _ := flagSet.GetUint64(flags.FlagAccountNumber)
|
||||
accSeq, _ := flagSet.GetUint64(flags.FlagSequence)
|
||||
var accNum, accSeq uint64
|
||||
if clientCtx.Offline {
|
||||
if flagSet.Changed(flags.FlagAccountNumber) && flagSet.Changed(flags.FlagSequence) {
|
||||
accNum, _ = flagSet.GetUint64(flags.FlagAccountNumber)
|
||||
accSeq, _ = flagSet.GetUint64(flags.FlagSequence)
|
||||
} else {
|
||||
return Factory{}, errors.New("account-number and sequence must be set in offline mode")
|
||||
}
|
||||
}
|
||||
|
||||
gasAdj, _ := flagSet.GetFloat64(flags.FlagGasAdjustment)
|
||||
memo, _ := flagSet.GetString(flags.FlagNote)
|
||||
timeoutHeight, _ := flagSet.GetUint64(flags.FlagTimeoutHeight)
|
||||
@@ -105,7 +113,7 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
|
||||
|
||||
f = f.WithPreprocessTxHook(clientCtx.PreprocessTxHook)
|
||||
|
||||
return f
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (f Factory) AccountNumber() uint64 { return f.accountNumber }
|
||||
@@ -435,19 +443,14 @@ func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
|
||||
}
|
||||
|
||||
initNum, initSeq := fc.accountNumber, fc.sequence
|
||||
if initNum == 0 || initSeq == 0 {
|
||||
if initNum == 0 && initSeq == 0 {
|
||||
num, seq, err := fc.accountRetriever.GetAccountNumberSequence(clientCtx, from)
|
||||
if err != nil {
|
||||
return fc, err
|
||||
}
|
||||
|
||||
if initNum == 0 {
|
||||
fc = fc.WithAccountNumber(num)
|
||||
}
|
||||
|
||||
if initSeq == 0 {
|
||||
fc = fc.WithSequence(seq)
|
||||
}
|
||||
fc = fc.WithAccountNumber(num)
|
||||
fc = fc.WithSequence(seq)
|
||||
}
|
||||
|
||||
return fc, nil
|
||||
|
||||
+8
-1
@@ -24,7 +24,10 @@ import (
|
||||
// GenerateOrBroadcastTxCLI will either generate and print and unsigned transaction
|
||||
// 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)
|
||||
txf, err := NewFactoryCLI(clientCtx, flagSet)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
|
||||
}
|
||||
@@ -69,6 +72,10 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
|
||||
}
|
||||
|
||||
if txf.SimulateAndExecute() || clientCtx.Simulate {
|
||||
if clientCtx.Offline {
|
||||
return errors.New("cannot estimate gas in offline mode")
|
||||
}
|
||||
|
||||
_, adjusted, err := CalculateGas(clientCtx, txf, msgs...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user