Skip to content

Commit

Permalink
chore: correct sign_delegate example
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Feb 1, 2024
1 parent 69cf1e4 commit 3e0e44e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions examples/sign_transaction/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,39 @@ use near_primitives::{
action::delegate::{DelegateAction, SignedDelegateAction},
signable_message::{SignableMessage, SignableMessageType},
};
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 sender_id = AccountId::from_str("bob.near").unwrap();

let transaction_public_key = near_crypto::PublicKey::ED25519(
near_crypto::ED25519PublicKey::from(ledger_pub_key.to_bytes()),
);
let block_hash = "Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E"
.parse::<CryptoHash>()
.unwrap();

let signer_account_str = hex::encode(&ledger_pub_key.to_bytes());

let mut tx = near_primitives::transaction::Transaction {
public_key: transaction_public_key,
block_hash,
nonce: 103595482000005,
signer_id: AccountId::from_str(&signer_account_str).unwrap(),
receiver_id: sender_id.clone(),
actions: vec![],
};

let sk = SecretKey::from_seed(
near_crypto::KeyType::ED25519,
&format!("{:?}", ledger_pub_key),
);

let sender_id = AccountId::from_str("bob.near").unwrap();
let signer = InMemorySigner::from_secret_key(sender_id.clone(), sk.clone());
let public_key = sk.public_key();
let delegate_public_key = sk.public_key();

const SIZE: usize = 3;
let transfers = (0..SIZE)
Expand All @@ -41,7 +59,7 @@ fn tx(ledger_pub_key: ed25519_dalek::PublicKey) -> near_primitives::transaction:
actions: transfers,
nonce: 127127122121,
max_block_height: 100500,
public_key,
public_key: delegate_public_key,
};
let signable_message =
SignableMessage::new(&delegate_action, SignableMessageType::DelegateAction);
Expand Down

0 comments on commit 3e0e44e

Please sign in to comment.