work. mutable scripts.

This commit is contained in:
Christopher Jeffrey 2016-06-14 16:26:26 -07:00
parent 5ae6a4e02c
commit 27b18c0fd2
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
6 changed files with 491 additions and 307 deletions

View File

@ -70,6 +70,7 @@ if (!utils.isBrowser)
* @property {Function} profiler - {@link module:profiler}.
* @property {Function} ldb - See {@link module:ldb}.
* @property {Function} script - {@link Script} constructor.
* @property {Function} opcode - {@link Opcode} constructor.
* @property {Function} stack - {@link Stack} constructor.
* @property {Function} witness - {@link Witness} constructor.
* @property {Function} input - {@link Input} constructor.
@ -147,6 +148,7 @@ function Environment(options) {
this.profiler = require('./profiler');
this.timedata = require('./timedata');
this.script = require('./script');
this.opcode = this.script.Opcode;
this.stack = this.script.Stack;
this.witness = this.script.Witness;
this.address = require('./address');

View File

@ -452,8 +452,9 @@ MinerBlock.prototype.updateCommitment = function updateCommitment() {
*/
MinerBlock.prototype.updateCoinbase = function updateCoinbase() {
this.coinbase.inputs[0].script[1] = bcoin.script.array(this.extraNonce);
this.coinbase.inputs[0].script.refresh();
var input = this.coinbase.inputs[0];
input.script.code[1] = bcoin.opcode.fromNumber(this.extraNonce);
input.script.compile();
this.coinbase.outputs[0].value = this.block.getReward(this.network);
};

File diff suppressed because it is too large Load Diff

View File

@ -1333,7 +1333,7 @@ TX.prototype.hasStandardInputs = function hasStandardInputs(flags) {
if (stack.length === 0)
return false;
redeem = stack.getRedeem(false);
redeem = stack.getRedeem();
if (!redeem)
return false;
@ -1645,22 +1645,6 @@ TX.prototype.isWatched = function isWatched(filter) {
if (!filter)
return false;
function testScript(code) {
var i, chunk;
for (i = 0; i < code.length; i++) {
chunk = code[i];
if (chunk === -1)
break;
if (!Buffer.isBuffer(chunk) || chunk.length === 0)
continue;
if (filter.test(chunk))
return true;
}
return false;
}
// 1. Test the tx hash
if (filter.test(this.hash()))
found = true;
@ -1670,7 +1654,7 @@ TX.prototype.isWatched = function isWatched(filter) {
for (i = 0; i < this.outputs.length; i++) {
output = this.outputs[i];
// Test the output script
if (testScript(output.script.toArray())) {
if (output.script.test(filter)) {
if (filter.update === constants.filterFlags.ALL) {
outpoint = bcoin.protocol.framer.outpoint(this.hash(), i);
filter.add(outpoint);
@ -1700,11 +1684,11 @@ TX.prototype.isWatched = function isWatched(filter) {
return true;
// Test the input script
if (testScript(input.script.toArray()))
if (input.script.test(filter))
return true;
// Test the witness
// if (testScript(input.witness.items))
// if (input.witness.test(filter))
// return true;
}

View File

@ -32,7 +32,7 @@ describe('Script', function() {
it('should encode/decode numbers', function() {
var script = [0, 0x51, 0x52, 0x60];
var encoded = bcoin.script.encodeArray(script);
var encoded = bcoin.script.fromArray(script).raw;
var decoded = bcoin.script.decode(encoded).map(function(op) { return op.value; });
assert.deepEqual(decoded, script);
});

View File

@ -7,6 +7,8 @@ var network = bcoin.protocol.network;
var utils = bcoin.utils;
var assert = require('assert');
var FAKE_SIG = new Buffer([0,0,0,0,0,0,0,0,0]);
var KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt'
+ 'qUP9iWfcHgJofs25xbaUpCps9GDXj83NiWvQCAkWQhVj5J4CorfnpKX94AZ';
@ -227,8 +229,8 @@ describe('Wallet', function() {
w.scriptInputs(fake, function(err) {
assert.ifError(err);
// Fake signature
fake.inputs[0].script.code[0] = new Buffer([0,0,0,0,0,0,0,0,0]);
fake.inputs[0].script.refresh();
fake.inputs[0].script.code[0] = bcoin.opcode.fromData(FAKE_SIG);
fake.inputs[0].script.compile();
// balance: 11000
// Fake TX should temporarly change output
@ -696,8 +698,8 @@ describe('Wallet', function() {
if (witness) {
send.inputs[0].witness.items[2] = new Buffer([]);
} else {
send.inputs[0].script.code[2] = 0;
send.inputs[0].script.refresh();
send.inputs[0].script.code[2] = new bcoin.opcode(0);
send.inputs[0].script.compile();
}
assert(!send.verify(flags));