2017-08-10 24 views
0

为什么下面不起作用?在计算和使用燃气时使用函数

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

回答

0

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

+0

limitTransactionCosts是一个功能 – BananazZ

+0

OK,这是与“ - ”在问题的符号,所以我认为 –

+0

请你为函数中添加代码也 –

0

发现我的错误。无论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;