Skip to content

Commit

Permalink
chore: add sign_stake example
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 25, 2024
1 parent 350ed9d commit 9696dbb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ path = "examples/sign_transaction/delete_key_ed25519.rs"
name = "sign_delete_key_secp256k1"
path = "examples/sign_transaction/delete_key_secp256k1.rs"

[[example]]
name = "sign_stake"
path = "examples/sign_transaction/stake.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 @@ -129,6 +129,12 @@ RUST_LOG=sign_delete_key_ed25519,near_ledger=info cargo run --example sign_delet
RUST_LOG=sign_delete_key_secp256k1,near_ledger=info cargo run --example sign_delete_key_secp256k1
```

#### Stake

```bash
RUST_LOG=sign_stake,near_ledger=info cargo run --example sign_stake
```

#### Transfer

```bash
Expand Down
25 changes: 25 additions & 0 deletions examples/sign_transaction/stake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use near_crypto::SecretKey;
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.clone());
let sk = SecretKey::from_seed(
near_crypto::KeyType::SECP256K1,
&format!("{:?}", ledger_pub_key),
);
let public_key = sk.public_key();
tx.actions = vec![near_primitives::transaction::Action::Stake(Box::new(
near_primitives::transaction::StakeAction {
stake: 1157130000000000000000000, // 1.15713 NEAR,
public_key,
},
))];
tx
}

fn main() -> Result<(), NEARLedgerError> {
common::get_key_sign_and_verify_flow(tx)
}

0 comments on commit 9696dbb

Please sign in to comment.