From cc3ca7dd99435cd1ea6b8749db3aebf6366d8930 Mon Sep 17 00:00:00 2001 From: Leister Francisco Alvarez Campos Date: Tue, 24 Aug 2021 10:31:11 -0600 Subject: [PATCH] feat(eden): load existing eden rate into eden scope (#686) * Publish changes to prod (#566) * avoid statefulsets update errors on actions runs refs #535. (#536) * deprecate demux service. refs #538 (#540) * add handler url from env var & other minor bug fixes (#542) * Add missing env var to config map (#543) * add handler url from env var & other minor bug fixes * add missing env var * fix: update some env vars * fix: update some env vars * fix: replace .env values with the previous ones * Feat/add tx link (#545) * feat: add tx link * feat: remove secrets * setup env workflow (#546) * wip * wip: add env files & db_data to .gitignore * fix: remove .env files * fix: remove .env files * fix: delete unnecessary code * refactor: remove unnecessary code * fix: minimal * Fix/rate action buttons not showing (#547) * wip * wip: add env files & db_data to .gitignore * fix: remove .env files * fix: remove .env files * fix: delete unnecessary code * refactor: remove unnecessary code * fix: minimal * fix: rate buttons not showing in certains densities * Fix/hasura console config (#556) * Deploy to mainnet (#544) * avoid statefulsets update errors on actions runs refs #535. (#536) * deprecate demux service. refs #538 (#540) * add handler url from env var & other minor bug fixes (#542) * Add missing env var to config map (#543) * add handler url from env var & other minor bug fixes * add missing env var * fix: update some env vars * fix: update some env vars * fix: replace .env values with the previous ones Co-authored-by: Andres Gomez Co-authored-by: JustinCast * wip * wip: add env files & db_data to .gitignore * fix: remove .env files * fix: remove .env files * fix: delete unnecessary code * refactor: remove unnecessary code * fix: minimal * feat: voting tool revamp * fix: remove comments * fix: add i18n entries * fix: bug fixes * fix: hasura console config Co-authored-by: Xavier <5632966+xavier506@users.noreply.github.com> Co-authored-by: Andres Gomez * Fix/add missing i18n entries (#554) * Deploy to mainnet (#544) * avoid statefulsets update errors on actions runs refs #535. (#536) * deprecate demux service. refs #538 (#540) * add handler url from env var & other minor bug fixes (#542) * Add missing env var to config map (#543) * add handler url from env var & other minor bug fixes * add missing env var * fix: update some env vars * fix: update some env vars * fix: replace .env values with the previous ones Co-authored-by: Andres Gomez Co-authored-by: JustinCast * wip * wip: add env files & db_data to .gitignore * fix: remove .env files * fix: remove .env files * fix: delete unnecessary code * refactor: remove unnecessary code * fix: minimal * feat: voting tool revamp * fix: remove comments * fix: add i18n entries * fix: bug fixes Co-authored-by: Xavier <5632966+xavier506@users.noreply.github.com> Co-authored-by: Andres Gomez * docs: add env example (#565) * fix: not able to sync proxies locally (#564) * fix: update hasura version * fix: hasura version && other minor bug fixes * Fix/update hasura version (#567) * fix: remove build:staging statement * latest changes Co-authored-by: Andres Gomez Co-authored-by: JustinCast * Update push-master-environment.yaml (#576) * fix(cron): update config values (#579) * Revert "fix(cron): update config values (#579)" (#580) This reverts commit 13ecf78f0cec5c1a938a1ee0aee646828995d940. * feat(eden): load existing eden rate into eden scope * feat(rateproducer): add singleton mutatino control * feat(rateproducer): add default contructor initializer * feat(rateproducer): final eden members migration Co-authored-by: Xavier <5632966+xavier506@users.noreply.github.com> Co-authored-by: Andres Gomez Co-authored-by: JustinCast Co-authored-by: Xavier Fernandez Co-authored-by: Leister Alvarez Campos --- .../rateproducer/include/rateproducer.hpp | 33 +++++++++++++-- contracts/rateproducer/src/rateproducer.cpp | 42 ++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/contracts/rateproducer/include/rateproducer.hpp b/contracts/rateproducer/include/rateproducer.hpp index 9aa55aaa..fcac3896 100644 --- a/contracts/rateproducer/include/rateproducer.hpp +++ b/contracts/rateproducer/include/rateproducer.hpp @@ -15,6 +15,7 @@ */ #include +#include #include #include #include @@ -27,7 +28,7 @@ #define MINVAL 0 #define MAXVAL 10 -#define MIN_VOTERS 21 +#define MIN_VOTERS 21 using namespace std; using namespace eosio; @@ -278,10 +279,28 @@ namespace eoscostarica { indexed_by<"bp"_n, const_mem_fun> > ratings_table; + /* + * Stores contract config for migration versioning + */ + struct config { + name owner; + uint32_t version; + }; + EOSIO_REFLECT( + config, + owner, + version + ) + typedef eosio::singleton<"globalconfig"_n, config> config_table; + struct rateproducer : public eosio::contract { // Use the base class constructors using eosio::contract::contract; + rateproducer(name receiver, name code, datastream ds) : + contract(receiver, code, ds), cfg(receiver, receiver.value) {} + + config_table cfg; /** * @@ -516,8 +535,15 @@ namespace eoscostarica { * @param user - Voter account name, * @param bp - Block Producer account name * - */ + */ void rmrate_aux(name scope, name user, name bp); + + /** + * + * Load existing eden member rates into rateproducer scope + * + */ + void loadedens(); }; EOSIO_ACTIONS(rateproducer, @@ -526,6 +552,7 @@ namespace eoscostarica { action(erase, bp_name), action(wipe), action(rminactive), - action(rmrate, user, bp)) + action(rmrate, user, bp), + action(loadedens)) } // namespace eoscostarica \ No newline at end of file diff --git a/contracts/rateproducer/src/rateproducer.cpp b/contracts/rateproducer/src/rateproducer.cpp index d36bcbdb..7897dbd3 100644 --- a/contracts/rateproducer/src/rateproducer.cpp +++ b/contracts/rateproducer/src/rateproducer.cpp @@ -171,7 +171,7 @@ namespace eoscostarica { }); } else { //update the entry - _stats.modify(itr,user, [&]( auto& row ) { + _stats.modify(itr, user, [&]( auto& row ) { if (transparency) { sum += transparency; if(row.transparency) { @@ -491,6 +491,46 @@ namespace eoscostarica { } } + + void rateproducer::loadedens() { + config c = cfg.get_or_create(_self, config{.owner = _self, .version = 0}); + require_auth(c.owner); + + // assert we only run once + // the comparison value needs to be hard-coded with each new migration + eosio::check(c.version < 1, "Migration already ran"); + + ratings_table _ratings_self(_self, _self.value); + ratings_table _ratings_eden(_self, eden_scope.value); + + for(auto itr = _ratings_self.begin(); itr != _ratings_self.end(); itr++) { + if(is_eden(itr->user)) { + _ratings_eden.emplace(_self, [&]( auto& row ) { + row.id = itr->id; + row.uniq_rating = itr->uniq_rating; + row.user = itr->user; + row.bp = itr->bp; + row.transparency = itr->transparency; + row.infrastructure = itr->infrastructure; + row.trustiness = itr->trustiness; + row.community = itr->community; + row.development = itr->development ; + }); + //save stats + save_bp_stats(eden_scope, + _self, + itr->bp, + itr->transparency, + itr->infrastructure, + itr->trustiness, + itr->community, + itr->development); + } + } + + c.version++; + cfg.set(c, c.owner); + } } // namespace eoscostarica