Skip to content

Commit

Permalink
fix for charge contract description after
Browse files Browse the repository at this point in the history
  • Loading branch information
anazarov79 committed Sep 26, 2019
2 parents 65c578a + f98eda2 commit e0977de
Show file tree
Hide file tree
Showing 13 changed files with 469 additions and 129 deletions.
160 changes: 55 additions & 105 deletions docs/ru-RU/golos.charge_contract.md

Large diffs are not rendered by default.

49 changes: 34 additions & 15 deletions golos.publication/golos.publication.abi
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,6 @@
}
]
},
{
"name": "createacc",
"base": "",
"fields": [
{
"name": "name",
"type": "name"
}
]
},
{
"name": "setlimit",
"base": "",
Expand Down Expand Up @@ -872,6 +862,34 @@
}
]
},
{
"name": "addpermlink",
"base": "",
"fields": [
{ "type": "mssgid", "name": "msg" },
{ "type": "mssgid", "name": "parent" },
{ "type": "uint16", "name": "level" },
{ "type": "uint32", "name": "childcount" }
]
},{
"name": "delpermlink",
"base": "",
"fields": [
{ "type": "mssgid", "name": "msg" }
]
},{
"name": "addpermlinks",
"base": "",
"fields": [
{ "type": "addpermlink[]", "name": "permlinks" }
]
},{
"name": "delpermlinks",
"base": "",
"fields": [
{ "type": "mssgid[]", "name": "permlinks" }
]
},
{
"name": "post_event",
"base": "",
Expand Down Expand Up @@ -964,10 +982,6 @@
"name": "closemssgs",
"type": "closemssgs"
},
{
"name": "createacc",
"type": "createacc"
},
{
"name": "setrules",
"type": "setrules"
Expand Down Expand Up @@ -1007,7 +1021,12 @@
{
"name": "setmaxpayout",
"type": "setmaxpayout"
}
},

{ "name": "addpermlink", "type": "addpermlink" },
{ "name": "delpermlink", "type": "delpermlink" },
{ "name": "addpermlinks", "type": "addpermlinks" },
{ "name": "delpermlinks", "type": "delpermlinks" }
],
"tables": [
{
Expand Down
71 changes: 70 additions & 1 deletion golos.publication/golos.publication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ extern "C" {
execute_action(&publication::set_max_payout);
if (NN(deletevotes) == action)
execute_action(&publication::deletevotes);

if (NN(addpermlink) == action)
execute_action(&publication::addpermlink);
if (NN(delpermlink) == action)
execute_action(&publication::delpermlink);
if (NN(addpermlinks) == action)
execute_action(&publication::addpermlinks);
if (NN(delpermlinks) == action)
execute_action(&publication::delpermlinks);
}
#undef NN
}
Expand Down Expand Up @@ -271,7 +280,7 @@ void publication::create_message(
item.cashout_time = cur_time + seconds(cashout_window_param.window).count();
});

