toBytes method

Uint8List toBytes()

serializes TxInput to bytes

Implementation

Uint8List toBytes() {
  final txidBytes = Uint16List.fromList(hexToBytes(txId).reversed.toList());

  final txoutBytes = Uint8List(4);
  ByteData.view(txoutBytes.buffer).setUint32(0, txIndex, Endian.little);

  final scriptSigBytes = scriptSig.toBytes();

  final scriptSigLengthVarint = encodeVarint(scriptSigBytes.length);
  final data = Uint8List.fromList([
    ...txidBytes,
    ...txoutBytes,
    ...scriptSigLengthVarint,
    ...scriptSigBytes,
    ...sequence,
  ]);
  return data;
}