在Rinkeyby测试网络上的InjectedWeb3环境的Remix IDE上部署了此合同。
我尝试删除了require中的错误msg语句,但它没有引发错误,但仍然无法正常工作,即该函数无论任何require条件如何都得到执行。
pragma solidity >=0.4.22 <0.7.0;
contract RegisterLand{
struct land{
uint area;
string location;
uint floorsAllowed;
mapping(uint => address) owner;
uint count;
bool idExists;
}
mapping(uint => land) lands;
function Register(uint id,uint area, string memory location, uint
floorsAllowed) public
{
require(
!lands[id].idExists,
"ID already exists"
);
lands[id] = land(area, location, floorsAllowed,0,true);
lands[id].owner[lands[id].count] = msg.sender;
}
function ViewLand(uint id) public view returns(address currentOwner,
uint
landArea, string memory landLocation, uint landFloors )
{
require(lands[id].idExists,
"Id doesn't exist.");
currentOwner = lands[id].owner[lands[id].count];
landArea = lands[id].area;
landLocation = lands[id].location;
landFloors = lands[id].floorsAllowed;
}
}
错误:
无法解码输出:错误:溢出(operation =“ setValue”, fault =“ overflow”,details =“数量最多只能安全存储53 位”,版本= 4.0.32)
答案 0 :(得分:1)
存在一个已知问题,要求查看/纯功能不能在公共网络上还原: https://forum.openzeppelin.com/t/require-in-view-pure-functions-dont-revert-on-public-networks/1211
如果您使用Remix JavaScript VM,则使用不存在的ViewLand
调用id
会按预期还原。
如果您对dapp开发有疑问,也可以在OpenZeppelin社区论坛中提问:https://forum.openzeppelin.com/
披露:我是OpenZeppelin的社区经理