Skip to content

Commit

Permalink
add admclear action for development
Browse files Browse the repository at this point in the history
  • Loading branch information
angelol committed Jan 31, 2019
1 parent 9df8cdd commit 908c216
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ followreq:

accept:
$(CLEOS) push action $(CONTRACT) accept '["angelosqueak", "alicesqueakr"]' -p angelosqueak

admclear:
$(CLEOS) push action $(CONTRACT) admclear '["angelosqueak"]' -p angelosqueak

show:
$(CLEOS) get table $(CONTRACT) $(CONTRACT) user
Expand Down
9 changes: 9 additions & 0 deletions contract/squeakr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ void squeakr::accessgrant(const name user, const name contract, const std::strin
check(followers_itr != followers_idx.end(), "You are not following this user, permission denied");
}

ACTION squeakr::admclear(const name sender) {
require_auth(_self);

erase_all(followers);
erase_all(requests);
erase_all(squeaks);
}

extern "C" {
[[noreturn]] void apply(uint64_t receiver, uint64_t code, uint64_t action) {
if (action == "accessgrant"_n.value && code == "priveosrules"_n.value) {
Expand All @@ -84,6 +92,7 @@ extern "C" {
(followreq)
(post)
(accept)
(admclear)
)
}
}
Expand Down
11 changes: 10 additions & 1 deletion contract/squeakr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ CONTRACT squeakr : public contract {
uint64_t id;
name follower;
name followee;
bool access_granted = false;

uint64_t primary_key()const { return id; }
uint64_t by_follower()const { return follower.value; }
Expand Down Expand Up @@ -76,12 +77,20 @@ CONTRACT squeakr : public contract {
ACTION followreq(const name follower, const name followee);
ACTION accept(const name followee, const name follower);
void accessgrant(const name user, const name contract, const std::string uuid, const eosio::public_key public_key);

ACTION admclear(const name sender);


private:
static uint128_t combine_ids(const uint64_t &x, const uint64_t &y) {
return (uint128_t{x} << 64) | y;
}

template<typename T>
static void erase_all(T& table) {
auto itr = table.begin();
while(itr != table.end()) {
itr = table.erase(itr);
}
}

};

0 comments on commit 908c216

Please sign in to comment.