Skip to content

Commit a807ea4

Browse files
committed
Merge #560: cleanup examples
288a6f1 examples: taproot: Use turbofish syntax (Tobin C. Harding) d981a95 examples: taproot: Do minor docs cleanup (Tobin C. Harding) b1ce6cd examples: Clean up import statements (Tobin C. Harding) 93ef502 examples: Remove base64 dev dependency (Tobin C. Harding) e83c09c Move bip-174 test out of examples and into tests (Tobin C. Harding) a836bcb examples: Use SPDX licence identifiers (Tobin C. Harding) a797fcc examples: htlc: Fix doc typos (Tobin C. Harding) Pull request description: Nothing too crazy here, just a few cleanups to the `examples` directory. Note though that commit `122be5d Move bip-174 test out of examples and into tests` moves a file out of `examples` and into a new `tests` directory. ACKs for top commit: sanket1729: ACK 288a6f1 apoelstra: ACK 288a6f1 Tree-SHA512: 736011c63ab6d929f9a76c1ebead1afdd5fbc9b3325844acde1dda980170e0b0dd1eb8c26dc7dcae9409e6ebdef10b43efcf8d322f04b77851e3910027f3e96e
2 parents 1f7f575 + 288a6f1 commit a807ea4

File tree

10 files changed

+36
-96
lines changed

10 files changed

+36
-96
lines changed

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ actual-serde = { package = "serde", version = "1.0.103", optional = true }
3434
serde_test = "1.0.147"
3535
bitcoin = { version = "0.30.0", features = ["base64"] }
3636
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
37-
actual-base64 = { package = "base64", version = "0.13.0" }
3837

3938
[[example]]
4039
name = "htlc"
@@ -52,10 +51,6 @@ required-features = ["std"]
5251
name = "verify_tx"
5352
required-features = ["std"]
5453

55-
[[example]]
56-
name = "psbt"
57-
required-features = ["std"]
58-
5954
[[example]]
6055
name = "xpub_descriptors"
6156
required-features = ["std"]

contrib/test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ then
5858
cargo run --example parse
5959
cargo run --example sign_multisig
6060
cargo run --example verify_tx > /dev/null
61-
cargo run --example psbt
6261
cargo run --example xpub_descriptors
6362
cargo run --example taproot --features=compiler
6463
cargo run --example psbt_sign_finalize --features=base64

examples/htlc.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
// Miniscript
2-
// Written in 2019 by
3-
// Thomas Eizinger <[email protected]>
4-
//
5-
// To the extent possible under law, the author(s) have dedicated all
6-
// copyright and related and neighboring rights to this software to
7-
// the public domain worldwide. This software is distributed without
8-
// any warranty.
9-
//
10-
// You should have received a copy of the CC0 Public Domain Dedication
11-
// along with this software.
12-
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13-
//
1+
// Written by Thomas Eizinger <[email protected]>
2+
// SPDX-License-Identifier: CC0-1.0
143

154
//! Example: Create an HTLC with miniscript using the policy compiler
165
176
use std::str::FromStr;
187

19-
use bitcoin::Network;
8+
use miniscript::bitcoin::Network;
209
use miniscript::descriptor::Wsh;
2110
use miniscript::policy::{Concrete, Liftable};
2211

@@ -51,7 +40,7 @@ fn main() {
5140
"or(and(pk(022222222222222222222222222222222222222222222222222222222222222222),sha256(1111111111111111111111111111111111111111111111111111111111111111)),and(pk(020202020202020202020202020202020202020202020202020202020202020202),older(4444)))"
5241
);
5342

