Skip to content

Commit

Permalink
Merge pull request #370 from hypha-dao/feature/remove_dtx_action
Browse files Browse the repository at this point in the history
add removedtx action
  • Loading branch information
n13 authored Mar 25, 2024
2 parents 085f27b + 24e5e1d commit b9242f0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
5 changes: 3 additions & 2 deletions include/dao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ namespace pricing {
ACTION reset(); // debugging - maybe with the dev flags

ACTION executenext(); // execute stored deferred actions
ACTION removedtx(); // delete stalled deferred action

// Actions for testing deferred transactions - only for unit tests
ACTION addtest(eosio::time_point_sec execute_time, uint64_t number, std::string text);
ACTION testdtrx(uint64_t number, std::string text);
// ACTION addtest(eosio::time_point_sec execute_time, uint64_t number, std::string text);
// ACTION testdtrx(uint64_t number, std::string text);

#ifdef DEVELOP_BUILD_HELPERS

Expand Down
65 changes: 42 additions & 23 deletions src/dao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3539,13 +3539,33 @@ void dao::executenext() {
act.data = itr->data;

act.send();

idx.erase(itr);
}
else {
eosio::check(false, "No deferred actions to execute at this time.");
}
}

// pick the next executable action, and delete it
// This is to be used when the scheduler is stalled due to transactions failing.
void dao::removedtx() {
// there should be a special permission for a serivce account set up to call this
// permission: scheduler
require_auth(get_self());

deferred_actions_tables deftrx(get_self(), get_self().value);
auto idx = deftrx.get_index<"bytime"_n>();
auto itr = idx.begin();
if (itr != idx.end() && itr->execute_time <= eosio::current_time_point()) {
idx.erase(itr);
}
else {
eosio::check(false, "No deferred actions to execute at this time.");
}
}


// Add a new deferred transaction
void dao::schedule_deferred_action(eosio::time_point_sec execute_time, eosio::action action) {

Expand All @@ -3561,36 +3581,35 @@ void dao::schedule_deferred_action(eosio::time_point_sec execute_time, eosio::ac
});
}


// Test methods for deferred transactions - delete
void dao::addtest(eosio::time_point_sec execute_time, uint64_t number, std::string text) {
require_auth(get_self());
// void dao::addtest(eosio::time_point_sec execute_time, uint64_t number, std::string text) {
// require_auth(get_self());

// 1 - Create an action object
eosio::action act(
eosio::permission_level(get_self(), eosio::name("active")),
get_self(),
eosio::name("testdtrx"),
std::make_tuple(number, text)
);
// // 1 - Create an action object
// eosio::action act(
// eosio::permission_level(get_self(), eosio::name("active")),
// get_self(),
// eosio::name("testdtrx"),
// std::make_tuple(number, text)
// );

/// 2 - Schedule the action
schedule_deferred_action(execute_time, act);
// /// 2 - Schedule the action
// schedule_deferred_action(execute_time, act);

}
// }

void dao::testdtrx(uint64_t number, std::string text) {
require_auth(get_self());
// void dao::testdtrx(uint64_t number, std::string text) {
// require_auth(get_self());

testdtrx_tables testdtrx(get_self(), get_self().value);
// testdtrx_tables testdtrx(get_self(), get_self().value);

// Add the new entry to the testdtrx table
testdtrx.emplace(get_self(), [&](auto& row) {
row.id = testdtrx.available_primary_key();
row.number = number;
row.text = text;
});
}
// // Add the new entry to the testdtrx table
// testdtrx.emplace(get_self(), [&](auto& row) {
// row.id = testdtrx.available_primary_key();
// row.number = number;
// row.text = text;
// });
// }



Expand Down

0 comments on commit b9242f0

Please sign in to comment.