Skip to content

Commit 25eb57e

Browse files
authored
Merge pull request rust-bitcoin#22 from tcharding/12-05-add-verify-tool
Add dev tooling
2 parents 7511890 + 4fdea9c commit 25eb57e

File tree

18 files changed

+1517
-186
lines changed

18 files changed

+1517
-186
lines changed

Cargo-minimal.lock

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
# It is not intended for manual editing.
33
version = 3
44

5+
[[package]]
6+
name = "aho-corasick"
7+
version = "1.1.3"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10+
dependencies = [
11+
"memchr",
12+
]
13+
14+
[[package]]
15+
name = "anyhow"
16+
version = "1.0.94"
17+
source = "registry+https://github.com/rust-lang/crates.io-index"
18+
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
19+
520
[[package]]
621
name = "arrayvec"
722
version = "0.7.4"
@@ -169,6 +184,12 @@ version = "0.4.18"
169184
source = "registry+https://github.com/rust-lang/crates.io-index"
170185
checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de"
171186

187+
[[package]]
188+
name = "memchr"
189+
version = "2.7.4"
190+
source = "registry+https://github.com/rust-lang/crates.io-index"
191+
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
192+
172193
[[package]]
173194
name = "minreq"
174195
version = "2.11.2"
@@ -198,6 +219,35 @@ dependencies = [
198219
"proc-macro2",
199220
]
200221

222+
[[package]]
223+
name = "regex"
224+
version = "1.11.1"
225+
source = "registry+https://github.com/rust-lang/crates.io-index"
226+
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
227+
dependencies = [
228+
"aho-corasick",
229+
"memchr",
230+
"regex-automata",
231+
"regex-syntax",
232+
]
233+
234+
[[package]]
235+
name = "regex-automata"
236+
version = "0.4.9"
237+
source = "registry+https://github.com/rust-lang/crates.io-index"
238+
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
239+
dependencies = [
240+
"aho-corasick",
241+
"memchr",
242+
"regex-syntax",
243+
]
244+
245+
[[package]]
246+
name = "regex-syntax"
247+
version = "0.8.5"
248+
source = "registry+https://github.com/rust-lang/crates.io-index"
249+
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
250+
201251
[[package]]
202252
name = "ryu"
203253
version = "1.0.18"
@@ -283,6 +333,14 @@ version = "1.0.8"
283333
source = "registry+https://github.com/rust-lang/crates.io-index"
284334
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
285335

336+
[[package]]
337+
name = "verify"
338+
version = "0.1.0"
339+
dependencies = [
340+
"anyhow",
341+
"regex",
342+
]
343+
286344
[[package]]
287345
name = "winapi"
288346
version = "0.3.9"

Cargo-recent.lock

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
# It is not intended for manual editing.
33
version = 3
44

5+
[[package]]
6+
name = "aho-corasick"
7+
version = "1.1.3"
8+
source = "registry+https://github.com/rust-lang/crates.io-index"
9+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10+
dependencies = [
11+
"memchr",
12+
]
13+
14+
[[package]]
15+
name = "anyhow"
16+
version = "1.0.94"
17+
source = "registry+https://github.com/rust-lang/crates.io-index"
18+
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
19+
520
[[package]]
621
name = "arrayvec"
722
version = "0.7.4"
@@ -169,6 +184,12 @@ version = "0.4.18"
169184
source = "registry+https://github.com/rust-lang/crates.io-index"
170185
checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de"
171186

187+
[[package]]
188+
name = "memchr"
189+
version = "2.7.4"
190+
source = "registry+https://github.com/rust-lang/crates.io-index"
191+
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
192+
172193
[[package]]
173194
name = "minreq"
174195
version = "2.11.2"
@@ -198,6 +219,35 @@ dependencies = [
198219
"proc-macro2",
199220
]
200221

