【问题标题】:Use of functions in calculation and gas use在计算和气体使用中使用函数
【发布时间】:2017-08-10 08:54:14
【问题描述】:

为什么以下不起作用?

uint transactionFee = (msg.value * 2) / 100;
uint transactionReward = (msg.value * 2) / 100;
uint receiverMoney = msg.value - limitTransactionCosts(transactionFee - transactionReward);

The contract won't allow this transaction to be executed

在此过程中:

uint transactionFee = (msg.value * 2) / 100;
uint transactionReward = (msg.value * 2) / 100;
transactionFee = limitTransactionCosts(transactionFee);
transactionReward = limitTransactionCosts(transactionReward);

uint receiverMoney = msg.value - transactionFee - transactionReward;

50.002 Gas

【问题讨论】:

    标签: ethereum solidity


    【解决方案1】:

    您的代码应该按预期工作,因为没有错误。 确保您的 limitTransactionCosts 具有有效的返回类型(int/float)。 请添加功能代码进一步分析。

    【讨论】:

    • limitTransactionCosts 是一个函数
    • 好的,问题中带有'-'符号,所以我假设
    【解决方案2】:

    发现我的错误。无论limitTransactionCosts如何,我都会发送交易费用和奖励。

    我知道的代码如下所示:

    // Calculate costs
        uint transactionCosts = (msg.value * 4) / 1000; 
        transactionCosts = limitTransactionCosts(transactionCosts);
    
        uint transactionFee = transactionCosts / 2;
        uint transactionReward = transactionCosts / 2;
    
        uint receiverMoney = msg.value - transactionCosts;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      相关资源
      最近更新 更多