Skip to content

Commit

Permalink
chore: add sign_multiple_transfers example (3x)
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 18, 2024
1 parent 3d1f579 commit 6dbbb72
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/blind_sign_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
})
Expand Down
26 changes: 26 additions & 0 deletions examples/sign_transaction/multiple_transfers.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>();
tx.actions = transfers;
tx
}

fn main() -> Result<(), NEARLedgerError> {
common::get_key_sign_and_verify_flow(tx)
}
2 changes: 1 addition & 1 deletion examples/sign_transaction/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6dbbb72

Please sign in to comment.