Objects passed as arguments are unmodified.
This commit is contained in:
parent
c47adf1c04
commit
3d1dc7aafe
@ -40,12 +40,15 @@ Object.defineProperty(Input.prototype, 'script', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Input.prototype._fromObject = function(params) {
|
Input.prototype._fromObject = function(params) {
|
||||||
|
var prevTxId;
|
||||||
if (_.isString(params.prevTxId) && JSUtil.isHexa(params.prevTxId)) {
|
if (_.isString(params.prevTxId) && JSUtil.isHexa(params.prevTxId)) {
|
||||||
params.prevTxId = new buffer.Buffer(params.prevTxId, 'hex');
|
prevTxId = new buffer.Buffer(params.prevTxId, 'hex');
|
||||||
|
} else {
|
||||||
|
prevTxId = params.prevTxId;
|
||||||
}
|
}
|
||||||
this.output = params.output ?
|
this.output = params.output ?
|
||||||
(params.output instanceof Output ? params.output : new Output(params.output)) : undefined;
|
(params.output instanceof Output ? params.output : new Output(params.output)) : undefined;
|
||||||
this.prevTxId = params.prevTxId || params.txidbuf;
|
this.prevTxId = prevTxId || params.txidbuf;
|
||||||
this.outputIndex = _.isUndefined(params.outputIndex) ? params.txoutnum : params.outputIndex;
|
this.outputIndex = _.isUndefined(params.outputIndex) ? params.txoutnum : params.outputIndex;
|
||||||
this.sequenceNumber = _.isUndefined(params.sequenceNumber) ?
|
this.sequenceNumber = _.isUndefined(params.sequenceNumber) ?
|
||||||
(_.isUndefined(params.seqnum) ? DEFAULT_SEQNUMBER : params.seqnum) : params.sequenceNumber;
|
(_.isUndefined(params.seqnum) ? DEFAULT_SEQNUMBER : params.seqnum) : params.sequenceNumber;
|
||||||
|
|||||||
@ -21,10 +21,13 @@ function Output(args) {
|
|||||||
if (bufferUtil.isBuffer(args.script)) {
|
if (bufferUtil.isBuffer(args.script)) {
|
||||||
this._scriptBuffer = args.script;
|
this._scriptBuffer = args.script;
|
||||||
} else {
|
} else {
|
||||||
|
var script;
|
||||||
if (_.isString(args.script) && JSUtil.isHexa(args.script)) {
|
if (_.isString(args.script) && JSUtil.isHexa(args.script)) {
|
||||||
args.script = new buffer.Buffer(args.script, 'hex');
|
script = new buffer.Buffer(args.script, 'hex');
|
||||||
|
} else {
|
||||||
|
script = args.script;
|
||||||
}
|
}
|
||||||
this.setScript(args.script);
|
this.setScript(script);
|
||||||
}
|
}
|
||||||
} else if (JSUtil.isValidJSON(args)) {
|
} else if (JSUtil.isValidJSON(args)) {
|
||||||
return Output.fromJSON(args);
|
return Output.fromJSON(args);
|
||||||
|
|||||||
@ -358,11 +358,11 @@ Transaction.prototype.fromObject = function(transaction) {
|
|||||||
self.uncheckedAddInput(new Input(input));
|
self.uncheckedAddInput(new Input(input));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
input.output.script = new Script(input.output.script);
|
var script = new Script(input.output.script);
|
||||||
var txin;
|
var txin;
|
||||||
if (input.output.script.isPublicKeyHashOut()) {
|
if (script.isPublicKeyHashOut()) {
|
||||||
txin = new Input.PublicKeyHash(input);
|
txin = new Input.PublicKeyHash(input);
|
||||||
} else if (input.output.script.isScriptHashOut() && input.publicKeys && input.threshold) {
|
} else if (script.isScriptHashOut() && input.publicKeys && input.threshold) {
|
||||||
txin = new Input.MultiSigScriptHash(
|
txin = new Input.MultiSigScriptHash(
|
||||||
input, input.publicKeys, input.threshold, input.signatures
|
input, input.publicKeys, input.threshold, input.signatures
|
||||||
);
|
);
|
||||||
|
|||||||
@ -63,8 +63,10 @@ describe('Transaction', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('serialize to Object roundtrip', function() {
|
it('serialize to Object roundtrip', function() {
|
||||||
new Transaction(testTransaction.toObject()).uncheckedSerialize()
|
var a = testTransaction.toObject();
|
||||||
.should.equal(testTransaction.uncheckedSerialize());
|
var newTransaction = new Transaction(a);
|
||||||
|
var b = newTransaction.toObject();
|
||||||
|
a.should.deep.equal(b);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('constructor returns a shallow copy of another transaction', function() {
|
it('constructor returns a shallow copy of another transaction', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user