Skip to content

Commit a2d9f17

Browse files
btc: WshScript field accessors
1 parent e3c3dba commit a2d9f17

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/runtime/value.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ impl FieldAccess for Value {
521521
Value::Descriptor(x) => x.get_field(field),
522522
Value::TapInfo(x) => x.get_field(field),
523523
Value::Address(x) => x.get_field(field),
524+
Value::WshScript(x) => x.get_field(field),
524525
_ => None,
525526
}
526527
}

src/stdlib/btc.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,20 @@ impl FieldAccess for Address {
552552
}
553553
}
554554

555+
impl FieldAccess for WshScript {
556+
fn get_field(self, field: &Value) -> Option<Value> {
557+
Some(match field.as_str()? {
558+
"script_pubkey" => self.0.to_p2wsh().into(),
559+
"explicit_script" => self.0.into(),
560+
"address_type" => bitcoin::AddressType::P2wsh.into(),
561+
"witness_program" => bitcoin::WitnessProgram::p2wsh(&self.0).into(),
562+
_ => {
563+
return None;
564+
}
565+
})
566+
}
567+
}
568+
555569
// Display
556570

557571
impl PrettyDisplay for ScriptBuf {

0 commit comments

Comments
 (0)