eos icon indicating copy to clipboard operation
eos copied to clipboard

How to make a 2-dimensional vector structure in multi_index table?

Open Danilo0120 opened this issue 7 years ago • 3 comments

@taokayan I want to make a 2-dimensional vector structure to store some information(more than 8192 elements) in multi_index table. but there is wrong.

HERE is wrong: /test$ eosio-cpp test.cpp -o test.wasm --abigen test.cpp:20:38: error: cannot refer to type member 'yourdata' in 'const addressbook::address' with '.' EOSLIB_SERIALIZE( address, (k2)(yourdata) ) ^ test.cpp:17:33: note: member 'yourdata' declared here typedef std::vector yourdata; ^ test.cpp:20:38: error: cannot refer to type member 'yourdata' in 'addressbook::address' with '.' EOSLIB_SERIALIZE( address, (k2)(yourdata) ) ^ test.cpp:17:33: note: member 'yourdata' declared here typedef std::vector yourdata; ^ 2 errors generated.

Danilo0120 avatar Feb 21 '19 14:02 Danilo0120

Here is my code:

#include<eosiolib/eosio.hpp>
#include<vector>
using namespace eosio;
using namespace std;
class addressbook : public eosio::contract
{


  // @abi table data i64
  struct [[eosio::table]] address {
     uint64_t account_name;
     string k2;

     struct chunk {
     std::vector<char> chunkdata; // 4k each
     };
     typedef std::vector<chunk> yourdata;

     uint64_t primary_key() const { return account_name; }
     EOSLIB_SERIALIZE( address, (k2)(yourdata) )
  };



  public:
    addressbook(account_name self):contract(self) {}
    typedef eosio::multi_index< N(address), address > address_index;

   [[eosio::action]]
    void get() {
      address_index addresses(_self, _self);
      addresses.emplace(_self, [&](auto& address) {
        address.account_name = N(dandandandan);
        address.k2 = ".0000000000000000002T0000G003iR0000A000H;0000Q0000W007g)0000A00010002s0000m008Uh0000C0004B000190000";
});
      auto itr = addresses.find(N(dandandandan));
      print("k2 is:",itr->k2);
      eosio_assert(itr != addresses.end(), "Couldn't get him.");
    }
};
EOSIO_ABI(addressbook, (get))

@jgiszczak Edited for clarity

Danilo0120 avatar Feb 21 '19 14:02 Danilo0120

I will appreciate it if anyone could solve it

Danilo0120 avatar Feb 21 '19 14:02 Danilo0120

Your EOSLIB_SERIALIZE() is missing (account_name) before (k2). You also need to use your type yourdata, as in yourdata user_data and include (user_data) in your EOSLIB_SERIALIZE() rather than (yourdata).

If you still have problems and wish to discuss further, please post it in https://eosio.stackexchange.com. To keep things organized, Github issues are intended for bug reporting and feature tracking, and Stack Exchange is the right place for any technical support discussions, including contract support. Thanks!

jgiszczak avatar Feb 21 '19 20:02 jgiszczak