get_table对于time_point类型得定位查询
根据场景需求需要对已存储得数据做更新查询,所以需要对update_timepoint做查询索引
struct [[eosio::table, eosio::contract("bcskill.com")]] xxxx_info {
uint64_t id; // 记录id
eosio::checksum256 trx_id; // 交易id
....
time_point create_timepoint; // 创建时间
time_point update_timepoint; // 更新时间
uint64_t primary_key() const { return id; }
eosio::checksum256 second_key() const { return trx_id; }
uint64_t third_key() const { return update_timepoint.time_since_epoch().count();} // 把time_point类型转换成微妙(1/1000000 秒)
};
table中测试数据如下
{
"rows": [{
"id": 0,
"trx_id": "d78c4da408a4d9c75ba03af4a481d79fa80e2b8e215e68a1fe1865fd866cc7bc",
...
"create_timepoint": "2020-12-17T11:24:07.500",
"update_timepoint": "2020-12-17T11:27:18.500"
},{
"id": 1,
"trx_id": "7bb0038be49b171f8a394bfdd7da15f9a005908b25ca1b6aed31b2975d721730",
...
"create_timepoint": "2020-12-17T11:29:01.500",
"update_timepoint": "2020-12-17T11:30:01.500"
},{
"id": 2,
"trx_id": "8cf1c32d38692dd93870c7a2376d617f85efa4f093588dbce94f9981d4e1818e",
...
"create_timepoint": "2020-12-17T11:30:01.500",
"update_timepoint": "2020-12-17T11:30:01.500"
}
],
"more": false
}
UTC时间转时间戳,目前没有找到现成的工具可以直接转换,
https://tool.lu/timestamp/ 只找到这个北京时间转时间戳的工具(稍后找到其他直接工具,或者单独开发个工具再做文章更新)
UTC 转北京时间(+8)
暂时先将UTC时间加8小时转换成本地时间,测试的UTC时间为2020-12-17T11:27:18.500
,转换为本地时间为2020-12-17 19:27:18
其中的.500
为0.5秒,后面再单独加上。
北京时间转时间戳
利用上面的在线工具2020-12-17 19:27:18
得到1608204438
,加上上面的0.500
得到1608204438.5
根据合约类型需要转换为微妙
1608204438.5
* 1000000
得到 1608204438500000
根据测试数据演示下查询
cleos get table bcskillsurou bcskillsurou ammtb --index 3 --key-type i64 -L 1608204438500000 -U 1608204438500000
得到指定的记录
{
"rows": [{
"id": 0,
"trx_id": "d78c4da408a4d9c75ba03af4a481d79fa80e2b8e215e68a1fe1865fd866cc7bc",
...
"create_timepoint": "2020-12-17T11:24:07.500",
"update_timepoint": "2020-12-17T11:27:18.500"
}
],
"more": false
}