Skip to content

Commit ec751fb

Browse files
committed
Introduce an example binary useful for profiling
1 parent fe8f040 commit ec751fb

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ required-features = ["compiler","std"]
6161
name = "psbt_sign_finalize"
6262
required-features = ["std", "base64"]
6363

64+
[[example]]
65+
name = "big"
66+
required-features = ["std", "base64", "compiler"]
67+
6468
[workspace]
6569
members = ["bitcoind-tests", "fuzz"]
6670
exclude = ["embedded"]

examples/big.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
//! This is not an example and will surely panic if executed, the purpose of this is using the
3+
//! compiled binary with tools like `cargo bloat` that cannot work with libraries.
4+
//!
5+
//! Ideal properties:
6+
//!
7+
//! * Call all the library API surface.
8+
//! * Depend on user input so that functions are not stripped out on the base of static input.
9+
//! * Use results so that calls are not stripped out.
10+
//!
11+
12+
use std::str::FromStr;
13+
use miniscript::{DefiniteDescriptorKey, Descriptor, DescriptorPublicKey, MiniscriptKey};
14+
use secp256k1::Secp256k1;
15+
fn main() {
16+
let empty = "".to_string();
17+
let mut args = std::env::args().collect::<Vec<_>>();
18+
let i = args.pop().unwrap_or(empty);
19+
20+
let d = Descriptor::<DescriptorPublicKey>::from_str(&i).unwrap();
21+
use_descriptor(d.clone());
22+
use_descriptor(Descriptor::<DefiniteDescriptorKey>::from_str(&i).unwrap());
23+
use_descriptor(Descriptor::<bitcoin::PublicKey>::from_str(&i).unwrap());
24+
use_descriptor(Descriptor::<String>::from_str(&i).unwrap());
25+
26+
let a = d.at_derivation_index(0).unwrap().address(bitcoin::Network::Bitcoin).unwrap();
27+
println!("{}", a);
28+
29+
let secp = Secp256k1::new();
30+
let (d, m) = Descriptor::parse_descriptor(&secp, &i).unwrap();
31+
use_descriptor(d);
32+
println!("{:?}", m);
33+
}
34+
35+
fn use_descriptor<K: MiniscriptKey>(d: Descriptor<K>) {
36+
println!("{}", d);
37+
println!("{:?}", d);
38+
println!("{:?}", d.desc_type());
39+
println!("{:?}", d.sanity_check());
40+
}

0 commit comments

Comments
 (0)