Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the query_txid_plugin as a option on the develop branch #1957

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
475a90a
Add the query_txid_plugin as a option on the develop branch
lelecommit Aug 23, 2019
f28c61c
Add the query_txid_plugin as a option on the develop branch
lelecommit Aug 23, 2019
a16942d
Add the query_txid_plugin as a option on the develop branch
lelecommit Aug 23, 2019
32ba6bb
Add the query_txid_plugin as a option on the develop branch
lelecommit Aug 26, 2019
975a7be
modify the indentation size and delete the error file
lelecommit Aug 27, 2019
47e635e
delete the message
lelecommit Aug 28, 2019
40228db
modify bulid option and fix the warning about the signed and unsigned…
lelecommit Aug 30, 2019
b577812
modify the message
lelecommit Aug 30, 2019
33fa8ca
Merge branch 'develop' of https://github.com/bitshares/bitshares-core…
lelecommit Sep 2, 2019
35a77a8
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
79727a8
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
cd8729d
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
50d0d76
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
1d02766
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
cc17f4c
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
24ff177
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
a853490
open the plugin for docker and travis ,revise opinions
lelecommit Sep 5, 2019
c1dafec
change the docker and travis.yml
lelecommit Sep 6, 2019
3be7ee2
change the docker and travis.yml
lelecommit Sep 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ dist: xenial
sudo: true

install:
- sudo apt-get install --allow-unauthenticated libboost-thread-dev libboost-iostreams-dev libboost-date-time-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-chrono-dev libboost-test-dev libboost-context-dev libboost-regex-dev libboost-coroutine-dev cmake parallel

- sudo apt-get install --allow-unauthenticated libboost-thread-dev libboost-iostreams-dev libboost-date-time-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-chrono-dev libboost-test-dev libboost-context-dev libboost-regex-dev libboost-coroutine-dev libleveldb-dev libsnappy-dev cmake parallel
addons:
sonarcloud:
organization: "flwyiq7go36p6lipr64tbesy5jayad3q"
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ else()
set( CMAKE_CXX_EXTENSIONS OFF )
endif()

set(LOAD_QUERY_TXID_PLUGIN OFF CACHE BOOL "query_txid plugin is off normal state")
if(${LOAD_QUERY_TXID_PLUGIN} STREQUAL "ON")
add_definitions(-DQUERY_TXID_PLUGIN_ABLE)
set( QUERY_TXID graphene_query_txid)
endif()

# http://stackoverflow.com/a/18369825
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
Expand Down Expand Up @@ -322,4 +328,5 @@ endif(ENABLE_INSTALLER)

