Skip to content

Commit 73a2a4c

Browse files
committed
Updated examples
1 parent 0f3a639 commit 73a2a4c

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

examples/htlc.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,39 @@ fn main() {
2727
let htlc_policy = Concrete::<bitcoin::PublicKey>::from_str(&format!("or(10@and(sha256({secret_hash}),pk({redeem_identity})),1@and(older({expiry}),pk({refund_identity})))",
2828
secret_hash = "1111111111111111111111111111111111111111111111111111111111111111",
2929
redeem_identity = "022222222222222222222222222222222222222222222222222222222222222222",
30-
refund_identity = "022222222222222222222222222222222222222222222222222222222222222222",
30+
refund_identity = "020202020202020202020202020202020202020202020202020202020202020202",
3131
expiry = "4444"
3232
)).unwrap();
3333

3434
let htlc_descriptor = Descriptor::Wsh(htlc_policy.compile().unwrap());
3535

36+
// Check whether the descriptor is safe
37+
// This checks whether all spend paths are accessible in bitcoin network.
38+
// It maybe possible that some of the spend require more than 100 elements in Wsh scripts
39+
// Or they contain a combination of timelock and heightlock.
40+
assert!(htlc_descriptor.check_safety().is_ok());
3641
assert_eq!(
3742
format!("{}", htlc_descriptor),
38-
"wsh(andor(pk(022222222222222222222222222222222222222222222222222222222222222222),sha256(1111111111111111111111111111111111111111111111111111111111111111),and_v(v:pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),older(4444))))"
43+
"wsh(andor(pk(022222222222222222222222222222222222222222222222222222222222222222),sha256(1111111111111111111111111111111111111111111111111111111111111111),and_v(v:pkh(51814f108670aced2d77c1805ddd6634bc9d4731),older(4444))))"
3944
);
4045

4146
assert_eq!(
4247
format!("{}", htlc_descriptor.lift().unwrap()),
43-
"or(and(pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),older(4444)),sha256(1111111111111111111111111111111111111111111111111111111111111111))"
48+
"or(and(pkh(4377a5acd66dc5cb67148a24818d1e51fa183bd2),pkh(51814f108670aced2d77c1805ddd6634bc9d4731),older(4444)),sha256(1111111111111111111111111111111111111111111111111111111111111111))"
4449
);
4550

4651
assert_eq!(
4752
format!("{:x}", htlc_descriptor.script_pubkey()),
48-
"00203c0a59874cb570ff3093bcd67e846c967127c9e3fcd30f0a20857b504599e50a"
53+
"0020d853877af928a8d2a569c9c0ed14bd16f6a80ce9cccaf8a6150fd8f7f8867ae2"
4954
);
5055

5156
assert_eq!(
5257
format!("{:x}", htlc_descriptor.witness_script()),
53-
"21022222222222222222222222222222222222222222222222222222222222222222ac6476a9144377a5acd66dc5cb67148a24818d1e51fa183bd288ad025c11b26782012088a82011111111111111111111111111111111111111111111111111111111111111118768"
58+
"21022222222222222222222222222222222222222222222222222222222222222222ac6476a91451814f108670aced2d77c1805ddd6634bc9d473188ad025c11b26782012088a82011111111111111111111111111111111111111111111111111111111111111118768"
5459
);
5560

5661
assert_eq!(
5762
format!("{}", htlc_descriptor.address(Network::Bitcoin).unwrap()),
58-
"bc1q8s99np6vk4c07vynhnt8aprvjecj0j0rlnfs7z3qs4a4q3veu59q8x3k8x"
63+
"bc1qmpfcw7he9z5d9ftfe8qw699azmm2sr8fen903fs4plv007yx0t3qxfmqv5"
5964
);
6065
}

examples/parse.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ fn main() {
2525
)
2626
.unwrap();
2727

28+
// Check whether the descriptor is safe
29+
// This checks whether all spend paths are accessible in bitcoin network.
30+
// It maybe possible that some of the spend require more than 100 elements in Wsh scripts
31+
// Or they contain a combination of timelock and heightlock.
32+
assert!(my_descriptor.check_safety().is_ok());
2833
assert_eq!(
2934
format!("{:x}", my_descriptor.script_pubkey()),
3035
"0020daef16dd7c946a3e735a6e43310cb2ce33dfd14a04f76bf8241a16654cb2f0f9"

src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,21 @@
6464
//! >::from_str("\
6565
//! sh(wsh(or_d(\
6666
//! c:pk_k(020e0338c96a8870479f2396c373cc7696ba124e8635d41b0ea581112b67817261),\
67-
//! c:pk_k(020e0338c96a8870479f2396c373cc7696ba124e8635d41b0ea581112b67817261)\
67+
//! c:pk_k(0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352)\
6868
//! )))\
6969
//! ").unwrap();
7070
//!
7171
//! // Derive the P2SH address
7272
//! assert_eq!(
7373
//! desc.address(bitcoin::Network::Bitcoin).unwrap().to_string(),
74-
//! "32aAVauGwencZwisuvd3anhhhQhNZQPyHv"
74+
//! "3CJxbQBfWAe1ZkKiGQNEYrioV73ZwvBWns"
7575
//! );
76+
//!
77+
//! // Check whether the descriptor is safe
78+
//! // This checks whether all spend paths are accessible in bitcoin network.
79+
//! // It maybe possible that some of the spend require more than 100 elements in Wsh scripts
80+
//! // Or they contain a combination of timelock and heightlock.
81+
//! assert!(desc.check_safety().is_ok());
7682
//!
7783
//! // Estimate the satisfaction cost
7884
//! assert_eq!(desc.max_satisfaction_weight().unwrap(), 293);

0 commit comments

Comments
 (0)