Skip to content

Commit

Permalink
make orderbook use Remote.getLedgerSequenceSync
Browse files Browse the repository at this point in the history
fix some variables naming in src/api
  • Loading branch information
darkdarkdragon committed Sep 30, 2015
1 parent d573c57 commit ac78171
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/api/ledger/transaction.js
Expand Up @@ -91,18 +91,17 @@ function getTransactionAsync(identifier: string, options: TransactionOptions,


function maxLedgerGetter(error_?: Error, tx?: Object) {
remote.getLedgerSequence(function(err?, seq: number) {
_.noop(err);
const maxLedgerVersion = options.maxLedgerVersion || seq;
this.getLedgerVersion().then((version) => {
const maxLedgerVersion = options.maxLedgerVersion || version;
callbackWrapper(error_, tx, maxLedgerVersion);
});
}, callbackWrapper);
}

async.waterfall([
_.partial(remote.requestTx.bind(remote),
{hash: identifier, binary: false}),
_.partial(attachTransactionDate, remote)
], maxLedgerGetter);
], maxLedgerGetter.bind(this));
}

function getTransaction(identifier: string,
Expand Down
7 changes: 3 additions & 4 deletions src/api/ledger/utils.js
Expand Up @@ -120,10 +120,9 @@ function getLedgerOptionsWithLedgerVersion(account: string, options: Object,
) {
callback(null, account, options);
} else {
this.remote.getLedgerSequence(common.convertErrors((err, sequence) => {
callback(err, account, _.assign({}, options, {
ledgerVersion: sequence}));
}));
this.getLedgerVersion().then((version) => {
callback(null, account, _.assign({}, options, {ledgerVersion: version}));
}, callback);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/transaction/utils.js
Expand Up @@ -59,8 +59,8 @@ function prepareTransaction(transaction: any, remote: any, instructions: any,
} else {
const offset = instructions.maxLedgerVersionOffset !== undefined ?
parseInt(instructions.maxLedgerVersionOffset, 10) : 3;
remote.getLedgerSequence((error, seq) => {
txJSON.LastLedgerSequence = seq + offset;
remote.getLedgerSequence((error, ledgerVersion) => {
txJSON.LastLedgerSequence = ledgerVersion + offset;
callback_(error);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/orderbook.js
Expand Up @@ -846,7 +846,7 @@ OrderBook.prototype.onTransaction = function(transaction) {


if (--this._transactionsLeft === 0 && !this._waitingForOffers) {
const lastClosedLedger = this._remote.getLedgerSequence();
const lastClosedLedger = this._remote.getLedgerSequenceSync();
if (this._isAutobridgeable) {
if (this._canRunAutobridgeCalc()) {
if (this._legOneBook._lastUpdateLedgerSequence === lastClosedLedger ||
Expand Down Expand Up @@ -1080,7 +1080,7 @@ OrderBook.prototype.notify = function(transaction) {

this.emit('transaction', transaction);

this._lastUpdateLedgerSequence = this._remote.getLedgerSequence();
this._lastUpdateLedgerSequence = this._remote.getLedgerSequenceSync();

if (!takerGetsTotal.is_zero()) {
this.emit('trade', takerPaysTotal, takerGetsTotal);
Expand Down

0 comments on commit ac78171

Please sign in to comment.