1+ /*
2+ * Copyright (c) 2019 GXChain and zhaoxiangfei、bijianing97 .
3+ *
4+ * The MIT License
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
124#include < graphene/query_txid/query_txid_plugin.hpp>
225#include < fc/io/fstream.hpp>
326#include < graphene/chain/transaction_entry_object.hpp>
@@ -34,7 +57,7 @@ class query_txid_plugin_impl
3457 void init ();
3558 static optional<trx_entry_object> query_trx_by_id (std::string txid);
3659 std::string db_path = " trx_entry.db" ;
37- uint64_t limit_batch = 1000 ; // limit of leveldb batch
60+ uint64_t limit_batch = 1000 ;
3861
3962 private:
4063 query_txid_plugin &_self;
@@ -43,20 +66,17 @@ class query_txid_plugin_impl
4366 fc::signal<void (const uint64_t )> sig_remove;
4467
4568 static leveldb::DB *leveldb;
46- void consume_block (); // Consume block
47- void remove_trx_index (const uint64_t trx_entry_id); // Remove trx_index in db
69+ void consume_block ();
70+ void remove_trx_index (const uint64_t trx_entry_id);
4871};
4972leveldb::DB *query_txid_plugin_impl::leveldb = nullptr ;
5073
5174void query_txid_plugin_impl::init ()
5275{
5376 try {
54- // Create leveldb
5577 leveldb::Options options;
5678 options.create_if_missing = true ;
5779 leveldb::Status s = leveldb::DB::Open (options, db_path, &leveldb);
58-
59- // Respond to the sig_db_write signale
6080 sig_db_write.connect ([&]() { consume_block (); });
6181 sig_remove.connect ([&](const uint64_t trx_entry_id) { remove_trx_index (trx_entry_id); });
6282 }
@@ -136,7 +156,6 @@ void query_txid_plugin_impl::remove_trx_index(const uint64_t trx_entry_id)
136156 try {
137157 graphene::chain::database &db = database ();
138158 const auto &trx_idx = db.get_index_type <trx_entry_index>().indices ();
139- // ilog("remove,${trx_ent_id},bengin: ${begin},end: ${end}",("trx_ent_id",trx_entry_id)("begin",trx_idx.begin()->id.instance())("end",trx_idx.rbegin()->id.instance()));
140159 for (auto itor = trx_idx.begin (); itor != trx_idx.end ();) {
141160 auto backup_itr = itor;
142161 ++itor;
@@ -151,8 +170,6 @@ void query_txid_plugin_impl::remove_trx_index(const uint64_t trx_entry_id)
151170}
152171} // namespace detail
153172
154- // -----------------------------------query_txid_plugin --------------------------------------
155-
156173query_txid_plugin::query_txid_plugin ()
157174 : my(new detail::query_txid_plugin_impl(*this ))
158175{
@@ -179,9 +196,7 @@ void query_txid_plugin::plugin_initialize(const boost::program_options::variable
179196{
180197 try {
181198 ilog (" query_txid plugin initialized" );
182- // Add the index of the trx_entry_index object table to the database
183199 database ().add_index <primary_index<trx_entry_index>>();
184- // Respond to the apply_block signal
185200 database ().applied_block .connect ([&](const signed_block &b) { my->collect_txid_index (b); });
186201 if (options.count (" query-txid-path" )) {
187202 my->db_path = options[" query-txid-path" ].as <std::string>();
@@ -191,7 +206,6 @@ void query_txid_plugin::plugin_initialize(const boost::program_options::variable
191206 if (options.count (" limit-batch" )) {
192207 my->limit_batch = options[" limit-batch" ].as <uint64_t >();
193208 }
194- // Initialize the plugin instance
195209 my->init ();
196210 }
197211 FC_LOG_AND_RETHROW ()
@@ -206,5 +220,4 @@ optional<trx_entry_object> query_txid_plugin::query_trx_by_id(std::string txid)
206220 return detail::query_txid_plugin_impl::query_trx_by_id (txid);
207221}
208222
209- } // namespace query_txid
210- } // namespace graphene
223+ } } // graphene::query_txid
0 commit comments