From 740b45ce7a0746d86b46372b6c50fa636851087a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Mon, 29 Jan 2024 16:14:07 +0200 Subject: [PATCH] chore: add `sign_deploy_contract` example --- Cargo.toml | 5 +++++ README.md | 6 +++++ examples/sign_transaction/deploy_contract.rs | 23 ++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 examples/sign_transaction/deploy_contract.rs diff --git a/Cargo.toml b/Cargo.toml index 6f8b4f3..0aec5f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,11 @@ path = "examples/sign_transaction/add_key_fullaccess.rs" name = "sign_add_key_functioncall" path = "examples/sign_transaction/add_key_functioncall.rs" +[[example]] +name = "sign_deploy_contract" +path = "examples/sign_transaction/deploy_contract.rs" + + [[example]] name = "blind_sign_transaction" diff --git a/README.md b/README.md index 171bc85..075435f 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,12 @@ RUST_LOG=sign_add_key_fullaccess,near_ledger=info cargo run --example sign_add_k RUST_LOG=sign_add_key_functioncall,near_ledger=info cargo run --example sign_add_key_functioncall ``` +#### Deploy contract + +```bash +RUST_LOG=sign_deploy_contract,near_ledger=info cargo run --example sign_deploy_contract +``` + #### Transfer ```bash diff --git a/examples/sign_transaction/deploy_contract.rs b/examples/sign_transaction/deploy_contract.rs new file mode 100644 index 0000000..bb6e7a4 --- /dev/null +++ b/examples/sign_transaction/deploy_contract.rs @@ -0,0 +1,23 @@ +use near_ledger::NEARLedgerError; +use near_primitives::transaction::DeployContractAction; +use near_primitives_core::hash::CryptoHash; + +#[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); + + let code = core::iter::repeat(42u8).take(300).collect::>(); + + let code_hash = CryptoHash::hash_bytes(&code); + println!("Contract code hash: {:?}", code_hash); + tx.actions = vec![near_primitives::transaction::Action::DeployContract( + DeployContractAction { code }, + )]; + tx +} + +fn main() -> Result<(), NEARLedgerError> { + common::get_key_sign_and_verify_flow(tx) +}