每次尝试修改代码时,我都会遇到一般性错误。我在byte32
函数中将"0xabcd"
的值传递为"0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
,将地址值传递为Setaddress
。
错误如下:
”事务处理到EternalStorage.setAddress错误:VM错误:恢复。 还原事务已还原到初始状态。 注意:如果您发送值,则应向构造函数付款。调试事务以获取更多信息。”
下面是我的代码
pragma solidity ^0.4.17;
contract EternalStorage {
address owner = msg.sender;
address latestVersion;
mapping(bytes32 => uint) uIntStorage;
mapping(bytes32 => address) addressStorage;
modifier onlyLatestVersion() {
require(msg.sender == latestVersion);
_;
}
function upgradeVersion(address _newVersion) public {
require(msg.sender == owner);
latestVersion = _newVersion;
}
// *** Getter Methods ***
function getUint(bytes32 _key) external view returns(uint) {
return uIntStorage[_key];
}
function getAddress(bytes32 _key) external view returns(address) {
return addressStorage[_key];
}
// *** Setter Methods ***
function setUint(bytes32 _key, uint _value) onlyLatestVersion external {
uIntStorage[_key] = _value;
}
function setAddress(bytes32 _key, address _value) onlyLatestVersion external payable{
addressStorage[_key] = _value;
}
// *** Delete Methods ***
function deleteUint(bytes32 _key) onlyLatestVersion external {
delete uIntStorage[_key];
}
function deleteAddress(bytes32 _key) onlyLatestVersion external {
delete addressStorage[_key];
}
}
答案 0 :(得分:1)
该错误消息表明到setAddress()
的事务已还原:
事务处理到EternalStorage.setAddress错误:VM错误:恢复。
requre()
中setAddress()
中只有一个onlyLatestVersion()
语句:
require(msg.sender == latestVersion);
因此,实际上可以确定交易的发件人(msg.sender
)没有设置为latestVersion
。这意味着您要么需要:
latestVersion
,或者... latestVersion
更改upgradeVersion()
,以使其与您的交易发送方相匹配。