tx: .inputAddrs()
This commit is contained in:
parent
2e3fb9a7a3
commit
50ed590c30
@ -270,3 +270,11 @@ script.isMultisig = function isMultisig(s, key) {
|
||||
return utils.isEqual(k, key);
|
||||
}).length;
|
||||
};
|
||||
|
||||
script.isPubkeyhashInput = function isPubkeyhashInput(s) {
|
||||
if (s.length !== 2)
|
||||
return false;
|
||||
|
||||
return 9 <= s[0].length && s[0].length <= 73 &&
|
||||
33 <= s[1].length && s[1].length <= 65;
|
||||
};
|
||||
|
||||
@ -71,7 +71,7 @@ TX.prototype._input = function _input(i, index) {
|
||||
var input = {
|
||||
out: {
|
||||
tx: (i.out ? i.out.tx : i.tx) || null,
|
||||
hash: hash,
|
||||
hash: utils.toHex(hash),
|
||||
index: i.out ? i.out.index : i.index,
|
||||
},
|
||||
script: i.script ? i.script.slice() : [],
|
||||
@ -234,6 +234,16 @@ TX.prototype.maxSize = function maxSize() {
|
||||
return size;
|
||||
};
|
||||
|
||||
TX.prototype.inputAddrs = function inputAddrs() {
|
||||
return this.inputs.filter(function(input) {
|
||||
return bcoin.script.isPubkeyhashInput(input.script);
|
||||
}).map(function(input) {
|
||||
var pub = input.script[1];
|
||||
var hash = utils.ripesha(pub);
|
||||
return bcoin.wallet.hash2addr(hash);
|
||||
});
|
||||
};
|
||||
|
||||
TX.prototype.toJSON = function toJSON() {
|
||||
// Compact representation
|
||||
var ts = new Array(4);
|
||||
|
||||
@ -48,7 +48,8 @@ describe('TX', function() {
|
||||
|
||||
it('should be verifiable', function() {
|
||||
var tx = bcoin.tx(parser.parseTX(bcoin.utils.toArray(raw, 'hex')));
|
||||
tx.input(bcoin.tx(parser.parseTX(bcoin.utils.toArray(inp, 'hex'))), 0);
|
||||
var p = bcoin.tx(parser.parseTX(bcoin.utils.toArray(inp, 'hex')));
|
||||
tx.input(p, 1);
|
||||
|
||||
assert(tx.verify());
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user