public bool IsStopExecuting(ByteString txReturnValue, out string preExecutionInformation) { var chargeTransactionFeesOutput = new ChargeTransactionFeesOutput(); chargeTransactionFeesOutput.MergeFrom(txReturnValue); preExecutionInformation = chargeTransactionFeesOutput.ChargingInformation; return(!chargeTransactionFeesOutput.Success); }
/// <summary> /// Related transactions will be generated by acs1 pre-plugin service, /// and will be executed before the origin transaction. /// </summary> /// <param name="input"></param> /// <returns></returns> public override ChargeTransactionFeesOutput ChargeTransactionFees(ChargeTransactionFeesInput input) { AssertTransactionGeneratedByPlugin(); Assert(input.MethodName != null && input.ContractAddress != null, "Invalid charge transaction fees input."); // Primary token not created yet. if (State.ChainPrimaryTokenSymbol.Value == null) { return(new ChargeTransactionFeesOutput { Success = true }); } // Record tx fee bill during current charging process. var bill = new TransactionFeeBill(); var fromAddress = Context.Sender; var methodFees = Context.Call <MethodFees>(input.ContractAddress, nameof(GetMethodFee), new StringValue { Value = input.MethodName }); var successToChargeBaseFee = true; if (methodFees != null && methodFees.Fees.Any()) { successToChargeBaseFee = ChargeBaseFee(GetBaseFeeDictionary(methodFees), ref bill); } var successToChargeSizeFee = true; if (!IsMethodFeeSetToZero(methodFees)) { // Then also do not charge size fee. successToChargeSizeFee = ChargeSizeFee(input, ref bill); } // Update balances. foreach (var tokenToAmount in bill.FeesMap) { ModifyBalance(fromAddress, tokenToAmount.Key, -tokenToAmount.Value); Context.Fire(new TransactionFeeCharged { Symbol = tokenToAmount.Key, Amount = tokenToAmount.Value }); if (tokenToAmount.Value == 0) { Context.LogDebug(() => $"Maybe incorrect charged tx fee of {tokenToAmount.Key}: it's 0."); } } var chargingResult = successToChargeBaseFee && successToChargeSizeFee; var chargingOutput = new ChargeTransactionFeesOutput { Success = chargingResult }; if (!chargingResult) { chargingOutput.ChargingInformation = "Transaction fee not enough."; } return(chargingOutput); }