optimize tx.
This commit is contained in:
parent
08ccb4c6ee
commit
15a3f4b28b
@ -62,10 +62,6 @@ function MTX(options) {
|
||||
|
||||
utils.inherits(MTX, bcoin.tx);
|
||||
|
||||
MTX.prototype._init = function _init() {
|
||||
;
|
||||
};
|
||||
|
||||
MTX.prototype.clone = function clone() {
|
||||
var tx = new MTX(this);
|
||||
|
||||
|
||||
@ -40,24 +40,17 @@ function TX(data, block) {
|
||||
|
||||
this._chain = data.chain;
|
||||
|
||||
if (data.inputs) {
|
||||
assert(this.inputs.length === 0);
|
||||
data.inputs.forEach(function(input) {
|
||||
this.addInput(input);
|
||||
}, this);
|
||||
}
|
||||
// assert(data.inputs.length !== 0);
|
||||
// assert(data.outputs.length !== 0);
|
||||
|
||||
if (data.outputs) {
|
||||
assert(this.outputs.length === 0);
|
||||
data.outputs.forEach(function(output) {
|
||||
this.addOutput(output);
|
||||
}, this);
|
||||
}
|
||||
data.inputs.forEach(function(input) {
|
||||
this.inputs.push(new bcoin.input(input));
|
||||
}, this);
|
||||
|
||||
this._init(block);
|
||||
}
|
||||
data.outputs.forEach(function(output) {
|
||||
this.outputs.push(new bcoin.output(output));
|
||||
}, this);
|
||||
|
||||
TX.prototype._init = function _init(block) {
|
||||
if (block && this.ts === 0) {
|
||||
if (block.type === 'merkleblock') {
|
||||
if (block.hasTX(this.hash('hex')))
|
||||
@ -72,7 +65,7 @@ TX.prototype._init = function _init(block) {
|
||||
|
||||
if (!this._size)
|
||||
this._size = this._raw.length;
|
||||
};
|
||||
}
|
||||
|
||||
TX.prototype.setBlock = function setBlock(block) {
|
||||
this.relayedBy = block.relayedBy;
|
||||
@ -84,15 +77,21 @@ TX.prototype.setBlock = function setBlock(block) {
|
||||
TX.prototype.clone = function clone() {
|
||||
var tx = new TX(this);
|
||||
|
||||
tx.inputs = tx.inputs.map(function(input) {
|
||||
input.script = input.script.slice();
|
||||
return input;
|
||||
});
|
||||
// tx.inputs = tx.inputs.map(function(input) {
|
||||
// var _raw = input.script._raw;
|
||||
// input.script = input.script.slice();
|
||||
// if (_raw)
|
||||
// utils.hidden(input.script, '_raw', _raw);
|
||||
// return input;
|
||||
// });
|
||||
|
||||
tx.outputs = tx.outputs.map(function(output) {
|
||||
output.script = output.script.slice();
|
||||
return output;
|
||||
});
|
||||
// tx.outputs = tx.outputs.map(function(output) {
|
||||
// var _raw = output.script._raw;
|
||||
// output.script = output.script.slice();
|
||||
// if (_raw)
|
||||
// utils.hidden(output.script, '_raw', _raw);
|
||||
// return output;
|
||||
// });
|
||||
|
||||
delete tx._raw;
|
||||
delete tx._size;
|
||||
@ -101,16 +100,10 @@ TX.prototype.clone = function clone() {
|
||||
};
|
||||
|
||||
TX.prototype.hash = function hash(enc) {
|
||||
var hash;
|
||||
if (!this._hash)
|
||||
this._hash = utils.dsha256(this.render());
|
||||
|
||||
if (this._hash)
|
||||
return enc === 'hex' ? utils.toHex(this._hash) : this._hash;
|
||||
|
||||
hash = utils.dsha256(this._raw);
|
||||
|
||||
this._hash = hash;
|
||||
|
||||
return enc === 'hex' ? utils.toHex(hash) : hash;
|
||||
return enc === 'hex' ? utils.toHex(this._hash) : this._hash;
|
||||
};
|
||||
|
||||
TX.prototype.render = function render() {
|
||||
@ -123,14 +116,6 @@ TX.prototype.getSize = function getSize() {
|
||||
return this._size || this.render().length;
|
||||
};
|
||||
|
||||
TX.prototype.addInput = function addInput(input) {
|
||||
assert(input.prevout);
|
||||
|
||||
input = bcoin.input(input);
|
||||
|
||||
this.inputs.push(input);
|
||||
};
|
||||
|
||||
TX.prototype._inputIndex = function _inputIndex(hash, index) {
|
||||
var i, ex;
|
||||
|
||||
@ -143,12 +128,6 @@ TX.prototype._inputIndex = function _inputIndex(hash, index) {
|
||||
return -1;
|
||||
};
|
||||
|
||||
TX.prototype.addOutput = function addOutput(output) {
|
||||
output = bcoin.output(output);
|
||||
|
||||
this.outputs.push(output);
|
||||
};
|
||||
|
||||
TX.prototype.getSubscript = function getSubscript(index) {
|
||||
var script;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user