Permalink
Browse files

Merge pull request #37 from eosdac/cdt1.3

Update the contract for the new compiler tools
  • Loading branch information...
michaeljyeates committed Nov 28, 2018
2 parents f016f0c + a8417a4 commit e1d6e950a569d56bb48c67171e236b8c19a97219
@@ -26,15 +26,14 @@ 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)) ) { \
TYPE thiscontract( self ); \
if( (code == self && action != "transfer"_n.value) || (code == name(TOKEN_CONTRACT).value && action == "transfer"_n.value) ) { \
switch( action ) { \
EOSIO_API( TYPE, MEMBERS ) \
EOSIO_DISPATCH_HELPER( TYPE, MEMBERS ) \
} \
/* does not allow destructor of thiscontract to run: eosio_exit(0); */ \
} \
@@ -2,6 +2,13 @@
#include <eosiolib/multi_index.hpp>
#include "external_types.hpp"

#define _STRINGIZE(x) #x
#define STRINGIZE(x) _STRINGIZE(x)

#ifdef TOKENCONTRACT
#define TOKEN_CONTRACT STRINGIZE(TOKENCONTRACT)
#endif

#ifndef TOKEN_CONTRACT
#define TOKEN_CONTRACT "eosdactokens"
#endif
@@ -10,10 +17,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;
@@ -29,13 +36,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;
@@ -75,7 +82,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;
@@ -92,7 +99,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) {
@@ -107,7 +114,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); }

@@ -119,19 +126,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); }

@@ -141,25 +148,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 {
@@ -169,26 +176,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 {
@@ -204,12 +211,13 @@ 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());
}
@@ -433,7 +441,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);
@@ -460,4 +468,4 @@ Nothing from this action is stored on the blockchain. It is only intended to ens
void migrate();
#endif

};
};
@@ -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;
@@ -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;
@@ -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.
@@ -22,7 +22,7 @@ struct member {
/// Hash of agreed terms
uint64_t agreedterms;

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

EOSLIB_SERIALIZE(member, (sender)(agreedterms))
};
@@ -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))
@@ -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) {
@@ -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) {
@@ -80,4 +80,4 @@ void daccustodian::migrate() {
it = holding_table.erase(it);
}
*/
}
}
Oops, something went wrong.

0 comments on commit e1d6e95

Please sign in to comment.