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");
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");
29 std::string contract_name_str = options.at(
"s-chain-contract").as<std::string>();
32 std::vector<std::string> actions = options.at(
"s-chain-actions").as<std::vector<std::string>>();
33 my->action_names.clear();
44 ilog(
"sub_chain_plugin starting up, adding /v3/sub_chain/get_last_s_id");
47 {
"/v3/sub_chain/get_last_s_id", [
this](
string,
string body,
auto cb) {
50 cb(200, last_s_id.
str());
52 cb(500,
"{\"error\": \"internal_error\", \"details\": \"" + e.
to_detail_string() +
"\"}");
58 ilog(
"sub_chain_plugin shutting down");
63 return my->contract_name;
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));
87 for(
const auto& trx : transactions ){
88 s_leaves.emplace_back( trx.id() );
91 return merkle( move(s_leaves) );
105 auto s_id_data = s_id.
data();
113 std::memcpy(&s_block_number, s_id_data,
sizeof(
uint32_t));
131 auto data =
fc::raw::pack(std::make_pair(my->prev_s_id, curr_s_root));
135 ilog(
"Computed interim S-ID: ${curr_s_id}", (
"curr_s_id", curr_s_id));
138 uint32_t next_s_block_number = prev_s_block_number + 1;
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));
145 std::memcpy(curr_s_id.
data(), &next_s_block_number_reversed,
sizeof(
uint32_t));
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);
168 return relevant_transactions;
178 if (
action.
account == my->contract_name && std::find(my->action_names.begin(), my->action_names.end(),
action.
name) != my->action_names.end()){
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
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
static sha256 hash(const char *d, uint32_t dlen)
const char * data() const
const vector< transaction_receipt > & get_pending_trx_receipts() const
sysio::chain::account_name & get_contract_name() const
void plugin_initialize(const variables_map &options)
virtual void set_program_options(options_description &, options_description &cfg) override
virtual ~sub_chain_plugin()
bool is_relevant_s_root_transaction(const sysio::chain::transaction &trx)
sysio::chain::checksum256_type & get_prev_s_id() const
void update_prev_s_id(const sysio::chain::checksum256_type &new_s_id)
uint32_t extract_s_block_number(const sysio::chain::checksum256_type &s_id)
sysio::chain::checksum256_type compute_curr_s_id(const sysio::chain::checksum256_type &curr_s_root)
std::vector< sysio::chain::transaction > find_relevant_transactions(sysio::chain::controller &curr_chain)
sysio::chain::checksum256_type calculate_s_root(const std::vector< sysio::chain::transaction > &transactions)
#define FC_LOG_AND_RETHROW()
void pack(Stream &s, const std::deque< T > &value)
uint32_t endian_reverse_u32(uint32_t x)
sysio::chain::action_name action_name
digest_type merkle(vector< digest_type > ids)
Immutable except for fc::from_variant.