Saving Table with FixedString32
I am writing a simple test contract which saves a struct with (Name,char[32]). Saving seems to work ok but when I try to read nothing is returned and eosc get table dbtest dbtest test fails with the following error. Attached is a simple test case, I think the length of 40 is correct so I am not sure why it has a negative over figure
1377035ms thread-0 main.cpp:906 main ] Failed with error: 10 assert_exception: Assert Exception status_code == 200: Error : 8 out_of_range_exception: Out of Range read datastream of length 40 over by -30 {"method":"read","len":40,"over":-30} thread-0 datastream.cpp:6 throw_datastream_range_error
{"msg":"8 out_of_range_exception: Out of Range\nread datastream of length 40 over by -30\n {\"method\":\"read\",\"len\":40,\"over\":-30}\n thread-0 datastream.cpp:6 throw_datastream_range_error"}
thread-0 httpc.cpp:113 call
{"server":"localhost","port":8888,"path":"/v1/chain/get_table_rows","postdata":{"json":true,"scope":"dbtest","code":"dbtest","table":"test"}}
thread-0 httpc.cpp:117 call
Can you change the value in the table?
Yes, if you look at the build.sh script it sets the value but then I cannot read it back out (maybe just my lack of c++ skills), the eosc command still asserts so I cannot verify that anything was written
maybe type char, doesn't work. Do you know that error?
3234004ms thread-0 producer_plugin.cpp:199 block_production_loo ] Got exception while generating block:
10 assert_exception: Assert Exception
itr != index.end():
{}
thread-0 chain_controller.cpp:112 get_recent_transaction
Output in eosd window
Maybe. At you too she will be.
Yes I get that error every time a message is sent but it doesnt seem to break anything
The get_recent_transaction is issue #429.
@michaeljyeates can you attach your implementation so that I can debug?
Edit: Just saw your attachment.
Can you modify your abi file as below and check again please? I changed the keyname in table section from "teststring" to "owner". I will continue debugging it tomorrow.
{
"types": [{
"newTypeName": "AccountName",
"type": "Name"
}
],
"structs": [{
"name": "teststring",
"base": "",
"fields": {
"owner": "Name",
"name": "FixedString32"
}
}
],
"actions": [{
"action": "store",
"type": "teststring"
},{
"action": "get",
"type": "teststring"
}
],
"tables": [{
"table": "test",
"type": "teststring",
"indextype": "i64",
"keynames" : ["owner"],
"keytypes" : ["Name"]
}
]
}
I tried changing that, same problem
Is there a way to delete the database or remove all entries?
You can remove the data-dir folder and start eosd again
On Sep 20, 2017 15:39, "michaeljyeates" [email protected] wrote:
Is there a way to delete the database or remove all entries?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/EOSIO/eos/issues/475#issuecomment-330943344, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOUotkjtpILHPEbzWJJEaDiWB-GdtsOks5skVv1gaJpZM4Pcf9h .
After some debugging here is a quick fix for your contract.
In dbtest.abi keynames of the table should be
"keynames" : ["owner"],
That change is needed to later query the tables using eosc
./eosc get table dbtest dbtest test
In dbtest.hpp TestString type should be
struct PACKED(TestString) {
AccountName owner;
char name[33];
};
static_assert( sizeof(TestString) == sizeof(uint64_t)+33, "unexpected packing" );
since the first byte of a serialized FixedString32 indicates its length.
Also in dbtest.hpp the call to Tests::get should be
Tests::get( owner, teststr );
otherwise you will be calling
static bool get( Record& r, uint64_t s = scope ) {
return impl::load_primary( s, code, table, &r, sizeof(Record) ) == sizeof(Record);
}
and a tx_missing_scope will arise since you were using owner as the scope to read from.
And finally in dbtest.cpp
print("Store string", (const char *)(teststr.name+1), "\n");
...
print("GOT teststring", (const char *)(teststr_row.name+1), "\n");
Note: This is a quick fix to make your contract work, in future versions the handling of types like FixedString32 inside the contract code will be easier.
Here is the output from ./eosc get table dbtest dbtest test
{
"rows": [{
"owner": "dbtest",
"name": "0123456789ABCDEF0123456789ABCDEF"
},{
"owner": "iiii",
"name": "0123456789ABCDEF0123456789ABCDEF"
},{
"owner": "xx",
"name": "0123456789ABCDEF0123456789ABCDEF"
},{
"owner": "yy",
"name": "0123456789ABCDEF0123456789ABCDEF"
}
],
"more": false
}
I am getting this error now
./dbtest.hpp:15:5: error: static_assert failed "unexpected packing"
Attached is my current version dbtest.zip
Are you using PACKED when declaring TestString?
struct PACKED(TestString) {
AccountName owner;
char name[33];
};
That worked, thanks!
thanks this post. I get the same issue today. following this post's suggestion, I update my struct, then my contract works fine. e.g., (schema1)(schema2) is missed in wrong version.
// @abi table
struct cont{
uint64_t key;
name issuer;
uint64_t schema1;
uint64_t schema2;
std::string link;
auto primary_key()const {return key;}
EOSLIB_SERIALIZE(cont, (key)(issuer)(link))
// should change to the following:
// EOSLIB_SERIALIZE(cont, (key)(issuer)(schema1)(schema2)(link))
}