@@ -307,7 +307,10 @@ impl PlatformAddress {
307307 pubkey_hash,
308308 )
309309 . map_err ( |e| {
310- ProtocolError :: Generic ( format ! ( "P2PKH signature verification failed: {}" , e) )
310+ ProtocolError :: AddressWitnessError ( format ! (
311+ "P2PKH signature verification failed: {}" ,
312+ e
313+ ) )
311314 } ) ?;
312315
313316 Ok ( AddressWitnessVerificationOperations :: for_p2pkh (
@@ -325,7 +328,7 @@ impl PlatformAddress {
325328 let script = ScriptBuf :: from_bytes ( redeem_script. to_vec ( ) ) ;
326329 let computed_hash = script. script_hash ( ) ;
327330 if computed_hash. as_byte_array ( ) != script_hash {
328- return Err ( ProtocolError :: Generic ( format ! (
331+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
329332 "Script hash {} does not match address hash {}" ,
330333 hex:: encode( computed_hash. as_byte_array( ) ) ,
331334 hex:: encode( script_hash)
@@ -343,7 +346,7 @@ impl PlatformAddress {
343346 . collect ( ) ;
344347
345348 if valid_signatures. len ( ) < threshold {
346- return Err ( ProtocolError :: Generic ( format ! (
349+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
347350 "Not enough signatures: got {}, need {}" ,
348351 valid_signatures. len( ) ,
349352 threshold
@@ -368,11 +371,14 @@ impl PlatformAddress {
368371 valid_signatures[ sig_idx] . as_slice ( ) ,
369372 )
370373 . map_err ( |e| {
371- ProtocolError :: Generic ( format ! ( "Invalid signature format: {}" , e) )
374+ ProtocolError :: AddressWitnessError ( format ! (
375+ "Invalid signature format: {}" ,
376+ e
377+ ) )
372378 } ) ?;
373379
374380 let pub_key = PublicKey :: from_slice ( & pubkeys[ pubkey_idx] ) . map_err ( |e| {
375- ProtocolError :: Generic ( format ! ( "Invalid public key: {}" , e) )
381+ ProtocolError :: AddressWitnessError ( format ! ( "Invalid public key: {}" , e) )
376382 } ) ?;
377383
378384 if secp
@@ -391,20 +397,22 @@ impl PlatformAddress {
391397 signable_bytes. len ( ) ,
392398 ) )
393399 } else {
394- Err ( ProtocolError :: Generic ( format ! (
400+ Err ( ProtocolError :: AddressWitnessError ( format ! (
395401 "Not enough valid signatures: verified {}, need {}" ,
396402 matched, threshold
397403 ) ) )
398404 }
399405 }
400406 ( PlatformAddress :: P2pkh ( _) , AddressWitness :: P2sh { .. } ) => {
401- Err ( ProtocolError :: Generic (
407+ Err ( ProtocolError :: AddressWitnessError (
402408 "P2PKH address requires P2pkh witness, got P2sh" . to_string ( ) ,
403409 ) )
404410 }
405- ( PlatformAddress :: P2sh ( _) , AddressWitness :: P2pkh { .. } ) => Err (
406- ProtocolError :: Generic ( "P2SH address requires P2sh witness, got P2pkh" . to_string ( ) ) ,
407- ) ,
411+ ( PlatformAddress :: P2sh ( _) , AddressWitness :: P2pkh { .. } ) => {
412+ Err ( ProtocolError :: AddressWitnessError (
413+ "P2SH address requires P2sh witness, got P2pkh" . to_string ( ) ,
414+ ) )
415+ }
408416 }
409417 }
410418
@@ -435,28 +443,28 @@ impl PlatformAddress {
435443 if byte >= OP_PUSHNUM_1 . to_u8 ( ) && byte <= OP_PUSHNUM_16 . to_u8 ( ) {
436444 ( byte - OP_PUSHNUM_1 . to_u8 ( ) + 1 ) as usize
437445 } else {
438- return Err ( ProtocolError :: Generic ( format ! (
446+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
439447 "Unsupported P2SH script type: only standard multisig (OP_M ... OP_N OP_CHECKMULTISIG) is supported. \
440448 First opcode was 0x{:02x}, expected OP_1 through OP_16",
441449 byte
442450 ) ) ) ;
443451 }
444452 }
445453 Some ( Ok ( dashcore:: blockdata:: script:: Instruction :: PushBytes ( _) ) ) => {
446- return Err ( ProtocolError :: Generic (
454+ return Err ( ProtocolError :: AddressWitnessError (
447455 "Unsupported P2SH script type: only standard multisig is supported. \
448456 Script starts with a data push instead of OP_M threshold."
449457 . to_string ( ) ,
450458 ) )
451459 }
452460 Some ( Err ( e) ) => {
453- return Err ( ProtocolError :: Generic ( format ! (
461+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
454462 "Error parsing P2SH script: {:?}" ,
455463 e
456464 ) ) )
457465 }
458466 None => {
459- return Err ( ProtocolError :: Generic (
467+ return Err ( ProtocolError :: AddressWitnessError (
460468 "Empty P2SH redeem script" . to_string ( ) ,
461469 ) )
462470 }
@@ -483,7 +491,7 @@ impl PlatformAddress {
483491 // This is OP_N, the total number of keys
484492 let n = ( byte - OP_PUSHNUM_1 . to_u8 ( ) + 1 ) as usize ;
485493 if pubkeys. len ( ) != n {
486- return Err ( ProtocolError :: Generic ( format ! (
494+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
487495 "Multisig script declares {} keys but contains {}" ,
488496 n,
489497 pubkeys. len( )
@@ -492,24 +500,24 @@ impl PlatformAddress {
492500 break ;
493501 } else if op == OP_CHECKMULTISIG || op == OP_CHECKMULTISIGVERIFY {
494502 // Hit CHECKMULTISIG without seeing OP_N - malformed
495- return Err ( ProtocolError :: Generic (
503+ return Err ( ProtocolError :: AddressWitnessError (
496504 "Malformed multisig script: OP_CHECKMULTISIG before OP_N" . to_string ( ) ,
497505 ) ) ;
498506 } else {
499- return Err ( ProtocolError :: Generic ( format ! (
507+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
500508 "Unsupported opcode 0x{:02x} in P2SH script. Only standard multisig is supported." ,
501509 byte
502510 ) ) ) ;
503511 }
504512 }
505513 Some ( Err ( e) ) => {
506- return Err ( ProtocolError :: Generic ( format ! (
514+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
507515 "Error parsing multisig script: {:?}" ,
508516 e
509517 ) ) )
510518 }
511519 None => {
512- return Err ( ProtocolError :: Generic (
520+ return Err ( ProtocolError :: AddressWitnessError (
513521 "Incomplete multisig script: unexpected end before OP_N" . to_string ( ) ,
514522 ) )
515523 }
@@ -518,7 +526,7 @@ impl PlatformAddress {
518526
519527 // Validate threshold
520528 if threshold > pubkeys. len ( ) {
521- return Err ( ProtocolError :: Generic ( format ! (
529+ return Err ( ProtocolError :: AddressWitnessError ( format ! (
522530 "Invalid multisig: threshold {} exceeds number of keys {}" ,
523531 threshold,
524532 pubkeys. len( )
@@ -531,24 +539,24 @@ impl PlatformAddress {
531539 if op == OP_CHECKMULTISIG {
532540 // Standard multisig - verify script is complete
533541 if instructions. next ( ) . is_some ( ) {
534- return Err ( ProtocolError :: Generic (
542+ return Err ( ProtocolError :: AddressWitnessError (
535543 "Multisig script has extra data after OP_CHECKMULTISIG" . to_string ( ) ,
536544 ) ) ;
537545 }
538546 Ok ( ( threshold, pubkeys) )
539547 } else if op == OP_CHECKMULTISIGVERIFY {
540- Err ( ProtocolError :: Generic (
548+ Err ( ProtocolError :: AddressWitnessError (
541549 "OP_CHECKMULTISIGVERIFY is not supported, only OP_CHECKMULTISIG"
542550 . to_string ( ) ,
543551 ) )
544552 } else {
545- Err ( ProtocolError :: Generic ( format ! (
553+ Err ( ProtocolError :: AddressWitnessError ( format ! (
546554 "Expected OP_CHECKMULTISIG, got opcode 0x{:02x}" ,
547555 op. to_u8( )
548556 ) ) )
549557 }
550558 }
551- _ => Err ( ProtocolError :: Generic (
559+ _ => Err ( ProtocolError :: AddressWitnessError (
552560 "Invalid multisig script: expected OP_CHECKMULTISIG after OP_N" . to_string ( ) ,
553561 ) ) ,
554562 }
0 commit comments