Skip to content

Commit

Permalink
parse dao ID in memo
Browse files Browse the repository at this point in the history
remove code that searches for the dao id. Fixes DEV-1299
  • Loading branch information
n13 committed May 2, 2024
1 parent b9242f0 commit 105d4e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 deletions.
11 changes: 8 additions & 3 deletions include/dao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,13 @@ namespace pricing {
if (get_first_receiver() == pegContract &&
to == get_self() &&
from != get_self()) {
if (memo == "redeem") {
onCashTokenTransfer(from, to, quantity, memo);

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

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 +560,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

0 comments on commit 105d4e6

Please sign in to comment.