Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在webase平台上借助Table.sol开发智能合约时存入Bytes32类型的数据后,返回值一直为0,查询不到原始插入的数据 #4650

Open
Moodyzjz opened this issue Oct 10, 2024 · 1 comment

Comments

@Moodyzjz
Copy link

pragma solidity ^0.4.25;
//pragma experimental ABIEncoderV2;

import "./Table.sol";
//
contract test{
    // event
    event selectEvent(int256 ret, bytes32 RootHash);
    
    
    constructor() public {
        // 构造函数中创建car_msg表
        createtestTable();
    }

    function createtestTable() private{
        TableFactory tf = TableFactory(0x1001);
        // 车辆数据管理表car_msg, key(主键:车企ID) : carID, field : time : , location : 经度范围、纬度范围, totalnum_car,  datahash, sig
        // 创建表
        tf.createTable("test_table", "ID", "RootHash");
    }

    function opentestTable() private returns(Table) {
        TableFactory tf = TableFactory(0x1001);
        Table table = tf.openTable("test_table");
        return table;
    }

    
    function select(string ID) public returns(int256,**bytes32**) {
        // 打开表
        Table table = opentestTable();
        // 查询
        Entries entries = table.select(ID, table.newCondition());
        bytes32 RootHash;
        if (0 == uint256(entries.size())) {
            emit selectEvent(-1, RootHash);
            return (-1, RootHash);
        } else {
            Entry entry = entries.get(0);
            RootHash=entry.getBytes4("RootHash");
            emit selectEvent(0,RootHash);
            return (0, RootHash);
            }
    }
    function register(string ID, bytes32 _RootHash) public returns(int256){
        int256 ret_code = 0;
        int256 ret= 0;
        bytes32 temp_RootHash;
        // 查询账户是否存在
        (ret, temp_RootHash) = select(ID);
        if(ret != 0) {
            Table table = opentestTable();

            Entry entry = table.newEntry();
            entry.set("ID", ID);
            entry.set("RootHash", _RootHash);
          
            // 插入
            int count = table.insert(ID, entry);
            if (count == 1) {
                // 成功
                ret_code = 0;
            } else {
                // 失败? 无权限或者其他错误
                ret_code = -2;
            }
        } else {
            // 账户已存在
            ret_code = -1;
        }

        return ret_code;
    }
       
}
@kyonRay
Copy link
Member

kyonRay commented Oct 12, 2024

2.0 table接口中entry应该没有set bytes32的接口,你可以先把bytes32的数据转成string类型,再进行设置看看。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants