From 5839c4982acf5840a5e3656076670dc8ba422b8a Mon Sep 17 00:00:00 2001 From: Paola Espinoza <71234240+hanakoori01@users.noreply.github.com> Date: Tue, 23 Aug 2022 21:05:09 -0600 Subject: [PATCH] Comment Section Fix (#966) * (hapi): fix destructuring data in logcomment * (BE): add new validation eden member to comment * (BE): change variable isEden to is_eden * (hapi): code review fix declaration of variables * (hapi): add validation of is_eden null * (hapi): fix validation of is_eden null * (hapi): code review add blank line * (SC): change genesis.eden to genesisdeden * (BE): code review genesis.eden --- .../rateproducer/include/rateproducer.hpp | 5 ++-- contracts/rateproducer/src/rateproducer.cpp | 14 ++++----- .../rateproducer-logcomment.updater.js | 30 +++++++------------ .../updaters/rateproducer-loglike.updater.js | 4 +-- hasura/metadata/actions.graphql | 5 +--- 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/contracts/rateproducer/include/rateproducer.hpp b/contracts/rateproducer/include/rateproducer.hpp index 8b4f3aa6..50ead6c5 100644 --- a/contracts/rateproducer/include/rateproducer.hpp +++ b/contracts/rateproducer/include/rateproducer.hpp @@ -516,9 +516,10 @@ namespace eoscostarica { * * @param rating_id - Id of the rating, * @param comment - Commentary + * @param is_eden - is eden member true/false * */ - void logcomment (uint64_t rating_id, std::string comment); + void logcomment (uint64_t rating_id, std::string comment, bool is_eden); /** * @@ -614,7 +615,7 @@ namespace eoscostarica { action(rminactive, ricardian_contract(rminactive_ricardian)), action(rmrate, user, bp, ricardian_contract(rmrate_ricardian)), action(migrate, ricardian_contract(migrate_ricardian)), - action(logcomment, rating_id, comment, ricardian_contract(logcomment_ricardian)), + action(logcomment, rating_id, comment, is_eden, ricardian_contract(logcomment_ricardian)), action(loglike, rating_id, user, like, ricardian_contract(loglike_ricardian))) } // namespace eoscostarica \ No newline at end of file diff --git a/contracts/rateproducer/src/rateproducer.cpp b/contracts/rateproducer/src/rateproducer.cpp index 5eef8f30..8ba56e9d 100644 --- a/contracts/rateproducer/src/rateproducer.cpp +++ b/contracts/rateproducer/src/rateproducer.cpp @@ -32,17 +32,17 @@ namespace eoscostarica { check( (MINVAL <= development && development <= MAXVAL), "Error development value out of range" ); check( (MINVAL <= community && community <= MAXVAL), "Error community value out of range" ); - bool isEden = scope.value == eden_scope.value; - name stats_ram_payer = isEden ? _self : user; + bool is_eden = scope.value == eden_scope.value; + name stats_ram_payer = is_eden ? _self : user; check( is_blockproducer(bp), "votes are allowed only for registered block producers" ); name proxy_name = get_proxy(user); if(proxy_name.length()) { check(is_active_proxy(proxy_name), "votes are allowed only for active proxies" ); - if(!isEden) check( MIN_VOTERS <= get_voters(proxy_name), "delegated proxy does not have enough voters" ); + if(!is_eden) check( MIN_VOTERS <= get_voters(proxy_name), "delegated proxy does not have enough voters" ); } else { - if(!isEden) check( MIN_VOTERS <= get_voters(user), "account does not have enough voters" ); + if(!is_eden) check( MIN_VOTERS <= get_voters(user), "account does not have enough voters" ); } ratings_table_v2 _ratings(_self, scope.value); @@ -75,7 +75,7 @@ namespace eoscostarica { development); if(!comment.empty()) { - SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { rating_id, comment }); + SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { rating_id, comment, is_eden }); } } else { @@ -115,7 +115,7 @@ namespace eoscostarica { &bp_average); if(!comment.empty()) { - SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { existing_rating->id, comment }); + SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { existing_rating->id, comment, is_eden }); } } } @@ -503,7 +503,7 @@ namespace eoscostarica { cfg.set(c, c.owner); } - void rateproducer::logcomment(uint64_t rating_id, std::string comment) { + void rateproducer::logcomment(uint64_t rating_id, std::string comment, bool is_eden) { require_auth(_self); check( comment.length() <= 500, "comment must be less or equal than 500 characters" ); } diff --git a/hapi/src/services/hyperion/updaters/rateproducer-logcomment.updater.js b/hapi/src/services/hyperion/updaters/rateproducer-logcomment.updater.js index 280bb144..d280f13f 100644 --- a/hapi/src/services/hyperion/updaters/rateproducer-logcomment.updater.js +++ b/hapi/src/services/hyperion/updaters/rateproducer-logcomment.updater.js @@ -1,4 +1,8 @@ -const { eosConfig } = require('../../../config') +const { + eosConfig, + generalContractScope, + edenContractScope +} = require('../../../config') const { save, updateUserRating } = require('../../comment.service') const EosApi = require('eosjs-api') @@ -17,16 +21,15 @@ module.exports = { try { const { transaction_id, - data: { - data: { rating_id: ratingId, comment } - } + data: { rating_id: ratingId, comment, is_eden: isEden } } = action - let userRatings - userRatings = await eosApi.getTableRows({ + if (isEden === null) return + + const userRatings = await eosApi.getTableRows({ json: true, code: eosConfig.baseAccount, - scope: 'eden', + scope: isEden ? edenContractScope : generalContractScope, table: 'rating', reverse: false, limit: 1, @@ -34,19 +37,6 @@ module.exports = { upper_bound: ratingId }) - if (!userRatings) { - userRatings = await eosApi.getTableRows({ - json: true, - code: eosConfig.baseAccount, - scope: 'rateproducer', - table: 'rating', - reverse: false, - limit: 1, - lower_bound: ratingId, - upper_bound: ratingId - }) - } - const [blockProducer] = userRatings.rows.filter( ({ id }) => id == ratingId ) diff --git a/hapi/src/services/hyperion/updaters/rateproducer-loglike.updater.js b/hapi/src/services/hyperion/updaters/rateproducer-loglike.updater.js index accc8613..4fad663c 100644 --- a/hapi/src/services/hyperion/updaters/rateproducer-loglike.updater.js +++ b/hapi/src/services/hyperion/updaters/rateproducer-loglike.updater.js @@ -9,9 +9,7 @@ module.exports = { const { transaction_id, actors, - data: { - data: { rating_id: ratingId, like } - } + data: { rating_id: ratingId, like } } = action await saveOrUpdate({ diff --git a/hasura/metadata/actions.graphql b/hasura/metadata/actions.graphql index fa6dc611..542f9b7f 100644 --- a/hasura/metadata/actions.graphql +++ b/hasura/metadata/actions.graphql @@ -1,7 +1,5 @@ type Mutation { - rateProducer( - ratingInput: RatingInput! - ): RatingOutput + rateProducer(ratingInput: RatingInput!): RatingOutput } input RatingInput { @@ -27,4 +25,3 @@ type deleteUserRateOutput { type AddCommentOutput { success: Boolean! } -