|
|
@ -332,6 +332,7 @@ Transaction.prototype.toObject = function toObject() { |
|
|
|
outputs.push(output.toObject()); |
|
|
|
}); |
|
|
|
var obj = { |
|
|
|
hash: this.hash, |
|
|
|
version: this.version, |
|
|
|
inputs: inputs, |
|
|
|
outputs: outputs, |
|
|
@ -349,10 +350,14 @@ Transaction.prototype.toObject = function toObject() { |
|
|
|
return obj; |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype.fromObject = function(transaction) { |
|
|
|
Transaction.prototype.fromObject = function(arg) { |
|
|
|
/* jshint maxstatements: 20 */ |
|
|
|
var self = this; |
|
|
|
if (transaction instanceof Transaction) { |
|
|
|
var transaction; |
|
|
|
if (arg instanceof Transaction) { |
|
|
|
transaction = transaction.toObject(); |
|
|
|
} else { |
|
|
|
transaction = arg; |
|
|
|
} |
|
|
|
_.each(transaction.inputs, function(input) { |
|
|
|
if (!input.output || !input.output.script) { |
|
|
@ -386,18 +391,20 @@ Transaction.prototype.fromObject = function(transaction) { |
|
|
|
} |
|
|
|
this.nLockTime = transaction.nLockTime; |
|
|
|
this.version = transaction.version; |
|
|
|
this._checkConsistency(); |
|
|
|
this._checkConsistency(arg); |
|
|
|
return this; |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype._checkConsistency = function() { |
|
|
|
Transaction.prototype._checkConsistency = function(arg) { |
|
|
|
if (!_.isUndefined(this._changeIndex)) { |
|
|
|
$.checkState(this._changeScript); |
|
|
|
$.checkState(this.outputs[this._changeIndex]); |
|
|
|
$.checkState(this.outputs[this._changeIndex].script.toString() === |
|
|
|
this._changeScript.toString()); |
|
|
|
} |
|
|
|
// TODO: add other checks
|
|
|
|
if (arg && arg.hash) { |
|
|
|
$.checkState(arg.hash === this.hash, 'Hash in object does not match transaction hash'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|