Skip to content

Commit

Permalink
Merge pull request #1294 from braydonf/tx-unmodified-arguments
Browse files Browse the repository at this point in the history
Objects passed as arguments are unmodified.
  • Loading branch information
pnagurny committed Jul 30, 2015
2 parents 6ac7ad9 + 3d1dc7a commit 0dec8e7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
7 changes: 5 additions & 2 deletions lib/transaction/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ Object.defineProperty(Input.prototype, 'script', {
});

Input.prototype._fromObject = function(params) {
var 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 ?
(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.sequenceNumber = _.isUndefined(params.sequenceNumber) ?
(_.isUndefined(params.seqnum) ? DEFAULT_SEQNUMBER : params.seqnum) : params.sequenceNumber;
Expand Down
7 changes: 5 additions & 2 deletions lib/transaction/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ function Output(args) {
if (bufferUtil.isBuffer(args.script)) {
this._scriptBuffer = args.script;
} else {
var 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)) {
return Output.fromJSON(args);
Expand Down
6 changes: 3 additions & 3 deletions lib/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ Transaction.prototype.fromObject = function(transaction) {
self.uncheckedAddInput(new Input(input));
return;
}
input.output.script = new Script(input.output.script);
var script = new Script(input.output.script);
var txin;
if (input.output.script.isPublicKeyHashOut()) {
if (script.isPublicKeyHashOut()) {
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(
input, input.publicKeys, input.threshold, input.signatures
);
Expand Down
6 changes: 4 additions & 2 deletions test/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ describe('Transaction', function() {
});

it('serialize to Object roundtrip', function() {
new Transaction(testTransaction.toObject()).uncheckedSerialize()
.should.equal(testTransaction.uncheckedSerialize());
var a = testTransaction.toObject();
var newTransaction = new Transaction(a);
var b = newTransaction.toObject();
a.should.deep.equal(b);
});

it('constructor returns a shallow copy of another transaction', function() {
Expand Down

0 comments on commit 0dec8e7

Please sign in to comment.