fromXdr method Null safety

Address fromXdr(
  1. XdrSCAddress xdr
)

Constructs an Address from the given xdr.

Implementation

static Address fromXdr(XdrSCAddress xdr) {
  if (xdr.discriminant == XdrSCAddressType.SC_ADDRESS_TYPE_ACCOUNT) {
    KeyPair kp = KeyPair.fromXdrPublicKey(xdr.accountId!.accountID);
    return Address(TYPE_ACCOUNT, accountId: kp.accountId);
  } else if (xdr.discriminant == XdrSCAddressType.SC_ADDRESS_TYPE_CONTRACT) {
    return Address(TYPE_CONTRACT,
        contractId: Util.bytesToHex(xdr.contractId!.hash));
  } else {
    throw Exception("unknown address type " + xdr.discriminant.toString());
  }
}