mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-08-23 08:30:51 +00:00
Fix merge conflicts
This commit is contained in:
@@ -202,6 +202,35 @@ Account.prototype.lines = function (callback) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve this account's single trust line.
|
||||
*
|
||||
* @param {string} currency Currency
|
||||
* @param {string} address Ripple address
|
||||
* @param {function (err, line)} callback Called with the result
|
||||
* @returns {Account}
|
||||
*/
|
||||
|
||||
Account.prototype.line = function (currency,address,callback) {
|
||||
var self = this,
|
||||
found,
|
||||
callback = typeof callback === 'function' ? callback : function(){};
|
||||
|
||||
self.lines(function(err,data){
|
||||
data.lines.forEach(function(line){
|
||||
if (address === line.account && currency === line.currency) {
|
||||
callback(null,line);
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (!found)
|
||||
callback();
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Notify object of a relevant transaction.
|
||||
*
|
||||
|
||||
@@ -37,9 +37,11 @@ function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pay
|
||||
function listenerAdded(type, listener) {
|
||||
if (~OrderBook.subscribe_events.indexOf(type)) {
|
||||
if (!self._subs && self._remote._connected) {
|
||||
self._subs += 1;
|
||||
self._subscribe();
|
||||
} else {
|
||||
self._subs += 1;
|
||||
}
|
||||
self._subs += 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,15 +59,8 @@ function OrderBook(remote, currency_gets, issuer_gets, currency_pays, issuer_pay
|
||||
}
|
||||
};
|
||||
|
||||
this.on('removeListener', listenerRemoved);
|
||||
|
||||
function remoteConnected() {
|
||||
if (self._subs) {
|
||||
self._subscribe();
|
||||
}
|
||||
};
|
||||
|
||||
this._remote.on('connect', remoteConnected);
|
||||
// ST: This *should* call _prepareSubscribe.
|
||||
this._remote.on('prepare_subscribe', this._subscribe.bind(this));
|
||||
|
||||
function remoteDisconnected() {
|
||||
self._sync = false;
|
||||
@@ -90,19 +85,43 @@ OrderBook.subscribe_events = ['transaction', 'model', 'trade'];
|
||||
*/
|
||||
OrderBook.prototype._subscribe = function () {
|
||||
var self = this;
|
||||
var request = self._remote.request_subscribe();
|
||||
request.books([ self.to_json() ], true);
|
||||
request.callback(function(err, res) {
|
||||
if (err) {
|
||||
// XXX What now?
|
||||
} else {
|
||||
if (self.is_valid() && self._subs) {
|
||||
var request = this._remote.request_subscribe();
|
||||
request.addBook(self.to_json(), true);
|
||||
request.once('success', function(res) {
|
||||
self._sync = true;
|
||||
self._offers = res.offers;
|
||||
self.emit('model', self._offers);
|
||||
}
|
||||
});
|
||||
});
|
||||
request.once('error', function(err) {
|
||||
// XXX What now?
|
||||
});
|
||||
request.request();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds this orderbook to a subscription request.
|
||||
|
||||
// ST: Currently this is not working because the server cannot give snapshots
|
||||
// for more than one order book in the same subscribe message.
|
||||
|
||||
OrderBook.prototype._prepareSubscribe = function (request) {
|
||||
var self = this;
|
||||
if (self.is_valid() && self._subs) {
|
||||
request.addBook(self.to_json(), true);
|
||||
request.once('success', function(res) {
|
||||
self._sync = true;
|
||||
self._offers = res.offers;
|
||||
self.emit('model', self._offers);
|
||||
});
|
||||
request.once('error', function(err) {
|
||||
// XXX What now?
|
||||
});
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
OrderBook.prototype.to_json = function () {
|
||||
var json = {
|
||||
taker_gets: {
|
||||
|
||||
@@ -275,42 +275,49 @@ Request.prototype.rtAccounts = function(accounts) {
|
||||
};
|
||||
|
||||
Request.prototype.books = function(books, snapshot) {
|
||||
var processedBooks = [ ];
|
||||
// Reset list of books (this method overwrites the current list)
|
||||
this.message.books = [ ];
|
||||
|
||||
for (var i = 0, l = books.length; i < l; i++) {
|
||||
var book = books[i];
|
||||
var json = { };
|
||||
|
||||
function processSide(side) {
|
||||
if (!book[side]) {
|
||||
throw new Error('Missing ' + side);
|
||||
}
|
||||
|
||||
var obj = json[side] = {
|
||||
currency: Currency.json_rewrite(book[side].currency)
|
||||
};
|
||||
if (obj.currency !== 'XRP') {
|
||||
obj.issuer = UInt160.json_rewrite(book[side].issuer);
|
||||
}
|
||||
}
|
||||
|
||||
processSide('taker_gets');
|
||||
processSide('taker_pays');
|
||||
|
||||
if (snapshot) {
|
||||
json.snapshot = true;
|
||||
}
|
||||
|
||||
if (book.both) {
|
||||
json.both = true;
|
||||
}
|
||||
|
||||
processedBooks.push(json);
|
||||
this.addBook(book, snapshot);
|
||||
}
|
||||
|
||||
this.message.books = processedBooks;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Request.prototype.addBook = function (book, snapshot) {
|
||||
if (!Array.isArray(this.message.books)) {
|
||||
this.message.books = [];
|
||||
}
|
||||
|
||||
var json = { };
|
||||
|
||||
function processSide(side) {
|
||||
if (!book[side]) {
|
||||
throw new Error('Missing ' + side);
|
||||
}
|
||||
|
||||
var obj = json[side] = {
|
||||
currency: Currency.json_rewrite(book[side].currency)
|
||||
};
|
||||
if (obj.currency !== 'XRP') {
|
||||
obj.issuer = UInt160.json_rewrite(book[side].issuer);
|
||||
}
|
||||
}
|
||||
|
||||
processSide('taker_gets');
|
||||
processSide('taker_pays');
|
||||
|
||||
if (snapshot) {
|
||||
json.snapshot = true;
|
||||
}
|
||||
|
||||
if (book.both) {
|
||||
json.both = true;
|
||||
}
|
||||
|
||||
this.message.books.push(json);
|
||||
};
|
||||
|
||||
exports.Request = Request;
|
||||
|
||||
@@ -222,6 +222,20 @@ Transaction.prototype.addSubmittedTxnID = function(hash) {
|
||||
}
|
||||
};
|
||||
|
||||
Transaction.prototype.findResultInCache = function(cache) {
|
||||
var cached;
|
||||
|
||||
for (var i = this.submittedTxnIDs.length - 1; i >= 0; i--) {
|
||||
var hash = this.submittedTxnIDs[i];
|
||||
cached = cache[hash];
|
||||
if (cached != null) {
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
return cached;
|
||||
};
|
||||
|
||||
Transaction.prototype.hash = function(prefix, as_uint256) {
|
||||
if (typeof prefix === 'string') {
|
||||
if (typeof hashprefixes[prefix] === 'undefined') {
|
||||
|
||||
@@ -36,9 +36,8 @@ function TransactionManager(account) {
|
||||
|
||||
self._sequenceCache[sequence] = transaction;
|
||||
|
||||
// ND: we need to check against all submissions ids
|
||||
// ND: we need to check against all submissions IDs
|
||||
var pending = self._pending.getBySubmissions(hash);
|
||||
// var pending = self._pending.get('_hash', hash);
|
||||
|
||||
self._remote._trace('transactionmanager: transaction_received:', transaction.transaction);
|
||||
|
||||
@@ -215,7 +214,7 @@ TransactionManager.prototype._resubmit = function(ledgers, pending) {
|
||||
return;
|
||||
}
|
||||
|
||||
var hashCached = self._cache[pending._hash];
|
||||
var hashCached = pending.findResultInCache(self._cache);
|
||||
self._remote._trace('transactionmanager: resubmit:', pending.tx_json);
|
||||
|
||||
if (hashCached) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ----- for secp256k1 ------
|
||||
|
||||
// Overwrite NIST-P256 with secp256k1 so we're on even footing
|
||||
// Overwrite NIST-P256 with secp256k1
|
||||
sjcl.ecc.curves.c256 = new sjcl.ecc.curve(
|
||||
sjcl.bn.pseudoMersennePrime(256, [[0,-1],[4,-1],[6,-1],[7,-1],[8,-1],[9,-1],[32,-1]]),
|
||||
"0x14551231950b75fc4402da1722fc9baee",
|
||||
|
||||
Reference in New Issue
Block a user