[英]Is the msg.sender address changed while passing to another contract as a parameter?
I'm here to ask my problem on solidity code. 我是在这里问我关于统一代码的问题。
Here is simple example code. 这是简单的示例代码。 Contract 'Map' has a mapped data.
合同“地图”具有映射的数据。 It has each address's T/F values.
它具有每个地址的T / F值。 I created an account
X
and add it to 'simpleMap'
. 我创建了一个帐户
X
并将其添加到'simpleMap'
。
Contract 'Ask' lookup mapping data through 'Map' contract. 通过“地图”合约进行合约“询问”查找映射数据。 What I expected result when
X
called askMe()
was TRUE
but it was always FALSE
. 当
X
调用askMe()
时,我期望的结果是TRUE
但始终为FALSE
。
When I called whoIsMsgSender
it returns the exact X
's account. 当我调用
whoIsMsgSender
它将返回确切的X
帐户。 What's the problem?? 有什么问题??
pragma solidity ^0.4.24;
contract Map {
mapping (address => bool) simpleMap;
function add(address _address) external {
simpleMap[_address] = true;
}
function isTrue(address _address) external view returns (bool _ret) {
return simpleMap[_address];
}
}
contract Ask {
Map public map = Map(Map's address like 0x~~ just for test);
function askMe() external view returns (bool _ret) {
return map.isTrue(msg.sender);
}
function whoIsMsgSender() external view returns (address _address) {
return msg.sender;
}
}
I tried your contracts in Remix, but askMe() returned true for me. 我在Remix中尝试了您的合同,但是askMe()为我返回了true。 How are you separating the two contracts?
您如何分开这两个合同? Maybe Map is not yet deployed before Ask is trying to call a function on it.
也许在Ask尝试在其上调用函数之前尚未部署Map。 I separated the two contracts:
我分开了两个合同:
pragma solidity ^0.4.24;
contract Map {
mapping (address => bool) simpleMap;
function add(address _address) external {
simpleMap[_address] = true;
}
function isTrue(address _address) external view returns (bool _ret) {
return simpleMap[_address];
}
}
pragma solidity ^0.4.24;
contract Map { function isTrue(address _address) external view returns (bool _ret); }
contract Ask {
Map public map = Map(MAP_ADDRESS);
function askMe() external view returns (bool _ret) {
return map.isTrue(msg.sender);
}
function whoIsMsgSender() external view returns (address _address) {
return msg.sender;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.