permlink_table.emplace(message_id.author, [&]( auto &item) {
permlink_table.emplace(message_id.author, [&](auto& item) {
item.id = message_pk;
item.parentacc = parent_id.author;
item.parent_id = parent_pk;
Expand All @@ -281,6 +290,66 @@ void publication::create_message(
});
}

void publication::addpermlink(structures::mssgid msg, structures::mssgid parent, uint16_t level, uint32_t childcount) {
require_auth(_self);
uint64_t parent_pk = 0;
if (parent.author) {
eosio::check(parent.permlink.size() > 0, "Parent permlink must not be empty");
tables::permlink_table tbl(_self, parent.author.value);
auto idx = tbl.get_index<"byvalue"_n>();
auto itr = idx.find(parent.permlink);
eosio::check(itr != idx.end(), "Parent permlink doesn't exist");
eosio::check(itr->level + 1 == level, "Parent permlink level mismatch");
eosio::check(itr->childcount > 0, "Parent permlink should have children");
// Note: can try to also check (itr.childcount <= actual children), but it's hard due scope
parent_pk = itr->id;
} else {
eosio::check(msg.permlink.size() > 0, "Permlink must not be empty");
eosio::check(msg.permlink.size() < config::max_length, "Permlink must be less than 256 symbols");
eosio::check(validate_permlink(msg.permlink), "Permlink must only contain 0-9, a-z and _ symbols");
eosio::check(0 == level, "Root permlink must have 0 level");
eosio::check(parent.permlink.size() == 0, "Root permlink must have empty parent");
}
eosio::check(is_account(msg.author), "Author account must exist");

tables::permlink_table tbl(_self, msg.author.value);
auto idx = tbl.get_index<"byvalue"_n>();
auto itr = idx.find(msg.permlink);
eosio::check(itr == idx.end(), "Permlink already exists");

tbl.emplace(_self, [&](auto& pl) {
pl.id = tbl.available_primary_key();
pl.parentacc = parent.author;
pl.parent_id = parent_pk;
pl.value = msg.permlink;
pl.level = level;
pl.childcount = childcount;
});
}

void publication::delpermlink(structures::mssgid msg) {
require_auth(_self);
tables::permlink_table tbl(_self, msg.author.value);
auto idx = tbl.get_index<"byvalue"_n>();
auto itr = idx.find(msg.permlink);
eosio::check(itr != idx.end(), "Permlink doesn't exist");
idx.erase(itr);
}

void publication::addpermlinks(std::vector<structures::permlink_info> permlinks) {
eosio::check(permlinks.size() > 0, "`permlinks` must not be empty");
for (const auto& p: permlinks) {
addpermlink(p.msg, p.parent, p.level, p.childcount);
}
}

void publication::delpermlinks(std::vector<structures::mssgid> permlinks) {
eosio::check(permlinks.size() > 0, "`permlinks` must not be empty");
for (const auto& p: permlinks) {
delpermlink(p);
}
}

void publication::update_message(structures::mssgid message_id,
std::string headermssg, std::string bodymssg,
std::string languagemssg, std::vector<std::string> tags,
Expand Down
7 changes: 7 additions & 0 deletions golos.publication/golos.publication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class publication : public contract {
void calcrwrdwt(name account, int64_t mssg_id, int64_t post_charge);
void paymssgrwrd(structures::mssgid message_id);
void deletevotes(int64_t message_id, name author);

[[eosio::action]]
void addpermlink(structures::mssgid msg, structures::mssgid parent, uint16_t level, uint32_t childcount);
[[eosio::action]] void delpermlink(structures::mssgid msg);
[[eosio::action]] void addpermlinks(std::vector<structures::permlink_info> permlinks);
[[eosio::action]] void delpermlinks(std::vector<structures::mssgid> permlinks);

private:
const posting_state& params();
void set_vote(name voter, const structures::mssgid &message_id, int16_t weight);
Expand Down
7 changes: 7 additions & 0 deletions golos.publication/objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ struct permlink {
}
};

struct permlink_info {
mssgid msg;
mssgid parent;
uint16_t level;
uint32_t childcount;
};

struct delegate_voter {
delegate_voter() = default;

Expand Down
7 changes: 0 additions & 7 deletions golos.publication/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ struct limitsarg {

enum class payment_t: enum_t { TOKEN, VESTING };

struct forumprops {
forumprops() = default;

name social_contract = name();
};

#ifdef UNIT_TEST_ENV
}} // eosio::testing
FC_REFLECT(eosio::testing::limitedact, (chargenum)(restorernum)(cutoffval)(chargeprice))
FC_REFLECT(eosio::testing::limitsarg, (restorers)(limitedacts)(vestingprices)(minvestings))
FC_REFLECT(eosio::testing::forumprops, (social_contract))
#endif

1 change: 1 addition & 0 deletions golos.vesting/golos.vesting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ void vesting::undelegate(name from, name to, asset quantity) {

void vesting::create(symbol symbol, name notify_acc) {
require_auth(name(token::get_issuer(config::token_name, symbol.code())));
eosio::check(is_account(notify_acc), "notify_acc account does not exist");

vesting_table table_vesting(_self, _self.value);
auto vesting = table_vesting.find(symbol.code().raw());
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif(VERSION_OUTPUT STREQUAL "MATCH")
enable_testing()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/contracts.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/contracts.hpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test_permlinks.csv ${CMAKE_CURRENT_BINARY_DIR}/test_permlinks.csv COPYONLY)

include_directories(${CMAKE_BINARY_DIR})

Expand Down
18 changes: 18 additions & 0 deletions tests/golos.posting_test_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,24 @@ struct golos_posting_api: base_contract_api {
return closemssgs(_code);
}

action_result add_permlink(mssgid msg, mssgid parent, uint16_t level = 0, uint32_t childcount = 0) {
return push(N(addpermlink), _code, args()
("msg", msg)
("parent", parent)
("level", level)
("childcount", childcount)
);
}
action_result del_permlink(mssgid msg) {
return push(N(delpermlink), _code, args()("msg", msg));
}
action_result add_permlinks(std::vector<permlink_info> permlinks) {
return push(N(addpermlinks), _code, args()("permlinks", permlinks));
}
action_result del_permlinks(std::vector<mssgid> permlinks) {
return push(N(delpermlinks), _code, args()("permlinks", permlinks));
}


action_result init_default_params() {
auto vote_changes = get_str_vote_changes(max_vote_changes);
Expand Down
Loading

0 comments on commit e0977de

Please sign in to comment.