Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
First step to updating for 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljyeates committed Nov 8, 2018
1 parent 536a505 commit ea2cfde
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 118 deletions.
6 changes: 3 additions & 3 deletions daccustodian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ using namespace std;
#define EOSIO_ABI_EX(TYPE, MEMBERS) \
extern "C" { \
void apply( uint64_t receiver, uint64_t code, uint64_t action ) { \
if( action == N(onerror)) { \
if( action == "onerror"_n.value) { \
/* onerror is only valid if it is for the "eosio" code account and authorized by "eosio"'s "active permission */ \
eosio_assert(code == N(eosio), "onerror action's are only valid from the \"eosio\" system account"); \
eosio_assert(code == "eosio"_n.value, "onerror action's are only valid from the \"eosio\" system account"); \
} \
auto self = receiver; \
if( (code == self && action != N(transfer)) || (code == eosio::string_to_name(TOKEN_CONTRACT) && action == N(transfer)) ) { \
if( (code == self && action != "transfer"_n.value) || (code == name(TOKEN_CONTRACT).value && action == "transfer"_n.value) ) { \
TYPE thiscontract( self ); \
switch( action ) { \
EOSIO_API( TYPE, MEMBERS ) \
Expand Down
77 changes: 39 additions & 38 deletions daccustodian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#define TRANSFER_DELAY 60*60
#endif

const permission_name ONE_PERMISSION = N(one);
const permission_name LOW_PERMISSION = N(low);
const permission_name MEDIUM_PERMISSION = N(med);
const permission_name HIGH_PERMISSION = N(high);
const name ONE_PERMISSION = "one"_n;
const name LOW_PERMISSION = "low"_n;
const name MEDIUM_PERMISSION = "med"_n;
const name HIGH_PERMISSION = "high"_n;

using namespace eosio;
using namespace std;
Expand All @@ -29,13 +29,13 @@ struct [[eosio::table("config")]] contr_config {
// - used for pay calculations if an eary election is called and to trigger deferred `newperiod` calls.
uint32_t periodlength = 7 * 24 * 60 * 60;
// account to have active auth set with all all custodians on the newperiod.
account_name authaccount = string_to_name("dacauthority");
name authaccount = "dacauthority"_n;

// The contract that holds the fund for the DAC. This is used as the source for custodian pay.
account_name tokenholder = string_to_name("eosdacthedac");
name tokenholder = "eosdacthedac"_n;

// The contract that will act as the service provider account for the dac. This is used as the source for custodian pay.
account_name serviceprovider;
name serviceprovider;

// The contract will direct all payments via the service provider.
bool should_pay_via_service_provider;
Expand Down Expand Up @@ -75,7 +75,7 @@ struct [[eosio::table("config")]] contr_config {
)
};

typedef singleton<N(config), contr_config> configscontainer;
typedef singleton<"config"_n, contr_config> configscontainer;

struct [[eosio::table("state")]] contr_state {
uint32_t lastperiodtime = 0;
Expand All @@ -92,7 +92,7 @@ struct [[eosio::table("state")]] contr_state {
)
};

typedef singleton<N(state), contr_state> statecontainer;
typedef singleton<"state"_n, contr_state> statecontainer;

// Utility to combine ids to help with indexing.
uint128_t combine_ids(const uint8_t &boolvalue, const uint64_t &longValue) {
Expand All @@ -107,7 +107,7 @@ struct [[eosio::table("candidates")]] candidate {
uint8_t is_active;
uint32_t custodian_end_time_stamp;

account_name primary_key() const { return static_cast<uint64_t>(candidate_name); }
uint64_t primary_key() const { return candidate_name.value; }

uint64_t by_number_votes() const { return static_cast<uint64_t>(total_votes); }

Expand All @@ -119,19 +119,19 @@ struct [[eosio::table("candidates")]] candidate {
(candidate_name)(requestedpay)(locked_tokens)(total_votes)(is_active)(custodian_end_time_stamp))
};

typedef multi_index<N(candidates), candidate,
indexed_by<N(bycandidate), const_mem_fun<candidate, account_name, &candidate::primary_key> >,
indexed_by<N(byvotes), const_mem_fun<candidate, uint64_t, &candidate::by_number_votes> >,
indexed_by<N(byvotesrank), const_mem_fun<candidate, uint64_t, &candidate::by_votes_rank> >,
indexed_by<N(byreqpay), const_mem_fun<candidate, uint64_t, &candidate::by_requested_pay> >
typedef multi_index<"candidates"_n, candidate,
indexed_by<"bycandidate"_n, const_mem_fun<candidate, uint64_t, &candidate::primary_key> >,
indexed_by<"byvotes"_n, const_mem_fun<candidate, uint64_t, &candidate::by_number_votes> >,
indexed_by<"byvotesrank"_n, const_mem_fun<candidate, uint64_t, &candidate::by_votes_rank> >,
indexed_by<"byreqpay"_n, const_mem_fun<candidate, uint64_t, &candidate::by_requested_pay> >
> candidates_table;

struct [[eosio::table("custodians")]] custodian {
name cust_name;
asset requestedpay;
uint64_t total_votes;

name primary_key() const { return cust_name; }
uint64_t primary_key() const { return cust_name.value; }

uint64_t by_votes_rank() const { return static_cast<uint64_t>(UINT64_MAX - total_votes); }

Expand All @@ -141,25 +141,25 @@ struct [[eosio::table("custodians")]] custodian {
(cust_name)(requestedpay)(total_votes))
};

typedef multi_index<N(custodians), custodian,
indexed_by<N(byvotesrank), const_mem_fun<custodian, uint64_t, &custodian::by_votes_rank> >,
indexed_by<N(byreqpay), const_mem_fun<custodian, uint64_t, &custodian::by_requested_pay> >
typedef multi_index<"custodians"_n, custodian,
indexed_by<"byvotesrank"_n, const_mem_fun<custodian, uint64_t, &custodian::by_votes_rank> >,
indexed_by<"byreqpay"_n, const_mem_fun<custodian, uint64_t, &custodian::by_requested_pay> >
> custodians_table;

struct [[eosio::table("votes")]]vote {
name voter;
name proxy;
std::vector<name> candidates;

account_name primary_key() const { return static_cast<uint64_t>(voter); }
uint64_t primary_key() const { return voter.value; }

account_name by_proxy() const { return static_cast<uint64_t>(proxy); }
uint64_t by_proxy() const { return proxy.value; }

EOSLIB_SERIALIZE(vote, (voter)(proxy)(candidates))
};

typedef eosio::multi_index<N(votes), vote,
indexed_by<N(byproxy), const_mem_fun<vote, account_name, &vote::by_proxy> >
typedef eosio::multi_index<"votes"_n, vote,
indexed_by<"byproxy"_n, const_mem_fun<vote, uint64_t, &vote::by_proxy> >
> votes_table;

struct [[eosio::table("pendingpay")]] pay {
Expand All @@ -169,26 +169,26 @@ struct [[eosio::table("pendingpay")]] pay {
string memo;

uint64_t primary_key() const { return key; }
account_name byreceiver() const { return receiver; }
uint64_t byreceiver() const { return receiver.value; }

EOSLIB_SERIALIZE(pay, (key)(receiver)(quantity)(memo))
};

typedef multi_index<N(pendingpay), pay,
indexed_by<N(byreceiver), const_mem_fun<pay, account_name, &pay::byreceiver> >
typedef multi_index<"pendingpay"_n, pay,
indexed_by<"byreceiver"_n, const_mem_fun<pay, uint64_t, &pay::byreceiver> >
> pending_pay_table;

struct [[eosio::table("pendingstake")]] tempstake {
account_name sender;
name sender;
asset quantity;
string memo;

account_name primary_key() const { return sender; }
uint64_t primary_key() const { return sender.value; }

EOSLIB_SERIALIZE(tempstake, (sender)(quantity)(memo))
};

typedef multi_index<N(pendingstake), tempstake> pendingstake_table_t;
typedef multi_index<"pendingstake"_n, tempstake> pendingstake_table_t;


class daccustodian : public contract {
Expand All @@ -204,18 +204,19 @@ class daccustodian : public contract {

public:

daccustodian(account_name self) : contract(self),
registered_candidates(_self, _self),
votes_cast_by_members(_self, _self),
pending_pay(_self, _self),
config_singleton(_self, _self),
contract_state(_self, _self) {
daccustodian( name s, name code, datastream<const char*> ds )
:contract(s,code,ds),
registered_candidates(_self, _self.value),
votes_cast_by_members(_self, _self.value),
pending_pay(_self, _self.value),
config_singleton(_self, _self.value),
contract_state(_self, _self.value) {

_currentState = contract_state.get_or_default(contr_state());
}

~daccustodian() {
contract_state.set(_currentState, _self); // This should not run during a contract_state migration since it will prevent changing the schema with data saved between runs.
contract_state.set(_currentState, _self.value); // This should not run during a contract_state migration since it will prevent changing the schema with data saved between runs.
}

[[eosio::action]]
Expand Down Expand Up @@ -433,7 +434,7 @@ Nothing from this action is stored on the blockchain. It is only intended to ens
contr_config configs();

void assertValidMember(name member);

void updateVoteWeight(name custodian, int64_t weight);

void updateVoteWeights(const vector<name> &votes, int64_t vote_weight);
Expand All @@ -460,4 +461,4 @@ Nothing from this action is stored on the blockchain. It is only intended to ens
void migrate();
#endif

};
};
10 changes: 5 additions & 5 deletions external_observable_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ void daccustodian::transfer(name from,
string memo) {
eosio::print("\nlistening to transfer with memo == dacaccountId");
if (to == _self) {
account_name dacId = eosio::string_to_name(memo.c_str());
name dacId = name(memo.c_str());
if (is_account(dacId)) {
pendingstake_table_t pendingstake(_self, dacId);
auto source = pendingstake.find(from);
pendingstake_table_t pendingstake(_self, dacId.value);
auto source = pendingstake.find(from.value);
if (source != pendingstake.end()) {
pendingstake.modify(source, _self, [&](tempstake &s) {
s.quantity += quantity;
Expand All @@ -27,14 +27,14 @@ void daccustodian::transfer(name from,

if (quantity.symbol == configs().lockupasset.symbol) {
// Update vote weight for the 'from' in the transfer if vote exists
auto existingVote = votes_cast_by_members.find(from);
auto existingVote = votes_cast_by_members.find(from.value);
if (existingVote != votes_cast_by_members.end()) {
updateVoteWeights(existingVote->candidates, -quantity.amount);
_currentState.total_weight_of_votes -= quantity.amount;
}

// Update vote weight for the 'to' in the transfer if vote exists
existingVote = votes_cast_by_members.find(to);
existingVote = votes_cast_by_members.find(to.value);
if (existingVote != votes_cast_by_members.end()) {
updateVoteWeights(existingVote->candidates, quantity.amount);
_currentState.total_weight_of_votes += quantity.amount;
Expand Down
20 changes: 10 additions & 10 deletions external_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ using namespace std;
struct currency_stats {
asset supply;
asset max_supply;
account_name issuer;
name issuer;
bool transfer_locked = false;

uint64_t primary_key() const { return supply.symbol.name(); }
uint64_t primary_key() const { return supply.symbol.code().raw(); }
};

typedef eosio::multi_index<N(stat), currency_stats> stats;
typedef eosio::multi_index<"stat"_n, currency_stats> stats;


// This is a reference to the member struct as used in the eosdactoken contract.
Expand All @@ -38,39 +38,39 @@ struct termsinfo {
EOSLIB_SERIALIZE(termsinfo, (terms)(hash)(version))
};

typedef multi_index<N(memberterms), termsinfo> memterms;
typedef multi_index<"memberterms"_n, termsinfo> memterms;

struct account {
asset balance;

uint64_t primary_key() const { return balance.symbol.name(); }
uint64_t primary_key() const { return balance.symbol.code().raw(); }
};

typedef multi_index<N(members), member> regmembers;
typedef eosio::multi_index<N(accounts), account> accounts;
typedef multi_index<"members"_n, member> regmembers;
typedef eosio::multi_index<"accounts"_n, account> accounts;

//Authority Structs
namespace eosiosystem {

struct key_weight {
eosio::public_key key;
weight_type weight;
uint16_t weight;

// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(key_weight, (key)(weight))
};

struct permission_level_weight {
permission_level permission;
weight_type weight;
uint16_t weight;

// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(permission_level_weight, (permission)(weight))
};

struct wait_weight {
uint32_t wait_sec;
weight_type weight;
uint16_t weight;

// explicit serialization macro is not necessary, used here only to improve compilation time
EOSLIB_SERIALIZE(wait_weight, (wait_sec)(weight))
Expand Down
18 changes: 9 additions & 9 deletions migration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ void daccustodian::migrate() {
// contract_state.remove();
// _currentState = contr_state{};

// cleanTable<candidates_table>(_self, _self);
// cleanTable<custodians_table>(_self, _self);
// cleanTable<votes_table>(_self, _self);
// cleanTable<pending_pay_table>(_self, _self);
// cleanTable<candidates_table>(_self, _self.value);
// cleanTable<custodians_table>(_self, _self.value);
// cleanTable<votes_table>(_self, _self.value);
// cleanTable<pending_pay_table>(_self, _self.value);

/*
//Copy to a holding table - Enable this for the first step
candidates_table oldcands(_self, _self);
candidates_table2 holding_table(_self, _self);
candidates_table oldcands(_self, _self.value);
candidates_table2 holding_table(_self, _self.value);
auto it = oldcands.begin();
while (it != oldcands.end()) {
holding_table.emplace(_self, [&](candidate2 &c) {
Expand All @@ -66,8 +66,8 @@ void daccustodian::migrate() {
// Copy back to the original table with the new schema - Enable this for the second step *after* modifying the original object's schema before copying back to the original table location.
candidates_table2 holding_table(_self, _self);
candidates_table oldcands(_self, _self);
candidates_table2 holding_table(_self, _self.value);
candidates_table oldcands(_self, _self.value);
auto it = holding_table.begin();
while (it != holding_table.end()) {
oldcands.emplace(_self, [&](candidate &c) {
Expand All @@ -80,4 +80,4 @@ void daccustodian::migrate() {
it = holding_table.erase(it);
}
*/
}
}
Loading

0 comments on commit ea2cfde

Please sign in to comment.