[英]Even after entering proper bytes32 value and address value. Setaddress function is not working
I am getting generic error every time I try to modify the code. 每次尝试修改代码时,我都会遇到一般性错误。 I am passing byte32
value as "0xabcd"
and address value as "0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
in Setaddress
function. 我传递byte32
值"0xabcd"
和地址值"0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
在Setaddress
功能。
The error is as below: 错误如下:
"transact to EternalStorage.setAddress errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The constructor should be payable if you send value. Debug the transaction to get more information." “事务处理到EternalStorage.setAddress错误:VM错误:恢复。恢复已将事务恢复到初始状态。注意:如果发送值,则应支付构造方法的费用。调试事务以获取更多信息。”
Below is my code 下面是我的代码
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];
}
}
The error message says that the transaction to setAddress()
reverted: 该错误消息表明,对setAddress()
的事务已还原:
transact to EternalStorage.setAddress errored: VM error: revert. 交易到EternalStorage.setAddress错误:VM错误:恢复。
There is only one requre()
statement in setAddress()
, in onlyLatestVersion()
: setAddress()
中的onlyLatestVersion()
只有一个requre()
语句:
require(msg.sender == latestVersion);
So it's virtually certain that the sender of the transaction ( msg.sender
) is not set to latestVersion
. 因此,几乎可以肯定的是,事务的发送方( msg.sender
)并未设置为latestVersion
。 That means you either need to: 这意味着您要么需要:
latestVersion
, or... 请确保您是从合同中将合同的版本latestVersion
的帐户发送的,或者... latestVersion
using the contract's function upgradeVersion()
, so that it matches your transaction sender. 使用合同的功能upgradeVersion()
更改latestVersion
,以使其与您的交易发送方匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.