Skip to content

Commit

Permalink
fix(contract): fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed May 2, 2022
2 parents 27554cc + d5f1abc commit 7cd9717
Show file tree
Hide file tree
Showing 64 changed files with 482 additions and 165 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ REACT_APP_VERSION=v1.4.21
REACT_APP_MAINNET_VERSION=v1.4.21
REACT_APP_EDEN_CONTRACT=genesisdeden
REACT_APP_UAL_APP_NAME=EOSRate

# CONTRACT
CONTRACT_ENDPOINT='<endpoint>'
CONTRACT_ACCOUNT='<account>'
23 changes: 13 additions & 10 deletions contracts/rateproducer/include/rateproducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ namespace eoscostarica {
* @param trustiness - Rate for trustiness category
* @param community - Rate for community category
* @param development - Rate for development category
* @param comment - Commentary
*
* @pre all rate category's vales must be an integer value
* @pre all rate category's vales must be between 1 -10
Expand All @@ -382,7 +383,8 @@ namespace eoscostarica {
int8_t infrastructure,
int8_t trustiness,
int8_t community,
int8_t development);
int8_t development,
std::string comment);


/**
Expand All @@ -397,6 +399,7 @@ namespace eoscostarica {
* @param trustiness - Rate for trustiness category
* @param community - Rate for community category
* @param development - Rate for development category
* @param comment - Commentary
*
* @pre all rate category's vales must be an integer value
* @pre all rate category's vales must be between 1 -10
Expand All @@ -413,7 +416,8 @@ namespace eoscostarica {
int8_t infrastructure,
int8_t trustiness,
int8_t community,
int8_t development);
int8_t development,
std::string comment);

/**
*
Expand Down Expand Up @@ -508,14 +512,13 @@ namespace eoscostarica {

/**
*
* Add a comment for a bp
* Add a comment for a rating
*
* @param user - Commenter account,
* @param bp - Block Producer account name
* @param rating_id - Id of the rating,
* @param comment - Commentary
*
*/
void logcomment (name user, name bp, std::string comment);
void logcomment (uint64_t rating_id, std::string comment);

/**
*
Expand All @@ -526,7 +529,7 @@ namespace eoscostarica {
* @param like - true/false
*
*/
void loglike (std::string transaction, name user, bool like);
void loglike (uint64_t rating_id, name user, bool like);

