@@ -40,6 +40,7 @@ use clarity_vm::clarity::{ClarityConnection, ClarityInstance};
40
40
use core:: mempool:: * ;
41
41
use core:: * ;
42
42
use net:: Error as net_error;
43
+ use serde:: Deserialize ;
43
44
use util:: get_epoch_time_ms;
44
45
use util:: hash:: MerkleTree ;
45
46
use util:: hash:: Sha512Trunc256Sum ;
@@ -159,6 +160,7 @@ pub struct TransactionSkipped {
159
160
/// Represents an event for a successful transaction. This transaction should be added to the block.
160
161
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
161
162
pub struct TransactionSuccessEvent {
163
+ #[ serde( deserialize_with = "hex_deserialize" , serialize_with = "hex_serialize" ) ]
162
164
pub txid : Txid ,
163
165
pub fee : u64 ,
164
166
pub execution_cost : ExecutionCost ,
@@ -168,17 +170,29 @@ pub struct TransactionSuccessEvent {
168
170
/// Represents an event for a failed transaction. Something went wrong when processing this transaction.
169
171
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
170
172
pub struct TransactionErrorEvent {
173
+ #[ serde( deserialize_with = "hex_deserialize" , serialize_with = "hex_serialize" ) ]
171
174
pub txid : Txid ,
172
175
pub error : String ,
173
176
}
174
177
175
178
/// Represents an event for a transaction that was skipped, but might succeed later.
176
179
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
177
180
pub struct TransactionSkippedEvent {
181
+ #[ serde( deserialize_with = "hex_deserialize" , serialize_with = "hex_serialize" ) ]
178
182
pub txid : Txid ,
179
183
pub error : String ,
180
184
}
181
185
186
+ fn hex_serialize < S : serde:: Serializer > ( txid : & Txid , s : S ) -> Result < S :: Ok , S :: Error > {
187
+ let inst = txid. to_hex ( ) ;
188
+ s. serialize_str ( inst. as_str ( ) )
189
+ }
190
+
191
+ fn hex_deserialize < ' de , D : serde:: Deserializer < ' de > > ( d : D ) -> Result < Txid , D :: Error > {
192
+ let inst_str = String :: deserialize ( d) ?;
193
+ Txid :: from_hex ( & inst_str) . map_err ( serde:: de:: Error :: custom)
194
+ }
195
+
182
196
/// `TransactionResult` represents the outcome of transaction processing.
183
197
/// We use this enum to involve the compiler in forcing us to always clearly
184
198
/// indicate the outcome of a transaction.
0 commit comments