|
|
@ -30,6 +30,9 @@ Object.defineProperty(Input.prototype, 'script', { |
|
|
|
writeable: false, |
|
|
|
enumerable: true, |
|
|
|
get: function() { |
|
|
|
if (this.isNull()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (!this._script) { |
|
|
|
this._script = new Script(this._scriptBuffer); |
|
|
|
} |
|
|
@ -59,8 +62,12 @@ Input.prototype.toObject = function toObject() { |
|
|
|
prevTxId: this.prevTxId.toString('hex'), |
|
|
|
outputIndex: this.outputIndex, |
|
|
|
sequenceNumber: this.sequenceNumber, |
|
|
|
script: this.script.toString(), |
|
|
|
script: this._scriptBuffer.toString('hex'), |
|
|
|
}; |
|
|
|
// add human readable form if input contains valid script
|
|
|
|
if (this.script) { |
|
|
|
obj.scriptString = this.script.toString(); |
|
|
|
} |
|
|
|
if (this.output) { |
|
|
|
obj.output = this.output.toObject(); |
|
|
|
} |
|
|
@ -88,6 +95,8 @@ Input.fromBufferReader = function(br) { |
|
|
|
input.outputIndex = br.readUInt32LE(); |
|
|
|
input._scriptBuffer = br.readVarLengthBuffer(); |
|
|
|
input.sequenceNumber = br.readUInt32LE(); |
|
|
|
// TODO: return different classes according to which input it is
|
|
|
|
// e.g: CoinbaseInput, PublicKeyHashInput, MultiSigScriptHashInput, etc.
|
|
|
|
return input; |
|
|
|
}; |
|
|
|
|
|
|
@ -105,14 +114,18 @@ Input.prototype.toBufferWriter = function(writer) { |
|
|
|
}; |
|
|
|
|
|
|
|
Input.prototype.setScript = function(script) { |
|
|
|
this._script = null; |
|
|
|
if (script instanceof Script) { |
|
|
|
this._script = script; |
|
|
|
this._scriptBuffer = script.toBuffer(); |
|
|
|
} else if (JSUtil.isHexa(script)) { |
|
|
|
// hex string script
|
|
|
|
this._scriptBuffer = new Buffer(script, 'hex'); |
|
|
|
} else if (_.isString(script)) { |
|
|
|
this._script = new Script(script); |
|
|
|
this._scriptBuffer = this._script.toBuffer(); |
|
|
|
// human readable string script
|
|
|
|
this._scriptBuffer = script.toBuffer(); |
|
|
|
} else if (BufferUtil.isBuffer(script)) { |
|
|
|
this._script = null; |
|
|
|
// buffer script
|
|
|
|
this._scriptBuffer = new buffer.Buffer(script); |
|
|
|
} else { |
|
|
|
throw new TypeError('Invalid argument type: script'); |
|
|
|