简体   繁体   中英

Is it possible to call a contract in solidity, using its storage but passing along msg.sender?

I have the following two contracts:


contract A {
  uint256 someData = 3

  function foo() public view returns (uint256) {
    // return something based on msg.sender and someData
  }
}

contract B {
  A public a;

  function bar() public {
    // I'd like to call a.foo with msg.sender for this context
    uint256 ret = a.foo()  
  }
}

As indicated, I want to call a.foo within B with the msg.sender in B 's context, but I want to use someData in A's storage. This means that using delegatecall wouldn't work as it'd use B's storage for the A.foo call.

Is there any way to do what I want here? The problem has to do with the fact that the 'real' A is already deployed on mainnet and I can't change the way it's written.

I don't think this is possible as of now. I just faced the same issue but not able to find any solution. It would be better if you can create a new contract from scratch and deploy it again on mainnet by transferring all the tokens to new address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM