From 84ab6657f31e8dd733cc28f8b99867f3acd42467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Fri, 19 Jan 2024 23:29:55 +0200 Subject: [PATCH] chore: add `sign_delete_account` `short/long` examples --- Cargo.toml | 9 ++++++++ README.md | 12 +++++++++++ .../sign_transaction/delete_account_long.rs | 20 ++++++++++++++++++ .../sign_transaction/delete_account_short.rs | 21 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 examples/sign_transaction/delete_account_long.rs create mode 100644 examples/sign_transaction/delete_account_short.rs diff --git a/Cargo.toml b/Cargo.toml index 5e654fc..adbe8f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,14 @@ path = "examples/sign_transaction/multiple_transfers.rs" name = "sign_create_account" path = "examples/sign_transaction/create_account.rs" +[[example]] +name = "sign_delete_account_short" +path = "examples/sign_transaction/delete_account_short.rs" + +[[example]] +name = "sign_delete_account_long" +path = "examples/sign_transaction/delete_account_long.rs" + [[example]] name = "blind_sign_transaction" @@ -52,3 +60,4 @@ near-primitives-core = "0.20.0" env_logger = "0.10.0" near-crypto = "0.20.0" near-primitives = "0.20.0" +near-account-id = { version = "1.0.0", features = ["internal_unstable"]} diff --git a/README.md b/README.md index 0272eaf..43f7c4a 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,18 @@ RUST_LOG=get_wallet_id,near_ledger=info cargo run --example get_wallet_id RUST_LOG=sign_create_account,near_ledger=info cargo run --example sign_create_account ``` +#### Delete account (short) + +```bash +RUST_LOG=sign_delete_account_short,near_ledger=info cargo run --example sign_delete_account_short +``` + +#### Delete account (long) + +```bash +RUST_LOG=sign_delete_account_long,near_ledger=info cargo run --example sign_delete_account_long +``` + #### Transfer ```bash diff --git a/examples/sign_transaction/delete_account_long.rs b/examples/sign_transaction/delete_account_long.rs new file mode 100644 index 0000000..b6a2a35 --- /dev/null +++ b/examples/sign_transaction/delete_account_long.rs @@ -0,0 +1,20 @@ +use near_account_id::AccountId; +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); + tx.actions = vec![near_primitives::transaction::Action::DeleteAccount( + near_primitives::transaction::DeleteAccountAction { + beneficiary_id: AccountId::new_unvalidated( + "dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c1b11b3b31673033936ad07bddc01f9da27d974811e480fb197c799e23480a489".to_string()), + }, + )]; + tx +} + +fn main() -> Result<(), NEARLedgerError> { + common::get_key_sign_and_verify_flow(tx) +} diff --git a/examples/sign_transaction/delete_account_short.rs b/examples/sign_transaction/delete_account_short.rs new file mode 100644 index 0000000..bcd3203 --- /dev/null +++ b/examples/sign_transaction/delete_account_short.rs @@ -0,0 +1,21 @@ +use std::str::FromStr; + +use near_account_id::AccountId; +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); + tx.actions = vec![near_primitives::transaction::Action::DeleteAccount( + near_primitives::transaction::DeleteAccountAction { + beneficiary_id: AccountId::from_str("bob.near").unwrap(), + }, + )]; + tx +} + +fn main() -> Result<(), NEARLedgerError> { + common::get_key_sign_and_verify_flow(tx) +}