File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -672,6 +672,12 @@ impl Address {
672
672
673
673
/// Constructs an [`Address`] from an output script (`scriptPubkey`).
674
674
pub fn from_script ( script : & script:: Script , network : Network ) -> Option < Address > {
675
+ if script. is_witness_program ( ) {
676
+ if script. witness_version ( ) == Some ( WitnessVersion :: V0 ) && !( script. is_v0_p2wpkh ( ) || script. is_v0_p2wsh ( ) ) {
677
+ return None
678
+ }
679
+ }
680
+
675
681
Some ( Address {
676
682
payload : Payload :: from_script ( script) ?,
677
683
network,
@@ -1398,4 +1404,13 @@ mod tests {
1398
1404
let result = address. is_related_to_xonly_pubkey ( & xonly_pubkey) ;
1399
1405
assert ! ( result) ;
1400
1406
}
1407
+
1408
+ #[ test]
1409
+ fn test_fail_address_from_script ( ) {
1410
+ let bad_p2wpkh = hex_script ! ( "0014dbc5b0a8f9d4353b4b54c3db48846bb15abfec" ) ;
1411
+ let bad_p2wsh = hex_script ! ( "00202d4fa2eb233d008cc83206fa2f4f2e60199000f5b857a835e3172323385623" ) ;
1412
+
1413
+ assert_eq ! ( Address :: from_script( & bad_p2wpkh, Network :: Bitcoin ) , None ) ;
1414
+ assert_eq ! ( Address :: from_script( & bad_p2wsh, Network :: Bitcoin ) , None ) ;
1415
+ }
1401
1416
}
You can’t perform that action at this time.
0 commit comments