Browse Source

- fix for genesis block bug introduced with recent reorganization

- some minor armor
fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
4281496b98
  1. 4
      app/api/coreApi.js
  2. 45
      app/api/rpcApi.js

4
app/api/coreApi.js

@ -356,7 +356,7 @@ function getBlockByHashWithTransactions(blockHash, txLimit, txOffset) {
for (var i = 0; i < transactions.length; i++) { for (var i = 0; i < transactions.length; i++) {
var transaction = transactions[i]; var transaction = transactions[i];
if (transaction) { if (transaction && transaction.vin) {
for (var j = 0; j < Math.min(maxInputsTracked, transaction.vin.length); j++) { for (var j = 0; j < Math.min(maxInputsTracked, transaction.vin.length); j++) {
if (transaction.vin[j].txid) { if (transaction.vin[j].txid) {
vinTxids.push(transaction.vin[j].txid); vinTxids.push(transaction.vin[j].txid);
@ -376,11 +376,13 @@ function getBlockByHashWithTransactions(blockHash, txLimit, txOffset) {
transactions.forEach(function(tx) { transactions.forEach(function(tx) {
txInputsByTransaction[tx.txid] = []; txInputsByTransaction[tx.txid] = [];
if (tx && tx.vin) {
for (var i = 0; i < Math.min(maxInputsTracked, tx.vin.length); i++) { for (var i = 0; i < Math.min(maxInputsTracked, tx.vin.length); i++) {
if (vinTxById[tx.vin[i].txid]) { if (vinTxById[tx.vin[i].txid]) {
txInputsByTransaction[tx.txid].push(vinTxById[tx.vin[i].txid]); txInputsByTransaction[tx.txid].push(vinTxById[tx.vin[i].txid]);
} }
} }
}
resolve({ getblock:block, transactions:transactions, txInputsByTransaction:txInputsByTransaction }); resolve({ getblock:block, transactions:transactions, txInputsByTransaction:txInputsByTransaction });
}); });

45
app/api/rpcApi.js

@ -152,41 +152,54 @@ function getRawTransactions(txids) {
return; return;
} }
if (coins[config.coin].genesisCoinbaseTransactionId) { var requests = [];
if (txids.length == 1 && txids[0] == coins[config.coin].genesisCoinbaseTransactionId) { var promises = [];
for (var i = 0; i < txids.length; i++) {
var txid = txids[i];
if (txid) {
if (coins[config.coin].genesisCoinbaseTransactionId && txid == coins[config.coin].genesisCoinbaseTransactionId) {
// copy the "confirmations" field from genesis block to the genesis-coinbase tx // copy the "confirmations" field from genesis block to the genesis-coinbase tx
promises.push(new Promise(function(resolve2, reject2) {
getBlockchainInfo().then(function(blockchainInfoResult) { getBlockchainInfo().then(function(blockchainInfoResult) {
var result = coins[config.coin].genesisCoinbaseTransaction; var result = coins[config.coin].genesisCoinbaseTransaction;
result.confirmations = blockchainInfoResult.blocks; result.confirmations = blockchainInfoResult.blocks;
resolve([result]); resolve2([result]);
}).catch(function(err) { }).catch(function(err) {
reject(err); reject2(err);
return;
}); });
}));
return; } else {
}
}
var requests = [];
for (var i = 0; i < txids.length; i++) {
var txid = txids[i];
if (txid) {
requests.push({ requests.push({
method: 'getrawtransaction', method: 'getrawtransaction',
parameters: [ txid, 1 ] parameters: [ txid, 1 ]
}); });
} }
} }
}
var requestBatches = utils.splitArrayIntoChunks(requests, 100); var requestBatches = utils.splitArrayIntoChunks(requests, 100);
promises.push(new Promise(function(resolve2, reject2) {
executeBatchesSequentially(requestBatches, function(results) { executeBatchesSequentially(requestBatches, function(results) {
resolve(results); resolve2(results);
});
}));
Promise.all(promises).then(function(results) {
console.log(JSON.stringify(results));
var finalResults = [];
for (var i = 0; i < results.length; i++) {
for (var j = 0; j < results[i].length; j++) {
finalResults.push(results[i][j]);
}
}
resolve(finalResults);
}); });
}); });
} }

Loading…
Cancel
Save