Skip to content

Commit

Permalink
chore: add sign_functioncall_str example
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 30, 2024
1 parent 2fb2028 commit ac238f0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions examples/sign_transaction/functioncall_str.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit ac238f0

Please sign in to comment.