addOutput method
Adds transaction output, which can be provided as:
- Address as
String
in either legacy or cashAddr format - scriptPubKey
Returns output id
Throws ArgumentError
if outputs can't be modified or the output format is invalid
Implementation
int addOutput(dynamic data, int value) {
assert (data is String || data is Uint8List);
Uint8List scriptPubKey;
if (data is String) {
if (Address.detectFormat(data) == Address.formatCashAddr) {
data = Address.toLegacyAddress(data);
}
scriptPubKey = _addressToOutputScript(data, _network);
} else if (data is Uint8List) {
scriptPubKey = data;
} else {
throw ArgumentError('Address invalid');
}
if (!_canModifyOutputs()) {
throw ArgumentError('No, this would invalidate signatures');
}
return _tx.addOutput(scriptPubKey, value);
}