output: remove output mutability and addr caching.
This commit is contained in:
parent
a8a752a212
commit
79eea76cc4
@ -476,9 +476,9 @@ Input.fromTX = function fromTX(tx, index) {
|
|||||||
|
|
||||||
Input.isInput = function isInput(obj) {
|
Input.isInput = function isInput(obj) {
|
||||||
return obj
|
return obj
|
||||||
&& obj.prevout !== undefined
|
&& typeof obj.prevout === 'object'
|
||||||
&& obj.script !== undefined
|
&& typeof obj.script === 'object'
|
||||||
&& obj.witness !== undefined
|
&& typeof obj.witness === 'object'
|
||||||
&& typeof obj.getAddress === 'function';
|
&& typeof obj.getAddress === 'function';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -232,7 +232,6 @@ MTX.prototype.addOutput = function addOutput(options, value) {
|
|||||||
options = Script.fromAddress(options);
|
options = Script.fromAddress(options);
|
||||||
|
|
||||||
output = new Output();
|
output = new Output();
|
||||||
output.mutable = true;
|
|
||||||
|
|
||||||
if (options instanceof Script) {
|
if (options instanceof Script) {
|
||||||
assert(util.isUInt53(value), 'Value must be a uint53.');
|
assert(util.isUInt53(value), 'Value must be a uint53.');
|
||||||
@ -1228,7 +1227,6 @@ MTX.prototype.fund = co(function* fund(coins, options) {
|
|||||||
change = new Output();
|
change = new Output();
|
||||||
change.value = select.change;
|
change.value = select.change;
|
||||||
change.script.fromAddress(select.changeAddress);
|
change.script.fromAddress(select.changeAddress);
|
||||||
change.mutable = true;
|
|
||||||
|
|
||||||
if (change.isDust(policy.MIN_RELAY)) {
|
if (change.isDust(policy.MIN_RELAY)) {
|
||||||
// Do nothing. Change is added to fee.
|
// Do nothing. Change is added to fee.
|
||||||
@ -1329,23 +1327,6 @@ MTX.prototype.setSequence = function setSequence(index, locktime, seconds) {
|
|||||||
input.sequence = locktime;
|
input.sequence = locktime;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark outputs as mutable.
|
|
||||||
* @private
|
|
||||||
* @param {Boolean} flag
|
|
||||||
*/
|
|
||||||
|
|
||||||
MTX.prototype._mutable = function _mutable(flag) {
|
|
||||||
var i, output;
|
|
||||||
|
|
||||||
for (i = 0; i < this.outputs.length; i++) {
|
|
||||||
output = this.outputs[i];
|
|
||||||
output.mutable = flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inspect the transaction.
|
* Inspect the transaction.
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
@ -1391,7 +1372,7 @@ MTX.prototype.getJSON = function getJSON(network) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MTX.fromJSON = function fromJSON(json) {
|
MTX.fromJSON = function fromJSON(json) {
|
||||||
return new MTX().fromJSON(JSON)._mutable(true);
|
return new MTX().fromJSON(JSON);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1401,7 +1382,7 @@ MTX.fromJSON = function fromJSON(json) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
MTX.fromReader = function fromReader(br) {
|
MTX.fromReader = function fromReader(br) {
|
||||||
return new MTX().fromReader(br)._mutable(true);
|
return new MTX().fromReader(br);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1414,7 +1395,7 @@ MTX.fromReader = function fromReader(br) {
|
|||||||
MTX.fromRaw = function fromRaw(data, enc) {
|
MTX.fromRaw = function fromRaw(data, enc) {
|
||||||
if (typeof data === 'string')
|
if (typeof data === 'string')
|
||||||
data = new Buffer(data, enc);
|
data = new Buffer(data, enc);
|
||||||
return new MTX().fromRaw(data)._mutable(true);
|
return new MTX().fromRaw(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1768,7 +1749,6 @@ CoinSelector.prototype.selectEstimate = co(function* selectEstimate() {
|
|||||||
|
|
||||||
// Add dummy output for change.
|
// Add dummy output for change.
|
||||||
change = new Output();
|
change = new Output();
|
||||||
change.mutable = true;
|
|
||||||
|
|
||||||
if (this.changeAddress) {
|
if (this.changeAddress) {
|
||||||
change.script.fromAddress(this.changeAddress);
|
change.script.fromAddress(this.changeAddress);
|
||||||
|
|||||||
@ -266,6 +266,19 @@ Outpoint.prototype.inspect = function inspect() {
|
|||||||
return '<Outpoint: ' + this.rhash() + '/' + this.index + '>';
|
return '<Outpoint: ' + this.rhash() + '/' + this.index + '>';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test an object to see if it is an outpoint.
|
||||||
|
* @param {Object} obj
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Outpoint.isOutpoint = function isOutpoint(obj) {
|
||||||
|
return obj
|
||||||
|
&& typeof obj.hash === 'string'
|
||||||
|
&& typeof obj.index === 'number'
|
||||||
|
&& typeof obj.toKey === 'function';
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -32,8 +32,6 @@ function Output(options) {
|
|||||||
|
|
||||||
this.value = 0;
|
this.value = 0;
|
||||||
this.script = new Script();
|
this.script = new Script();
|
||||||
this.mutable = false;
|
|
||||||
this._address = null;
|
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
this.fromOptions(options);
|
this.fromOptions(options);
|
||||||
@ -87,15 +85,7 @@ Output.prototype.getType = function getType() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Output.prototype.getAddress = function getAddress() {
|
Output.prototype.getAddress = function getAddress() {
|
||||||
var address = this._address;
|
return this.script.getAddress();
|
||||||
|
|
||||||
if (!address) {
|
|
||||||
address = this.script.getAddress();
|
|
||||||
if (!this.mutable)
|
|
||||||
this._address = address;
|
|
||||||
}
|
|
||||||
|
|
||||||
return address;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -300,8 +290,8 @@ Output.fromRaw = function fromRaw(data, enc) {
|
|||||||
|
|
||||||
Output.isOutput = function isOutput(obj) {
|
Output.isOutput = function isOutput(obj) {
|
||||||
return obj
|
return obj
|
||||||
&& obj.value !== undefined
|
&& typeof obj.value === 'number'
|
||||||
&& obj.script !== undefined
|
&& typeof obj.script === 'object'
|
||||||
&& typeof obj.getAddress === 'function';
|
&& typeof obj.getAddress === 'function';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1561,7 +1561,6 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
|
|||||||
// Add the outputs
|
// Add the outputs
|
||||||
for (i = 0; i < outputs.length; i++) {
|
for (i = 0; i < outputs.length; i++) {
|
||||||
output = new Output(outputs[i]);
|
output = new Output(outputs[i]);
|
||||||
output.mutable = true;
|
|
||||||
|
|
||||||
if (output.isDust())
|
if (output.isDust())
|
||||||
throw new Error('Output is dust.');
|
throw new Error('Output is dust.');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user