diff --git a/include/bitcoin/node/chasers/chaser_candidate.hpp b/include/bitcoin/node/chasers/chaser_candidate.hpp index bd7c809f..3e857e49 100644 --- a/include/bitcoin/node/chasers/chaser_candidate.hpp +++ b/include/bitcoin/node/chasers/chaser_candidate.hpp @@ -29,7 +29,6 @@ namespace node { class full_node; /// Construct candidate blocks upon modification of the transaction DAG. -/// Notify subscribers with "candidate" event. class BCN_API chaser_candidate : public chaser, protected network::tracker { @@ -37,6 +36,10 @@ class BCN_API chaser_candidate typedef std::unique_ptr uptr; chaser_candidate(full_node& node) NOEXCEPT; + +private: + void handle_event(const code& ec, chase value) NOEXCEPT; + void do_handle_event(const code& ec, chase value) NOEXCEPT; }; } // namespace node diff --git a/include/bitcoin/node/chasers/chaser_check.hpp b/include/bitcoin/node/chasers/chaser_check.hpp index 5dfcfc89..ac39fa28 100644 --- a/include/bitcoin/node/chasers/chaser_check.hpp +++ b/include/bitcoin/node/chasers/chaser_check.hpp @@ -29,7 +29,6 @@ namespace node { class full_node; /// Chase down blocks for the candidate header chain. -/// Notify subscribers with "block checked" event. class BCN_API chaser_check : public chaser, protected network::tracker { diff --git a/include/bitcoin/node/chasers/chaser_confirm.hpp b/include/bitcoin/node/chasers/chaser_confirm.hpp index 6eb0d77c..42d95e87 100644 --- a/include/bitcoin/node/chasers/chaser_confirm.hpp +++ b/include/bitcoin/node/chasers/chaser_confirm.hpp @@ -29,7 +29,6 @@ namespace node { class full_node; /// Chase down valid blocks for confirmation. -/// Notify subscribers with "block confirmed" event. class BCN_API chaser_confirm : public chaser, protected network::tracker { @@ -37,6 +36,10 @@ class BCN_API chaser_confirm typedef std::unique_ptr uptr; chaser_confirm(full_node& node) NOEXCEPT; + +private: + void handle_event(const code& ec, chase value) NOEXCEPT; + void do_handle_event(const code& ec, chase value) NOEXCEPT; }; } // namespace node diff --git a/include/bitcoin/node/chasers/chaser_connect.hpp b/include/bitcoin/node/chasers/chaser_connect.hpp index 8b0dea8e..8297ad8e 100644 --- a/include/bitcoin/node/chasers/chaser_connect.hpp +++ b/include/bitcoin/node/chasers/chaser_connect.hpp @@ -29,7 +29,6 @@ namespace node { class full_node; /// Chase down blocks in the the candidate header chain for validation. -/// Notify subscribers with the "block connected" event. class BCN_API chaser_connect : public chaser, protected network::tracker { @@ -37,6 +36,10 @@ class BCN_API chaser_connect typedef std::unique_ptr uptr; chaser_connect(full_node& node) NOEXCEPT; + +private: + void handle_event(const code& ec, chase value) NOEXCEPT; + void do_handle_event(const code& ec, chase value) NOEXCEPT; }; } // namespace node diff --git a/include/bitcoin/node/chasers/chaser_header.hpp b/include/bitcoin/node/chasers/chaser_header.hpp index 39bb6236..27b58d41 100644 --- a/include/bitcoin/node/chasers/chaser_header.hpp +++ b/include/bitcoin/node/chasers/chaser_header.hpp @@ -29,7 +29,6 @@ namespace node { class full_node; /// Chase down stronger header branches for the candidate chain. -/// Notify subscribers with "strong header" event. class BCN_API chaser_header : public chaser, protected network::tracker { @@ -37,6 +36,10 @@ class BCN_API chaser_header typedef std::unique_ptr uptr; chaser_header(full_node& node) NOEXCEPT; + +private: + void handle_event(const code& ec, chase value) NOEXCEPT; + void do_handle_event(const code& ec, chase value) NOEXCEPT; }; } // namespace node diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index 20735ff1..31b49019 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -36,6 +36,10 @@ class BCN_API chaser_transaction typedef std::unique_ptr uptr; chaser_transaction(full_node& node) NOEXCEPT; + +private: + void handle_event(const code& ec, chase value) NOEXCEPT; + void do_handle_event(const code& ec, chase value) NOEXCEPT; }; } // namespace node diff --git a/src/chasers/chaser_candidate.cpp b/src/chasers/chaser_candidate.cpp index 589abe4d..bef2ea71 100644 --- a/src/chasers/chaser_candidate.cpp +++ b/src/chasers/chaser_candidate.cpp @@ -18,19 +18,51 @@ */ #include +#include #include +#include #include #include namespace libbitcoin { namespace node { +using namespace std::placeholders; + BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) chaser_candidate::chaser_candidate(full_node& node) NOEXCEPT : chaser(node), tracker(node.log) { + subscribe(std::bind(&chaser_candidate::handle_event, this, _1, _2)); +} + +void chaser_candidate::handle_event(const code& ec, chase value) NOEXCEPT +{ + boost::asio::post(strand(), + std::bind(&chaser_candidate::do_handle_event, this, ec, value)); +} + +void chaser_candidate::do_handle_event(const code& ec, chase value) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_candidate"); + + // The code should be error::service_stopped when error::stop is set. + if (ec) + return; + + switch (value) + { + case chase::start: + // TODO: initialize. + break; + case chase::transaction: + // TODO: handle transaction graph change (may issue 'candidate'). + break; + default: + return; + } } BC_POP_WARNING() diff --git a/src/chasers/chaser_confirm.cpp b/src/chasers/chaser_confirm.cpp index 7ab99e2a..fc543e46 100644 --- a/src/chasers/chaser_confirm.cpp +++ b/src/chasers/chaser_confirm.cpp @@ -18,19 +18,51 @@ */ #include +#include #include +#include #include #include namespace libbitcoin { namespace node { +using namespace std::placeholders; + BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) chaser_confirm::chaser_confirm(full_node& node) NOEXCEPT : chaser(node), tracker(node.log) { + subscribe(std::bind(&chaser_confirm::handle_event, this, _1, _2)); +} + +void chaser_confirm::handle_event(const code& ec, chase value) NOEXCEPT +{ + boost::asio::post(strand(), + std::bind(&chaser_confirm::do_handle_event, this, ec, value)); +} + +void chaser_confirm::do_handle_event(const code& ec, chase value) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_confirm"); + + // The code should be error::service_stopped when error::stop is set. + if (ec) + return; + + switch (value) + { + case chase::start: + // TODO: initialize. + break; + case chase::connected: + // TODO: handle new strong connected branch (may issue 'confirmed'). + break; + default: + return; + } } BC_POP_WARNING() diff --git a/src/chasers/chaser_connect.cpp b/src/chasers/chaser_connect.cpp index f850b1ec..c3d7c5e4 100644 --- a/src/chasers/chaser_connect.cpp +++ b/src/chasers/chaser_connect.cpp @@ -18,19 +18,51 @@ */ #include +#include #include +#include #include #include namespace libbitcoin { namespace node { +using namespace std::placeholders; + BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) chaser_connect::chaser_connect(full_node& node) NOEXCEPT : chaser(node), tracker(node.log) { + subscribe(std::bind(&chaser_connect::handle_event, this, _1, _2)); +} + +void chaser_connect::handle_event(const code& ec, chase value) NOEXCEPT +{ + boost::asio::post(strand(), + std::bind(&chaser_connect::do_handle_event, this, ec, value)); +} + +void chaser_connect::do_handle_event(const code& ec, chase value) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_connect"); + + // The code should be error::service_stopped when error::stop is set. + if (ec) + return; + + switch (value) + { + case chase::start: + // TODO: initialize. + break; + case chase::checked: + // TODO: handle the new checked blocks (may issue 'connected'). + break; + default: + return; + } } BC_POP_WARNING() diff --git a/src/chasers/chaser_header.cpp b/src/chasers/chaser_header.cpp index 4b898ef4..b02efe61 100644 --- a/src/chasers/chaser_header.cpp +++ b/src/chasers/chaser_header.cpp @@ -18,21 +18,52 @@ */ #include +#include #include +#include #include #include namespace libbitcoin { namespace node { +using namespace std::placeholders; + BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) chaser_header::chaser_header(full_node& node) NOEXCEPT : chaser(node), tracker(node.log) { + subscribe(std::bind(&chaser_header::handle_event, this, _1, _2)); +} + +void chaser_header::handle_event(const code& ec, chase value) NOEXCEPT +{ + boost::asio::post(strand(), + std::bind(&chaser_header::do_handle_event, this, ec, value)); +} + +void chaser_header::do_handle_event(const code& ec, chase value) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_header"); + + // The code should be error::service_stopped when error::stop is set. + if (ec) + return; + + switch (value) + { + case chase::start: + // TODO: initialize. + break; + default: + return; + } } +// TODO: handle new headers (may issue 'header'). + BC_POP_WARNING() } // namespace database diff --git a/src/chasers/chaser_transaction.cpp b/src/chasers/chaser_transaction.cpp index ed3d4328..8f6c2de7 100644 --- a/src/chasers/chaser_transaction.cpp +++ b/src/chasers/chaser_transaction.cpp @@ -18,21 +18,55 @@ */ #include +#include #include +#include #include #include namespace libbitcoin { namespace node { +using namespace std::placeholders; + BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) chaser_transaction::chaser_transaction(full_node& node) NOEXCEPT : chaser(node), tracker(node.log) { + subscribe(std::bind(&chaser_transaction::handle_event, this, _1, _2)); +} + +void chaser_transaction::handle_event(const code& ec, chase value) NOEXCEPT +{ + boost::asio::post(strand(), + std::bind(&chaser_transaction::do_handle_event, this, ec, value)); +} + +void chaser_transaction::do_handle_event(const code& ec, chase value) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_transaction"); + + // The code should be error::service_stopped when error::stop is set. + if (ec) + return; + + switch (value) + { + case chase::start: + // TODO: initialize. + break; + case chase::confirmed: + // TODO: handle the new confirmed blocks (may issue 'transaction'). + break; + default: + return; + } } +// TODO: handle the new unconfirmed transactions (may issue 'transaction'). + BC_POP_WARNING() } // namespace database