Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse dao id in memo (DEV-1299) #371

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/dao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,17 @@ namespace pricing {
if (get_first_receiver() == pegContract &&
to == get_self() &&
from != get_self()) {

const size_t prefix_length = 7; // "redeem,"

if (memo == "redeem") {
onCashTokenTransfer(from, to, quantity, memo);
EOS_CHECK(false, "redeem must have a dao id specified like this: redeem,[daoId]");
}

if (memo.substr(0, prefix_length) == "redeem,") {
string number_str = memo.substr(prefix_length);
uint64_t daoId = stoi(number_str);
onCashTokenTransfer(from, to, quantity, daoId, memo);
}
else {
EOS_CHECK(
Expand Down Expand Up @@ -555,7 +564,7 @@ namespace pricing {
std::optional<TimeShare>& lastUsedTimeShare,
int64_t initTimeShare);

void onCashTokenTransfer(const name& from, const name& to, const asset& quantity, const string& memo);
void onCashTokenTransfer(const name& from, const name& to, const asset& quantity, const uint64_t& daoId, const string& memo);

void onNativeTokenTransfer(const name& from, const name& to, const asset& quantity, const string& memo);

Expand Down
48 changes: 2 additions & 46 deletions src/treasury/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,9 @@ void dao::onNativeTokenTransfer(const name& from, const name& to, const asset& q
#endif
}

void dao::onCashTokenTransfer(const name& from, const name& to, const asset& quantity, const string& memo)
void dao::onCashTokenTransfer(const name& from, const name& to, const asset& quantity, const uint64_t& daoID, const string& memo)
{

#ifndef USE_TREASURY
EOS_CHECK(
false,
Expand All @@ -485,51 +486,6 @@ void dao::onCashTokenTransfer(const name& from, const name& to, const asset& qua
#else
EOS_CHECK(quantity.amount > 0, "quantity must be > 0");
EOS_CHECK(quantity.is_valid(), "quantity invalid");

//Since the symbols must be unique for each Cash token we can use the
//raw value as the edge name
name lookupEdgeName = name(quantity.symbol.raw());

//This would be a very weird scenario where the symbol raw value
//equals the edge name 'dao' which would cause unexpected behaviour
if (lookupEdgeName == common::DAO) {
// auto settings = getSettingsDocument();
// settings->setSetting(
// "errors",
// Content{ "cash_critital_error", to_str("Symbol raw value colapses with 'dao' edge name:", quantity) }
// );
EOS_CHECK(
false,
to_str("Symbol raw value colapses with 'dao' edge name:", quantity)
)

return;
}

uint64_t daoID = 0;

auto rootID = getRootID();
//Fast lookup
if (auto [exists, edge] = Edge::getIfExists(get_self(), rootID, lookupEdgeName); exists) {
daoID = edge.getToNode();
}
//We have to find which DAO this token belongs to (if any)
else {
auto daoEdges = getGraph().getEdgesFrom(rootID, common::DAO);

for (auto& edge : daoEdges) {
auto daoSettings = getSettingsDocument(edge.getToNode());

//Some DAO's might not have a peg token so let's use the default asset{}
if (daoSettings->getSettingOrDefault<asset>(common::PEG_TOKEN).symbol == quantity.symbol) {
//If we find it, let's create a lookup edge for the next time we get this symbol
daoID = edge.getToNode();
Edge(get_self(), get_self(), rootID, daoID, lookupEdgeName);
break;
}
}
}

EOS_CHECK(
daoID != 0,
"No DAO uses the transfered token"
Expand Down
Loading