合同修改映射数据时,web3js发送交易失败,但需要重新混合

时间:2018-11-02 10:28:08

标签: mapping solidity web3js contract remix

首先,web3版本:1.0.0-beta.36

合同代码为:

pragma solidity ^0.4.25;

contract Main {
  struct Model {
    uint256 key;
    uint64 createTime;
  }

  Model[] public models;

  mapping(uint256 => address) public modelOwner;

  function total() view public returns (uint256) {
    return models.length;
  }

  function getData(uint256 _tokenId) view returns ( uint256, uint64){

    Model _model = models[_tokenId];
    return  (_model.key, _model.createTime);
  }

  function createData(uint256 _key, address _owner) returns (uint){

    Model memory _model = Model({key : _key, createTime : uint64(now)});

    uint256 newModelId = models.push(_model) - 1;

    // modelOwner[newModelId] = _owner;

    return newModelId;
  }
}

我通过remix和web3.js发送交易:

myContract.methods.createData(
 key,
 addressA
).send({
 from: addressB 
})

问题是:

  1. 当我删除函数modelOwner[newModelId] = _owner;中的代码createData时,web3和remix都可以工作(列表模型增加);
  2. 当我添加modelOwner[newModelId] = _owner;时,重新混合工作,但是web3失败,因为返回的方法getData的结果不正确(列表模型没有增加);

0 个答案:

没有答案