EOS.IO Asked by Efraim on November 22, 2021
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);
}
}
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.
Answered by Phillip Hamnett - EOS42 on November 22, 2021
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
Answered by Saxtheowl on November 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP