Skip to content

Commit

Permalink
Comment Section Fix (#966)
Browse files Browse the repository at this point in the history
* (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
  • Loading branch information
hanakoori01 authored Aug 24, 2022
1 parent db31101 commit 5839c49
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
5 changes: 3 additions & 2 deletions contracts/rateproducer/include/rateproducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
*
Expand Down Expand Up @@ -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
14 changes: 7 additions & 7 deletions contracts/rateproducer/src/rateproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 });
}
}
}
Expand Down Expand Up @@ -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" );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -17,36 +21,22 @@ 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,
lower_bound: ratingId,
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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module.exports = {
const {
transaction_id,
actors,
data: {
data: { rating_id: ratingId, like }
}
data: { rating_id: ratingId, like }
} = action

await saveOrUpdate({
Expand Down
5 changes: 1 addition & 4 deletions hasura/metadata/actions.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
type Mutation {
rateProducer(
ratingInput: RatingInput!
): RatingOutput
rateProducer(ratingInput: RatingInput!): RatingOutput
}

input RatingInput {
Expand All @@ -27,4 +25,3 @@ type deleteUserRateOutput {
type AddCommentOutput {
success: Boolean!
}

0 comments on commit 5839c49

Please sign in to comment.