Merge pull request #76 from matiu/bug/fix-unconfirmed-tx2

update to bitcore 0.1.19
This commit is contained in:
Manuel Aráoz 2014-05-13 17:34:32 -03:00
commit e0ea644a5d
1 changed files with 2 additions and 42 deletions

View File

@ -452,46 +452,6 @@ TransactionDb.prototype.removeFromTxId = function(txid, cb) {
}; };
// TODO. replace with
// Script.prototype.getAddrStrs if that one get merged in bitcore
TransactionDb.prototype.getAddrStr = function(s) {
var self = this;
var addrStrs = [];
var type = s.classify();
var addr;
switch (type) {
case Script.TX_PUBKEY:
var chunk = s.captureOne();
addr = new Address(self.network.addressVersion, bitcore.util.sha256ripe160(chunk));
addrStrs.push(addr.toString());
break;
case Script.TX_PUBKEYHASH:
addr = new Address(self.network.addressVersion, s.captureOne());
addrStrs.push(addr.toString());
break;
case Script.TX_SCRIPTHASH:
addr = new Address(self.network.addressVersion, s.captureOne());
addrStrs.push(addr.toString());
break;
case Script.TX_MULTISIG:
var chunks = s.capture();
chunks.forEach(function(chunk) {
if (chunk && Buffer.isBuffer(chunk)) {
var a = new Address(self.network.addressVersion, bitcore.util.sha256ripe160(chunk));
addrStrs.push(a.toString());
}
});
break;
case Script.TX_UNKNOWN:
break;
}
return addrStrs;
};
TransactionDb.prototype.adaptTxObject = function(txInfo) { TransactionDb.prototype.adaptTxObject = function(txInfo) {
var self = this; var self = this;
// adapt bitcore TX object to bitcoind JSON response // adapt bitcore TX object to bitcoind JSON response
@ -503,11 +463,11 @@ TransactionDb.prototype.adaptTxObject = function(txInfo) {
if (tx.outs) { if (tx.outs) {
tx.outs.forEach(function(o) { tx.outs.forEach(function(o) {
var s = new Script(o.s); var s = new Script(o.s);
var addrs = self.getAddrStr(s); var addrs = new Address.fromScriptPubKey(s, config.network);
// support only for p2pubkey p2pubkeyhash and p2sh // support only for p2pubkey p2pubkeyhash and p2sh
if (addrs.length === 1) { if (addrs.length === 1) {
tx.out[to].addrStr = addrs[0]; tx.out[to].addrStr = addrs[0].toString();
tx.out[to].n = to; tx.out[to].n = to;
} }
to++; to++;