public override Empty ChargeTransactionFees(ChargeTransactionFeesInput input) { if (input.Equals(new ChargeTransactionFeesInput())) { return(new Empty()); } ChargeFirstSufficientToken(input.SymbolToAmount, out var symbol, out var amount, out var existingBalance); if (State.PreviousBlockTransactionFeeTokenSymbolList.Value == null) { State.PreviousBlockTransactionFeeTokenSymbolList.Value = new TokenSymbolList(); } if (!State.PreviousBlockTransactionFeeTokenSymbolList.Value.SymbolList.Contains(symbol)) { State.PreviousBlockTransactionFeeTokenSymbolList.Value.SymbolList.Add(symbol); } var fromAddress = Context.Sender; State.Balances[fromAddress][symbol] = existingBalance.Sub(amount); State.ChargedFees[fromAddress][symbol] = State.ChargedFees[fromAddress][symbol].Add(amount); return(new Empty()); }
public override Empty ChargeTransactionFees(ChargeTransactionFeesInput input) { if (input.Equals(new ChargeTransactionFeesInput())) { return(new Empty()); } var tokenInfo = AssertValidToken(input.Symbol, input.Amount); Assert(tokenInfo.Symbol == State.NativeTokenSymbol.Value, "The paid fee is not in native token."); var fromAddress = Context.Sender; var existingBalance = State.Balances[fromAddress][input.Symbol]; Assert(existingBalance >= input.Amount, "Insufficient balance."); State.Balances[fromAddress][input.Symbol] = existingBalance.Sub(input.Amount); State.ChargedFees[fromAddress][input.Symbol] = State.ChargedFees[fromAddress][input.Symbol].Add(input.Amount); return(new Empty()); }