|
|
@ -226,33 +226,46 @@ Transaction.prototype.toObject = function toObject() { |
|
|
|
this.outputs.forEach(function(output) { |
|
|
|
outputs.push(output.toObject()); |
|
|
|
}); |
|
|
|
return { |
|
|
|
changeScript: this._changeScript ? this._changeScript.toString() : undefined, |
|
|
|
changeIndex: !_.isUndefined(this._changeIndex) ? this._changeIndex : undefined, |
|
|
|
fee: this._fee ? this._fee : undefined, |
|
|
|
var obj = { |
|
|
|
version: this.version, |
|
|
|
inputs: inputs, |
|
|
|
outputs: outputs, |
|
|
|
nLockTime: this.nLockTime |
|
|
|
}; |
|
|
|
if (this._changeScript) { |
|
|
|
obj.changeScript = this._changeScript.toString(); |
|
|
|
} |
|
|
|
if (!_.isUndefined(this._changeIndex)) { |
|
|
|
obj.changeIndex = this._changeIndex; |
|
|
|
} |
|
|
|
if (!_.isUndefined(this._fee)) { |
|
|
|
obj.fee = this._fee; |
|
|
|
} |
|
|
|
return obj; |
|
|
|
}; |
|
|
|
|
|
|
|
Transaction.prototype.fromObject = function(transaction) { |
|
|
|
var self = this; |
|
|
|
_.each(transaction.inputs, function(input) { |
|
|
|
if (input.output && input.output.script) { |
|
|
|
if (!input.output || !input.output.script) { |
|
|
|
self.uncheckedAddInput(new Input(input)); |
|
|
|
return; |
|
|
|
} |
|
|
|
input.output.script = new Script(input.output.script); |
|
|
|
var txin; |
|
|
|
if (input.output.script.isPublicKeyHashOut()) { |
|
|
|
self.addInput(new Input.PublicKeyHash(input)); |
|
|
|
return; |
|
|
|
console.log('p2pkh'); |
|
|
|
console.log(input.output.script); |
|
|
|
txin = new Input.PublicKeyHash(input); |
|
|
|
} else if (input.output.script.isScriptHashOut() && input.publicKeys && input.threshold) { |
|
|
|
self.addInput(new Input.MultiSigScriptHash( |
|
|
|
console.log('p2sh'); |
|
|
|
txin = new Input.MultiSigScriptHash( |
|
|
|
input, input.publicKeys, input.threshold, input.signatures |
|
|
|
)); |
|
|
|
return; |
|
|
|
} |
|
|
|
); |
|
|
|
} else { |
|
|
|
throw new errors.Transaction.Input.UnsupportedScript(input.output.script); |
|
|
|
} |
|
|
|
self.uncheckedAddInput(new Input(input)); |
|
|
|
self.addInput(txin); |
|
|
|
}); |
|
|
|
_.each(transaction.outputs, function(output) { |
|
|
|
self.addOutput(new Output(output)); |
|
|
|