decode method

  1. @override
RuntimeCall decode(
  1. Input input
)
override

Implementation

@override
RuntimeCall decode(final Input input) {
  final palletIndex = input.read();
  final pallet = registry.palletByIndex(palletIndex);

  if (pallet == null) {
    throw MetadataException('Pallet with index $palletIndex not found');
  }

  final calls = pallet.calls;
  if (calls == null) {
    throw MetadataException('Pallet ${pallet.name} has no calls');
  }

  // Read call index
  final callIndex = input.read();
  final callVariant = registry.getVariantByIndex(calls.type, callIndex);

  if (callVariant == null) {
    throw MetadataException('Call with index $callIndex not found in pallet ${pallet.name}');
  }

  // Decode arguments
  final args = <String, dynamic>{};
  for (final field in callVariant.fields) {
    final codec = registry.codecFor(field.type);
    args[field.name ?? 'unnamed'] = codec.decode(input);
  }

  return RuntimeCall(
    palletName: pallet.name,
    palletIndex: palletIndex,
    callName: callVariant.name,
    callIndex: callIndex,
    args: args,
  );
}