Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Saving Table with FixedString32 #475

Closed

Description

@michaeljyeates

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":"/https/github.com/v1/chain/get_table_rows","postdata":{"json":true,"scope":"dbtest","code":"dbtest","table":"test"}}
thread-0  httpc.cpp:117 call

dbtest.zip

Activity

  1. liderako commented on Sep 19, 2017

    @liderako

    Can you change the value in the table?

  2. michaeljyeates commented on Sep 19, 2017

    @michaeljyeates
    Author

    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

  3. liderako commented on Sep 19, 2017

    @liderako

    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.

  4. michaeljyeates commented on Sep 19, 2017

    @michaeljyeates
    Author

    Yes I get that error every time a message is sent but it doesnt seem to break anything

  5. heifner commented on Sep 19, 2017

    @heifner
    Contributor

    The get_recent_transaction is issue #429.

  6. pavybez commented on Sep 20, 2017

    @pavybez

    @michaeljyeates can you attach your implementation so that I can debug?

    Edit: Just saw your attachment.

  7. self-assigned this
    on Sep 20, 2017
  8. pavybez commented on Sep 20, 2017

    @pavybez

    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"] } ] }

  9. michaeljyeates commented on Sep 20, 2017

    @michaeljyeates
    Author

    I tried changing that, same problem

  10. michaeljyeates commented on Sep 20, 2017

    @michaeljyeates
    Author

    Is there a way to delete the database or remove all entries?

  11. elmato commented on Sep 20, 2017

    @elmato
    Contributor
  12. elmato commented on Sep 21, 2017

    @elmato
    Contributor

    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.

  13. elmato commented on Sep 21, 2017

    @elmato
    Contributor

    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
    }
  14. michaeljyeates commented on Sep 22, 2017

    @michaeljyeates
    Author

    I am getting this error now

    ./dbtest.hpp:15:5: error: static_assert failed "unexpected packing"

    Attached is my current version
    dbtest.zip

  15. elmato commented on Sep 22, 2017

    @elmato
    Contributor

    Are you using PACKED when declaring TestString?

    struct PACKED(TestString) {
         AccountName       owner;
         char              name[33];
    };
  16. michaeljyeates commented on Sep 22, 2017

    @michaeljyeates
    Author

    That worked, thanks!

  17. added this to the EOS Dawn 1.1 milestone on Nov 9, 2017
  18. gpmn commented on May 30, 2018

    @gpmn

    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))
    

    }

  19. added a commit that references this issue on Aug 3, 2020
  20. added a commit that references this issue on Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions