Skip to content

Commit

Permalink
Add tx nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Aug 30, 2024
1 parent a3bde1f commit 034132c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rollup/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod tests {

// Add a transaction to the sequencer.
let transaction = SignedTransaction::new(
Transaction::dynamic(sequencer.signer.address, 100),
Transaction::dynamic(sequencer.signer.address, 100, 1),
&sequencer.signer,
);
sequencer.add_transaction(transaction.clone());
Expand Down
14 changes: 9 additions & 5 deletions rollup/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct TransactionHeader {
recipient: Address,
/// The amount of value transferred by the transaction.
amount: u64,
/// The nonce of the transaction.
nonce: u64,
}

/// A dynamic transaction containing a transaction header and dynamic fee data.
Expand Down Expand Up @@ -65,26 +67,28 @@ pub enum Transaction {

impl Transaction {
/// Creates a new dynamic transaction.
pub fn dynamic(sender: Address, amount: u64) -> Self {
pub fn dynamic(sender: Address, amount: u64, nonce: u64) -> Self {
Transaction::Dynamic(DynamicTxData {
header: TransactionHeader {
chain_id: CHAIN_ID,
sender,
recipient: Address::random(),
amount,
recipient: Address::random(),
nonce,
},
max_fee_per_gas: 0,
max_priority_fee_per_gas: 0,
})
}

/// Creates a new withdrawal transaction.
pub fn withdrawal(sender: Address, amount: u64, dest_chain: u64) -> Self {
pub fn withdrawal(sender: Address, amount: u64, nonce: u64, dest_chain: u64) -> Self {
Transaction::Withdrawal(WithdrawalTxData {
header: TransactionHeader {
chain_id: CHAIN_ID,
sender,
recipient: sender,
nonce,
amount,
},
dest_chain,
Expand Down Expand Up @@ -146,12 +150,12 @@ mod tests {
fn test_transaction() {
// Create a dynamic transaction and verify.
let signer = Signer::random();
let tx = Transaction::dynamic(signer.address, 100);
let tx = Transaction::dynamic(signer.address, 100, 1);
let tx = SignedTransaction::new(tx.clone(), &signer);
assert!(tx.verify());

// Create a withdrawal transaction and verify.
let tx = Transaction::withdrawal(signer.address, 100, 1);
let tx = Transaction::withdrawal(signer.address, 100, 1, 2);
let tx = SignedTransaction::new(tx.clone(), &signer);
assert!(tx.verify());
}
Expand Down
4 changes: 2 additions & 2 deletions script/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn tx_loop() {
for i in 0.. {
// Send a deposit transaction.
let signer = Signer::random();
let transaction = Transaction::dynamic(signer.address, i);
let transaction = Transaction::dynamic(signer.address, i, i);
let signed = SignedTransaction::new(transaction, &signer);
if let Err(e) = send_transaction(signed).await {
handle_request_err(e).await;
Expand All @@ -57,7 +57,7 @@ async fn tx_loop() {

// Send a withdrawal transaction.
let dest_chain = 1u64;
let transaction = Transaction::withdrawal(signer.address, i, dest_chain);
let transaction = Transaction::withdrawal(signer.address, i, dest_chain, i);
let signed = SignedTransaction::new(transaction, &signer);
if let Err(e) = send_transaction(signed).await {
handle_request_err(e).await;
Expand Down

0 comments on commit 034132c

Please sign in to comment.