OriginProtocol / origin-playground

Playground for us to try out new ideas, specifically around Identity (ERC 725) & the Origin Marketplace
https://playground.originprotocol.com
MIT License
159 stars 72 forks source link

Use of `call` #16

Open wanderingstan opened 6 years ago

wanderingstan commented 6 years ago

At ERC725-alliance talk in Berlin, @ali2251 mentioned we're using call in our contracts, which is not reccomended:

I think this is the only case here: https://github.com/OriginProtocol/origin-playground/blob/0c9ba5c008d410e1ca82a2b1eed15705db49af0f/contracts/KeyHolder.sol#L86

@nick , I recall you explaining once why we had to do that. Does that still hold, or have improvements to solidity fixed it?

cuongdo commented 6 years ago

It looks like call was considered "ancient" as of 1 year ago:

https://github.com/ethereum/solidity/issues/2884#issuecomment-329169020

wanderingstan commented 6 years ago

@ali2251 ☝️ (Sorry had your username wrong at first)

junaid02012 commented 4 years ago

Hi,

This is Junaid. I have been working on ERC725. I have upgraded the contracts to 0.5.12 version but i'm facing error in following line.

bool success = executions[_id].to.call(executions[_id].data, 0);

TypeError: Wrong argument count for function call.

Please tell me how can i handle this error. Thanks

    struct Execution {
        address to;
        uint256 value;
        bytes data;
        bool approved;
        bool executed;
    }

    mapping (bytes32 => Key) keys;
    mapping (uint256 => bytes32[]) keysByPurpose;
    mapping (uint256 => Execution) executions;

    function approve(uint256 _id, bool _approve)
        public
        returns (bool s)
    {
        require(keyHasPurpose(keccak256(abi.encodePacked(msg.sender)), 2), "Sender does not have action key");

        emit Approved(_id, _approve);

        if (_approve == true) {
            executions[_id].approved = true;
            uint count = 0;
            bool success = executions[_id].to.call(executions[_id].data, 0);
            if (success) {
                executions[_id].executed = true;
                emit Executed(
                    _id,
                    executions[_id].to,
                    executions[_id].value,
                    executions[_id].data
                );
                return true;
            } else {
                emit ExecutionFailed(
                    _id,
                    executions[_id].to,
                    executions[_id].value,
                    executions[_id].data
                );
                return false;
            }
        } else {
            executions[_id].approved = false;
        }
        return true;
    }