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) {
|
||||
return obj
|
||||
&& obj.prevout !== undefined
|
||||
&& obj.script !== undefined
|
||||
&& obj.witness !== undefined
|
||||
&& typeof obj.prevout === 'object'
|
||||
&& typeof obj.script === 'object'
|
||||
&& typeof obj.witness === 'object'
|
||||
&& typeof obj.getAddress === 'function';
|
||||
};
|
||||
|
||||
|
||||
@ -232,7 +232,6 @@ MTX.prototype.addOutput = function addOutput(options, value) {
|
||||
options = Script.fromAddress(options);
|
||||
|
||||
output = new Output();
|
||||
output.mutable = true;
|
||||
|
||||
if (options instanceof Script) {
|
||||
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.value = select.change;
|
||||
change.script.fromAddress(select.changeAddress);
|
||||
change.mutable = true;
|
||||
|
||||
if (change.isDust(policy.MIN_RELAY)) {
|
||||
// Do nothing. Change is added to fee.
|
||||
@ -1329,23 +1327,6 @@ MTX.prototype.setSequence = function setSequence(index, locktime, seconds) {
|
||||
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.
|
||||
* @returns {Object}
|
||||
@ -1391,7 +1372,7 @@ MTX.prototype.getJSON = function getJSON(network) {
|
||||
*/
|
||||
|
||||
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) {
|
||||
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) {
|
||||
if (typeof data === 'string')
|
||||
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.
|
||||
change = new Output();
|
||||
change.mutable = true;
|
||||
|
||||
if (this.changeAddress) {
|
||||
change.script.fromAddress(this.changeAddress);
|
||||
|
||||
@ -266,6 +266,19 @@ Outpoint.prototype.inspect = function inspect() {
|
||||
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
|
||||
*/
|
||||
|
||||
@ -32,8 +32,6 @@ function Output(options) {
|
||||
|
||||
this.value = 0;
|
||||
this.script = new Script();
|
||||
this.mutable = false;
|
||||
this._address = null;
|
||||
|
||||
if (options)
|
||||
this.fromOptions(options);
|
||||
@ -87,15 +85,7 @@ Output.prototype.getType = function getType() {
|
||||
*/
|
||||
|
||||
Output.prototype.getAddress = function getAddress() {
|
||||
var address = this._address;
|
||||
|
||||
if (!address) {
|
||||
address = this.script.getAddress();
|
||||
if (!this.mutable)
|
||||
this._address = address;
|
||||
}
|
||||
|
||||
return address;
|
||||
return this.script.getAddress();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -300,8 +290,8 @@ Output.fromRaw = function fromRaw(data, enc) {
|
||||
|
||||
Output.isOutput = function isOutput(obj) {
|
||||
return obj
|
||||
&& obj.value !== undefined
|
||||
&& obj.script !== undefined
|
||||
&& typeof obj.value === 'number'
|
||||
&& typeof obj.script === 'object'
|
||||
&& typeof obj.getAddress === 'function';
|
||||
};
|
||||
|
||||
|
||||
@ -1561,7 +1561,6 @@ Wallet.prototype.createTX = co(function* createTX(options, force) {
|
||||
// Add the outputs
|
||||
for (i = 0; i < outputs.length; i++) {
|
||||
output = new Output(outputs[i]);
|
||||
output.mutable = true;
|
||||
|
||||
if (output.isDust())
|
||||
throw new Error('Output is dust.');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user