tx.scriptOutput
This commit is contained in:
parent
bf3906b4d4
commit
871e36c426
@ -395,7 +395,7 @@ TX.prototype.output = function output(obj, value) {
|
|||||||
TX.prototype.out = TX.prototype.output;
|
TX.prototype.out = TX.prototype.output;
|
||||||
|
|
||||||
TX.prototype.scriptOutput = function scriptOutput(index, options) {
|
TX.prototype.scriptOutput = function scriptOutput(index, options) {
|
||||||
var output, script, keys, m, n, hash, locktime, flags;
|
var output, script, keys, m, n, hash, flags;
|
||||||
|
|
||||||
if (typeof index !== 'number')
|
if (typeof index !== 'number')
|
||||||
index = this.outputs.indexOf(index);
|
index = this.outputs.indexOf(index);
|
||||||
@ -437,23 +437,13 @@ TX.prototype.scriptOutput = function scriptOutput(index, options) {
|
|||||||
delete options.color;
|
delete options.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.lock != null) {
|
|
||||||
locktime = [
|
|
||||||
new bn(options.lock).toArray(),
|
|
||||||
'checklocktimeverify',
|
|
||||||
'drop'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(options.keys)) {
|
if (Array.isArray(options.keys)) {
|
||||||
// Bare Multisig Transaction
|
// Bare Multisig Transaction
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0010.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0010.mediawiki
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0011.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0011.mediawiki
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0019.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0019.mediawiki
|
||||||
// m [key1] [key2] ... n checkmultisig
|
// m [key1] [key2] ... n checkmultisig
|
||||||
keys = options.keys;
|
keys = options.keys.map(utils.toBuffer);
|
||||||
|
|
||||||
keys = keys.map(utils.toBuffer);
|
|
||||||
|
|
||||||
m = options.m || keys.length;
|
m = options.m || keys.length;
|
||||||
n = options.n || keys.length;
|
n = options.n || keys.length;
|
||||||
@ -465,17 +455,6 @@ TX.prototype.scriptOutput = function scriptOutput(index, options) {
|
|||||||
assert(n >= 1 && n <= 3);
|
assert(n >= 1 && n <= 3);
|
||||||
|
|
||||||
script = bcoin.script.redeem(keys, m, n);
|
script = bcoin.script.redeem(keys, m, n);
|
||||||
|
|
||||||
// P2SH Transaction
|
|
||||||
// hash160 [hash] eq
|
|
||||||
if (options.scripthash) {
|
|
||||||
hash = utils.ripesha(bcoin.script.encode(script));
|
|
||||||
script = [
|
|
||||||
'hash160',
|
|
||||||
hash,
|
|
||||||
'eq'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
} else if (bcoin.wallet.validateAddress(options.address, 'scripthash')) {
|
} else if (bcoin.wallet.validateAddress(options.address, 'scripthash')) {
|
||||||
// P2SH Transaction
|
// P2SH Transaction
|
||||||
// https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki
|
// https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki
|
||||||
@ -516,8 +495,23 @@ TX.prototype.scriptOutput = function scriptOutput(index, options) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locktime)
|
// P2SH Transaction
|
||||||
script = locktime.concat(script);
|
// hash160 [hash] eq
|
||||||
|
if (options.scripthash) {
|
||||||
|
if (options.lock != null) {
|
||||||
|
script = [
|
||||||
|
new bn(options.lock).toArray(),
|
||||||
|
'checklocktimeverify',
|
||||||
|
'drop'
|
||||||
|
].concat(script);
|
||||||
|
}
|
||||||
|
hash = utils.ripesha(bcoin.script.encode(script));
|
||||||
|
script = [
|
||||||
|
'hash160',
|
||||||
|
hash,
|
||||||
|
'eq'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
output.script = script;
|
output.script = script;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user