ETH-Pantheon / Aion

A system for Scheduling transactions with arbitrary bytecode on the Ethereum Network
https://www.aion.ethpantheon.com
MIT License
26 stars 13 forks source link

I think the README example needs a payable fallback in the interface #16

Closed zach-is-my-name closed 4 years ago

zach-is-my-name commented 4 years ago

I'm not completely sure, but it seems that the example given in the README requires a fallback function to be added to the interface. This may not affect the behavior of Aion itself, but when trying to invoke payable or fund MyContract.

// interface Aion
contract Aion {
    uint256 public serviceFee;
    function ScheduleCall(uint256 blocknumber, address to, uint256 value, uint256 gaslimit, uint256 gasprice, bytes data, bool schedType) public payable returns (uint);

++ function() public payable {
     }
}

// Main contract
contract MyContract{
    Aion aion;

    function scheduleTransaction(uint256 value, uint256 gaslimit, uint256 gasprice, bool time_or_block) public {
        aion = Aion(0xFcFB45679539667f7ed55FA59A15c8Cad73d9a4E);
        uint256 callCost = value + gaslimit*gasprice + aion.serviceFee();
        aion.ScheduleCall.value(callCost)( block.number+15, address(this), value, gaslimit, gasprice, hex"00", time_or_block);
    }

    function () public payable {}

}

From Solidity Docs v0.42

pragma solidity ^0.4.0;


    // This function is called for all messages sent to
    // this contract (there is no other function).
    // Sending Ether to this contract will cause an exception,
    // because the fallback function does not have the `payable`
    // modifier.
    function() public { x = 1; }
    uint x;
}

// This contract keeps all Ether sent to it with no way
// to get it back.
contract Sink {
    function() public payable { }
}

contract Caller {
    function callTest(Test test) public {
        test.call(0xabcdef01); // hash does not exist
        // results in test.x becoming == 1.

        // The following will not compile, but even
        // if someone sends ether to that contract,
        // the transaction will fail and reject the
        // Ether.
        //test.send(2 ether);
    }
}

Remix: trying to fund TestAion. Only un-commenting function() public payable allow send without data to succeed

browser/TestAion.sol : dweb:/ipfs/Qmf2q3bU98EXBoGCNTdC5MqR1GkQ4ZgxPUyhQnFTwzCC7V metadata.json : dweb:/ipfs/QmNQhQV19DntECVgPjCDb771HWF8ZZnXY8JxB4NwrmmeD7

jfdelgad commented 4 years ago

Hello,

It is not necessary to add the fallback function in the interface. I am not sure what you mean by "Only un-commenting function() public payable allow send without data to succeed"

Looking into your code, the error is that callCost is calculated using gasLimit=900000 but aion.ScheduleCall is called using 600000. This will revert as the value passed to the function do not match the calculation using the gasLimit passed to it.

Let me know if this solves the issue.

zach-is-my-name commented 4 years ago

Yes it does. Very sorry