Skip to content

Commit

Permalink
Merge pull request #4 from Near-One/telezhnaya/nonce
Browse files Browse the repository at this point in the history
Update libraries, fix issue with nonce
  • Loading branch information
telezhnaya authored Oct 14, 2024
2 parents b60f86f + 1f67d68 commit 70152fc
Show file tree
Hide file tree
Showing 10 changed files with 818 additions and 2,991 deletions.
3,734 changes: 780 additions & 2,954 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ prometheus-client = "0.22.2"
regex = "1.10.4"
serde_json = "1.0.115"
strum = { version = "0.26.2", features = ["derive"] }
strum_macros = "0.26.4"
thiserror = "1.0.58"
tokio = { version = "1.37.0", features = ["rt-multi-thread", "tokio-macros", "parking_lot", "signal", "process"] }
tower-http = { version = "0.5.2", features = ["timeout"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

near-crypto = "0.21.2"
near-jsonrpc-client = "0.9.0"
near-jsonrpc-primitives = "0.21.2"
near-primitives = "0.21.2"
strum_macros = "0.26.2"
near-crypto = "0.26.0"
near-jsonrpc-client = "0.13.0"
near-jsonrpc-primitives = "0.26.0"
near-primitives = "0.26.0"

[dev-dependencies]
more-asserts = "0.3.1"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.77.0 as builder
FROM rust:1.81.0 as builder
RUN apt-get update && apt-get install -y curl libudev-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app
COPY . .
Expand Down
7 changes: 4 additions & 3 deletions src/transaction/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ async fn run_account_transactions_once(
opts.signer_id
);

let current_nonce = nonce.saturating_add((tx_number + repeats_number + 1) as u64);
let current_nonce =
nonce.saturating_add((tx_number * opts.repeats_number + repeats_number + 1) as u64);
match tx_sample
.execute(
&rpc_client,
Expand Down Expand Up @@ -255,7 +256,7 @@ mod tests {

fn get_transaction_request(
&self,
_: &InMemorySigner,
_: InMemorySigner,
_: Opts,
_: Nonce,
_: CryptoHash,
Expand Down Expand Up @@ -295,7 +296,7 @@ mod tests {

fn get_transaction_request(
&self,
_: &InMemorySigner,
_: InMemorySigner,
_: Opts,
_: Nonce,
_: CryptoHash,
Expand Down
10 changes: 5 additions & 5 deletions src/transaction/fungible_token_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_crypto::InMemorySigner;
use near_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest;
use near_primitives::action::FunctionCallAction;
use near_primitives::hash::CryptoHash;
use near_primitives::transaction::{Action, Transaction};
use near_primitives::transaction::{Action, Transaction, TransactionV0};
use near_primitives::types::Nonce;

use super::TransactionKind;
Expand All @@ -24,12 +24,12 @@ impl TransactionSample for FungibleTokenTransfer {

fn get_transaction_request(
&self,
signer: &InMemorySigner,
signer: InMemorySigner,
opts: Opts,
nonce: Nonce,
block_hash: CryptoHash,
) -> RpcSendTransactionRequest {
let transaction = Transaction {
let transaction = Transaction::V0(TransactionV0 {
signer_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
nonce: nonce + 1,
Expand All @@ -43,9 +43,9 @@ impl TransactionSample for FungibleTokenTransfer {
gas: 100_000_000_000_000, // 100 TeraGas
deposit: 1,
}))],
};
});
RpcSendTransactionRequest {
signed_transaction: transaction.sign(signer),
signed_transaction: transaction.sign(&signer.into()),
wait_until: Default::default(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait TransactionSample: Send + Sync {

fn get_transaction_request(
&self,
signer: &InMemorySigner,
signer: InMemorySigner,
opts: Opts,
nonce: Nonce,
block_hash: CryptoHash,
Expand All @@ -61,7 +61,7 @@ pub trait TransactionSample: Send + Sync {
let signer =
InMemorySigner::from_secret_key(opts.signer_id.clone(), opts.signer_key.clone());

let request = self.get_transaction_request(&signer, opts, nonce, block_hash);
let request = self.get_transaction_request(signer, opts, nonce, block_hash);

match rpc_client.call(request.clone()).await {
Ok(response) => {
Expand Down Expand Up @@ -90,7 +90,7 @@ pub trait TransactionSample: Send + Sync {
sender_account_id: request
.signed_transaction
.transaction
.signer_id
.signer_id()
.clone(),
},
wait_until: request.wait_until.clone(),
Expand Down
10 changes: 5 additions & 5 deletions src/transaction/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_crypto::InMemorySigner;
use near_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest;
use near_primitives::action::FunctionCallAction;
use near_primitives::hash::CryptoHash;
use near_primitives::transaction::{Action, Transaction};
use near_primitives::transaction::{Action, Transaction, TransactionV0};
use near_primitives::types::Nonce;

use super::TransactionKind;
Expand All @@ -24,13 +24,13 @@ impl TransactionSample for Swap {

fn get_transaction_request(
&self,
signer: &InMemorySigner,
signer: InMemorySigner,
opts: Opts,
nonce: Nonce,
block_hash: CryptoHash,
) -> RpcSendTransactionRequest {
let msg = format!("{{\"actions\":[{{\"pool_id\":{},\"token_in\":\"{}\",\"token_out\":\"{}\",\"amount_in\":\"1000000000000000000000\",\"min_amount_out\":\"1\"}}]}}", opts.pool_id, opts.wrap_near_id, opts.ft_account_id);
let transaction = Transaction {
let transaction = Transaction::V0 (TransactionV0 {
signer_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
nonce: nonce + 1,
Expand All @@ -51,9 +51,9 @@ impl TransactionSample for Swap {
deposit: 1,
})),
],
};
});
RpcSendTransactionRequest {
signed_transaction: transaction.sign(signer),
signed_transaction: transaction.sign(&signer.into()),
wait_until: Default::default(),
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/transaction/token_transfer_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_crypto::InMemorySigner;
use near_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest;
use near_primitives::action::TransferAction;
use near_primitives::hash::CryptoHash;
use near_primitives::transaction::{Action, Transaction};
use near_primitives::transaction::{Action, Transaction, TransactionV0};
use near_primitives::types::Nonce;

use super::TransactionKind;
Expand All @@ -24,21 +24,21 @@ impl TransactionSample for TokenTransferDefault {

fn get_transaction_request(
&self,
signer: &InMemorySigner,
signer: InMemorySigner,
opts: Opts,
nonce: Nonce,
block_hash: CryptoHash,
) -> RpcSendTransactionRequest {
let transaction = Transaction {
let transaction = Transaction::V0(TransactionV0 {
signer_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
nonce: nonce + 1,
receiver_id: opts.receiver_id,
block_hash,
actions: vec![Action::Transfer(TransferAction { deposit: 1 })],
};
});
RpcSendTransactionRequest {
signed_transaction: transaction.sign(signer),
signed_transaction: transaction.sign(&signer.into()),
wait_until: Default::default(),
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/transaction/token_transfer_final.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_crypto::InMemorySigner;
use near_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest;
use near_primitives::action::TransferAction;
use near_primitives::hash::CryptoHash;
use near_primitives::transaction::{Action, Transaction};
use near_primitives::transaction::{Action, Transaction, TransactionV0};
use near_primitives::types::Nonce;
use near_primitives::views::TxExecutionStatus;

Expand All @@ -25,21 +25,21 @@ impl TransactionSample for TokenTransferFinal {

fn get_transaction_request(
&self,
signer: &InMemorySigner,
signer: InMemorySigner,
opts: Opts,
nonce: Nonce,
block_hash: CryptoHash,
) -> RpcSendTransactionRequest {
let transaction = Transaction {
let transaction = Transaction::V0(TransactionV0 {
signer_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
nonce: nonce + 1,
receiver_id: opts.receiver_id,
block_hash,
actions: vec![Action::Transfer(TransferAction { deposit: 1 })],
};
});
RpcSendTransactionRequest {
signed_transaction: transaction.sign(signer),
signed_transaction: transaction.sign(&signer.into()),
wait_until: TxExecutionStatus::Final,
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/transaction/token_transfer_included_final.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use near_crypto::InMemorySigner;
use near_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest;
use near_primitives::action::TransferAction;
use near_primitives::hash::CryptoHash;
use near_primitives::transaction::{Action, Transaction};
use near_primitives::transaction::{Action, Transaction, TransactionV0};
use near_primitives::types::Nonce;
use near_primitives::views::TxExecutionStatus;

Expand All @@ -25,21 +25,21 @@ impl TransactionSample for TokenTransferIncludedFinal {

fn get_transaction_request(
&self,
signer: &InMemorySigner,
signer: InMemorySigner,
opts: Opts,
nonce: Nonce,
block_hash: CryptoHash,
) -> RpcSendTransactionRequest {
let transaction = Transaction {
let transaction = Transaction::V0(TransactionV0 {
signer_id: signer.account_id.clone(),
public_key: signer.public_key.clone(),
nonce: nonce + 1,
receiver_id: opts.receiver_id,
block_hash,
actions: vec![Action::Transfer(TransferAction { deposit: 1 })],
};
});
RpcSendTransactionRequest {
signed_transaction: transaction.sign(signer),
signed_transaction: transaction.sign(&signer.into()),
wait_until: TxExecutionStatus::IncludedFinal,
}
}
Expand Down

0 comments on commit 70152fc

Please sign in to comment.