Skip to content

Commit 32ba6bb

Browse files
committed
Add the query_txid_plugin as a option on the develop branch
1 parent a16942d commit 32ba6bb

File tree

5 files changed

+76
-25
lines changed

5 files changed

+76
-25
lines changed

libraries/chain/include/graphene/chain/transaction_entry_object.hpp

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
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
#pragma once
225
#include <graphene/db/object.hpp>
3-
//#include <graphene/chain/protocol/types.hpp>
4-
//#include <graphene/db/object.hpp>
526
#include <graphene/protocol/types.hpp>
627
#include <boost/multi_index/composite_key.hpp>
728

@@ -20,7 +41,6 @@ namespace graphene { namespace chain {
2041
uint32_t trx_in_block;
2142
};
2243

23-
// struct by_id;
2444
struct by_txid;
2545
struct by_blocknum;
2646

@@ -39,4 +59,4 @@ namespace graphene { namespace chain {
3959
} } // graphene::chain
4060

4161
FC_REFLECT_DERIVED( graphene::chain::trx_entry_object, (graphene::chain::object),
42-
(txid)(block_num)(trx_in_block))
62+
(txid)(block_num)(trx_in_block))

libraries/plugins/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ add_subdirectory( es_objects )
1010
add_subdirectory( api_helper_indexes )
1111
if(${LOAD_QUERY_TXID_PLUGIN} STREQUAL "ON")
1212
add_subdirectory( query_txid )
13-
endif()
13+
endif()

libraries/plugins/query_txid/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ if(LevelDB_INCLUDE_PATH AND LevelDB_LIBRARY AND Snappy_LIBRARY)
2121
else(LevelDB_INCLUDE_PATH AND LevelDB_LIBRARY AND Snappy_LIBRARY)
2222
message(FATAL_ERROR "You need leveldb and snappy")
2323
endif()
24-

libraries/plugins/query_txid/include/graphene/query_txid/query_txid_plugin.hpp

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
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
#pragma once
225
#include <graphene/app/plugin.hpp>
326
#include <graphene/chain/transaction_entry_object.hpp>
427
#include <graphene/chain/database.hpp>
5-
6-
728
namespace graphene
829
{
930
namespace query_txid
1031
{
11-
1232
using namespace chain;
1333
namespace detail
1434
{
@@ -35,5 +55,4 @@ class query_txid_plugin : public graphene::app::plugin
3555

3656
std::unique_ptr<detail::query_txid_plugin_impl> my;
3757
};
38-
} // namespace query_txid
39-
} // namespace graphene
58+
} }// graphene::query_txid

libraries/plugins/query_txid/query_txid_plugin.cpp

+27-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
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
};
4972
leveldb::DB *query_txid_plugin_impl::leveldb = nullptr;
5073

5174
void 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-
156173
query_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

Comments
 (0)