0

I would like to update this code, because it is CDT 1.2. I would like to update for CDT 1.5 or CDT 1.6. What do I need to change?

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

using namespace eosio;

class hello : public eosio::contract {
  public:
      using contract::contract;

      hello(account_name self) : contract(self) {}

      /// @abi table 
      struct account {
          account_name owner;
          uint64_t balance;

          uint64_t primary_key() const { return owner; };
      };

      typedef eosio::multi_index<N(account), account> accs; 

      /// @abi action 
      void addbalance(account_name owner, uint64_t amount) {
           accs accounts(_self, owner);
           auto existing = accounts.find(owner);

           if (existing == accounts.end())
           {
               /* Add new account */
               accounts.emplace(_self, [&](auto& a) {
                   a.owner = owner;
                   a.balance = amount;
               });
           } else {
               /* Update existing account */
               const auto& st = *existing;
               accounts.modify(st, 0, [&](auto& a) {
                   a.balance += amount;
               });
           }
      }

      void on(const currency::transfer& t) {
          if (t.to == _self) {
              addbalance(t.from, t.quantity.amount);
          }
      }

      void use(account_name contract, account_name act) {
          if (act == N(transfer)) {
              on(unpack_action_data<currency::transfer>());
              return;
          }

          auto& thiscontract = *this;
          switch( act ) {
             EOSIO_API( hello, (addbalance));
          };
      }
};

extern "C" {
   [[noreturn]] void apply( uint64_t receiver, uint64_t code, uint64_t action ) {
      hello  h( receiver );
      h.use( code, action );
      eosio_exit(0);
   }
}
0

You can use this official page to guide you on how to install the latest CDT

https://developers.eos.io/eosio-home/docs/installing-the-contract-development-toolkit

| improve this answer | |
  • Thnak you. I saw, but I would like update beacuse I would like to us the CDT 1.6. – Efraim May 28 '19 at 7:47
  • Once you have done the step I gave you in the link, your compiler will try to compile to the 1.6.1 cdt, if it dont compile maybe you gonna have to change part of your code – Saxtheowl May 28 '19 at 12:31
  • ok I tried, but fatal error: 'eosiolib/currency.hpp' file not found..which file neeod too change in cdt 1.6? – Efraim May 28 '19 at 13:52
  • and affet a lot error, so I think I need change full code, or rewrite. – Efraim May 28 '19 at 14:00
  • Yes, you gonna have to rewrite part of your code, we can help you for general stuff about EOS but we dont know how your program work – Saxtheowl May 28 '19 at 14:21
0

This is a list of all changes to eosio.cdt at each version: https://github.com/EOSIO/eosio.cdt/releases

Start reading it from the version you are currently using until the version you want to migrate to. There was a large amount of breaking changes when going from v1.2.x to v1.3.x.

A lot of the libraries changes location and/or were deleted or merged. For example currency.hpp no longer exists, and the folder eosiolib is now deprecated. Any contracts written before v1.3 will require significant reworking.

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