From ac238f03bf96f6937793c1da5b6421b41e897836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Tue, 30 Jan 2024 16:03:15 +0200 Subject: [PATCH] chore: add `sign_functioncall_str` example --- Cargo.toml | 3 ++ README.md | 6 ++++ examples/sign_transaction/functioncall_str.rs | 28 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 examples/sign_transaction/functioncall_str.rs diff --git a/Cargo.toml b/Cargo.toml index 0aec5f1..47f70be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,9 @@ path = "examples/sign_transaction/add_key_functioncall.rs" name = "sign_deploy_contract" path = "examples/sign_transaction/deploy_contract.rs" +[[example]] +name = "sign_functioncall_str" +path = "examples/sign_transaction/functioncall_str.rs" [[example]] name = "blind_sign_transaction" diff --git a/README.md b/README.md index 075435f..3539fba 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,12 @@ RUST_LOG=sign_add_key_functioncall,near_ledger=info cargo run --example sign_add RUST_LOG=sign_deploy_contract,near_ledger=info cargo run --example sign_deploy_contract ``` +#### Function call (string arg) + +```bash +RUST_LOG=sign_functioncall_str,near_ledger=info cargo run --example sign_functioncall_str +``` + #### Transfer ```bash diff --git a/examples/sign_transaction/functioncall_str.rs b/examples/sign_transaction/functioncall_str.rs new file mode 100644 index 0000000..ada585d --- /dev/null +++ b/examples/sign_transaction/functioncall_str.rs @@ -0,0 +1,28 @@ +use near_ledger::NEARLedgerError; +use near_primitives::transaction::FunctionCallAction; + +#[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.clone()); + + let args = r#"{"previous_vesting_schedule_with_salt":{"vesting_schedule":{"start_timestamp":"1577919600000000000","cliff_timestamp":"1609455600000000000","end_timestamp":"1704150000000000000"},"salt":"7bc709c22801118b743fae3866edb4dea1630a97ab9cd67e993428b94a0f397a"}, "vesting_schedule_with_salt":{"vesting_schedule":{"start_timestamp":"1577919600000000000","cliff_timestamp":"1609455600000000000","end_timestamp":"1704150000000000000"},"salt":"7bc709c22801118b743fae3866edb4dea1630a97ab9cd67e993428b94a0f397a"}}"#; + + let f_call = FunctionCallAction { + method_name: "saturating_add_signed".to_string(), + args: args.as_bytes().to_vec(), + gas: 127127122121, + deposit: 150000000000000000000000, // 0.15 NEAR, + }; + + tx.actions = vec![near_primitives::transaction::Action::FunctionCall( + Box::new(f_call), + )]; + tx +} + +fn main() -> Result<(), NEARLedgerError> { + common::get_key_sign_and_verify_flow(tx)?; + Ok(()) +}