have tx.verify handle p2sh correctly.
This commit is contained in:
parent
a9a9cf0879
commit
5f8ad78e4d
@ -418,6 +418,9 @@ TX.prototype.verify = function verify(index, force) {
|
||||
if (!force && this.ts !== 0)
|
||||
return true;
|
||||
|
||||
if (this.inputs.length === 0)
|
||||
return false;
|
||||
|
||||
return this.inputs.every(function(input, i) {
|
||||
if (index !== undefined && index !== i)
|
||||
return true;
|
||||
@ -434,7 +437,20 @@ TX.prototype.verify = function verify(index, force) {
|
||||
if (!res)
|
||||
return false;
|
||||
|
||||
return stack.length > 0 && utils.isEqual(stack.pop(), [ 1 ]);
|
||||
if (stack.length === 0 || !utils.isEqual(stack.pop(), [ 1 ]))
|
||||
return false;
|
||||
|
||||
if (bcoin.script.isScripthash(prev)) {
|
||||
var redeem = input.script[input.script.length - 1];
|
||||
if (!Array.isArray(redeem))
|
||||
return false;
|
||||
redeem = bcoin.script.decode(redeem);
|
||||
res = bcoin.script.execute(redeem, stack, this, i);
|
||||
if (!res)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, this);
|
||||
};
|
||||
|
||||
|
||||
@ -2,6 +2,33 @@ var assert = require('assert');
|
||||
var bn = require('bn.js');
|
||||
var bcoin = require('../');
|
||||
|
||||
function printScript(input) {
|
||||
var scripts = [];
|
||||
var script = input.script;
|
||||
scripts.push(script);
|
||||
var prev = input.out.tx.outputs[input.out.index].script;
|
||||
scripts.push(prev);
|
||||
if (bcoin.script.isScripthash(prev)) {
|
||||
var redeem = bcoin.script.decode(input.script[input.script.length - 1]);
|
||||
scripts.push(redeem);
|
||||
}
|
||||
scripts = scripts.map(function(script) {
|
||||
return script.map(function(chunk) {
|
||||
if (Array.isArray(chunk)) {
|
||||
if (chunk.length === 0)
|
||||
return [0];
|
||||
return [bcoin.utils.toHex(chunk)];
|
||||
}
|
||||
if (typeof chunk === 'number')
|
||||
return [chunk];
|
||||
return chunk;
|
||||
});
|
||||
});
|
||||
scripts.forEach(function(script) {
|
||||
console.log(script);
|
||||
});
|
||||
}
|
||||
|
||||
describe('Wallet', function() {
|
||||
it('should generate new key and address', function() {
|
||||
var w = bcoin.wallet();
|
||||
@ -284,17 +311,19 @@ describe('Wallet', function() {
|
||||
// Create a tx requiring 2 signatures
|
||||
var send = bcoin.tx();
|
||||
send.output({ address: receive.getAddress(), value: 5460 });
|
||||
assert(!send.verify());
|
||||
var result = w1.fill(send);
|
||||
assert(result);
|
||||
|
||||
// printScript(send.inputs[0]);
|
||||
|
||||
assert(!send.verify());
|
||||
w2.sign(send);
|
||||
|
||||
// XXX Still verifies for some reason.
|
||||
// send.inputs[0].script[1] = [];
|
||||
// send.inputs[0].script[2] = [];
|
||||
assert(send.verify());
|
||||
|
||||
// console.log(utx.outputs[0].script);
|
||||
// console.log(send.inputs[0].script);
|
||||
send.inputs[0].script[2] = [];
|
||||
assert(!send.verify());
|
||||
|
||||
cb();
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user