toXdr method

XdrSCAddress toXdr()

Returns a XdrSCAddress object created from this Address object.

Implementation

XdrSCAddress toXdr() {
  if (_type == TYPE_ACCOUNT) {
    if (accountId == null) {
      throw Exception("invalid address, has no account id");
    }
    return XdrSCAddress.forAccountId(accountId!);
  } else if (_type == TYPE_CONTRACT) {
    if (contractId == null) {
      throw Exception("invalid address, has no contract id");
    }
    return XdrSCAddress.forContractId(contractId!);
  } else if (_type == TYPE_MUXED_ACCOUNT) {
    if (muxedAccountId == null) {
      throw Exception("invalid address, has no muxed account id");
    }
    return XdrSCAddress.forAccountId(accountId!);
  } else if (_type == TYPE_CLAIMABLE_BALANCE) {
    if (claimableBalanceId == null) {
      throw Exception("invalid address, has no claimable balance id");
    }
    return XdrSCAddress.forClaimableBalanceId(claimableBalanceId!);
  } else if (_type == TYPE_LIQUIDITY_POOL) {
    if (liquidityPoolId == null) {
      throw Exception("invalid address, has no liquidity pool id");
    }
    return XdrSCAddress.forLiquidityPoolId(liquidityPoolId!);
  } else {
    throw Exception("unknown address type " + _type.toString());
  }
}