1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crateSingleHashMode;
use crateSingleSpendingCondition;
use crateStacksTransaction;
use crateTransactionSigner;
use crateError;
use crateStacksPrivateKey;
use crateStacksPublicKey;
/// Sign a transaction with a sponsor private key.
///
/// # Arguments
///
/// * `transaction` - The transaction to sign.
/// * `sponsor_private_key` - The private key of the sponsor.
/// * `fee` - The sponsor fee.
/// * `nonce` - The sponsor nonce.
/// * `hash_mode` - The sponsor hash mode.
///
/// # Example
///
/// ```rust
/// use stacks_rs::transaction::STXTokenTransfer;
/// use stacks_rs::transaction::SingleHashMode;
/// use stacks_rs::transaction::AnchorMode;
/// use stacks_rs::transaction::PostConditionMode;
/// use stacks_rs::transaction::sponsor_transaction;
/// use stacks_rs::transaction::PostConditions;
/// use stacks_rs::crypto::hex_to_bytes;
/// use stacks_rs::StacksPrivateKey;
/// use stacks_rs::StacksTestnet;
///
/// let pk_hex = "edf9aee84d9b7abc145504dde6726c64f369d37ee34ded868fabd876c26570bc";
/// let pk_bytes = hex_to_bytes(pk_hex).unwrap();
///
/// let sponsor_hex = "9888d734e6e80a943a6544159e31d6c7e342f695ec867d549c569fa0028892d4";
/// let sponsor_pk_bytes = hex_to_bytes(pk_hex).unwrap();
/// let sponsor_key = StacksPrivateKey::from_slice(&sponsor_pk_bytes).unwrap();
///
/// let tx = STXTokenTransfer::new(
/// "ST2G0KVR849MZHJ6YB4DCN8K5TRDVXF92A664PHXT",
/// StacksPrivateKey::from_slice(&pk_bytes).unwrap(),
/// 1337,
/// 0,
/// 0,
/// StacksTestnet::new(),
/// AnchorMode::Any,
/// "test memo",
/// PostConditionMode::Deny,
/// PostConditions::empty(),
/// true,
/// );
///
/// let mut signed_tx = tx.sign().unwrap();
///
/// sponsor_transaction(
/// &mut signed_tx,
/// sponsor_key,
/// 1000,
/// 0,
/// SingleHashMode::P2PKH,
/// ).unwrap();
/// ```