#include <sub_chain_plugin.hpp>
Definition at line 22 of file sub_chain_plugin.hpp.
◆ sub_chain_plugin()
sysio::sub_chain_plugin::sub_chain_plugin |
( |
| ) |
|
◆ ~sub_chain_plugin()
sysio::sub_chain_plugin::~sub_chain_plugin |
( |
| ) |
|
|
virtual |
◆ calculate_s_root()
Calculate the S-Root from a vector of relevant s-transactions.
S-Root Fields (according to doc)
- Previous Block S-ID
- Current Block S-Root
- Parameters
-
transactions | a vector of relevant s-transactions |
- Returns
- the merkle S-Root calculated from the orderd s-leaves
Definition at line 84 of file sub_chain_plugin.cpp.
84 {
85
86 vector<digest_type> s_leaves;
87 for( const auto& trx : transactions ){
88 s_leaves.emplace_back( trx.id() );
89 }
90
91 return merkle( move(s_leaves) );
92}
digest_type merkle(vector< digest_type > ids)
◆ compute_curr_s_id()
Compute the new S-ID from the previous S-ID and the current S-Root.
- Parameters
-
curr_s_root | the current S-Root |
- Returns
- the new S-ID
Definition at line 127 of file sub_chain_plugin.cpp.
127 {
128
129
130
131 auto data =
fc::raw::pack(std::make_pair(my->prev_s_id, curr_s_root));
132
134
135 ilog(
"Computed interim S-ID: ${curr_s_id}", (
"curr_s_id", curr_s_id));
136
138 uint32_t next_s_block_number = prev_s_block_number + 1;
139
140 ilog(
"Extracted prev_s_block_number from prev_s_id: ${prev_s_block_number}, next: ${next_s_block_number}",
141 ("prev_s_block_number", prev_s_block_number)("next_s_block_number", next_s_block_number));
142
143
145 std::memcpy(curr_s_id.data(), &next_s_block_number_reversed,
sizeof(
uint32_t));
146
147
148 return curr_s_id;
149}
static sha256 hash(const char *d, uint32_t dlen)
uint32_t extract_s_block_number(const sysio::chain::checksum256_type &s_id)
void pack(Stream &s, const std::deque< T > &value)
uint32_t endian_reverse_u32(uint32_t x)
fc::sha256 checksum256_type
◆ extract_s_block_number()
Extract the block number from an S-ID. Takes the 32 least-significant bits from the previous S-ID to get the previous S-Block number
- Parameters
-
s_id | the S-ID to extract the block number from |
- Returns
- the previous block number
Definition at line 100 of file sub_chain_plugin.cpp.
100 {
101
102
103
104
105 auto s_id_data = s_id.
data();
106
107
108
110
111
112
113 std::memcpy(&s_block_number, s_id_data,
sizeof(
uint32_t));
114
115
116
118}
const char * data() const
◆ find_relevant_transactions()
Find transactions that are relevant for the S-Root calculation.
- Parameters
-
chain | the active chain controller |
- Returns
- a vector of transactions deemed relevant
Definition at line 156 of file sub_chain_plugin.cpp.
156 {
157 std::vector<sysio::chain::transaction> relevant_transactions;
159 for (const auto& trx_receipt : pending_trx_receipts) {
160 if (std::holds_alternative<sysio::chain::packed_transaction>(trx_receipt.trx)) {
161 const auto& packed_trx = std::get<sysio::chain::packed_transaction>(trx_receipt.trx);
162 const auto& trx = packed_trx.get_transaction();
164 relevant_transactions.push_back(trx);
165 }
166 }
167 }
168 return relevant_transactions;
169}
const vector< transaction_receipt > & get_pending_trx_receipts() const
bool is_relevant_s_root_transaction(const sysio::chain::transaction &trx)
◆ get_contract_name()
account_name & sysio::sub_chain_plugin::get_contract_name |
( |
| ) |
const |
◆ get_prev_s_id()
◆ is_relevant_s_root_transaction()
Determine if a transaction is relevant to the S-Root process.
- Parameters
-
trx | the transaction to check |
- Returns
- true if relevant, false otherwise
Definition at line 176 of file sub_chain_plugin.cpp.
176 {
178 if (
action.account == my->contract_name && std::find(my->action_names.begin(), my->action_names.end(),
action.name) != my->action_names.end()){
179 return true;
180 }
181 }
182 return false;
183}
◆ plugin_initialize()
void sysio::sub_chain_plugin::plugin_initialize |
( |
const variables_map & | options | ) |
|
Definition at line 23 of file sub_chain_plugin.cpp.
23 {
24 try {
25 if (!options.count("s-chain-contract") || !options.count("s-chain-actions")) {
26 SYS_ASSERT(
false, plugin_config_exception,
"sub_chain_plugin requires both --s-chain-contract and --s-chain-actions to be set");
27 }
28 else {
29 std::string contract_name_str = options.at("s-chain-contract").as<std::string>();
31
32 std::vector<std::string> actions = options.at("s-chain-actions").as<std::vector<std::string>>();
33 my->action_names.clear();
36 }
37 }
38
39
40
42}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
#define FC_LOG_AND_RETHROW()
sysio::chain::action_name action_name
Immutable except for fc::from_variant.
◆ plugin_shutdown()
void sysio::sub_chain_plugin::plugin_shutdown |
( |
| ) |
|
◆ plugin_startup()
void sysio::sub_chain_plugin::plugin_startup |
( |
| ) |
|
Definition at line 43 of file sub_chain_plugin.cpp.
43 {
44 ilog(
"sub_chain_plugin starting up, adding /v3/sub_chain/get_last_s_id");
45
47 {
"/v3/sub_chain/get_last_s_id", [
this](
string,
string body,
auto cb) {
48 try {
50 cb(200, last_s_id.str());
52 cb(500,
"{\"error\": \"internal_error\", \"details\": \"" + e.
to_detail_string() +
"\"}");
53 }
54 }}
55 });
56}
abstract_plugin & get_plugin(const string &name) const
Used to generate a useful error report when an exception is thrown.
std::string to_detail_string(log_level ll=log_level::all) const
sysio::chain::checksum256_type & get_prev_s_id() const
◆ set_program_options()
void sysio::sub_chain_plugin::set_program_options |
( |
options_description & | , |
|
|
options_description & | cfg ) |
|
overridevirtual |
Implements appbase::abstract_plugin.
Definition at line 18 of file sub_chain_plugin.cpp.
18 {
19 cfg.add_options()
20 ("s-chain-contract", bpo::value<std::string>()->default_value("settle.wns"), "Contract name for identifying relevant S-transactions.")
21 ("s-chain-actions", bpo::value<std::vector<std::string>>()->composing(), "List of action names for relevant S-transactions for a given s-chain-contract");
22}
◆ update_prev_s_id()
Definition at line 68 of file sub_chain_plugin.cpp.
68 {
69 ilog(
"Updating OLD prev_s_id: \t${prev_s_id}", (
"prev_s_id", my->prev_s_id));
70 my->prev_s_id = new_s_id;
71 ilog(
"Updated NEW prev_s_id: \t${prev_s_id}", (
"prev_s_id", my->prev_s_id));
72}
The documentation for this class was generated from the following files: