I am not able to filter a hash correctly, using get table / get_table_rows. Also I noticed that the abi is not generating a secondary index, although I am assuming this is not the problem, since anyway it is returning something.
Any tip would be appreciated. Thanks!
cleos get table testtesttest testtesttest hasher --index 2 --key-type sha256 -L 45d944598dccadd8c5a56e29c9786f05fa4b23402b735de61ce2912c86bac4de
is returning 3 rows instead of 1
{
"rows": [{
"id": 0,
"owner": "test1",
"hash": "cb285a3e234c39b13b170a4cc376bd002640f270d8219fe2c2f93d8c9c53491a",
"tx": "e5aa66ed5b24a2c236257d79225de7d05bb85ad41181d3f4bd4a5c35e65d64f0"
},{
"id": 1,
"owner": "test1",
"hash": "45d944598dccadd8c5a56e29c9786f05fa4b23402b735de61ce2912c86bac4de",
"tx": "388cbcb1351e17a7441be6513ab7d54d62eadcc32cdbafed22de43cf7584da60"
},{
"id": 2,
"owner": "test1",
"hash": "39b9193df3f4caf1518696ff85942b1dd40f3bbfb989d8f6703228dda8d28e54",
"tx": "a021da6dec167cd4f1b6d4440061ab9273e159791c0d6ca106b3c7d72178c62b"
}
],
"more": false
}
Table implementation works within smartcontract (I am using the hash to check existance), but it is not working from cleos get table.
private:
TABLE hasher_rec
{
uint64_t id;
name owner;
capi_checksum256 hash;
capi_checksum256 tx;
uint64_t primary_key() const { return id; }
fixed_bytes<32> by_hash() const { return checksum256_to_sha256(hash); } // key256 replaced with digest256 = typedef fixed_bytes<32>
static fixed_bytes<32> checksum256_to_sha256(const capi_checksum256 &hash)
{
const uint64_t *p64 = reinterpret_cast<const uint64_t *>(&hash);
return fixed_bytes<32>::make_from_word_sequence<uint64_t>(p64[0], p64[1], p64[2], p64[3]);
}
EOSLIB_SERIALIZE(hasher_rec, (id)(owner)(hash)(tx))
};
typedef multi_index<name("hasher"), hasher_rec,
indexed_by<name("hash"), const_mem_fun<hasher_rec, fixed_bytes<32>, &hasher_rec::by_hash>>
> hasher_table_type;
hasher_table_type _hasher;
This is the abi
"tables": [
{
"name": "hasher",
"type": "hasher_rec",
"index_type": "i64",
"key_names": [],
"key_types": []
}
],
I tried changing it to
"tables": [
{
"name": "hasher",
"type": "hasher_rec",
"index_type": "i64",
"key_names": ["hash"],
"key_types": ["sha256"]
}
]
Thanks!