简体   繁体   English

即使输入正确的bytes32值和地址值也是如此。 Setaddress功能不起作用

[英]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: 这意味着您要么需要:

  1. Make sure you are sending from the account that the contract has as the latestVersion , or... 请确保您是从合同中将合同的版本latestVersion的帐户发送的,或者...
  2. Change latestVersion using the contract's function upgradeVersion() , so that it matches your transaction sender. 使用合同的功能upgradeVersion()更改latestVersion ,以使其与您的交易发送方匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Solidity 密钥以最省气的方式通过 keccak256 散列两个字节 32 变量 - How to hash two bytes32 vars via keccak256 in the most gas-efficient way using Solidity keys address.call.value(amount)() 方法不适用于我 - address.call.value(amount)( ) method is not working with me 错误:无效地址(arg="", coderType="address", value=[0]) - ERROR: invalid address (arg="", coderType="address", value=[0]) 从应付地址到请求的字节内存的隐式转换无效。 此函数需要一个字节参数 - Invalid implicit conversion from address payable to bytes memory requested. This function requires a single bytes argument 用区块链上的同一地址中的结构检查2映射的值 - Checking value of 2 mapping with struct in the same address on blockchain 即使将数据集更改为另一个值,Hash 也不会更改 - Hash does not change even when data set is changed to another value Solidity:“错误:无效的数值”,即使在引号内使用数值,为什么? - Solidity: “Error: invalid number value”, even when using the number value within quote marks, why? Solidity 中合约地址变量会消耗多少状态字节? - How many state bytes will contract address variable consume in Solidity? 我想通过正确的推导路径从助记符中获取地址 - I want to get the address from mnemonic with the proper derivation path Flutter 和 Ethereum:未处理的异常:RangeError:值不在范围内:32 - Flutter & Ethereum : Unhandled Exception: RangeError: Value not in range: 32
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM