@@ -91,6 +91,59 @@ pub struct AssetMap {
91
91
asset_map : HashMap < PrincipalData , HashMap < AssetIdentifier , Vec < Value > > > ,
92
92
}
93
93
94
+ impl AssetMap {
95
+ pub fn to_json ( & self ) -> serde_json:: Value {
96
+ let stx : serde_json:: map:: Map < _ , _ > = self . stx_map
97
+ . iter ( )
98
+ . map ( |( principal, amount) | ( format ! ( "{}" , principal) , serde_json:: value:: Value :: String ( format ! ( "{}" , amount) ) ) )
99
+ . collect ( ) ;
100
+
101
+ let burns : serde_json:: map:: Map < _ , _ > = self . burn_map
102
+ . iter ( )
103
+ . map ( |( principal, amount) | ( format ! ( "{}" , principal) , serde_json:: value:: Value :: String ( format ! ( "{}" , amount) ) ) )
104
+ . collect ( ) ;
105
+
106
+ let tokens : serde_json:: map:: Map < _ , _ > = self . token_map
107
+ . iter ( )
108
+ . map ( |( principal, token_map) | {
109
+ let token_json : serde_json:: map:: Map < _ , _ > = token_map
110
+ . iter ( )
111
+ . map ( |( asset_id, amount) | ( format ! ( "{}" , asset_id) , serde_json:: value:: Value :: String ( format ! ( "{}" , amount) ) ) )
112
+ . collect ( ) ;
113
+
114
+ ( format ! ( "{}" , principal) , serde_json:: value:: Value :: Object ( token_json) )
115
+ } )
116
+ . collect ( ) ;
117
+
118
+ let assets : serde_json:: map:: Map < _ , _ > = self . asset_map
119
+ . iter ( )
120
+ . map ( |( principal, nft_map) | {
121
+ let nft_json : serde_json:: map:: Map < _ , _ > = nft_map
122
+ . iter ( )
123
+ . map ( |( asset_id, nft_values) | {
124
+ let nft_array = nft_values
125
+ . iter ( )
126
+ . map ( |nft_value| serde_json:: value:: Value :: String ( format ! ( "{}" , nft_value) ) )
127
+ . collect ( ) ;
128
+
129
+ ( format ! ( "{}" , asset_id) , serde_json:: value:: Value :: Array ( nft_array) )
130
+ } )
131
+ . collect ( ) ;
132
+
133
+ ( format ! ( "{}" , principal) , serde_json:: value:: Value :: Object ( nft_json) )
134
+ } )
135
+ . collect ( ) ;
136
+
137
+ json ! ( {
138
+ "stx" : stx,
139
+ "burns" : burns,
140
+ "tokens" : tokens,
141
+ "assets" : assets
142
+ } )
143
+ }
144
+ }
145
+
146
+
94
147
#[ derive( Debug , Clone ) ]
95
148
pub struct EventBatch {
96
149
pub events : Vec < StacksTransactionEvent > ,
@@ -640,6 +693,10 @@ impl<'a> OwnedEnvironment<'a> {
640
693
Ok ( ( asset_map, event_batch) )
641
694
}
642
695
696
+ pub fn get_cost_total ( & self ) -> ExecutionCost {
697
+ self . context . cost_track . get_total ( )
698
+ }
699
+
643
700
/// Destroys this environment, returning ownership of its database reference.
644
701
/// If the context wasn't top-level (i.e., it had uncommitted data), return None,
645
702
/// because the database is not guaranteed to be in a sane state.
0 commit comments