Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
fix: Fix validate tx nonce bug (#15)
Browse files Browse the repository at this point in the history
* fix: Fix validate tx nonce bug

* refactor: Refactor if/else
  • Loading branch information
code0xff authored Oct 3, 2023
1 parent 4b6a712 commit a82d1ed
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions frame/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ impl<T: Config> Pallet<T> {
let (who, _) = Self::account(&origin);
if tx.auth_info.signer_infos[0].sequence < who.sequence {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Stale))
}
if tx.auth_info.signer_infos[0].sequence > who.sequence {
} else if tx.auth_info.signer_infos[0].sequence > who.sequence {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Future))
}

Expand All @@ -272,10 +271,11 @@ impl<T: Config> Pallet<T> {
// Controls that must be performed by the pool.
fn validate_transaction_in_pool(origin: H160, tx: &hp_cosmos::Tx) -> TransactionValidity {
let (who, _) = Self::account(&origin);
if who.sequence < tx.auth_info.signer_infos[0].sequence {
let transaction_nonce = tx.auth_info.signer_infos[0].sequence;

if transaction_nonce < who.sequence {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Stale))
}
if who.sequence > tx.auth_info.signer_infos[0].sequence {
} else if transaction_nonce > who.sequence {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Future))
}
let mut total_payment = 0u128;
Expand All @@ -289,7 +289,6 @@ impl<T: Config> Pallet<T> {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Payment))
}

let transaction_nonce = tx.auth_info.signer_infos[0].sequence;
let mut builder =
ValidTransactionBuilder::default().and_provides((origin, transaction_nonce));

Expand Down

0 comments on commit a82d1ed

Please sign in to comment.