encodeTo method

  1. @override
void encodeTo(
  1. Map<String, dynamic> value,
  2. Output output
)
override

Convert self to a slice and append it to the destination.

Implementation

@override
void encodeTo(Map<String, dynamic> value, Output output) {
  assertion(value['version'] == 4,
      'Unsupported extrinsic version, Expected 4 but got ${value['version']}');
  assertion(value['calls'] != null, 'No calls found to encode.');

  final ByteOutput tempOutput = ByteOutput();

  int meta = 4;

  if (value['signature'] != null) {
    //
    // 0b10000000 ~ 128 in BigInt
    meta |= BigInt.from(128).toInt();

    //
    // Start encoding the signature
    chainInfo.scaleCodec
        .encodeTo('ExtrinsicSignatureCodec', value['signature'], tempOutput);
  }

  chainInfo.scaleCodec.encodeTo('Call', value['calls'], tempOutput);

  CompactCodec.codec.encodeTo(tempOutput.length + 1, output);

  output
    ..pushByte(meta)
    ..write(tempOutput.toBytes());
}