Added jsonl output to stream in order to better delimit on client.
This commit is contained in:
parent
230f3681bd
commit
9a7b39230f
@ -609,7 +609,7 @@ WalletService.prototype._endpointGetTransactions = function() {
|
||||
var rs = new Readable;
|
||||
|
||||
transactions.forEach(function(transaction) {
|
||||
rs.push(JSON.stringify(self._formatTransaction(transaction)));
|
||||
rs.push(utils.toJSONL(self._formatTransaction(transaction)));
|
||||
});
|
||||
|
||||
rs.push(null);
|
||||
@ -626,6 +626,7 @@ WalletService.prototype._formatTransactions = function(txs) {
|
||||
|
||||
WalletService.prototype._formatTransaction = function(tx) {
|
||||
var obj = tx.toObject();
|
||||
//jsonl parser will not allow newline characters here
|
||||
for(var i = 0; i < tx.inputs.length; i++) {
|
||||
obj.inputs[i].inputSatoshis = tx.__inputValues[i];
|
||||
}
|
||||
|
||||
@ -752,4 +752,14 @@ exports.hasRequiredArgsForEncoding = function(args) {
|
||||
return true;
|
||||
};
|
||||
|
||||
exports.toJSONL = function(obj) {
|
||||
//this should be a standard obj that JSON.stringify will handle
|
||||
//general newlines within key values or data values are not permitted
|
||||
//this is intended to be used for bitcoin tx's that don't have newlines
|
||||
//within keys or values themselves
|
||||
var str = JSON.stringify(obj);
|
||||
str = str.replace(/\n/g, '');
|
||||
return str + '\n';
|
||||
};
|
||||
|
||||
module.exports = exports;
|
||||
|
||||
15
test/services/wallet-api/utils.js
Normal file
15
test/services/wallet-api/utils.js
Normal file
@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var should = require('chai').should();
|
||||
var utils = require('../../../lib/services/wallet-api/utils');
|
||||
|
||||
describe('Wallet-Api service utils', function() {
|
||||
it('should create jsonl from obj', function() {
|
||||
var obj = {
|
||||
1: 'test',
|
||||
'foo bar': 'test1',
|
||||
array: [1,2,'test']
|
||||
};
|
||||
utils.toJSONL(obj).should.equal('{"1":"test","foo bar":"test1","array":[1,2,"test"]}\n');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user