diff --git a/contract/Makefile b/contract/Makefile index 17e1a85..c655207 100644 --- a/contract/Makefile +++ b/contract/Makefile @@ -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 diff --git a/contract/squeakr.cpp b/contract/squeakr.cpp index a90ed4e..25e3018 100644 --- a/contract/squeakr.cpp +++ b/contract/squeakr.cpp @@ -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) { @@ -84,6 +92,7 @@ extern "C" { (followreq) (post) (accept) + (admclear) ) } } diff --git a/contract/squeakr.hpp b/contract/squeakr.hpp index 50c7629..6ac9ded 100644 --- a/contract/squeakr.hpp +++ b/contract/squeakr.hpp @@ -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; } @@ -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 + static void erase_all(T& table) { + auto itr = table.begin(); + while(itr != table.end()) { + itr = table.erase(itr); + } + } }; \ No newline at end of file