Optional account_tx binary parsing

This commit is contained in:
wltsmrz
2014-05-05 15:05:02 -07:00
parent 473d8a8d8c
commit a48a25e236

View File

@@ -247,6 +247,7 @@ function Remote(opts, trace) {
Object.keys(tx).forEach(function(prop) { Object.keys(tx).forEach(function(prop) {
switch (prop) { switch (prop) {
case 'secret':
case 'submittedIDs': case 'submittedIDs':
case 'clientID': case 'clientID':
case 'submitIndex': case 'submitIndex':
@@ -969,12 +970,21 @@ Remote.prototype.requestAccountOffers = function(accountID, account_index, ledge
limit: integer // optional limit: integer // optional
*/ */
Remote.prototype.requestAccountTransactions =
Remote.prototype.requestAccountTx = function(options, callback) { Remote.prototype.requestAccountTx = function(options, callback) {
// XXX Does this require the server to be trusted? // XXX Does this require the server to be trusted?
//utils.assert(this.trusted); //utils.assert(this.trusted);
var request = new Request(this, 'account_tx'); var request = new Request(this, 'account_tx');
if (options.min_ledger !== void(0)) {
options.ledger_index_min = options.min_ledger;
}
if (options.max_ledger !== void(0)) {
options.ledger_index_max = options.max_ledger;
}
Object.keys(options).forEach(function(o) { Object.keys(options).forEach(function(o) {
switch (o) { switch (o) {
case 'account': case 'account':
@@ -1006,7 +1016,7 @@ Remote.prototype.requestAccountTx = function(options, callback) {
var SerializedObject = require('./serializedobject').SerializedObject; var SerializedObject = require('./serializedobject').SerializedObject;
function parseBinary(transaction) { function parseBinaryTransaction(transaction) {
var tx = { validated: transaction.validated }; var tx = { validated: transaction.validated };
tx.meta = new SerializedObject(transaction.meta).to_json(); tx.meta = new SerializedObject(transaction.meta).to_json();
tx.tx = new SerializedObject(transaction.tx_blob).to_json(); tx.tx = new SerializedObject(transaction.tx_blob).to_json();
@@ -1028,8 +1038,8 @@ Remote.prototype.requestAccountTx = function(options, callback) {
self.removeAllListeners('success'); self.removeAllListeners('success');
self.once('success', function(res) { self.once('success', function(res) {
if (options.binary) { if (options.parseBinary) {
res.transactions = res.transactions.map(parseBinary); res.transactions = res.transactions.map(parseBinaryTransaction);
} }
if (fn !== Boolean) { if (fn !== Boolean) {
@@ -1061,6 +1071,10 @@ Remote.prototype.requestAccountTx = function(options, callback) {
request.filter = accountTxFilter; request.filter = accountTxFilter;
if (typeof options.parseBinary !== 'boolean') {
options.parseBinary = true;
}
if (options.binary || (options.map || options.reduce)) { if (options.binary || (options.map || options.reduce)) {
options.filter = options.filter || Boolean; options.filter = options.filter || Boolean;
} }
@@ -1419,12 +1433,6 @@ Remote.prototype.accountSeqCache = function(account, ledger, callback) {
var account_info = this.accounts[account]; var account_info = this.accounts[account];
var request = account_info.caching_seq_request; var request = account_info.caching_seq_request;
if (!request) {
// console.log('starting: %s', account);
request = this.requestLedgerEntry('account_root');
request.accountRoot(account);
request.ledgerChoose(ledger);
function accountRootSuccess(message) { function accountRootSuccess(message) {
delete account_info.caching_seq_request; delete account_info.caching_seq_request;
@@ -1436,8 +1444,6 @@ Remote.prototype.accountSeqCache = function(account, ledger, callback) {
request.emit('success_account_seq_cache', message); request.emit('success_account_seq_cache', message);
}; };
request.once('success', accountRootSuccess);
function accountRootError(message) { function accountRootError(message) {
// console.log('error: %s', account); // console.log('error: %s', account);
delete account_info.caching_seq_request; delete account_info.caching_seq_request;
@@ -1445,6 +1451,12 @@ Remote.prototype.accountSeqCache = function(account, ledger, callback) {
request.emit('error_account_seq_cache', message); request.emit('error_account_seq_cache', message);
}; };
if (!request) {
// console.log('starting: %s', account);
request = this.requestLedgerEntry('account_root');
request.accountRoot(account);
request.ledgerChoose(ledger);
request.once('success', accountRootSuccess);
request.once('error', accountRootError); request.once('error', accountRootError);
account_info.caching_seq_request = request; account_info.caching_seq_request = request;