MESSAGE( STATUS "" )
MESSAGE( STATUS "PROFILER: ${USE_PROFILER}" )
MESSAGE( STATUS "LOAD_QUERY_TXID_PLUGIN: ${LOAD_QUERY_TXID_PLUGIN}")
MESSAGE( STATUS "" )
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ RUN \
libboost-coroutine-dev \
libtool \
doxygen \
libleveldb-dev \
libsnappy-dev \
ca-certificates \
fish \
&& \
Expand All @@ -47,6 +49,7 @@ RUN \
git submodule update --init --recursive && \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DLOAD_QUERY_TXID_PLUGIN=ON \
-DGRAPHENE_DISABLE_UNITY_BUILD=ON \
. && \
make witness_node cli_wallet get_dev_key && \
Expand Down
5 changes: 3 additions & 2 deletions libraries/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ add_library( graphene_app
# need to link graphene_debug_witness because plugins aren't sufficiently isolated #246
target_link_libraries( graphene_app
graphene_market_history graphene_account_history graphene_elasticsearch graphene_grouped_orders
graphene_api_helper_indexes
graphene_api_helper_indexes ${QUERY_TXID}
graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness )
target_include_directories( graphene_app
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" )
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../plugins/query_txid_object/include")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is superfluous. The library dependency above should make the plugin include files available to app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I get it. You need the include even when the plugin is disabled, because it declares the structure that is used in the return value of the API calls.

You can work around this by typedefing query_trx_info to some other known structure in that case (the API call should always throw an error, so the actual return type will not be used).


if(MSVC)
set_source_files_properties( application.cpp api.cpp database_api.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
Expand Down
45 changes: 42 additions & 3 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
#include <boost/range/iterator_range.hpp>

#include <cctype>

#ifdef QUERY_TXID_PLUGIN_ABLE
#include <graphene/query_txid/query_txid_plugin.hpp>
#endif
template class fc::api<graphene::app::database_api>;

namespace graphene { namespace app {
Expand Down Expand Up @@ -244,7 +246,6 @@ processed_transaction database_api::get_transaction( uint32_t block_num, uint32_
{
return my->get_transaction( block_num, trx_in_block );
}

optional<signed_transaction> database_api::get_recent_transaction_by_id( const transaction_id_type& id )const
{
try {
Expand Down Expand Up @@ -1877,7 +1878,10 @@ std::string database_api::get_transaction_hex(const signed_transaction& trx)cons
{
return my->get_transaction_hex( trx );
}

optional<query_trx_info> database_api::get_transaction_by_txid(transaction_id_type txid)const
{
return my->get_transaction_by_txid(txid);
}
std::string database_api_impl::get_transaction_hex(const signed_transaction& trx)const
{
return fc::to_hex(fc::raw::pack(trx));
Expand All @@ -1888,6 +1892,41 @@ std::string database_api::get_transaction_hex_without_sig(
{
return my->get_transaction_hex_without_sig(trx);
}
optional<query_trx_info> database_api_impl::get_transaction_by_txid(transaction_id_type txid)const
{
try{
#ifdef QUERY_TXID_PLUGIN_ABLE
auto &txid_index = _db.get_index_type<trx_entry_index>().indices().get<by_txid>();
auto itor = txid_index.find(txid);
if(itor != txid_index.end()){
auto trx_entry = *itor;
auto opt_block = _db.fetch_block_by_number(trx_entry.block_num);
FC_ASSERT(opt_block);
FC_ASSERT(opt_block->transactions.size() > trx_entry.trx_in_block);
optional<query_trx_info> res = opt_block->transactions[trx_entry.trx_in_block];
res->query_txid_block_number = trx_entry.block_num;
res->query_txid_trx_in_block = trx_entry.trx_in_block;
return res;
}
else{
std::string txid_str(txid);
auto result = query_txid::query_txid_plugin::query_trx_by_id(txid_str);
if(!result){
return{};
}
auto trx_entry = *result;
auto opt_block = _db.fetch_block_by_number(trx_entry.block_num);
FC_ASSERT(opt_block);
FC_ASSERT(opt_block->transactions.size() > trx_entry.trx_in_block);
optional<query_trx_info> res = opt_block->transactions[trx_entry.trx_in_block];
res->query_txid_block_number = trx_entry.block_num;
res->query_txid_trx_in_block = trx_entry.trx_in_block;
return res;
}
#endif
}
FC_CAPTURE_AND_RETHROW((txid));
}

std::string database_api_impl::get_transaction_hex_without_sig(
const signed_transaction &trx) const
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/database_api_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
map<uint32_t, optional<block_header>> get_block_header_batch(const vector<uint32_t> block_nums)const;
optional<signed_block> get_block(uint32_t block_num)const;
processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;

optional<query_trx_info> get_transaction_by_txid(transaction_id_type txid)const;
// Globals
chain_property_object get_chain_properties()const;
global_property_object get_global_properties()const;
Expand Down
4 changes: 4 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#include <fc/network/ip.hpp>

#include <graphene/query_txid_object/transaction_entry_object.hpp>

#include <boost/container/flat_set.hpp>

#include <functional>
Expand Down Expand Up @@ -177,6 +179,7 @@ class database_api
* @return the transaction at the given position
*/
processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;
optional<query_trx_info> get_transaction_by_txid(transaction_id_type txid)const;

/**
* If the transaction has not expired, this method will return the transaction for the given ID or
Expand Down Expand Up @@ -912,6 +915,7 @@ FC_API(graphene::app::database_api,
(get_block)
(get_transaction)
(get_recent_transaction_by_id)
(get_transaction_by_txid)

// Globals
(get_chain_properties)
Expand Down
4 changes: 4 additions & 0 deletions libraries/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ add_subdirectory( debug_witness )
add_subdirectory( snapshot )
add_subdirectory( es_objects )
add_subdirectory( api_helper_indexes )
add_subdirectory( query_txid_object )
if(${LOAD_QUERY_TXID_PLUGIN} STREQUAL "ON")
add_subdirectory( query_txid )
endif()
1 change: 1 addition & 0 deletions libraries/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ Folder | Name | Description
[market_history](market_history) | Market History | Save market history data | Market data | Stable | 5
[snapshot](snapshot) | Snapshot | Get a json of all objects in blockchain at a specificed time or block | Debug | Stable |
[witness](witness) | Witness | Generate and sign blocks | Block producer | Stable |
[query_txid](query_txid) | Query_txid | Get the transaction data by transaction id | Data | Experimental | 8
23 changes: 23 additions & 0 deletions libraries/plugins/query_txid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
file(GLOB HEADERS "include/graphene/query_txid/*.hpp")

add_library( graphene_query_txid
query_txid_plugin.cpp
)
find_path(LevelDB_INCLUDE_PATH NAMES leveldb/db.h leveldb/write_batch.h)
find_library(LevelDB_LIBRARY NAMES libleveldb.a)
find_library(Snappy_LIBRARY NAMES libsnappy.a)

if(LevelDB_INCLUDE_PATH AND LevelDB_LIBRARY AND Snappy_LIBRARY)
target_link_libraries( graphene_query_txid graphene_chain graphene_app ${LevelDB_LIBRARY} ${Snappy_LIBRARY} )
target_include_directories( graphene_query_txid
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ${LevelDB_INCLUDE_PATH})
install( TARGETS
graphene_query_txid

RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
else(LevelDB_INCLUDE_PATH AND LevelDB_LIBRARY AND Snappy_LIBRARY)
message(FATAL_ERROR "You need leveldb and snappy")
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2019 GXChain and zhaoxiangfei、bijianing97 .
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
#include <graphene/app/plugin.hpp>
#include <graphene/query_txid_object/transaction_entry_object.hpp>
#include <graphene/chain/database.hpp>
namespace graphene
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
{
namespace query_txid
{
using namespace chain;
namespace detail
{
class query_txid_plugin_impl;
}
class query_txid_plugin : public graphene::app::plugin
{
public:
query_txid_plugin();
virtual ~query_txid_plugin();

std::string plugin_name() const override;

virtual void plugin_set_program_options(
boost::program_options::options_description &cli,
boost::program_options::options_description &cfg) override;

virtual void plugin_initialize(const boost::program_options::variables_map &options) override;
virtual void plugin_startup() override;

static optional<trx_entry_object> query_trx_by_id(std::string txid);

friend class detail::query_txid_plugin_impl;

std::unique_ptr<detail::query_txid_plugin_impl> my;
};
} }// graphene::query_txid
Loading