Skip to content

Commit 5839c49

Browse files
authored
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
1 parent db31101 commit 5839c49

File tree

5 files changed

+22
-36
lines changed

5 files changed

+22
-36
lines changed

contracts/rateproducer/include/rateproducer.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,10 @@ namespace eoscostarica {
516516
*
517517
* @param rating_id - Id of the rating,
518518
* @param comment - Commentary
519+
* @param is_eden - is eden member true/false
519520
*
520521
*/
521-
void logcomment (uint64_t rating_id, std::string comment);
522+
void logcomment (uint64_t rating_id, std::string comment, bool is_eden);
522523

523524
/**
524525
*
@@ -614,7 +615,7 @@ namespace eoscostarica {
614615
action(rminactive, ricardian_contract(rminactive_ricardian)),
615616
action(rmrate, user, bp, ricardian_contract(rmrate_ricardian)),
616617
action(migrate, ricardian_contract(migrate_ricardian)),
617-
action(logcomment, rating_id, comment, ricardian_contract(logcomment_ricardian)),
618+
action(logcomment, rating_id, comment, is_eden, ricardian_contract(logcomment_ricardian)),
618619
action(loglike, rating_id, user, like, ricardian_contract(loglike_ricardian)))
619620

620621
} // namespace eoscostarica

contracts/rateproducer/src/rateproducer.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ namespace eoscostarica {
3232
check( (MINVAL <= development && development <= MAXVAL), "Error development value out of range" );
3333
check( (MINVAL <= community && community <= MAXVAL), "Error community value out of range" );
3434

35-
bool isEden = scope.value == eden_scope.value;
36-
name stats_ram_payer = isEden ? _self : user;
35+
bool is_eden = scope.value == eden_scope.value;
36+
name stats_ram_payer = is_eden ? _self : user;
3737

3838
check( is_blockproducer(bp), "votes are allowed only for registered block producers" );
3939

4040
name proxy_name = get_proxy(user);
4141
if(proxy_name.length()) {
4242
check(is_active_proxy(proxy_name), "votes are allowed only for active proxies" );
43-
if(!isEden) check( MIN_VOTERS <= get_voters(proxy_name), "delegated proxy does not have enough voters" );
43+
if(!is_eden) check( MIN_VOTERS <= get_voters(proxy_name), "delegated proxy does not have enough voters" );
4444
} else {
45-
if(!isEden) check( MIN_VOTERS <= get_voters(user), "account does not have enough voters" );
45+
if(!is_eden) check( MIN_VOTERS <= get_voters(user), "account does not have enough voters" );
4646
}
4747

4848
ratings_table_v2 _ratings(_self, scope.value);
@@ -75,7 +75,7 @@ namespace eoscostarica {
7575
development);
7676

7777
if(!comment.empty()) {
78-
SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { rating_id, comment });
78+
SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { rating_id, comment, is_eden });
7979
}
8080

8181
} else {
@@ -115,7 +115,7 @@ namespace eoscostarica {
115115
&bp_average);
116116

117117
if(!comment.empty()) {
118-
SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { existing_rating->id, comment });
118+
SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { existing_rating->id, comment, is_eden });
119119
}
120120
}
121121
}
@@ -503,7 +503,7 @@ namespace eoscostarica {
503503
cfg.set(c, c.owner);
504504
}
505505

506-
void rateproducer::logcomment(uint64_t rating_id, std::string comment) {
506+
void rateproducer::logcomment(uint64_t rating_id, std::string comment, bool is_eden) {
507507
require_auth(_self);
508508
check( comment.length() <= 500, "comment must be less or equal than 500 characters" );
509509
}

hapi/src/services/hyperion/updaters/rateproducer-logcomment.updater.js

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const { eosConfig } = require('../../../config')
1+
const {
2+
eosConfig,
3+
generalContractScope,
4+
edenContractScope
5+
} = require('../../../config')
26
const { save, updateUserRating } = require('../../comment.service')
37
const EosApi = require('eosjs-api')
48

@@ -17,36 +21,22 @@ module.exports = {
1721
try {
1822
const {
1923
transaction_id,
20-
data: {
21-
data: { rating_id: ratingId, comment }
22-
}
24+
data: { rating_id: ratingId, comment, is_eden: isEden }
2325
} = action
24-
let userRatings
2526

26-
userRatings = await eosApi.getTableRows({
27+
if (isEden === null) return
28+
29+
const userRatings = await eosApi.getTableRows({
2730
json: true,
2831
code: eosConfig.baseAccount,
29-
scope: 'eden',
32+
scope: isEden ? edenContractScope : generalContractScope,
3033
table: 'rating',
3134
reverse: false,
3235
limit: 1,
3336
lower_bound: ratingId,
3437
upper_bound: ratingId
3538
})
3639

37-
if (!userRatings) {
38-
userRatings = await eosApi.getTableRows({
39-
json: true,
40-
code: eosConfig.baseAccount,
41-
scope: 'rateproducer',
42-
table: 'rating',
43-
reverse: false,
44-
limit: 1,
45-
lower_bound: ratingId,
46-
upper_bound: ratingId
47-
})
48-
}
49-
5040
const [blockProducer] = userRatings.rows.filter(
5141
({ id }) => id == ratingId
5242
)

hapi/src/services/hyperion/updaters/rateproducer-loglike.updater.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ module.exports = {
99
const {
1010
transaction_id,
1111
actors,
12-
data: {
13-
data: { rating_id: ratingId, like }
14-
}
12+
data: { rating_id: ratingId, like }
1513
} = action
1614

1715
await saveOrUpdate({

hasura/metadata/actions.graphql

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
type Mutation {
2-
rateProducer(
3-
ratingInput: RatingInput!
4-
): RatingOutput
2+
rateProducer(ratingInput: RatingInput!): RatingOutput
53
}
64

75
input RatingInput {
@@ -27,4 +25,3 @@ type deleteUserRateOutput {
2725
type AddCommentOutput {
2826
success: Boolean!
2927
}
30-

0 commit comments

Comments
 (0)