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

fix: fetch account number/sequence when not in offline mode #16075

Merged
merged 10 commits into from
May 10, 2023
Merged
15 changes: 10 additions & 5 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ func (f Factory) getSimPK() (cryptotypes.PubKey, error) {

// Prepare ensures the account defined by ctx.GetFromAddress() exists and
// if the account number and/or the account sequence number are zero (not set),
// they will be queried for and set on the provided Factory. A new Factory with
// the updated fields will be returned.
// they will be queried (when not in offline mode) for and set on the provided Factory.
// A new Factory with the updated fields will be returned.
func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
fc := f
from := clientCtx.GetFromAddress()
Expand All @@ -471,14 +471,19 @@ func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
}
Copy link
Member Author

Choose a reason for hiding this comment

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

From an offline standpoint, I think, we should not even try the above right?
So, if in offline mode, we simply return the factory early? and keep the ||?

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, doing that then.


initNum, initSeq := fc.accountNumber, fc.sequence
if initNum == 0 && initSeq == 0 {
if !clientCtx.Offline && (initNum == 0 || initSeq == 0) {
num, seq, err := fc.accountRetriever.GetAccountNumberSequence(clientCtx, from)
if err != nil {
return fc, err
}

fc = fc.WithAccountNumber(num)
fc = fc.WithSequence(seq)
if initNum == 0 {
Copy link
Member Author

Choose a reason for hiding this comment

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

Partly reverts #15123

fc = fc.WithAccountNumber(num)
}

if initSeq == 0 {
fc = fc.WithSequence(seq)
}
}

return fc, nil
Expand Down