@@ -1037,6 +1037,52 @@ Remote.prototype.requestLedgerCurrent = function(callback) {
1037
1037
return new Request ( this , 'ledger_current' ) . callback ( callback ) ;
1038
1038
} ;
1039
1039
1040
+ /**
1041
+ * Request ledger_data
1042
+ *
1043
+ * Get the contents of a specified ledger
1044
+ *
1045
+ * @param {Object } options
1046
+ * @property {Boolean } [options.binary] - Flag which determines if rippled returns binary or parsed JSON
1047
+ * @property {String|Number } [options.ledger] - Hash or sequence of a ledger to get contents for
1048
+ * @property {Number } [options.limit] - Number of contents to retrieve from the ledger
1049
+ * @property {Function } callback
1050
+ *
1051
+ * @callback
1052
+ * @param {Error } error
1053
+ * @param {LedgerData } ledgerData
1054
+ *
1055
+ * @return {Request } request
1056
+ */
1057
+
1058
+ Remote . prototype . requestLedgerData = function ( options , callback ) {
1059
+ var request = new Request ( this , 'ledger_data' ) ;
1060
+
1061
+ request . message . binary = options . binary !== false ;
1062
+ request . selectLedger ( options . ledger ) ;
1063
+ request . message . limit = options . limit ;
1064
+
1065
+ request . once ( 'success' , function ( res ) {
1066
+ if ( options . binary === false ) {
1067
+ request . emit ( 'state' , res ) ;
1068
+ return ;
1069
+ }
1070
+
1071
+ async . mapSeries ( res . state , function ( ledgerData , next ) {
1072
+ async . setImmediate ( function ( ) {
1073
+ next ( null , Remote . parseBinaryLedgerData ( ledgerData ) ) ;
1074
+ } ) ;
1075
+ } , function ( err , state ) {
1076
+ res . state = state ;
1077
+ request . emit ( 'state' , res ) ;
1078
+ } ) ;
1079
+ } ) ;
1080
+
1081
+ request . callback ( callback , 'state' ) ;
1082
+
1083
+ return request ;
1084
+ } ;
1085
+
1040
1086
/**
1041
1087
* Request ledger_entry
1042
1088
*
@@ -1201,17 +1247,40 @@ Remote.prototype.requestTransactionEntry = function(hash, ledgerHash, callback)
1201
1247
/**
1202
1248
* Request tx
1203
1249
*
1204
- * @param {String } transaction hash
1250
+ * @param {Object|String } hash
1251
+ * @property {String } hash.hash - Transaction hash
1252
+ * @property {Boolean } [hash.binary=true] - Flag which determines if rippled returns binary or parsed JSON
1205
1253
* @param [Function] callback
1206
1254
* @return {Request } request
1207
1255
*/
1208
1256
1209
1257
Remote . prototype . requestTransaction =
1210
1258
Remote . prototype . requestTx = function ( hash , callback ) {
1259
+ var options ;
1260
+
1261
+ if ( typeof hash === 'string' ) {
1262
+ options = {
1263
+ hash : hash
1264
+ }
1265
+ } else {
1266
+ options = hash ;
1267
+ }
1268
+
1211
1269
var request = new Request ( this , 'tx' ) ;
1212
1270
1213
- request . message . transaction = hash ;
1214
- request . callback ( callback ) ;
1271
+ request . message . binary = options . binary !== false ;
1272
+ request . message . transaction = options . hash ;
1273
+
1274
+ request . once ( 'success' , function ( res ) {
1275
+ if ( options . binary === false ) {
1276
+ request . emit ( 'transaction' , res ) ;
1277
+ return ;
1278
+ }
1279
+
1280
+ request . emit ( 'transaction' , Remote . parseBinaryTransaction ( res ) ) ;
1281
+ } ) ;
1282
+
1283
+ request . callback ( callback , 'transaction' ) ;
1215
1284
1216
1285
return request ;
1217
1286
} ;
@@ -1387,16 +1456,15 @@ Remote.prototype.requestAccountOffers = function(options, callback) {
1387
1456
* Request account_tx
1388
1457
*
1389
1458
* @param {Object } options
1390
- *
1391
- * @param {String } account
1392
- * @param [Number] ledger_index_min defaults to -1 if ledger_index_max is specified.
1393
- * @param [Number] ledger_index_max defaults to -1 if ledger_index_min is specified.
1394
- * @param [Boolean] binary, defaults to false
1395
- * @param [Boolean] parseBinary, defaults to true
1396
- * @param [Boolean] count, defaults to false
1397
- * @param [Boolean] descending, defaults to false
1398
- * @param [Number] offset, defaults to 0
1399
- * @param [Number] limit
1459
+ * @property {String } options.account
1460
+ * @property {Number } options.ledger_index_min - Defaults to -1 if ledger_index_max is specified.
1461
+ * @property {Number } options.ledger_index_max - Defaults to -1 if ledger_index_min is specified.
1462
+ * @property {Boolean } options.binary - Defaults to true
1463
+ * @property {Boolean } options.parseBinary - Defaults to true
1464
+ * @property {Boolean } options.count - Defaults to false
1465
+ * @property {Boolean } options.descending - Defaults to false
1466
+ * @property {Number } options.offset - Defaults to 0
1467
+ * @property {Number } options.limit
1400
1468
*
1401
1469
* @param [Function] callback
1402
1470
* @return {Request }
@@ -1409,6 +1477,8 @@ Remote.prototype.requestAccountTx = function(options, callback) {
1409
1477
1410
1478
var request = new Request ( this , 'account_tx' ) ;
1411
1479
1480
+ options . binary = options . binary !== false ;
1481
+
1412
1482
if ( options . min_ledger !== void ( 0 ) ) {
1413
1483
options . ledger_index_min = options . min_ledger ;
1414
1484
}
@@ -1448,7 +1518,7 @@ Remote.prototype.requestAccountTx = function(options, callback) {
1448
1518
1449
1519
async . mapSeries ( res . transactions , function ( transaction , next ) {
1450
1520
async . setImmediate ( function ( ) {
1451
- next ( null , Remote . parseBinaryTransaction ( transaction ) ) ;
1521
+ next ( null , Remote . parseBinaryAccountTransaction ( transaction ) ) ;
1452
1522
} ) ;
1453
1523
} , function ( err , transactions ) {
1454
1524
res . transactions = transactions ;
@@ -1466,22 +1536,71 @@ Remote.prototype.requestAccountTx = function(options, callback) {
1466
1536
* @return {Transaction }
1467
1537
*/
1468
1538
1469
- Remote . parseBinaryTransaction = function ( transaction ) {
1539
+ Remote . parseBinaryAccountTransaction = function ( transaction ) {
1470
1540
var tx_obj = new SerializedObject ( transaction . tx_blob ) ;
1471
- var meta = new SerializedObject ( transaction . meta ) ;
1541
+ var tx_obj_json = tx_obj . to_json ( ) ;
1542
+ var meta = new SerializedObject ( transaction . meta ) . to_json ( ) ;
1472
1543
1473
1544
var tx_result = {
1474
- validated : transaction . validated ,
1475
- ledger_index : transaction . ledger_index
1545
+ validated : transaction . validated
1476
1546
} ;
1477
1547
1478
- tx_result . meta = meta . to_json ( ) ;
1479
- tx_result . tx = tx_obj . to_json ( ) ;
1548
+ tx_result . meta = meta ;
1549
+ tx_result . tx = tx_obj_json ;
1480
1550
tx_result . tx . hash = tx_obj . hash ( hashprefixes . HASH_TX_ID ) . to_hex ( ) ;
1551
+ tx_result . tx . ledger_index = transaction . ledger_index ;
1552
+ tx_result . tx . inLedger = transaction . ledger_index ;
1553
+
1554
+ if ( typeof meta . DeliveredAmount === 'object' ) {
1555
+ tx_result . meta . delivered_amount = meta . DeliveredAmount ;
1556
+ } else if ( typeof tx_obj_json . Amount === 'string' || typeof tx_obj_json . Amount === 'object' ) {
1557
+ tx_result . meta . delivered_amount = tx_obj_json . Amount ;
1558
+ }
1559
+
1560
+ return tx_result ;
1561
+ } ;
1562
+
1563
+ Remote . parseBinaryTransaction = function ( transaction ) {
1564
+ var tx_obj = new SerializedObject ( transaction . tx ) . to_json ( ) ;
1565
+ var meta = new SerializedObject ( transaction . meta ) . to_json ( ) ;
1566
+
1567
+ var tx_result = tx_obj ;
1568
+
1569
+ tx_result . date = transaction . date ;
1570
+ tx_result . hash = transaction . hash ;
1571
+ tx_result . inLedger = transaction . inLedger ;
1572
+ tx_result . ledger_index = transaction . ledger_index ;
1573
+ tx_result . meta = meta ;
1574
+ tx_result . validated = transaction . validated ;
1575
+
1576
+ if ( typeof meta . DeliveredAmount === 'object' ) {
1577
+ tx_result . meta . delivered_amount = meta . DeliveredAmount ;
1578
+ } else if ( typeof tx_obj . Amount === 'string' || typeof tx_obj . Amount === 'object' ) {
1579
+ tx_result . meta . delivered_amount = tx_obj . Amount ;
1580
+ }
1481
1581
1482
1582
return tx_result ;
1483
1583
} ;
1484
1584
1585
+ /**
1586
+ * Parse binary ledger state data
1587
+ *
1588
+ * @param {Object } ledgerData
1589
+ * @property {String } ledgerData.data
1590
+ * @property {String } ledgerData.index
1591
+ *
1592
+ * @return {State }
1593
+ */
1594
+
1595
+ Remote . parseBinaryLedgerData = function ( ledgerData ) {
1596
+ var data = new SerializedObject ( ledgerData . data ) ;
1597
+
1598
+ var state = data . to_json ( ) ;
1599
+ state . index = ledgerData . index ;
1600
+
1601
+ return state ;
1602
+ } ;
1603
+
1485
1604
/**
1486
1605
* Request the overall transaction history.
1487
1606
*
0 commit comments