Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.d/scriptpubkey-witness-v0-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Fixed

- **`scriptPubKey` `type` is `nonstandard` for a version 0 witness
program that is neither 20 nor 32 bytes, as in Core.** A version 0
program is a key hash at 20 bytes and a script hash at 32. Any other
length, such as `0003abcdef`, was `witness_unknown`. It is now
`nonstandard`. Versions 1 to 16 that are not taproot or an anchor stay
`witness_unknown`.
8 changes: 6 additions & 2 deletions crates/rbitcoin-rpc/src/methods/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ pub fn script_core_type(script: &bitcoin::Script) -> &'static str {
"witness_v1_taproot"
} else if is_p2anchor(script) {
"anchor"
} else if script.is_witness_program() {
"witness_unknown"
} else if let Some(version) = script.witness_version() {
if version == bitcoin::WitnessVersion::V0 {
"nonstandard"
} else {
"witness_unknown"
}
} else if script.is_op_return() {
"nulldata"
} else if script.is_p2pk() {
Expand Down
22 changes: 22 additions & 0 deletions crates/rbitcoin-rpc/tests/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,28 @@ fn decodescript_multisig_type_matches_core() {
let _ = std::fs::remove_dir_all(&dir);
}

#[test]
fn decodescript_witness_program_type_matches_core() {
let program = |version: &str, len: usize| format!("{version}{len:02x}{}", "ab".repeat(len));
let rows = [
(program("00", 2), "nonstandard"),
(program("00", 21), "nonstandard"),
(program("00", 40), "nonstandard"),
(program("00", 20), "witness_v0_keyhash"),
(program("00", 32), "witness_v0_scripthash"),
(program("51", 2), "witness_unknown"),
("51024e73".into(), "anchor"),
(program("60", 40), "witness_unknown"),
(program("51", 41), "nonstandard"),
];
let (ctx, dir) = ctx_empty();
for (hex, ty) in &rows {
let script = dispatch(&ctx, "decodescript", vec![json!(hex)]).unwrap();
assert_eq!(script["type"], json!(ty), "{hex}");
}
let _ = std::fs::remove_dir_all(&dir);
}

#[test]
fn help_and_getrpcinfo_list_methods() {
let (ctx, dir) = ctx_empty();
Expand Down
Loading