222+
[[package]]
223+
name = "regex"
224+
version = "1.11.1"
225+
source = "registry+https://github.com/rust-lang/crates.io-index"
226+
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
227+
dependencies = [
228+
"aho-corasick",
229+
"memchr",
230+
"regex-automata",
231+
"regex-syntax",
232+
]
233+
234+
[[package]]
235+
name = "regex-automata"
236+
version = "0.4.9"
237+
source = "registry+https://github.com/rust-lang/crates.io-index"
238+
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
239+
dependencies = [
240+
"aho-corasick",
241+
"memchr",
242+
"regex-syntax",
243+
]
244+
245+
[[package]]
246+
name = "regex-syntax"
247+
version = "0.8.5"
248+
source = "registry+https://github.com/rust-lang/crates.io-index"
249+
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
250+
201251
[[package]]
202252
name = "ryu"
203253
version = "1.0.18"
@@ -283,6 +333,14 @@ version = "1.0.8"
283333
source = "registry+https://github.com/rust-lang/crates.io-index"
284334
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
285335

336+
[[package]]
337+
name = "verify"
338+
version = "0.1.0"
339+
dependencies = [
340+
"anyhow",
341+
"regex",
342+
]
343+
286344
[[package]]
287345
name = "winapi"
288346
version = "0.3.9"

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["client", "types", "jsonrpc"]
2+
members = ["client", "types", "jsonrpc", "verify"]
33
exclude = ["integration_test", "node"]
44
resolver = "2"
55

contrib/extract.pl

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/perl
2+
# SPDX-License-Identifier: CC0-1.0
3+
#
4+
# Create the `types/src/vXYZ/mod.rs` rusdoc.
5+
6+
use strict;
7+
use warnings;
8+
use Getopt::Long qw(:config no_auto_abbrev);
9+
10+
# The script name.
11+
my $SCRIPT = $0;
12+
13+
# The Bitcoin Core version we are working with.
14+
my $CORE_VERSION = "0.17.1";
15+
# The file holding output of `bitcoin-cli --help`.
16+
my $RPC_HELP_FILE = "types/src/v17/rpc-api.txt";
17+
18+
# Command line options.
19+
my $help = 0;
20+
my $debug = 0;
21+
22+
sub help
23+
{
24+
my ($exitcode) = @_;
25+
26+
print << "EOM";
27+
28+
Usage: $SCRIPT [OPTIONS]
29+
30+
Options:
31+
32+
-d, --debug Display debugging output.
33+
-h, --help Display this help and exit.
34+
35+
Generates the rustdocs for the `types/vX.rs` module. Before running script set CORE_VERSION and RPC_HELP_FILE.
36+
37+
EOM
38+
exit($exitcode);
39+
}
40+
41+
GetOptions(
42+
'd|debug' => \$debug,
43+
'h|help' => \$help,
44+
) or help(1);
45+
46+
help(0) if ($help);
47+
48+
main();
49+
50+
exit 0;
51+
52+
sub dprint
53+
{
54+
printf(STDERR @_) if $debug;
55+
}
56+
57+
sub main {
58+
59+
# Open the file for reading
60+
open(my $fh, '<', $RPC_HELP_FILE) or die "Could not open file '$RPC_HELP_FILE': $!\n";
61+
62+
# Loop over each line in the file
63+
while (my $line = <$fh>) {
64+
chomp($line);
65+
if ($line =~ /^== (.+) ==/) { # Section heading.
66+
my $section = $1; # Captures the placeholder text
67+
start_section($section);
68+
} elsif ($line =~ /^\s*$/) { # Blank line.
69+
end_section();
70+
} else {
71+
add_method($line);
72+
}
73+
}
74+
75+
end_section();
76+
print_footer();
77+
78+
# Close the file handle.
79+
close($fh);
80+
}
81+
82+
sub print_header {
83+
print <<'EOM';
84+
//! # JSON-RPC types for Bitcoin Core `v$CORE_VERSION`
85+
//!
86+
//! These structs are shaped for the JSON data returned by the JSON-RPC API. They use stdlib types
87+
//! (or custom types) and where necessary implement an `into_model` function to convert the type to
88+
//! a [`crate::model`] type of the same name. The types in this module are version specific. The
89+
//! types in the `model` module are version nonspecific and are strongly typed using `rust-bitcoin`.
90+
//!
91+
//! ### Method name and implementation status
92+
//!
93+
//! Every JSON-RPC method supported by this version of Bitcoin Core is listed below along with its
94+
//! current implementation status.
95+
//!
96+
EOM
97+
}
98+
99+
sub print_footer {
100+
print <<'EOM'
101+
//!
102+
//! **Items marked omitted were omitted because:**
103+
//!
104+
//! - Method does not return anything.
105+
//! - Method returns a simple type (e.g. bool or integer).
106+
//! - Method is deprecated.
107+
EOM
108+
}
109+
110+
# Print the blurb for the start of a section.
111+
sub start_section {
112+
my ($section) = @_; # Get the first argument
113+
114+
print <<'EOM';
115+
//! <details>
116+
//! <summary> Methods from the $section section </summary>
117+
//!
118+
//! | JSON-PRC Method Name | Status |
119+
//! |:-----------------------------------|:---------------:|
120+
EOM
121+
}
122+
123+
# Print the blurb for the end of a section.
124+
sub end_section {
125+
print<<'EOM';
126+
//!
127+
//! </details>
128+
//!
129+
EOM
130+
}
131+
132+
sub add_method {
133+
my ($line) = @_;
134+
if ($line =~ /^(\S+)/) {
135+
my ($method) = $1;
136+
printf "//! \| %-34s \| |\n", $method
137+
}
138+
}

