1- //! JSON serialization using strings for BoxValue and TokenAmount
1+ //! JSON serialization according to EIP-12 ( using strings for BoxValue and TokenAmount)
22
33use derive_more:: FromStr ;
44use ergo_lib:: chain:: ergo_box:: BoxId ;
@@ -17,7 +17,7 @@ use ergo_lib::ergotree_ir::ergo_tree::ErgoTree;
1717use serde:: Serialize ;
1818
1919#[ derive( Serialize , PartialEq , Debug , Clone ) ]
20- pub ( crate ) struct TransactionJsonDapp {
20+ pub ( crate ) struct TransactionJsonEip12 {
2121 #[ cfg_attr( feature = "json" , serde( rename = "id" ) ) ]
2222 pub tx_id : TxId ,
2323 /// inputs, that will be spent by this transaction.
@@ -29,12 +29,12 @@ pub(crate) struct TransactionJsonDapp {
2929 #[ cfg_attr( feature = "json" , serde( rename = "dataInputs" ) ) ]
3030 pub data_inputs : Vec < DataInput > ,
3131 #[ cfg_attr( feature = "json" , serde( rename = "outputs" ) ) ]
32- pub outputs : Vec < ErgoBoxJsonDapp > ,
32+ pub outputs : Vec < ErgoBoxJsonEip12 > ,
3333}
3434
35- impl From < Transaction > for TransactionJsonDapp {
35+ impl From < Transaction > for TransactionJsonEip12 {
3636 fn from ( t : Transaction ) -> Self {
37- TransactionJsonDapp {
37+ TransactionJsonEip12 {
3838 tx_id : t. id ( ) ,
3939 inputs : t. inputs ,
4040 data_inputs : t. data_inputs ,
@@ -44,7 +44,7 @@ impl From<Transaction> for TransactionJsonDapp {
4444}
4545
4646#[ derive( Serialize , PartialEq , Debug , Clone ) ]
47- pub ( crate ) struct UnsignedTransactionJsonDapp {
47+ pub ( crate ) struct UnsignedTransactionJsonEip12 {
4848 /// unsigned inputs, that will be spent by this transaction.
4949 #[ cfg_attr( feature = "json" , serde( rename = "inputs" ) ) ]
5050 pub inputs : Vec < UnsignedInput > ,
@@ -55,28 +55,28 @@ pub(crate) struct UnsignedTransactionJsonDapp {
5555 pub data_inputs : Vec < DataInput > ,
5656 /// box candidates to be created by this transaction
5757 #[ cfg_attr( feature = "json" , serde( rename = "outputs" ) ) ]
58- pub outputs : Vec < ErgoBoxCandidateJsonDapp > ,
58+ pub outputs : Vec < ErgoBoxCandidateJsonEip12 > ,
5959}
6060
61- impl From < UnsignedTransaction > for UnsignedTransactionJsonDapp {
61+ impl From < UnsignedTransaction > for UnsignedTransactionJsonEip12 {
6262 fn from ( _: UnsignedTransaction ) -> Self {
6363 todo ! ( )
6464 }
6565}
6666
6767#[ derive( Serialize , PartialEq , Eq , Debug , Clone ) ]
68- pub ( crate ) struct ErgoBoxJsonDapp {
68+ pub ( crate ) struct ErgoBoxJsonEip12 {
6969 #[ serde( rename = "boxId" , alias = "id" ) ]
7070 pub box_id : Option < BoxId > ,
7171 /// amount of money associated with the box
7272 #[ serde( rename = "value" ) ]
73- pub value : BoxValueJsonDapp ,
73+ pub value : BoxValueJsonEip12 ,
7474 /// guarding script, which should be evaluated to true in order to open this box
7575 #[ serde( rename = "ergoTree" , with = "ergo_lib::chain::json::ergo_tree" ) ]
7676 pub ergo_tree : ErgoTree ,
7777 /// secondary tokens the box contains
7878 #[ serde( rename = "assets" ) ]
79- pub tokens : Vec < TokenJsonDapp > ,
79+ pub tokens : Vec < TokenJsonEip12 > ,
8080 /// additional registers the box can carry over
8181 #[ serde( rename = "additionalRegisters" ) ]
8282 pub additional_registers : NonMandatoryRegisters ,
@@ -93,9 +93,9 @@ pub(crate) struct ErgoBoxJsonDapp {
9393 pub index : u16 ,
9494}
9595
96- impl From < ErgoBox > for ErgoBoxJsonDapp {
96+ impl From < ErgoBox > for ErgoBoxJsonEip12 {
9797 fn from ( b : ErgoBox ) -> Self {
98- ErgoBoxJsonDapp {
98+ ErgoBoxJsonEip12 {
9999 box_id : b. box_id ( ) . into ( ) ,
100100 value : b. value . into ( ) ,
101101 ergo_tree : b. ergo_tree ,
@@ -112,15 +112,15 @@ impl From<ErgoBox> for ErgoBoxJsonDapp {
112112/// that will be calculated after full transaction formation.
113113/// Use [`box_builder::ErgoBoxCandidateBuilder`] to create an instance.
114114#[ derive( Serialize , PartialEq , Eq , Clone , Debug ) ]
115- pub ( crate ) struct ErgoBoxCandidateJsonDapp {
115+ pub ( crate ) struct ErgoBoxCandidateJsonEip12 {
116116 /// amount of money associated with the box
117117 #[ serde( rename = "value" ) ]
118- pub value : BoxValueJsonDapp ,
118+ pub value : BoxValueJsonEip12 ,
119119 /// guarding script, which should be evaluated to true in order to open this box
120120 #[ serde( rename = "ergoTree" , with = "ergo_lib::chain::json::ergo_tree" ) ]
121121 pub ergo_tree : ErgoTree ,
122122 #[ serde( rename = "assets" ) ]
123- pub tokens : Vec < TokenJsonDapp > ,
123+ pub tokens : Vec < TokenJsonEip12 > ,
124124 /// additional registers the box can carry over
125125 #[ serde( rename = "additionalRegisters" ) ]
126126 pub additional_registers : NonMandatoryRegisters ,
@@ -136,38 +136,38 @@ pub(crate) struct ErgoBoxCandidateJsonDapp {
136136 serde:: Serialize , serde:: Deserialize , PartialEq , Eq , Hash , Debug , Clone , Copy , FromStr ,
137137) ]
138138/// Box value in nanoERGs with bound checks
139- pub ( crate ) struct BoxValueJsonDapp ( #[ serde_as( as = "serde_with::DisplayFromStr" ) ] u64 ) ;
139+ pub ( crate ) struct BoxValueJsonEip12 ( #[ serde_as( as = "serde_with::DisplayFromStr" ) ] u64 ) ;
140140
141- impl From < BoxValue > for BoxValueJsonDapp {
141+ impl From < BoxValue > for BoxValueJsonEip12 {
142142 fn from ( bv : BoxValue ) -> Self {
143- BoxValueJsonDapp ( * bv. as_u64 ( ) )
143+ BoxValueJsonEip12 ( * bv. as_u64 ( ) )
144144 }
145145}
146146
147147/// Token represented with token id paired with it's amount
148148#[ derive( Serialize , PartialEq , Eq , Debug , Clone ) ]
149- pub struct TokenJsonDapp {
149+ pub struct TokenJsonEip12 {
150150 /// token id
151151 #[ serde( rename = "tokenId" ) ]
152152 pub token_id : TokenId ,
153153 /// token amount
154154 #[ serde( rename = "amount" ) ]
155- pub amount : TokenAmountJsonDapp ,
155+ pub amount : TokenAmountJsonEip12 ,
156156}
157157
158- impl From < Token > for TokenJsonDapp {
158+ impl From < Token > for TokenJsonEip12 {
159159 fn from ( t : Token ) -> Self {
160- TokenJsonDapp {
160+ TokenJsonEip12 {
161161 token_id : t. token_id ,
162- amount : TokenAmountJsonDapp ( t. amount . as_u64 ( ) ) ,
162+ amount : TokenAmountJsonEip12 ( t. amount . as_u64 ( ) ) ,
163163 }
164164 }
165165}
166166
167167/// Token amount with bound checks
168168#[ serde_with:: serde_as]
169169#[ derive( Serialize , PartialEq , Eq , Hash , Debug , Clone , Copy , PartialOrd , Ord ) ]
170- pub struct TokenAmountJsonDapp (
170+ pub struct TokenAmountJsonEip12 (
171171 // Encodes as string always
172172 #[ serde_as( as = "serde_with::DisplayFromStr" ) ] u64 ,
173173) ;
0 commit comments