withdrawal method

Map<String, dynamic> withdrawal({
  1. required Object amount,
  2. String type = '0x2::sui::SUI',
  3. WithdrawalSource from = WithdrawalSource.sender,
  4. String? allowance,
  5. String? funder,
})

Reserves funds without redeeming them, for Move calls that accept a Withdrawal.

Implementation

Map<String, dynamic> withdrawal({
  required Object amount,
  String type = '0x2::sui::SUI',
  WithdrawalSource from = WithdrawalSource.sender,
  String? allowance,
  String? funder,
}) {
  if ((from == WithdrawalSource.allowance) !=
          (allowance != null && funder != null) ||
      (from != WithdrawalSource.allowance &&
          (allowance != null || funder != null))) {
    throw ArgumentError(
      'Allowance withdrawals require both allowance and funder',
    );
  }
  return _blockData.addInput('withdrawal', {
    r'$kind': 'FundsWithdrawal',
    'FundsWithdrawal': {
      'reservation': {'MaxAmountU64': parseBalanceAmount(amount).toString()},
      'typeArg': {
        'Balance': type.contains('@') ? type : normalizeStructTagString(type),
      },
      'withdrawFrom': switch (from) {
        WithdrawalSource.sender => {'Sender': true},
        WithdrawalSource.sponsor => {'Sponsor': true},
        WithdrawalSource.allowance => {
          'SenderAllowance': {
            'funder': normalizeSuiAddress(funder!),
            'allowance': normalizeSuiAddress(allowance!),
          },
        },
      },
    },
  });
}