首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Callcode \ Delegatecall不工作

Callcode \ Delegatecall不工作
EN

Ethereum用户
提问于 2016-08-24 08:53:04
回答 1查看 1.2K关注 0票数 3

我在玩calldelegatecallcallcode,发现函数reset在我调用了一个回调代码之后停止了工作(以下是我的操作):

来自JS方面:

代码语言:javascript
复制
— A.makeCall({gas:300000}); // NO ERRORS
— A.sender(); // 0x0000000000000000000000000000000000000000 AS EXPECTED
— A.myVar(); // 0 AS EXPECTED
— B.sender(); // addressA AS EXPECTED
— B.myVar(); // 1 AS EXPECTED

— A.reset({gas: 300000}); // NO ERRORS;

— A.sender(); // 0x0000000000000000000000000000000000000000 AS EXPECTED
— A.myVar(); // 0 AS EXPECTED
— B.sender(); // 0x0 AS EXPECTED
— B.myVar(); // 0 AS EXPECTED

— A.makeCallCode({gas:300000}); // NO ERRORS
— A.sender(); // 0x0000000000000000000000000000000000000002 Oops! It looks like there was no access to msg.sender and sender variable was assigned argument x instead. 
— A.myVar(); // 0 Oops! Nothing was assigned, because of the ↑
— B.sender(); // 0x0 AS EXPECTED
— B.myVar(); // 0 AS EXPECTED

— A.reset({gas: 300000}); //ALL KIND OF ERRORS; WTF IS GOING ON HERE? NO MATTER HOW MUCH GAS I SUPPLY IT STILL FAILS. https://testnet.etherscan.io/tx/0x6654b6739f55690c7114fa9e8cfb7a5959e73d60c37782aee4e211487de859f2 
代码语言:javascript
复制
contract A {
    address public addressB;   
    address public sender;
    uint public myVar;

    function A() {
        addressB = new B();
    }

    function makeCall(){
        addressB.call(bytes4(sha3('set(uint256)')), 1);
    }
    function makeCallCode(){
        addressB.callcode(bytes4(sha3('set(uint256)')), 2);
    }
    function makeDelegateCall(){
        addressB.delegatecall(bytes4(sha3('set(uint256)')), 3);
    }

    function reset(){
        sender = 0;
        myVar = 0;
        B(addressB).reset();
    }
}

contract B {
    address public sender;
    uint public myVar;

    function set(uint x){
        myVar = x;
        sender = msg.sender;
    }
    function reset(){
        sender = 0;
        myVar = 0;        
    }
}
EN

回答 1

Ethereum用户

回答已采纳

发布于 2016-08-24 15:33:30

这个问题与存储中变量的排列方式有关。被叫合同和被叫合同的存储应该匹配。这个问题的答案可以在这里找到-- https://github.com/ethereum/solidity/issues/944

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/8276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档