|
|
@ -4,7 +4,7 @@ var _ = require('lodash'); |
|
|
|
var BufferWriter = require('../../encoding/bufferwriter'); |
|
|
|
var buffer = require('buffer'); |
|
|
|
var bufferUtil = require('../../util/buffer'); |
|
|
|
var jsUtil = require('../../util/js'); |
|
|
|
var JSUtil = require('../../util/js'); |
|
|
|
var Script = require('../../script'); |
|
|
|
|
|
|
|
function Input(params) { |
|
|
@ -28,7 +28,7 @@ Object.defineProperty(Input.prototype, 'script', { |
|
|
|
}); |
|
|
|
|
|
|
|
Input.prototype._fromObject = function(params) { |
|
|
|
if (_.isString(params.prevTxId) && jsUtil.isHexa(params.prevTxId)) { |
|
|
|
if (_.isString(params.prevTxId) && JSUtil.isHexa(params.prevTxId)) { |
|
|
|
params.prevTxId = new buffer.Buffer(params.prevTxId, 'hex'); |
|
|
|
} |
|
|
|
this.prevTxId = params.prevTxId; |
|
|
@ -40,7 +40,7 @@ Input.prototype._fromObject = function(params) { |
|
|
|
return this; |
|
|
|
}; |
|
|
|
|
|
|
|
Input.prototype.toJSON = function() { |
|
|
|
Input.prototype.toObject = function toObject() { |
|
|
|
return { |
|
|
|
prevTxId: this.prevTxId, |
|
|
|
outputIndex: this.outputIndex, |
|
|
@ -49,7 +49,14 @@ Input.prototype.toJSON = function() { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
Input.prototype.toJSON = function toJSON() { |
|
|
|
return JSON.stringify(this.toObject()); |
|
|
|
}; |
|
|
|
|
|
|
|
Input.fromJSON = function(json) { |
|
|
|
if (JSUtil.isValidJSON(json)) { |
|
|
|
json = JSON.parse(json); |
|
|
|
} |
|
|
|
return new Input({ |
|
|
|
prevTxId: json.prevTxId || json.txidbuf, |
|
|
|
outputIndex: json.outputIndex || json.txoutnum, |
|
|
|