From 6dbbb72f4ea1c18aaaca386028fabc767f41ad5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Thu, 18 Jan 2024 19:37:10 +0200 Subject: [PATCH] chore: add `sign_multiple_transfers` example (3x) --- Cargo.toml | 4 +++ README.md | 6 +++++ examples/blind_sign_transaction.rs | 2 +- .../sign_transaction/multiple_transfers.rs | 26 +++++++++++++++++++ examples/sign_transaction/transfer.rs | 2 +- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 examples/sign_transaction/multiple_transfers.rs diff --git a/Cargo.toml b/Cargo.toml index 513da99..ed1c0b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,10 @@ name = "get_public_key" name = "sign_transfer" path = "examples/sign_transaction/transfer.rs" +[[example]] +name = "sign_multiple_transfers" +path = "examples/sign_transaction/multiple_transfers.rs" + [[example]] name = "blind_sign_transaction" diff --git a/README.md b/README.md index 58ab612..2622717 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,12 @@ RUST_LOG=get_public_key,near_ledger=info cargo run --example get_public_key RUST_LOG=sign_transfer,near_ledger=info cargo run --example sign_transfer ``` +#### Multiple transfers + +```bash +RUST_LOG=sign_multiple_transfers,near_ledger=info cargo run --example sign_multiple_transfers +``` + ### Blind sign a transaction ```bash diff --git a/examples/blind_sign_transaction.rs b/examples/blind_sign_transaction.rs index ad9b42e..8027894 100644 --- a/examples/blind_sign_transaction.rs +++ b/examples/blind_sign_transaction.rs @@ -16,7 +16,7 @@ fn long_tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transac .map(|_el| { near_primitives::transaction::Action::Transfer( near_primitives::transaction::TransferAction { - deposit: 150000000000000000000000 * _el as u128, + deposit: 150000000000000000000000 * _el as u128, // 0.15 NEAR }, ) }) diff --git a/examples/sign_transaction/multiple_transfers.rs b/examples/sign_transaction/multiple_transfers.rs new file mode 100644 index 0000000..6e367b9 --- /dev/null +++ b/examples/sign_transaction/multiple_transfers.rs @@ -0,0 +1,26 @@ +use near_ledger::NEARLedgerError; + + +#[path = "../common/lib.rs"] +mod common; + +fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction::Transaction { + let mut tx = common::tx_template(ledger_pub_key); + + const SIZE: usize = 3; + let transfers = (0..SIZE) + .map(|_el| { + near_primitives::transaction::Action::Transfer( + near_primitives::transaction::TransferAction { + deposit: 150000000000000000000000 * _el as u128, // 0.15 NEAR + }, + ) + }) + .collect::>(); + tx.actions = transfers; + tx +} + +fn main() -> Result<(), NEARLedgerError> { + common::get_key_sign_and_verify_flow(tx) +} diff --git a/examples/sign_transaction/transfer.rs b/examples/sign_transaction/transfer.rs index 5e115a5..62b4a2b 100644 --- a/examples/sign_transaction/transfer.rs +++ b/examples/sign_transaction/transfer.rs @@ -8,7 +8,7 @@ fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction: let mut tx = common::tx_template(ledger_pub_key); tx.actions = vec![near_primitives::transaction::Action::Transfer( near_primitives::transaction::TransferAction { - deposit: 150000000000000000000000, + deposit: 150000000000000000000000, // 0.15 NEAR }, )]; tx