Retrofitting for new bitcore-node.
This commit is contained in:
parent
b63a2208fc
commit
d866dd7a65
2
.gitignore
vendored
2
.gitignore
vendored
@ -38,3 +38,5 @@ db/testnet/blocks
|
|||||||
|
|
||||||
README.html
|
README.html
|
||||||
public
|
public
|
||||||
|
|
||||||
|
package-lock.json
|
||||||
|
|||||||
@ -24,7 +24,7 @@ AddressController.prototype.show = function(req, res) {
|
|||||||
options.to = parseInt(req.query.to);
|
options.to = parseInt(req.query.to);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getAddressSummary(req.addr, options, function(err, data) {
|
this._address.getAddressSummary(req.addr, options, function(err, data) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
@ -139,14 +139,29 @@ AddressController.prototype.utxo = function(req, res) {
|
|||||||
|
|
||||||
AddressController.prototype.multiutxo = function(req, res) {
|
AddressController.prototype.multiutxo = function(req, res) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.node.getAddressUnspentOutputs(req.addrs, true, function(err, utxos) {
|
|
||||||
if(err && err.code === -5) {
|
var finalUtxos = [];
|
||||||
return res.jsonp([]);
|
|
||||||
} else if(err) {
|
async.eachLimit(req.addrs, 4, function(addr, next) {
|
||||||
|
|
||||||
|
self.node.getAddressUnspentOutputs(addr, {}, function(err, utxos) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
finalUtxos = finalUtxos.concat(utxos);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
}, function(err) {
|
||||||
|
|
||||||
|
if (err) {
|
||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.jsonp(utxos.map(self.transformUtxo.bind(self)));
|
res.jsonp(finalUtxos.map(self.transformUtxo.bind(self)));
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -190,6 +205,7 @@ AddressController.prototype.multitxs = function(req, res) {
|
|||||||
options.to = parseInt(req.query.to) || parseInt(req.body.to) || parseInt(options.from) + 10;
|
options.to = parseInt(req.query.to) || parseInt(req.body.to) || parseInt(options.from) + 10;
|
||||||
|
|
||||||
self.node.getAddressHistory(req.addrs, options, function(err, result) {
|
self.node.getAddressHistory(req.addrs, options, function(err, result) {
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
return self.common.handleErrors(err, res);
|
return self.common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
@ -211,24 +227,16 @@ AddressController.prototype.multitxs = function(req, res) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfos, options, callback) {
|
AddressController.prototype.transformAddressHistoryForMultiTxs = function(txs, options, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var items = txinfos.map(function(txinfo) {
|
|
||||||
return txinfo.tx;
|
|
||||||
}).filter(function(value, index, self) {
|
|
||||||
return self.indexOf(value) === index;
|
|
||||||
});
|
|
||||||
|
|
||||||
async.map(
|
async.map(
|
||||||
items,
|
txs,
|
||||||
function(item, next) {
|
function(tx, next) {
|
||||||
self.txController.transformTransaction(item, options, next);
|
self.txController.transformTransaction(tx, options, next);
|
||||||
},
|
},
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = AddressController;
|
module.exports = AddressController;
|
||||||
|
|||||||
@ -140,13 +140,13 @@ BlockController.prototype.transformBlock = function(block, info) {
|
|||||||
nonce: block.nonce,
|
nonce: block.nonce,
|
||||||
bits: block.bits,
|
bits: block.bits,
|
||||||
difficulty: null,
|
difficulty: null,
|
||||||
chainwork: null,
|
chainwork: info.chainwork,
|
||||||
confirmations: null,
|
confirmations: null,
|
||||||
previousblockhash: bcoin.util.revHex(block.prevBlock),
|
previousblockhash: bcoin.util.revHex(block.prevBlock),
|
||||||
nextblockhash: null,
|
nextblockhash: null,
|
||||||
reward: null,
|
reward: null,
|
||||||
isMainChain: null,
|
isMainChain: null,
|
||||||
poolInfo: null
|
poolInfo: this.getPoolInfo(block)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ BlockController.prototype._getBlockSummary = function(hash, moreTimestamp, next)
|
|||||||
|
|
||||||
var br = new bitcore.encoding.BufferReader(blockBuffer);
|
var br = new bitcore.encoding.BufferReader(blockBuffer);
|
||||||
|
|
||||||
// take a shortcut to get number of transactions and the blocksize.
|
// TODO: take a shortcut to get number of transactions and the blocksize.
|
||||||
// Also reads the coinbase transaction and only that.
|
// Also reads the coinbase transaction and only that.
|
||||||
// Old code parsed all transactions in every block _and_ then encoded
|
// Old code parsed all transactions in every block _and_ then encoded
|
||||||
// them all back together to get the binary size of the block.
|
// them all back together to get the binary size of the block.
|
||||||
@ -320,7 +320,7 @@ BlockController.prototype.list = function(req, res) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
BlockController.prototype.getPoolInfo = function(block) {
|
BlockController.prototype.getPoolInfo = function(block) {
|
||||||
var coinbaseBuffer = block.transactions[0].inputs[0]._scriptBuffer;
|
var coinbaseBuffer = block.txs[0].inputs[0].script.raw;
|
||||||
|
|
||||||
for(var k in this.poolStrings) {
|
for(var k in this.poolStrings) {
|
||||||
if (coinbaseBuffer.toString('utf-8').match(k)) {
|
if (coinbaseBuffer.toString('utf-8').match(k)) {
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
var bitcore = require('bitcore-lib');
|
var bitcore = require('bitcore-lib');
|
||||||
var _ = bitcore.deps._;
|
var _ = bitcore.deps._;
|
||||||
var bcoin = require('bcoin');
|
|
||||||
var $ = bitcore.util.preconditions;
|
var $ = bitcore.util.preconditions;
|
||||||
var Common = require('./common');
|
var Common = require('./common');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
@ -49,14 +48,18 @@ TxController.prototype.transaction = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TxController.prototype.transformTransaction = function(transaction, options, callback) {
|
TxController.prototype.transformTransaction = function(transaction, options, callback) {
|
||||||
|
|
||||||
if (_.isFunction(options)) {
|
if (_.isFunction(options)) {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
$.checkArgument(_.isFunction(callback));
|
$.checkArgument(_.isFunction(callback));
|
||||||
|
|
||||||
var confirmations = 0;
|
var confirmations = 0;
|
||||||
|
|
||||||
if(transaction.__height >= 0) {
|
if(transaction.__height >= 0) {
|
||||||
var height = this._block.height;
|
var height = this._block.getTip().height;
|
||||||
confirmations = height - transaction.__height + 1;
|
confirmations = height - transaction.__height + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +78,7 @@ TxController.prototype.transformTransaction = function(transaction, options, cal
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
options.inputiValues = transaction.__inputValues;
|
options.inputValues = transaction.__inputValues;
|
||||||
transformed.vin = transaction.inputs.map(this.transformInput.bind(this, options));
|
transformed.vin = transaction.inputs.map(this.transformInput.bind(this, options));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +87,7 @@ TxController.prototype.transformTransaction = function(transaction, options, cal
|
|||||||
transformed.blockhash = transaction.blockHash;
|
transformed.blockhash = transaction.blockHash;
|
||||||
transformed.blockheight = transaction.__height;
|
transformed.blockheight = transaction.__height;
|
||||||
transformed.confirmations = transaction.confirmations;
|
transformed.confirmations = transaction.confirmations;
|
||||||
// TODO consider mempool txs with receivedTime?
|
|
||||||
var time = transaction.__timestamp ? transaction.__timestamp : Math.round(Date.now() / 1000);
|
var time = transaction.__timestamp ? transaction.__timestamp : Math.round(Date.now() / 1000);
|
||||||
transformed.time = time;
|
transformed.time = time;
|
||||||
if (transformed.confirmations) {
|
if (transformed.confirmations) {
|
||||||
@ -201,6 +204,7 @@ TxController.prototype.transformInvTransaction = function(transaction) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TxController.prototype.rawTransaction = function(req, res, next) {
|
TxController.prototype.rawTransaction = function(req, res, next) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var txid = req.params.txid;
|
var txid = req.params.txid;
|
||||||
|
|
||||||
@ -212,10 +216,11 @@ TxController.prototype.rawTransaction = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.rawTransaction = {
|
req.rawTransaction = {
|
||||||
'rawtx': transaction.toBuffer().toString('hex')
|
'rawtx': transaction.toRaw().toString('hex')
|
||||||
};
|
};
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user