Skip to content

Commit

Permalink
Merge pull request #76 from matiu/bug/fix-unconfirmed-tx2
Browse files Browse the repository at this point in the history
update to bitcore 0.1.19
  • Loading branch information
maraoz committed May 13, 2014
2 parents dfddf83 + 3a6b90f commit e0ea644
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions lib/TransactionDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
var self = this;
// adapt bitcore TX object to bitcoind JSON response
Expand All @@ -503,11 +463,11 @@ TransactionDb.prototype.adaptTxObject = function(txInfo) {
if (tx.outs) {
tx.outs.forEach(function(o) {
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
if (addrs.length === 1) {
tx.out[to].addrStr = addrs[0];
tx.out[to].addrStr = addrs[0].toString();
tx.out[to].n = to;
}
to++;
Expand Down

0 comments on commit e0ea644

Please sign in to comment.