bytes property

  1. @override
Uint8List get bytes
override

Implementation

@override
Uint8List get bytes {
  final inputBuffers = inputs.map((input) => input.bytes);
  const inputLengthByte = 1;
  final inputsByteLength = inputBuffers.fold(
    0,
    (prev, buffer) => prev + buffer.length,
  );

  final outputBuffers = outputs.map((output) => output.bytes);
  const outputLengthByte = 1;
  final outputsByteLength = outputBuffers.fold(
    0,
    (prev, buffer) => prev + buffer.length,
  );

  var txByteLength = 4 +
      inputLengthByte +
      inputsByteLength +
      outputLengthByte +
      outputsByteLength +
      8 +
      4 +
      8 +
      4;

  ///
  /// Construct Buffer
  ///
  final buffer = Uint8List(txByteLength);
  var offset = 0;

  /// Version
  offset += buffer.bytes.writeUint32(offset, version);

  /// Inputs
  offset += buffer.bytes.writeVarInt(offset, inputs.length);
  for (final input in inputs) {
    offset += buffer.writeSlice(offset, input.bytes);
  }

  /// Outputs
  offset += buffer.bytes.writeVarInt(offset, outputs.length);
  for (final output in outputs) {
    offset += buffer.writeSlice(offset, output.bytes);
  }

  /// Fee
  offset += buffer.bytes.writeUint64(offset, fee.toInt());

  /// Weight
  offset += buffer.bytes.writeUint32(offset, weight.toInt());

  /// ValidFrom
  offset += buffer.bytes.writeUint64(offset, validFrom);

  /// ValidUntil
  offset += buffer.bytes.writeUint32(offset, validUntil);

  return buffer;
}