integration_test/tests/blockchain.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,25 @@ fn get_block_header_verbose() { // verbose = true
7676
// optional as suggested in the docs but to no avail.
7777
#[test]
7878
#[cfg(feature = "0_17_1")]
79+
fn get_block_stats() {
80+
get_block_stats_by_height();
81+
get_block_stats_by_hash();
82+
}
83+
7984
fn get_block_stats_by_height() {
8085
let node = Node::new_no_wallet();
8186
let json = node.client.get_block_stats_by_height(0).expect("getblockstats");
8287
assert!(json.into_model().is_ok());
8388
}
8489

85-
// FIXME: Same as get_block_stats_by_height above.
86-
#[test]
87-
#[cfg(feature = "0_17_1")]
8890
fn get_block_stats_by_hash() { // verbose = true
8991
let node = Node::new_no_wallet();
9092
let block_hash = best_block_hash();
9193
let json = node.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
9294
assert!(json.into_model().is_ok());
9395
}
9496

97+
9598
#[test]
9699
fn get_block_stats_by_height_txindex() {
97100
let node = Node::new_no_wallet_txindex();
@@ -130,37 +133,37 @@ fn get_difficulty() {
130133

131134
#[test]
132135
#[cfg(feature = "TODO")]
133-
fn get_mempool_ancestors() {}
136+
fn get_mempool_ancestors() { todo!() }
134137

135138
#[test]
136139
#[cfg(feature = "TODO")]
137-
fn get_mempool_descendants() {}
140+
fn get_mempool_descendants() { todo!() }
138141

139142
#[test]
140143
#[cfg(feature = "TODO")]
141-
fn get_mempool_entry() {}
144+
fn get_mempool_entry() { todo!() }
142145

143146
#[test]
144147
#[cfg(feature = "TODO")]
145-
fn get_mempool_info() {}
148+
fn get_mempool_info() { todo!() }
146149

147150
#[test]
148151
#[cfg(feature = "TODO")]
149-
fn get_raw_mempool() {}
152+
fn get_raw_mempool() { todo!() }
150153

151154
#[test]
152155
#[cfg(feature = "TODO")]
153-
fn get_tx_out() {}
156+
fn get_tx_out() { todo!() }
154157

155158
#[test]
156159
#[cfg(feature = "TODO")]
157-
fn get_tx_out_proof() {}
160+
fn get_tx_out_proof() { todo!() }
158161

159162
#[test]
160163
#[cfg(feature = "TODO")]
161-
fn get_tx_out_set_info() {}
164+
fn get_tx_out_set_info() { todo!() }
162165

163166
#[test]
164167
#[cfg(feature = "TODO")]
165-
fn verify_tx_out_proof() {}
168+
fn verify_tx_out_proof() { todo!() }
166169

0 commit comments

Comments
 (0)