@@ -32,7 +32,7 @@ use rusqlite::{Connection, OpenFlags, NO_PARAMS};
32
32
use address:: c32:: c32_address;
33
33
use chainstate:: stacks:: index:: { storage:: TrieFileStorage , MarfTrieId } ;
34
34
use util:: db:: FromColumn ;
35
- use util:: hash:: Sha512Trunc256Sum ;
35
+ use util:: hash:: { bytes_to_hex , Sha512Trunc256Sum } ;
36
36
37
37
use util:: log;
38
38
use vm:: ContractName ;
@@ -65,6 +65,8 @@ use serde::Serialize;
65
65
use serde_json:: json;
66
66
use util:: strings:: StacksString ;
67
67
68
+ use codec:: StacksMessageCodec ;
69
+
68
70
use std:: convert:: TryFrom ;
69
71
70
72
use crate :: clarity_vm:: database:: marf:: MarfedKV ;
@@ -766,6 +768,14 @@ pub fn add_assets(result: &mut serde_json::Value, assets: bool, asset_map: Asset
766
768
}
767
769
}
768
770
771
+ pub fn add_serialized_output ( result : & mut serde_json:: Value , value : Value ) {
772
+ let result_raw = {
773
+ let bytes = ( & value) . serialize_to_vec ( ) ;
774
+ bytes_to_hex ( & bytes)
775
+ } ;
776
+ result[ "output_serialized" ] = serde_json:: to_value ( result_raw. as_str ( ) ) . unwrap ( ) ;
777
+ }
778
+
769
779
/// Returns (process-exit-code, Option<json-output>)
770
780
pub fn invoke_command ( invoked_by : & str , args : & [ String ] ) -> ( i32 , Option < serde_json:: Value > ) {
771
781
if args. len ( ) < 1 {
@@ -1158,9 +1168,11 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1158
1168
match result_and_cost {
1159
1169
( Ok ( result) , cost) => {
1160
1170
let mut result_json = json ! ( {
1161
- "output" : serde_json:: to_value( & result) . unwrap( )
1171
+ "output" : serde_json:: to_value( & result) . unwrap( ) ,
1172
+ "success" : true ,
1162
1173
} ) ;
1163
1174
1175
+ add_serialized_output ( & mut result_json, result) ;
1164
1176
add_costs ( & mut result_json, costs, cost) ;
1165
1177
1166
1178
( 0 , Some ( result_json) )
@@ -1169,7 +1181,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1169
1181
let mut result_json = json ! ( {
1170
1182
"error" : {
1171
1183
"runtime" : serde_json:: to_value( & format!( "{}" , error) ) . unwrap( )
1172
- }
1184
+ } ,
1185
+ "success" : false ,
1173
1186
} ) ;
1174
1187
1175
1188
add_costs ( & mut result_json, costs, cost) ;
@@ -1208,9 +1221,11 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1208
1221
match result_and_cost {
1209
1222
( Ok ( result) , cost) => {
1210
1223
let mut result_json = json ! ( {
1211
- "output" : serde_json:: to_value( & result) . unwrap( )
1224
+ "output" : serde_json:: to_value( & result) . unwrap( ) ,
1225
+ "success" : true ,
1212
1226
} ) ;
1213
1227
1228
+ add_serialized_output ( & mut result_json, result) ;
1214
1229
add_costs ( & mut result_json, costs, cost) ;
1215
1230
1216
1231
( 0 , Some ( result_json) )
@@ -1219,7 +1234,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1219
1234
let mut result_json = json ! ( {
1220
1235
"error" : {
1221
1236
"runtime" : serde_json:: to_value( & format!( "{}" , error) ) . unwrap( )
1222
- }
1237
+ } ,
1238
+ "success" : false ,
1223
1239
} ) ;
1224
1240
1225
1241
add_costs ( & mut result_json, costs, cost) ;
@@ -1278,9 +1294,11 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1278
1294
match result_and_cost {
1279
1295
( Ok ( result) , cost) => {
1280
1296
let mut result_json = json ! ( {
1281
- "output" : serde_json:: to_value( & result) . unwrap( )
1297
+ "output" : serde_json:: to_value( & result) . unwrap( ) ,
1298
+ "success" : true ,
1282
1299
} ) ;
1283
1300
1301
+ add_serialized_output ( & mut result_json, result) ;
1284
1302
add_costs ( & mut result_json, costs, cost) ;
1285
1303
1286
1304
( 0 , Some ( result_json) )
@@ -1289,7 +1307,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1289
1307
let mut result_json = json ! ( {
1290
1308
"error" : {
1291
1309
"runtime" : serde_json:: to_value( & format!( "{}" , error) ) . unwrap( )
1292
- }
1310
+ } ,
1311
+ "success" : false ,
1293
1312
} ) ;
1294
1313
1295
1314
add_costs ( & mut result_json, costs, cost) ;
@@ -1480,8 +1499,10 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1480
1499
let mut result = json ! ( {
1481
1500
"message" : "Transaction executed and committed." ,
1482
1501
"output" : serde_json:: to_value( & data. data) . unwrap( ) ,
1502
+ "success" : true ,
1483
1503
} ) ;
1484
1504
1505
+ add_serialized_output ( & mut result, * data. data ) ;
1485
1506
add_costs ( & mut result, costs, cost) ;
1486
1507
add_assets ( & mut result, assets, asset_map) ;
1487
1508
@@ -1496,9 +1517,12 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1496
1517
let mut result = json ! ( {
1497
1518
"message" : "Aborted." ,
1498
1519
"output" : serde_json:: to_value( & data. data) . unwrap( ) ,
1520
+ "success" : false ,
1499
1521
} ) ;
1500
1522
1501
1523
add_costs ( & mut result, costs, cost) ;
1524
+ add_serialized_output ( & mut result, * data. data ) ;
1525
+ add_assets ( & mut result, assets, asset_map) ;
1502
1526
1503
1527
( 0 , Some ( result) )
1504
1528
}
@@ -1507,7 +1531,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1507
1531
"error" : {
1508
1532
"runtime" : "Expected a ResponseType result from transaction." ,
1509
1533
"output" : serde_json:: to_value( & x) . unwrap( )
1510
- }
1534
+ } ,
1535
+ "success" : false ,
1511
1536
} ) ;
1512
1537
( 1 , Some ( result) )
1513
1538
}
@@ -1517,7 +1542,8 @@ pub fn invoke_command(invoked_by: &str, args: &[String]) -> (i32, Option<serde_j
1517
1542
"error" : {
1518
1543
"runtime" : "Transaction execution error." ,
1519
1544
"error" : serde_json:: to_value( & format!( "{}" , error) ) . unwrap( )
1520
- }
1545
+ } ,
1546
+ "success" : false ,
1521
1547
} ) ;
1522
1548
( 1 , Some ( result) )
1523
1549
}
0 commit comments