/**
*
Expand Down Expand Up @@ -620,14 +623,14 @@ namespace eoscostarica {

EOSIO_ACTIONS(rateproducer,
"rateproducer"_n,
action(rate, user, bp, transparency, infrastructure, trustiness, community, development, ricardian_contract(rate_ricardian)),
action(rate, user, bp, transparency, infrastructure, trustiness, community, development, comment, ricardian_contract(rate_ricardian)),
action(erase, bp_name, ricardian_contract(erase_ricardian)),
action(rminactive, ricardian_contract(rminactive_ricardian)),
action(rmrate, user, bp, ricardian_contract(rmrate_ricardian)),
action(migrate, ricardian_contract(migrate_ricardian)),
action(freeupram, ricardian_contract(freeupram_ricardian)),
action(migratestats, ricardian_contract(migratestats_ricardian)),
action(logcomment, user, bp, comment, ricardian_contract(logcomment_ricardian)),
action(loglike, transaction, user, like, ricardian_contract(loglike_ricardian)))
action(logcomment, rating_id, comment, ricardian_contract(logcomment_ricardian)),
action(loglike, rating_id, user, like, ricardian_contract(loglike_ricardian)))

} // namespace eoscostarica
11 changes: 11 additions & 0 deletions contracts/rateproducer/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-include ../../.env

compile:
@mkdir -p build
@cd build && cmake `clsdk-cmake-args` .. && make -j $(nproc)
@cd build && cp rateproducer.* ..
@echo "compiled"

deploy:
cleos -u $(CONTRACT_ENDPOINT) set contract $(CONTRACT_ACCOUNT) ./
@echo "deployed"
22 changes: 11 additions & 11 deletions contracts/rateproducer/rateproducer_mainnet.abi
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
{
"name": "development",
"type": "int8"
},
{
"name": "comment",
"type": "string"
}
]
},
Expand Down Expand Up @@ -85,12 +89,8 @@
"base": "",
"fields": [
{
"name": "user",
"type": "name"
},
{
"name": "bp",
"type": "name"
"name": "rating_id",
"type": "uint64"
},
{
"name": "comment",
Expand All @@ -103,8 +103,8 @@
"base": "",
"fields": [
{
"name": "transaction",
"type": "string"
"name": "rating_id",
"type": "uint64"
},
{
"name": "user",
Expand Down Expand Up @@ -197,7 +197,7 @@
{
"name": "rate",
"type": "rate",
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Rate a block producer\nsummary: The intent of the `{{ rate }}` action is to allow the `issuer` account to rate a blockproducer into five categories: Community, Development, Infraestructure, Transparency, Trustiness.\n---"
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Rate a block producer\nsummary: The intent of the `{{ rate }}` action is to allow the `issuer` account to rate a blockproducer into five categories: Community, Development, Infraestructure, Transparency, Trustiness. Additionally, users could add a description to their rating.\n---"
},
{
"name": "erase",
Expand Down Expand Up @@ -232,12 +232,12 @@
{
"name": "logcomment",
"type": "logcomment",
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional information about block producer\nsummary: The intent of the `{{ logcomment }}` action is to add additional information and optinions of users about block producers.\n---"
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional information about block producer\nsummary: The intent of the `{{ logcomment }}` action is to add additional information and optinions.\n---"
},
{
"name": "loglike",
"type": "loglike",
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional feedback about comment\nsummary: The intent of the `{{ loglike }}` action is to add feedback of users comment about block producers.\n---"
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional feedback about comment\nsummary: The intent of the `{{ loglike }}` action is to add feedback of users comment about ratings.\n---"
}
],
"tables": [
Expand Down
22 changes: 11 additions & 11 deletions contracts/rateproducer/rateproducer_testnet.abi
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
{
"name": "development",
"type": "int8"
},
{
"name": "comment",
"type": "string"
}
]
},
Expand Down Expand Up @@ -85,12 +89,8 @@
"base": "",
"fields": [
{
"name": "user",
"type": "name"
},
{
"name": "bp",
"type": "name"
"name": "rating_id",
"type": "uint64"
},
{
"name": "comment",
Expand All @@ -103,8 +103,8 @@
"base": "",
"fields": [
{
"name": "transaction",
"type": "string"
"name": "rating_id",
"type": "uint64"
},
{
"name": "user",
Expand Down Expand Up @@ -197,7 +197,7 @@
{
"name": "rate",
"type": "rate",
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Rate a block producer\nsummary: The intent of the `{{ rate }}` action is to allow the `issuer` account to rate a blockproducer into five categories: Community, Development, Infraestructure, Transparency, Trustiness.\n---"
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Rate a block producer\nsummary: The intent of the `{{ rate }}` action is to allow the `issuer` account to rate a blockproducer into five categories: Community, Development, Infraestructure, Transparency, Trustiness. Additionally, users could add a description to their rating.\n---"
},
{
"name": "erase",
Expand Down Expand Up @@ -232,12 +232,12 @@
{
"name": "logcomment",
"type": "logcomment",
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional information about block producer\nsummary: The intent of the `{{ logcomment }}` action is to add additional information and optinions of users about block producers.\n---"
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional information about block producer\nsummary: The intent of the `{{ logcomment }}` action is to add additional information and optinions.\n---"
},
{
"name": "loglike",
"type": "loglike",
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional feedback about comment\nsummary: The intent of the `{{ loglike }}` action is to add feedback of users comment about block producers.\n---"
"ricardian_contract": "---\nspec_version: 0.1.0\ntitle: Add additional feedback about comment\nsummary: The intent of the `{{ loglike }}` action is to add feedback of users comment about ratings.\n---"
}
],
"tables": [
Expand Down
Binary file modified contracts/rateproducer/rateproducer_testnet.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions contracts/rateproducer/ricardian/rateproducer-ricardian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace eoscostarica {
const char* rate_ricardian = R"(---
spec_version: 0.1.0
title: Rate a block producer
summary: The intent of the `{{ rate }}` action is to allow the `issuer` account to rate a blockproducer into five categories: Community, Development, Infraestructure, Transparency, Trustiness.
summary: The intent of the `{{ rate }}` action is to allow the `issuer` account to rate a blockproducer into five categories: Community, Development, Infraestructure, Transparency, Trustiness. Additionally, users could add a description to their rating.
---)";

const char* erase_ricardian = R"(---
Expand Down Expand Up @@ -45,13 +45,13 @@ summary: The intent of the `{{ migratestats }}` action is to remove from stats t
const char* logcomment_ricardian = R"(---
spec_version: 0.1.0
title: Add additional information about block producer
summary: The intent of the `{{ logcomment }}` action is to add additional information and optinions of users about block producers.
summary: The intent of the `{{ logcomment }}` action is to add additional information and optinions.
---)";

const char* loglike_ricardian = R"(---
spec_version: 0.1.0
title: Add additional feedback about comment
summary: The intent of the `{{ loglike }}` action is to add feedback of users comment about block producers.
summary: The intent of the `{{ loglike }}` action is to add feedback of users comment about ratings.
---)";

// CLAUSES
Expand Down
29 changes: 20 additions & 9 deletions contracts/rateproducer/src/rateproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ namespace eoscostarica {
int8_t infrastructure,
int8_t trustiness,
int8_t community,
int8_t development) {
int8_t development,
std::string comment) {
require_auth(user);
name scope = is_eden(user) ? eden_scope : _self;
rate_aux(scope, user, bp, transparency, infrastructure, trustiness, community, development);
rate_aux(scope, user, bp, transparency, infrastructure, trustiness, community, development, comment);
}

void rateproducer::rate_aux(
Expand All @@ -22,7 +23,8 @@ namespace eoscostarica {
int8_t infrastructure,
int8_t trustiness,
int8_t community,
int8_t development) {
int8_t development,
std::string comment) {
check( (transparency + infrastructure + trustiness + community + development), "Error vote must have value for at least one category" );
check( (MINVAL <= transparency && transparency <= MAXVAL), "Error transparency value out of range" );
check( (MINVAL <= infrastructure && infrastructure <= MAXVAL), "Error infrastructure value out of range" );
Expand Down Expand Up @@ -50,8 +52,10 @@ namespace eoscostarica {
auto existing_rating = uniq_rating_index.find(uniq_rating);

if( existing_rating == uniq_rating_index.end() ) {
uint64_t rating_id = _ratings.available_primary_key();

_ratings.emplace(user, [&]( auto& row ) {
row.id = _ratings.available_primary_key();
row.id = rating_id;
row.user = user;
row.bp = bp;
row.transparency = transparency;
Expand All @@ -69,6 +73,10 @@ namespace eoscostarica {
trustiness,
community,
development);

if(!comment.empty()) {
SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { rating_id, comment });
}

} else {
uniq_rating_index.modify(existing_rating, user, [&]( auto& row ) {
Expand Down Expand Up @@ -105,6 +113,10 @@ namespace eoscostarica {
&bp_development,
&bp_ratings_cntr,
&bp_average);

if(!comment.empty()) {
SEND_INLINE_ACTION(*this, logcomment, { {get_self(), name("active")} }, { existing_rating->id, comment });
}
}
}

Expand Down Expand Up @@ -573,15 +585,14 @@ namespace eoscostarica {
cfg.set(c, c.owner);
}

void rateproducer::logcomment(name user, name bp, std::string comment) {
require_auth(user);
check( is_blockproducer(bp), "comments are allowed only for registered block producers" );
void rateproducer::logcomment(uint64_t rating_id, std::string comment) {
require_auth(_self);
check( comment.length() <= 500, "comment must be less or equal than 500 characters" );
}

void rateproducer::loglike(std::string transaction, name user, bool like) {
void rateproducer::loglike(uint64_t rating_id, name user, bool like) {
require_auth(user);
check( transaction.length() == 64, "transaction length is incorrect" );
check( rating_id >= 0, "Wrong rating id" );
}
} // namespace eoscostarica

Expand Down
32 changes: 24 additions & 8 deletions hapi/src/services/comment.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,28 @@ const save = async payload => {
return data.insert_comment_one
}

const updateUserRating = async payload => {
const mutation = `
mutation ($bp: String!, $user: String!, $id_bc_rating: Int!) {
update_user_ratings(where: {bp: {_eq: $bp}, user: {_eq: $user}}, _set: {id_bc_rating: $id_bc_rating}) {
affected_rows
}
}
`

const data = await hasuraUtil.instance.request(mutation, { ...payload })

return data.update_user_ratings
}

const update = async payload => {
const mutation = `
mutation ( $transaction: String!, $total_like: Int!, $total_dislike: Int!) {
update_comment_by_pk(pk_columns: {transaction: $transaction}, _set: {total_like: $total_like, total_dislike: $total_dislike}) {
total_like
total_dislike
mutation ( $rating_id: Int!, $total_like: Int!, $total_dislike: Int!) {
update_comment(where: {rating_id: {_eq: $rating_id}}, _set: {total_like: $total_like, total_dislike: $total_dislike}) {
returning {
total_like
total_dislike
}
}
}
`
Expand All @@ -30,18 +46,18 @@ const update = async payload => {
const updatelike = async payload => {
const total_like = await countLikes({
like: { _eq: true },
comment_transaction: { _eq: payload.comment_transaction }
rating_id: { _eq: payload.rating_id }
})
const total_dislike = await countLikes({
like: { _eq: false },
comment_transaction: { _eq: payload.comment_transaction }
rating_id: { _eq: payload.rating_id }
})

await update({
transaction: payload.comment_transaction,
rating_id: payload.rating_id,
total_like: total_like.aggregate.count,
total_dislike: total_dislike.aggregate.count
})
}

module.exports = { save, updatelike }
module.exports = { save, updatelike, updateUserRating }
Loading

0 comments on commit 7cd9717

Please sign in to comment.