-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 855e907
Showing
5 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef COMMON_UTILITIES_H | ||
#define COMMON_UTILITIES_H | ||
#include <eosio/eosio.hpp> | ||
#include <eosio/symbol.hpp> | ||
|
||
namespace eosdac { | ||
|
||
using namespace eosio; | ||
using namespace std; | ||
|
||
// Utility to combine ids to help with indexing. | ||
uint128_t combine_ids(const uint8_t &boolvalue, const uint64_t &longValue) { | ||
return (uint128_t{boolvalue} << 64) | longValue; | ||
} | ||
|
||
uint128_t combine_ids(const uint16_t &value, const uint64_t &longValue) { | ||
return (uint128_t{value} << 64) | longValue; | ||
} | ||
|
||
static const uint128_t combine_ids(const uint64_t &x, const uint64_t &y) { | ||
return (uint128_t{x} << 64) | y; | ||
} | ||
|
||
static const __uint128_t raw_from_extended_symbol(const extended_symbol &symbol) { | ||
return (uint128_t{symbol.get_contract().value} << 64) | symbol.get_symbol().code().raw(); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include "common_utilities.hpp" | ||
|
||
#ifndef EOSDAC_DIRECTORY_H | ||
#define EOSDAC_DIRECTORY_H | ||
namespace eosdac { | ||
namespace directory { | ||
using namespace eosio; | ||
|
||
namespace types { | ||
|
||
enum account_type: uint8_t { | ||
AUTH = 0, | ||
TREASURY = 1, | ||
CUSTODIAN = 2, | ||
MSIGS = 3, | ||
SERVICE = 5, | ||
PROPOSALS = 6, | ||
ESCROW = 7, | ||
ROUTER = 8, | ||
EXTERNAL = 254, | ||
OTHER = 255 | ||
}; | ||
|
||
enum ref_type: uint8_t { | ||
HOMEPAGE = 0, | ||
LOGO_URL = 1, | ||
DESCRIPTION = 2, | ||
LOGO_NOTEXT_URL = 3, | ||
BACKGROUND_URL = 4, | ||
COLORS = 5, | ||
CLIENT_EXTENSION = 6 | ||
}; | ||
|
||
enum dac_state_type: uint8_t { | ||
dac_state_typeINACTIVE = 0, | ||
dac_state_typeACTIVE = 1 | ||
}; | ||
|
||
struct [[eosio::table("dacs"), eosio::contract("dacdirectory")]] dac { | ||
eosio::name owner; | ||
eosio::name dac_id; | ||
std::string title; | ||
eosio::extended_symbol symbol; | ||
std::map<uint8_t, std::string> refs; | ||
std::map<uint8_t, eosio::name> accounts; | ||
uint8_t dac_state; | ||
|
||
eosio::name account_for_type( uint8_t type) const { | ||
eosio::print("\ngetting account for type: ", type,"\n"); | ||
return accounts.at(type); | ||
} | ||
|
||
uint64_t primary_key() const { return dac_id.value; } | ||
uint64_t by_owner() const { return owner.value; } | ||
uint128_t by_symbol() const { return eosdac::raw_from_extended_symbol(symbol); } | ||
}; | ||
} | ||
|
||
namespace tables { | ||
using namespace types; | ||
|
||
typedef eosio::multi_index< "dacs"_n, dac, | ||
eosio::indexed_by<"byowner"_n, eosio::const_mem_fun<dac, uint64_t, &dac::by_owner>>, | ||
eosio::indexed_by<"bysymbol"_n, eosio::const_mem_fun<dac, uint128_t, &dac::by_symbol>> | ||
> dac_table; | ||
} | ||
|
||
namespace actions { | ||
|
||
} | ||
|
||
const types::dac dac_for_id(name id) { | ||
tables::dac_table dactable("dacdirectory"_n, "dacdirectory"_n.value); | ||
return dactable.get(id.value, "ERR::DAC_NOT_FOUND::DAC not found in directory"); | ||
} | ||
|
||
const types::dac dac_for_symbol(eosio::extended_symbol sym) { | ||
tables::dac_table dactable("dacdirectory"_n, "dacdirectory"_n.value); | ||
auto index = dactable.get_index<"bysymbol"_n>(); | ||
auto dac_idx = index.find(eosdac::raw_from_extended_symbol(sym)); | ||
print("\ndac_for_symbol: ", sym, "\n"); | ||
eosio::check(dac_idx != index.end() && dac_idx->symbol == sym, "ERR::DAC_NOT_FOUND_SYMBOL::DAC not found in directory for the given symbol"); | ||
return *dac_idx; | ||
} | ||
} | ||
} | ||
#endif |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
#include "directory.hpp" | ||
|
||
#ifndef EOSDAC_NOTIFY_H | ||
#define EOSDAC_NOTIFY_H | ||
|
||
namespace eosdac { | ||
namespace notify { | ||
using namespace eosio; | ||
|
||
namespace types { | ||
|
||
struct account_balance_delta { | ||
name account; | ||
asset balance_delta; | ||
}; | ||
|
||
struct account_weight_delta { | ||
name account; | ||
int64_t weight_delta; | ||
}; | ||
|
||
struct account_stake_delta { | ||
name account; | ||
asset stake_delta; | ||
}; | ||
} | ||
|
||
void balanceobsv(vector<types::account_balance_delta> account_balance_deltas, name dac_id); | ||
using balanceobsv_action = action_wrapper< "balanceobsv"_n, &balanceobsv >; | ||
void stakeobsv(vector<types::account_stake_delta> account_stake_deltas, name dac_id); | ||
using stakeobsv_action = action_wrapper< "stakeobsv"_n, &stakeobsv >; | ||
void weightobsv(vector<types::account_weight_delta> account_weight_deltas, name dac_id); | ||
using weightobsv_action = action_wrapper< "weightobsv"_n, &weightobsv >; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
|
||
namespace eosdac { | ||
namespace token { | ||
using namespace eosio; | ||
using std::string; | ||
|
||
namespace types { | ||
|
||
struct [[eosio::table]] member_type { | ||
name sender; | ||
uint64_t agreedtermsversion; | ||
|
||
uint64_t primary_key() const { return sender.value; } | ||
}; | ||
|
||
|
||
struct [[eosio::table]] termsinfo_type { | ||
string terms; | ||
string hash; | ||
uint64_t version; | ||
|
||
termsinfo_type() : terms(""), hash(""), version(0) {} | ||
|
||
termsinfo_type(string _terms, string _hash, uint64_t _version) | ||
: terms(_terms), hash(_hash), version(_version) {} | ||
|
||
uint64_t primary_key() const { return version; } | ||
uint64_t by_latest_version() const { return UINT64_MAX - version; } | ||
}; | ||
|
||
} | ||
|
||
namespace tables { | ||
using namespace types; | ||
|
||
typedef multi_index<"members"_n, member_type> member_table; | ||
|
||
typedef multi_index<"memberterms"_n, termsinfo_type, | ||
indexed_by<"bylatestver"_n, const_mem_fun<termsinfo_type, uint64_t, &termsinfo_type::by_latest_version> > | ||
> member_terms_table; | ||
|
||
} | ||
|
||
namespace actions { | ||
|
||
} | ||
|
||
static void assert_valid_member(name member, name dac_id) { | ||
name member_terms_account; | ||
|
||
member_terms_account = directory::dac_for_id(dac_id).symbol.get_contract(); // Need this line without the temp block | ||
tables::member_table reg_members(member_terms_account, dac_id.value); | ||
tables::member_terms_table memberterms(member_terms_account, dac_id.value); | ||
|
||
const auto ®mem = reg_members.get(member.value, "ERR::GENERAL_REG_MEMBER_NOT_FOUND::Account is not registered with members."); | ||
check((regmem.agreedtermsversion != 0), "ERR::GENERAL_MEMBER_HAS_NOT_AGREED_TO_ANY_TERMS::Account has not agreed to any terms"); | ||
auto latest_member_terms = (--memberterms.end()); | ||
check(latest_member_terms->version == regmem.agreedtermsversion, "ERR::GENERAL_MEMBER_HAS_NOT_AGREED_TO_LATEST_TERMS::Agreed terms isn't the latest."); | ||
} | ||
} | ||
} |