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
+ */
1
24
#include < graphene/query_txid/query_txid_plugin.hpp>
2
25
#include < fc/io/fstream.hpp>
3
26
#include < graphene/chain/transaction_entry_object.hpp>
@@ -34,7 +57,7 @@ class query_txid_plugin_impl
34
57
void init ();
35
58
static optional<trx_entry_object> query_trx_by_id (std::string txid);
36
59
std::string db_path = " trx_entry.db" ;
37
- uint64_t limit_batch = 1000 ; // limit of leveldb batch
60
+ uint64_t limit_batch = 1000 ;
38
61
39
62
private:
40
63
query_txid_plugin &_self;
@@ -43,20 +66,17 @@ class query_txid_plugin_impl
43
66
fc::signal<void (const uint64_t )> sig_remove;
44
67
45
68
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);
48
71
};
49
72
leveldb::DB *query_txid_plugin_impl::leveldb = nullptr ;
50
73
51
74
void query_txid_plugin_impl::init ()
52
75
{
53
76
try {
54
- // Create leveldb
55
77
leveldb::Options options;
56
78
options.create_if_missing = true ;
57
79
leveldb::Status s = leveldb::DB::Open (options, db_path, &leveldb);
58
-
59
- // Respond to the sig_db_write signale
60
80
sig_db_write.connect ([&]() { consume_block (); });
61
81
sig_remove.connect ([&](const uint64_t trx_entry_id) { remove_trx_index (trx_entry_id); });
62
82
}
@@ -136,7 +156,6 @@ void query_txid_plugin_impl::remove_trx_index(const uint64_t trx_entry_id)
136
156
try {
137
157
graphene::chain::database &db = database ();
138
158
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()));
140
159
for (auto itor = trx_idx.begin (); itor != trx_idx.end ();) {
141
160
auto backup_itr = itor;
142
161
++itor;
@@ -151,8 +170,6 @@ void query_txid_plugin_impl::remove_trx_index(const uint64_t trx_entry_id)
151
170
}
152
171
} // namespace detail
153
172
154
- // -----------------------------------query_txid_plugin --------------------------------------
155
-
156
173
query_txid_plugin::query_txid_plugin ()
157
174
: my(new detail::query_txid_plugin_impl(*this ))
158
175
{
@@ -179,9 +196,7 @@ void query_txid_plugin::plugin_initialize(const boost::program_options::variable
179
196
{
180
197
try {
181
198
ilog (" query_txid plugin initialized" );
182
- // Add the index of the trx_entry_index object table to the database
183
199
database ().add_index <primary_index<trx_entry_index>>();
184
- // Respond to the apply_block signal
185
200
database ().applied_block .connect ([&](const signed_block &b) { my->collect_txid_index (b); });
186
201
if (options.count (" query-txid-path" )) {
187
202
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
191
206
if (options.count (" limit-batch" )) {
192
207
my->limit_batch = options[" limit-batch" ].as <uint64_t >();
193
208
}
194
- // Initialize the plugin instance
195
209
my->init ();
196
210
}
197
211
FC_LOG_AND_RETHROW ()
@@ -206,5 +220,4 @@ optional<trx_entry_object> query_txid_plugin::query_trx_by_id(std::string txid)
206
220
return detail::query_txid_plugin_impl::query_trx_by_id (txid);
207
221
}
208
222
209
- } // namespace query_txid
210
- } // namespace graphene
223
+ } } // graphene::query_txid
0 commit comments