ADAByronAddrAttrs.fromCbor constructor

ADAByronAddrAttrs.fromCbor(
  1. CborMapValue<CborObject<Object?>, CborObject<Object?>> cborValue
)

Implementation

factory ADAByronAddrAttrs.fromCbor(CborMapValue cborValue) {
  const cborOne = CborIntValue(1);
  const cborTwo = CborIntValue(2);
  if (cborValue.value.length > 2 ||
      (cborValue.value.isNotEmpty &&
          !cborValue.value.containsKey(cborOne) &&
          !cborValue.value.containsKey(cborTwo))) {
    throw AddressConverterException.addressBytesValidationFailed(
      reason: "Invalid address attributes.",
    );
  }
  final hdPath =
      cborValue.value.containsKey(cborOne)
          ? CborBytesValue.decode(
            (cborValue.value[cborOne]! as CborBytesValue).value,
          ).value
          : null;
  final networkMagic =
      cborValue.value.containsKey(cborTwo)
          ? CborIntValue.decode(
            (cborValue.value[cborTwo]! as CborBytesValue).value,
          ).value
          : null;
  return ADAByronAddrAttrs(
    hdPathEncBytes: hdPath,
    networkMagic: networkMagic,
  );
}