Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relay execution value #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

juliosantos
Copy link

This isn't tested yet — I'm not sure it's desired. The standard should likely be updated first, as per this comment and the next (or the contract should include another payable function). Thoughts?

@nick
Copy link
Contributor

nick commented Jun 20, 2018

Makes sense... we can wait for the standard to be updated first though perhaps

Copy link

@ricktobacco ricktobacco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please explain how this line you changed works (perhaps as a docstring/comment in the code)? i am new to solidity and would very much like to understand...thank you!
p.s. could to.call.value be replaced with transfer ?

@DanielVF
Copy link
Contributor

@ricktobacco, this line is a bit of a glimpse into the darkest abysses of Solidity. :)

At the simplest level, it runs some code on another contract.

An example of doing something similar in JavaScript would be something like:

// Equivalent to foo.bar()

const objectName = "foo"
const functionName = "bar"
window[objectName][functionName].call()

Going back to Solidity, the first argument to the solidity call function is the hash of the name/ABI of the function you want to call. Here is an example, calling a function on another contract when you know all about about the other contract, and then calling an arbitrary function on that other contract:

https://ethfiddle.com/79HU5M1aCH

pragma solidity ^0.4.18;

contract CodeRunner {
  address otherContract;

  function setOtherContract(address _otherContract) public {
    otherContract = _otherContract;
  }

  function callWithKnownFunction() public {
    // Here we cast the other contract to a "Target" and then call "foo" on it.
    Target(otherContract).foo();
  }

  function callWithCall() public returns (bool){
    // Now we don't know what kind of contract the other contract is
    // We're just blindly firing off a call to run a function we hope is there
    bytes4 hashOfFunctionToCall = bytes4(keccak256("foo()"));
    bool success = otherContract.call(hashOfFunctionToCall);
    return success;
  }
  
}

contract Target {
  uint _callCount = 0;

  function foo() public {
    _callCount += 1;
  }

  function callCount() public view returns (uint) {
    return _callCount;
  }
}

So if you do a bytes4(keccak256("foo()")); then you can get the hash of the foo() function, which you can use to call it.

In this identity playground code, someone can submit a contract address and a function hash that they wish the identity to call (using the execute method). Later on, that could be approved, and then the identity contract would call the function you submitted on the contract you submitted from the identity contract.

When doing a call in Solidity, you can also explicitly set the amount of gas to be used and the amount of eth to transfer. This commit explicitly sets an amount to transfer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants