From 2145cadc10b0915d38f91805fdfaae53fd18fc6f Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 9 Jan 2017 13:26:18 -0800 Subject: [PATCH] mtx/script: minor. optimize script.fromProgram. --- lib/primitives/mtx.js | 16 ++++++++++++---- lib/primitives/tx.js | 3 +-- lib/script/script.js | 18 +++++++++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/primitives/mtx.js b/lib/primitives/mtx.js index d02013e2..42d64994 100644 --- a/lib/primitives/mtx.js +++ b/lib/primitives/mtx.js @@ -260,11 +260,10 @@ MTX.prototype.verify = function verify(flags) { * (if workers are enabled). * @param {VerifyFlags?} [flags=STANDARD_VERIFY_FLAGS] * @returns {Promise} - * @returns {Boolean} Whether the inputs are valid. */ MTX.prototype.verifyAsync = function verifyAsync(flags) { - return TX.prototype.verify.call(this, this.view, flags); + return TX.prototype.verifyAsync.call(this, this.view, flags); }; /** @@ -291,7 +290,7 @@ MTX.prototype.getInputValue = function getInputValue() { */ MTX.prototype.getInputAddresses = function getInputAddresses() { - return TX.prototype.getInputValue.call(this, this.view); + return TX.prototype.getInputAddresses.call(this, this.view); }; /** @@ -312,6 +311,15 @@ MTX.prototype.getInputHashes = function getInputHashes(enc) { return TX.prototype.getInputHashes.call(this, this.view, enc); }; +/** + * Get all address hashes. + * @returns {Hash[]} hashes + */ + +MTX.prototype.getHashes = function getHashes(enc) { + return TX.prototype.getHashes.call(this, this.view, enc); +}; + /** * Test whether the transaction has * all coins available/filled. @@ -1200,7 +1208,7 @@ MTX.prototype.fund = co(function* fund(coins, options) { assert(options, 'Options are required.'); assert(options.changeAddress, 'Change address is required.'); - assert(this.inputs.length === 0, 'TX is already filled.'); + assert(this.inputs.length === 0, 'TX is already funded.'); // Select necessary coins. select = yield this.selectCoins(coins, options); diff --git a/lib/primitives/tx.js b/lib/primitives/tx.js index b9e02723..bc82fef9 100644 --- a/lib/primitives/tx.js +++ b/lib/primitives/tx.js @@ -778,7 +778,6 @@ TX.prototype.verifyInput = function verifyInput(index, coin, flags) { * @param {CoinView} view * @param {VerifyFlags?} [flags=STANDARD_VERIFY_FLAGS] * @returns {Promise} - * @returns {Boolean} Whether the inputs are valid. */ TX.prototype.verifyAsync = co(function* verifyAsync(view, flags) { @@ -797,7 +796,7 @@ TX.prototype.verifyAsync = co(function* verifyAsync(view, flags) { * verified. * @param {Coin|Output} coin - Previous output. * @param {VerifyFlags} [flags=STANDARD_VERIFY_FLAGS] - * @returns {Boolean} Whether the input is valid. + * @returns {Promise} */ TX.prototype.verifyInputAsync = co(function* verifyInputAsync(index, coin, flags) { diff --git a/lib/script/script.js b/lib/script/script.js index b812323c..9deb3ff3 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -1779,11 +1779,23 @@ Script.fromNulldata = function fromNulldata(flags) { */ Script.prototype.fromProgram = function fromProgram(version, data) { + var op; + assert(util.isNumber(version) && version >= 0 && version <= 16); assert(Buffer.isBuffer(data) && data.length >= 2 && data.length <= 40); - this.push(Opcode.fromSmall(version)); - this.push(data); - this.compile(); + + op = Opcode.fromSmall(version); + + this.raw = new Buffer(2 + data.length); + this.raw[0] = op.value; + this.raw[1] = data.length; + data.copy(this.raw, 2); + + data = this.raw.slice(2, 2 + data.length); + + this.code.push(op); + this.code.push(new Opcode(data.length, data)); + return this; };