From 105d4e60368087dfe86c6282395957cddb76c455 Mon Sep 17 00:00:00 2001 From: NIK Date: Thu, 2 May 2024 21:05:32 +0800 Subject: [PATCH 1/3] parse dao ID in memo remove code that searches for the dao id. Fixes DEV-1299 --- include/dao.hpp | 11 ++++++--- src/treasury/actions.cpp | 48 ++-------------------------------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/include/dao.hpp b/include/dao.hpp index 33f062b..a9b5d54 100644 --- a/include/dao.hpp +++ b/include/dao.hpp @@ -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( @@ -555,7 +560,7 @@ namespace pricing { std::optional& 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); diff --git a/src/treasury/actions.cpp b/src/treasury/actions.cpp index bf88f0f..4397c6f 100644 --- a/src/treasury/actions.cpp +++ b/src/treasury/actions.cpp @@ -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, @@ -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(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" From f51a0dbf5249a6b0ca58c745744f68717ec3e443 Mon Sep 17 00:00:00 2001 From: NIK Date: Thu, 2 May 2024 21:15:41 +0800 Subject: [PATCH 2/3] Update submodule to latest commit --- document-graph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document-graph b/document-graph index 7a5a7da..f8ded45 160000 --- a/document-graph +++ b/document-graph @@ -1 +1 @@ -Subproject commit 7a5a7da22e0875717910c1a72d12f4a030871b68 +Subproject commit f8ded45a4053d425717464aae3388b88023b47c1 From 138fbfc8633055434795b9c927cdfeb0f62ff50b Mon Sep 17 00:00:00 2001 From: NIK Date: Thu, 2 May 2024 21:31:26 +0800 Subject: [PATCH 3/3] nice error message for old redeem memo --- include/dao.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/dao.hpp b/include/dao.hpp index a9b5d54..2a2f304 100644 --- a/include/dao.hpp +++ b/include/dao.hpp @@ -473,6 +473,10 @@ namespace pricing { from != get_self()) { const size_t prefix_length = 7; // "redeem," + + if (memo == "redeem") { + 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);