mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
JS: Fix transparent caching of ledger entries.
This commit is contained in:
committed by
Stefan Thomas
parent
8cb65c7d28
commit
0d52f87c8b
@@ -584,51 +584,63 @@ Remote.prototype.request_ledger_entry = function (type) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var request = new Request(this, 'ledger_entry');
|
var request = new Request(this, 'ledger_entry');
|
||||||
|
|
||||||
if (type)
|
// Transparent caching. When .request() is invoked, look in the Remote object for the result.
|
||||||
this.type = type;
|
// If not found, listen, cache result, and emit it.
|
||||||
|
//
|
||||||
// Transparent caching:
|
// Transparent caching:
|
||||||
this.request_default = this.request;
|
if ('account_root' === type) {
|
||||||
this.request = function () { // Intercept default request.
|
request.request_default = request.request;
|
||||||
if (self._ledger_hash) {
|
|
||||||
// XXX Add caching.
|
|
||||||
}
|
|
||||||
// else if (req.ledger_index)
|
|
||||||
// else if ('ripple_state' === this.type) // YYY Could be cached per ledger.
|
|
||||||
else if ('account_root' === this.type) {
|
|
||||||
var cache = self.ledgers.current.account_root;
|
|
||||||
|
|
||||||
if (!cache)
|
request.request = function () { // Intercept default request.
|
||||||
{
|
// .self = Remote
|
||||||
cache = self.ledgers.current.account_root = {};
|
// this = Request
|
||||||
}
|
|
||||||
|
|
||||||
var node = self.ledgers.current.account_root[request.message.account_root];
|
// console.log('request_ledger_entry: caught');
|
||||||
|
|
||||||
if (node) {
|
// if (self._ledger_hash) {
|
||||||
// Emulate fetch of ledger entry.
|
// // XXX Add caching.
|
||||||
self.emit('success', {
|
// }
|
||||||
// YYY Missing lots of fields.
|
// else if (req.ledger_index)
|
||||||
'node' : node,
|
// else if ('ripple_state' === request.type) // YYY Could be cached per ledger.
|
||||||
});
|
if ('account_root' === type) {
|
||||||
}
|
var cache = self.ledgers.current.account_root;
|
||||||
else {
|
|
||||||
// Was not cached.
|
|
||||||
|
|
||||||
// XXX Only allow with trusted mode. Must sync response with advance.
|
if (!cache)
|
||||||
switch (response.type) {
|
{
|
||||||
case 'account_root':
|
cache = self.ledgers.current.account_root = {};
|
||||||
request.on('success', function (message) {
|
|
||||||
// Cache node.
|
|
||||||
self.ledgers.current.account_root[message.node.Account] = message.node;
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// This type not cached.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.request_default();
|
var node = self.ledgers.current.account_root[request.message.account_root];
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
// Emulate fetch of ledger entry.
|
||||||
|
// console.log('request_ledger_entry: emulating');
|
||||||
|
request.emit('success', {
|
||||||
|
// YYY Missing lots of fields.
|
||||||
|
'node' : node,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Was not cached.
|
||||||
|
|
||||||
|
// XXX Only allow with trusted mode. Must sync response with advance.
|
||||||
|
switch (type) {
|
||||||
|
case 'account_root':
|
||||||
|
request.on('success', function (message) {
|
||||||
|
// Cache node.
|
||||||
|
// console.log('request_ledger_entry: caching');
|
||||||
|
self.ledgers.current.account_root[message.node.Account] = message.node;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// This type not cached.
|
||||||
|
// console.log('request_ledger_entry: non-cached type');
|
||||||
|
}
|
||||||
|
|
||||||
|
// console.log('request_ledger_entry: invoking');
|
||||||
|
request.request_default();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user