11//! JSON serialization according to EIP-12 (using strings for BoxValue and TokenAmount)
22
3+ use std:: convert:: TryInto ;
4+
35use derive_more:: FromStr ;
46use ergo_lib:: chain:: ergo_box:: BoxId ;
57use ergo_lib:: chain:: ergo_box:: BoxValue ;
@@ -37,8 +39,11 @@ impl From<Transaction> for TransactionJsonEip12 {
3739 fn from ( t : Transaction ) -> Self {
3840 TransactionJsonEip12 {
3941 tx_id : t. id ( ) ,
40- inputs : t. inputs ,
41- data_inputs : t. data_inputs ,
42+ inputs : t. inputs . try_into ( ) . unwrap ( ) ,
43+ data_inputs : t
44+ . data_inputs
45+ . map ( |di| di. try_into ( ) . unwrap ( ) )
46+ . unwrap_or_else ( Vec :: new) ,
4247 outputs : t. outputs . into_iter ( ) . map ( |b| b. into ( ) ) . collect ( ) ,
4348 }
4449 }
@@ -62,8 +67,11 @@ pub(crate) struct UnsignedTransactionJsonEip12 {
6267impl From < UnsignedTransaction > for UnsignedTransactionJsonEip12 {
6368 fn from ( t : UnsignedTransaction ) -> Self {
6469 UnsignedTransactionJsonEip12 {
65- inputs : t. inputs ,
66- data_inputs : t. data_inputs ,
70+ inputs : t. inputs . try_into ( ) . unwrap ( ) ,
71+ data_inputs : t
72+ . data_inputs
73+ . map ( |di| di. try_into ( ) . unwrap ( ) )
74+ . unwrap_or_else ( Vec :: new) ,
6775 outputs : t. output_candidates . into_iter ( ) . map ( |b| b. into ( ) ) . collect ( ) ,
6876 }
6977 }
0 commit comments