Browse Source

fixes for some bugs in the recent caching functionality

fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
f3474c7b44
  1. 4
      app/api/coreApi.js
  2. 12
      app/api/rpcApi.js

4
app/api/coreApi.js

@ -38,6 +38,9 @@ function tryCacheThenRpcApi(cache, cacheKey, cacheMaxAge, rpcApiFunction) {
cache.set(cacheKey, result, cacheMaxAge);
resolve(result);
} else {
resolve(result);
}
});
}
@ -181,7 +184,6 @@ function getBlocksByHeight(blockHeights) {
var combinedBlocks = [];
if (blockHeightsNotInCache.length > 0) {
rpcApi.getBlocksByHeight(blockHeightsNotInCache).then(function(queriedBlocks) {
console.log("qbs: " + queriedBlocks);
var queriedBlocksCurrentIndex = 0;
for (var i = 0; i < blockHeights.length; i++) {
if (blocksByIndex.hasOwnProperty(i)) {

12
app/api/rpcApi.js

@ -31,10 +31,10 @@ function getBlockByHeight(blockHeight) {
return new Promise(function(resolve, reject) {
getBlocksByHeight([blockHeight]).then(function(results) {
if (results && results.length > 0) {
resolve({ success:true, getblock:results[0] });
resolve(results[0]);
} else {
resolve({ success:false });
resolve(null);
}
}).catch(function(err) {
reject(err);
@ -85,6 +85,8 @@ function getBlockByHash(blockHash) {
}
function getBlocksByHash(blockHashes) {
console.log("rpc.getBlocksByHash: " + blockHashes);
return new Promise(function(resolve, reject) {
var batch = [];
for (var i = 0; i < blockHashes.length; i++) {
@ -121,8 +123,12 @@ function getRawTransaction(txid) {
return new Promise(function(resolve, reject) {
getRawTransactions([txid]).then(function(results) {
if (results && results.length > 0) {
resolve(results[0]);
if (results[0].txid) {
resolve(results[0]);
} else {
resolve(null);
}
} else {
resolve(null);
}

Loading…
Cancel
Save