Merge pull request #188 from ryanxcharles/bug/script-push-data
script parsing should be more loose on pushdata
This commit is contained in:
commit
3ad329f032
@ -58,17 +58,14 @@ Script.prototype.parse = function() {
|
|||||||
} else if (opcode === OP_PUSHDATA1) {
|
} else if (opcode === OP_PUSHDATA1) {
|
||||||
len = parser.word8();
|
len = parser.word8();
|
||||||
chunk = parser.buffer(len);
|
chunk = parser.buffer(len);
|
||||||
if (chunk.length < len) throw new Error('Invalid data size: not enough data');
|
|
||||||
this.chunks.push(chunk);
|
this.chunks.push(chunk);
|
||||||
} else if (opcode === OP_PUSHDATA2) {
|
} else if (opcode === OP_PUSHDATA2) {
|
||||||
len = parser.word16le();
|
len = parser.word16le();
|
||||||
chunk = parser.buffer(len);
|
chunk = parser.buffer(len);
|
||||||
if (chunk.length < len) throw new Error('Invalid data size: not enough data');
|
|
||||||
this.chunks.push(chunk);
|
this.chunks.push(chunk);
|
||||||
} else if (opcode === OP_PUSHDATA4) {
|
} else if (opcode === OP_PUSHDATA4) {
|
||||||
len = parser.word32le();
|
len = parser.word32le();
|
||||||
chunk = parser.buffer(len);
|
chunk = parser.buffer(len);
|
||||||
if (chunk.length < len) throw new Error('Invalid data size: not enough data');
|
|
||||||
this.chunks.push(chunk);
|
this.chunks.push(chunk);
|
||||||
} else {
|
} else {
|
||||||
this.chunks.push(opcode);
|
this.chunks.push(opcode);
|
||||||
|
|||||||
@ -84,6 +84,15 @@ describe('Script', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#parse', function() {
|
||||||
|
it('should parse this valid script', function() {
|
||||||
|
var scriptHex = '6a0843435000010001004c75726c3d687474702533612532662532666c6f63616c686f7374253361343636313125326663253266324d794a6e5065774c5a6241596a6843666f695652526679733937746d5231516d4b61';
|
||||||
|
var script = new Script(new Buffer(scriptHex, 'hex'));
|
||||||
|
should.exist(script);
|
||||||
|
script.chunks[2].length.should.equal(75);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
testdata.dataScriptAll.forEach(function(datum) {
|
testdata.dataScriptAll.forEach(function(datum) {
|
||||||
if (datum.length < 2) throw new Error('Invalid test data');
|
if (datum.length < 2) throw new Error('Invalid test data');
|
||||||
var human = datum[0] + ' ' + datum[1];
|
var human = datum[0] + ' ' + datum[1];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user