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