54-
// Get the scriptPpubkey for this Wsh descriptor.
43+
// Get the scriptPubkey for this Wsh descriptor.
5544
assert_eq!(
5645
format!("{:x}", htlc_descriptor.script_pubkey()),
5746
"0020d853877af928a8d2a569c9c0ed14bd16f6a80ce9cccaf8a6150fd8f7f8867ae2"
@@ -63,7 +52,7 @@ fn main() {
6352
"21022222222222222222222222222222222222222222222222222222222222222222ac6476a91451814f108670aced2d77c1805ddd6634bc9d473188ad025c11b26782012088a82011111111111111111111111111111111111111111111111111111111111111118768"
6453
);
6554

66-
// Get the address for this Wsh descriptor.v
55+
// Get the address for this Wsh descriptor.
6756
assert_eq!(
6857
format!("{}", htlc_descriptor.address(Network::Bitcoin)),
6958
"bc1qmpfcw7he9z5d9ftfe8qw699azmm2sr8fen903fs4plv007yx0t3qxfmqv5"

examples/parse.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
// Miniscript
2-
// Written in 2019 by
3-
// Andrew Poelstra <[email protected]>
4-
//
5-
// To the extent possible under law, the author(s) have dedicated all
6-
// copyright and related and neighboring rights to this software to
7-
// the public domain worldwide. This software is distributed without
8-
// any warranty.
9-
//
10-
// You should have received a copy of the CC0 Public Domain Dedication
11-
// along with this software.
12-
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13-
//
1+
// SPDX-License-Identifier: CC0-1.0
142

153
//! Example: Parsing a descriptor from a string.
164

examples/psbt_sign_finalize.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
13
use std::collections::BTreeMap;
24
use std::str::FromStr;
35

4-
use actual_base64 as base64;
5-
use bitcoin::sighash::SighashCache;
6-
use bitcoin::PrivateKey;
76
use miniscript::bitcoin::consensus::encode::deserialize;
87
use miniscript::bitcoin::hashes::hex::FromHex;
9-
use miniscript::bitcoin::psbt::PartiallySignedTransaction as Psbt;
8+
use miniscript::bitcoin::psbt::{self, Psbt};
9+
use miniscript::bitcoin::sighash::SighashCache;
1010
use miniscript::bitcoin::{
11-
self, psbt, secp256k1, Address, Network, OutPoint, Script, Sequence, Transaction, TxIn, TxOut,
11+
self, base64, secp256k1, Address, Network, OutPoint, PrivateKey, Script, Sequence, Transaction,
12+
TxIn, TxOut,
1213
};
1314
use miniscript::psbt::{PsbtExt, PsbtInputExt};
1415
use miniscript::Descriptor;

examples/sign_multisig.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
// Miniscript
2-
// Written in 2019 by
3-
// Andrew Poelstra <[email protected]>
4-
//
5-
// To the extent possible under law, the author(s) have dedicated all
6-
// copyright and related and neighboring rights to this software to
7-
// the public domain worldwide. This software is distributed without
8-
// any warranty.
9-
//
10-
// You should have received a copy of the CC0 Public Domain Dedication
11-
// along with this software.
12-
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13-
//
1+
// SPDX-License-Identifier: CC0-1.0
142

153
//! Example: Signing a 2-of-3 multisignature.
164

examples/taproot.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
13
use std::collections::HashMap;
24
use std::str::FromStr;
35

4-
use bitcoin::address::WitnessVersion;
5-
use bitcoin::key::XOnlyPublicKey;
6-
use bitcoin::secp256k1::{rand, KeyPair};
7-
use bitcoin::Network;
6+
use miniscript::bitcoin::address::WitnessVersion;
7+
use miniscript::bitcoin::key::{KeyPair, XOnlyPublicKey};
8+
use miniscript::bitcoin::secp256k1::rand;
9+
use miniscript::bitcoin::Network;
810
use miniscript::descriptor::DescriptorType;
911
use miniscript::policy::Concrete;
1012
use miniscript::{translate_hash_fail, Descriptor, Miniscript, Tap, TranslatePk, Translator};
@@ -21,9 +23,8 @@ impl Translator<String, XOnlyPublicKey, ()> for StrPkTranslator {
2123
self.pk_map.get(pk).copied().ok_or(())
2224
}
2325

24-
// We don't need to implement these methods as we are not using them in the policy
25-
// Fail if we encounter any hash fragments.
26-
// See also translate_hash_clone! macro
26+
// We don't need to implement these methods as we are not using them in the policy.
27+
// Fail if we encounter any hash fragments. See also translate_hash_clone! macro.
2728
translate_hash_fail!(String, XOnlyPublicKey, ());
2829
}
2930

@@ -39,7 +40,7 @@ fn main() {
3940
.replace(&[' ', '\n', '\t'][..], "");
4041

4142
let _ms = Miniscript::<String, Tap>::from_str("and_v(v:ripemd160(H),pk(A))").unwrap();
42-
let pol: Concrete<String> = Concrete::from_str(&pol_str).unwrap();
43+
let pol = Concrete::<String>::from_str(&pol_str).unwrap();
4344
// In case we can't find an internal key for the given policy, we set the internal key to
4445
// a random pubkey as specified by BIP341 (which are *unspendable* by any party :p)
4546
let desc = pol.compile_tr(Some("UNSPENDABLE_KEY".to_string())).unwrap();
@@ -52,7 +53,7 @@ fn main() {
5253
// Check whether the descriptors are safe.
5354
assert!(desc.sanity_check().is_ok());
5455

55-
// Descriptor Type and Version should match respectively for Taproot
56+
// Descriptor type and version should match respectively for taproot
5657
let desc_type = desc.desc_type();
5758
assert_eq!(desc_type, DescriptorType::Tr);
5859
assert_eq!(desc_type.segwit_version().unwrap(), WitnessVersion::V1);
@@ -99,11 +100,12 @@ fn main() {
99100

100101
let real_desc = desc.translate_pk(&mut t).unwrap();
101102

102-
// Max Satisfaction Weight for compilation, corresponding to the script-path spend
103-
// `multi_a(2,PUBKEY_1,PUBKEY_2) at taptree depth 1, having
104-
// Max Witness Size = varint(control_block_size) + control_block size +
105-
// varint(script_size) + script_size + max_satisfaction_size
106-
// = 1 + 65 + 1 + 70 + 132 = 269
103+
// Max satisfaction weight for compilation, corresponding to the script-path spend
104+
// `multi_a(2,PUBKEY_1,PUBKEY_2) at taptree depth 1, having:
105+
//
106+
// max_witness_size = varint(control_block_size) + control_block size +
107+
// varint(script_size) + script_size + max_satisfaction_size
108+
// = 1 + 65 + 1 + 70 + 132 = 269
107109
let max_sat_wt = real_desc.max_weight_to_satisfy().unwrap();
108110
assert_eq!(max_sat_wt, 269);
109111

examples/verify_tx.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
// Miniscript
2-
// Written in 2019 by
3-
// Andrew Poelstra <[email protected]>
4-
//
5-
// To the extent possible under law, the author(s) have dedicated all
6-
// copyright and related and neighboring rights to this software to
7-
// the public domain worldwide. This software is distributed without
8-
// any warranty.
9-
//
10-
// You should have received a copy of the CC0 Public Domain Dedication
11-
// along with this software.
12-
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13-
//
1+
// SPDX-License-Identifier: CC0-1.0
142

153
//! Example: Verifying a signed transaction.
164
175
use std::str::FromStr;
186

19-
use bitcoin::consensus::Decodable;
20-
use bitcoin::secp256k1::{self, Secp256k1};
21-
use bitcoin::{absolute, sighash, Sequence};
7+
use miniscript::bitcoin::consensus::Decodable;
8+
use miniscript::bitcoin::secp256k1::{self, Secp256k1};
9+
use miniscript::bitcoin::{absolute, sighash, Sequence};
2210
use miniscript::interpreter::KeySigPair;
2311

2412
fn main() {

examples/xpub_descriptors.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
// Miniscript
2-
// Written in 2019 by
3-
// Andrew Poelstra <[email protected]>
4-
//
5-
// To the extent possible under law, the author(s) have dedicated all
6-
// copyright and related and neighboring rights to this software to
7-
// the public domain worldwide. This software is distributed without
8-
// any warranty.
9-
//
10-
// You should have received a copy of the CC0 Public Domain Dedication
11-
// along with this software.
12-
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13-
//
1+
// SPDX-License-Identifier: CC0-1.0
142

153
//! Example: Parsing a xpub and getting an address.
164

examples/psbt.rs renamed to tests/bip-174.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
13
use bitcoin::consensus::encode::deserialize;
24
use bitcoin::hashes::hex::FromHex;
35
use bitcoin::psbt::Psbt;

0 commit comments

Comments
 (0)