1

I am trying to add secondary index to my table so I can use it to query for elements based on it. My struct looks like this:

struct [[eosio::table]] user
  {
    name userAccount;         // user accountname - primary key
    std::string userKey;      // user random unique key
    std::string userName;     // user firstname
    std::string userLastname; // user lastname
    std::string userEmail;    // user email
    std::string userCity;     // user city
    std::string userMobile;   // user mobilephone
    std::string userCartype;  // user cartype
    uint64_t primary_key() const { return userAccount.value; }
    std::string secondary_key() const { return userEmail; }
  };

typedef multi_index<name("users"), user> users_table;.

So, the thing is, after I compile the contract and apply it to my account it says that there are no changes to the contract. Am I missing something ? Is there another way of getting user based on userEmail?

p.s The main purpouse of this is to use rpc.get_table_rows in order to retrieve the user info based on the userEmail.

  • In addition to my answer below: Don't store personal data like Emails, Names, Phone-Numbers etc. on a Blockchain! – cmadh Jul 25 '19 at 0:35
  • It seems that I need to do a bigger research of my data storing and usage and confront the fact that I maybe spent one week trying to get things done in a wrong way :( – Viktor Gagaleski Jul 25 '19 at 8:12
2

You can't use a string as key type.

A secondary index supports several key types, listed below.

uint64_t           - Primitive 64-bit unsigned integer key
uint128_t          - Primitive 128-bit unsigned integer key, or a 128-bit fixed-size lexicographical key
checksum256        - 256-bit fixed-size lexicographical key
double             - Double precision floating point key
long double        - Quadruple precision floating point key
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.