mtx/script: minor. optimize script.fromProgram.

This commit is contained in:
Christopher Jeffrey 2017-01-09 13:26:18 -08:00
parent 29e03892e7
commit 2145cadc10
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 28 additions and 9 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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;
};