-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the block_publisher class (#4178)
* Add the block_publisher class * Move the block publishing to the block_publisher class * Remove unnecessary header
- Loading branch information
Showing
6 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <nano/node/active_transactions.hpp> | ||
#include <nano/node/block_publisher.hpp> | ||
#include <nano/node/blockprocessor.hpp> | ||
|
||
nano::block_publisher::block_publisher (nano::active_transactions & active) : | ||
active{ active } | ||
{ | ||
} | ||
|
||
void nano::block_publisher::connect (nano::block_processor & block_processor) | ||
{ | ||
block_processor.processed.add ([this] (auto const & result, auto const & block) { | ||
switch (result.code) | ||
{ | ||
case nano::process_result::fork: | ||
observe (block); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
void nano::block_publisher::observe (std::shared_ptr<nano::block> block) | ||
{ | ||
active.publish (block); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace nano | ||
{ | ||
class active_transactions; | ||
class block_processor; | ||
class block; | ||
|
||
// This class tracks processed blocks to be published. | ||
class block_publisher | ||
{ | ||
public: | ||
block_publisher (nano::active_transactions & active); | ||
void connect (nano::block_processor & block_processor); | ||
|
||
private: | ||
// Block_processor observer | ||
void observe (std::shared_ptr<nano::block> block); | ||
|
||
nano::active_transactions & active; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters