ADAByronAddrAttrs.fromCbor constructor

ADAByronAddrAttrs.fromCbor(
  1. CborMapValue 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 const AddressConverterException('Invalid address attributes');
  }
  final hdPath = cborValue.value.containsKey(cborOne)
      ? CborObject.fromCbor(
              (cborValue.value[cborOne]! as CborBytesValue).value)
          .value
      : null;
  final networkMagic = cborValue.value.containsKey(cborTwo)
      ? CborObject.fromCbor(
              (cborValue.value[cborTwo]! as CborBytesValue).value)
          .value
      : null;
  return ADAByronAddrAttrs(
      hdPathEncBytes: hdPath, networkMagic: networkMagic);
}