addInput method
Add input from transaction data, which can be:
- hash as a String
- hash as a Uint8List
- instance of Transaction
Returns vin of the input
Throws ArgumentError
if the inputs of this transaction can't be modified or if txHashOrInstance
is invalid
Implementation
int addInput(dynamic txHashOrInstance, int vout, [int sequence, Uint8List prevOutScript]) {
assert(txHashOrInstance is String || txHashOrInstance is Uint8List || txHashOrInstance is Transaction);
if (!_canModifyInputs()) {
throw new ArgumentError('No, this would invalidate signatures');
}
Uint8List hash;
var value;
if (txHashOrInstance is String) {
hash = Uint8List.fromList(HEX.decode(txHashOrInstance).reversed.toList());
} else if (txHashOrInstance is Uint8List) {
hash = txHashOrInstance;
} else if (txHashOrInstance is Transaction) {
final txOut = txHashOrInstance.outputs[vout];
prevOutScript = txOut.script;
value = txOut.value;
hash = txHashOrInstance.getHash();
} else {
throw ArgumentError('txHash invalid');
}
return _addInputUnsafe(hash, vout, new Input(sequence: sequence, prevOutScript: prevOutScript, value: value));
}