@@ -416,7 +416,7 @@ pub fn parse_shared_chain_and_index(input: &Input) -> Result<(u32, u32), String>
416416 Ok ( ( chain, index) )
417417}
418418
419- #[ derive( Debug ) ]
419+ #[ derive( Debug , strum :: IntoStaticStr ) ]
420420pub enum OutputScriptError {
421421 OutputIndexOutOfBounds { vout : u32 } ,
422422 NoUtxoFields ,
@@ -436,6 +436,7 @@ impl std::fmt::Display for OutputScriptError {
436436}
437437
438438impl std:: error:: Error for OutputScriptError { }
439+ crate :: impl_wasm_error_code!( OutputScriptError ) ;
439440
440441/// Identifies a key in the wallet triple (user, backup, bitgo)
441442#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
@@ -627,7 +628,7 @@ impl ParsedInput {
627628}
628629
629630/// Error type for parsing a single PSBT input
630- #[ derive( Debug ) ]
631+ #[ derive( Debug , strum :: IntoStaticStr ) ]
631632pub enum ParseInputError {
632633 /// Failed to extract output script or value from input
633634 Utxo ( OutputScriptError ) ,
@@ -670,6 +671,17 @@ impl std::fmt::Display for ParseInputError {
670671
671672impl std:: error:: Error for ParseInputError { }
672673
674+ impl crate :: error:: WasmErrorCode for ParseInputError {
675+ fn code ( & self ) -> String {
676+ let variant: & str = self . into ( ) ;
677+ match self {
678+ Self :: Utxo ( e) => format ! ( "ParseInputError.{}/{}" , variant, e. code( ) ) ,
679+ Self :: Address ( e) => format ! ( "ParseInputError.{}/{}" , variant, e. code( ) ) ,
680+ _ => format ! ( "ParseInputError.{}" , variant) ,
681+ }
682+ }
683+ }
684+
673685/// Get both output script and value from a PSBT input
674686pub fn get_output_script_and_value (
675687 input : & Input ,
@@ -697,7 +709,7 @@ fn get_output_script_from_input(
697709 get_output_script_and_value ( input, prevout) . map ( |( script, _value) | script)
698710}
699711
700- #[ derive( Debug , Clone , PartialEq , Eq ) ]
712+ #[ derive( Debug , Clone , PartialEq , Eq , strum :: IntoStaticStr ) ]
701713pub enum InputValidationErrorKind {
702714 /// Failed to extract output script from input
703715 InvalidOutputScript ( String ) ,
@@ -739,7 +751,15 @@ impl std::fmt::Display for InputValidationError {
739751 }
740752}
741753
742- #[ derive( Debug , PartialEq , Eq ) ]
754+ crate :: impl_wasm_error_code!( InputValidationErrorKind ) ;
755+
756+ impl crate :: error:: WasmErrorCode for InputValidationError {
757+ fn code ( & self ) -> String {
758+ self . kind . code ( )
759+ }
760+ }
761+
762+ #[ derive( Debug , PartialEq , Eq , strum:: IntoStaticStr ) ]
743763pub enum PsbtValidationError {
744764 /// Number of prevouts does not match number of PSBT inputs
745765 InputLengthMismatch {
@@ -776,6 +796,19 @@ impl std::fmt::Display for PsbtValidationError {
776796
777797impl std:: error:: Error for PsbtValidationError { }
778798
799+ impl crate :: error:: WasmErrorCode for PsbtValidationError {
800+ fn code ( & self ) -> String {
801+ let variant: & str = self . into ( ) ;
802+ match self {
803+ Self :: InvalidInputs ( errors) => {
804+ let inner = errors. first ( ) . map ( |e| e. code ( ) ) . unwrap_or_default ( ) ;
805+ format ! ( "PsbtValidationError.{}/{}" , variant, inner)
806+ }
807+ _ => format ! ( "PsbtValidationError.{}" , variant) ,
808+ }
809+ }
810+ }
811+
779812/// Validates that all inputs in a PSBT belong to the wallet
780813pub fn validate_psbt_wallet_inputs (
781814 psbt : & Psbt ,
0 commit comments