1

Dependencies:
EOSIO.CDT (Contract Development Toolkit) Version : 1.3.1

My code:

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>

using namespace eosio;

CONTRACT addressbook : public eosio::contract {

 public:
    using contract::contract;

    addressbook(name self): contract(self) {}

   [[eosio::action]]
   void upsert(name user, std::string first_name, std::string 
   last_name, std::string street, std::string city, std::string state) 
   {
       require_auth( user );
       address_index addresses(_self, _self);
       auto iterator = addresses.find( user );
       if( iterator == addresses.end() )
       {
           addresses.emplace(user, [&]( auto& row ) {
           row.key = user;
           row.first_name = first_name;
           row.last_name = last_name;
           row.street = street;
           row.city = city;
           row.state = state;
        });
      }
    else 
    {
       std::string changes;
       addresses.modify(iterator, user, [&]( auto& row ) {
       row.key = user;
       row.first_name = first_name;
       row.last_name = last_name;
       row.street = street;
       row.city = city;
       row.state = state;
     });
   }
 }

[[eosio::action]]
void erase(name user){
   // require_auth(user);
    address_index addresses(_self, _self);
    auto iterator = addresses.find( user );
    eosio_assert(iterator != addresses.end(), "Record does not 
        exist");
    addresses.erase(iterator);
}

 private:
 struct [[eosio::table]] person {
       name key;
       std::string first_name;
       std::string last_name;
       std::string street;
       std::string city;
       std::string state;
       uint64_t primary_key() const { return key; }
  };
   typedef eosio::multi_index<"people"_n, person> address_index;

  };

EOSIO_ABI( addressbook, (upsert)(erase) )

Error message:

    ./addressbook.cpp:12:30: error: no matching constructor for 
     initialization of 'eosio::contract'
     addressbook(name self) : contract(self) {}
1

I am not sure but i think you need to remove this

addressbook(name self) : contract(self) {}

because they are not supporting this constructor anymore. Have a look at new constructor

contract( name receiver, name code, datastream<const char*> ds ):_self(receiver),_code(code),_ds(ds) {}

You can use in your code like

addressbook(name self) : contract(_self,_code,_ds){}
| improve this answer | |
  • thank you. removed but : line code : address_index addresses(_self, _self); to error. – Son Le Oct 16 '18 at 1:26
  • i have edited my answer try this – Mr.Y Oct 18 '18 at 8:39
1

Thank Mr.Y. I fixed, and made action insert,update,remove,search... is ok. Thanks for your instructions, I will look at eosio code more thoroughly.
1. remove line:

addressbook(name self) : contract(self) {} 

2. change line :

address_index addresses(_self, _self);

to :

address_index addresses(_self, _self.value);

3. change line :

auto iterator = addresses.find( user );

to :

unit64 user_index=user.value;
auto iterator = addresses.find( user_index );
| 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.