diff --git a/Script.js b/Script.js index ffc4ace5f..0a218c5d5 100644 --- a/Script.js +++ b/Script.js @@ -38,7 +38,7 @@ function spec(b) { } this.chunks = []; this.parse(); - }; + } this.class = Script; Script.TX_UNKNOWN = TX_UNKNOWN; @@ -265,47 +265,6 @@ function spec(b) { return this.buffer; }; - Script.fromStringContent = function(s) { - var chunks = []; - var split = s.split(' '); - for (var i = 0; i < split.length; i++) { - var word = split[i]; - if (word === '') continue; - if (word.length > 2 && word.substring(0, 2) === '0x') { - // raw hex value - //console.log('hex value'); - chunks.push(new Buffer(word.substring(2, word.length), 'hex')); - } else { - var opcode = Opcode.map['OP_' + word]; - if (typeof opcode !== 'undefined') { - // op code in string form - //console.log('opcode'); - chunks.push(opcode); - } else { - var integer = parseInt(word); - if (!isNaN(integer)) { - // integer - //console.log('integer'); - var data = util.intToBuffer(integer); - chunks.push(data); - } else if (word[0] === '\'' && word[word.length-1] === '\'') { - // string - //console.log('string'); - word = word.substring(1,word.length-1); - var hex = ''; - for(var c=0;c 0) { + s += ' '; + } + + if (Buffer.isBuffer(chunk)) { + if (chunk.length === 0) { + s += '0'; + } else { + s += '0x' + util.formatBuffer(encodeLen(chunk.length), 0) + ' '; + s += '0x' + util.formatBuffer(chunk, 0); + } + } else { + var opcode = Opcode.reverseMap[chunk]; + if (typeof opcode === 'undefined') { + opcode = '0x'+chunk.toString(16); + } + s += opcode; + } + } + return s; + + }; + + Script.stringToBuffer = function(s) { + var buf = new Put(); + var split = s.split(' '); + for (var i = 0; i < split.length; i++) { + var word = split[i]; + if (word === '') continue; + if (word.length > 2 && word.substring(0, 2) === '0x') { + // raw hex value + //console.log('hex value'); + buf.put(new Buffer(word.substring(2, word.length), 'hex')); + } else { + var opcode = Opcode.map['OP_' + word]; + if (typeof opcode !== 'undefined') { + // op code in string form + //console.log('opcode'); + buf.word8(opcode); + } else { + var integer = parseInt(word); + if (!isNaN(integer)) { + // integer + //console.log('integer'); + var data = util.intToBuffer(integer); + buf.put(Script.chunksToBuffer([data])); + } else if (word[0] === '\'' && word[word.length-1] === '\'') { + // string + //console.log('string'); + word = word.substring(1,word.length-1); + var hexString = ''; + for(var c=0;c