script: encode/decode op1-16 as single numbers

fix #33
This commit is contained in:
Stanislas Marion 2014-11-14 18:15:54 +01:00 committed by Fedor Indutny
parent 64e15c8f82
commit 7655ad12c7
2 changed files with 2 additions and 4 deletions

View File

@ -25,7 +25,7 @@ script.decode = function decode(s) {
// Raw number
if (b >= 0x51 && b <= 0x60) {
opcodes.push([ b - 0x50 ]);
opcodes.push(b - 0x50);
continue;
}
@ -63,8 +63,6 @@ script.encode = function encode(s) {
if (Array.isArray(instr)) {
if (instr.length === 0) {
res.push(0);
} else if (instr.length === 1 && 0 < instr[0] && instr[0] <= 16) {
res.push(0x50 + instr[0]);
} else if (1 <= instr.length && instr.length <= 0x4b) {
res = res.concat(instr.length, instr);
} else if (instr.length <= 0xff) {

View File

@ -24,7 +24,7 @@ describe('Script', function() {
});
it('should encode/decode numbers', function() {
var script = [ [], [1], [2], [16] ];
var script = [ [], 1, 2, 16 ];
var encoded = bcoin.script.encode(script);
assert.deepEqual(encoded, [ 0, 0x51, 0x52, 0x60 ]);
var decoded = bcoin.script.decode(encoded);