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 5 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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ else()
set( CMAKE_CXX_EXTENSIONS OFF )
endif()

option(LOAD_QUERY_TXID_PLUGIN OFF)
if(${LOAD_QUERY_TXID_PLUGIN} STREQUAL "ON")
add_definitions(-DQUERY_TXID_PLUGIN_ABLE)
set( QUERY_TXID graphene_query_txid)
endif()
MESSAGE("the query_txid plugin is ${LOAD_QUERY_TXID_PLUGIN}")
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved

# http://stackoverflow.com/a/18369825
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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"
Expand Down
42 changes: 40 additions & 2 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +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>;

Expand Down Expand Up @@ -244,7 +247,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 +1879,10 @@ std::string database_api::get_transaction_hex(const signed_transaction& trx)cons
{
return my->get_transaction_hex( trx );
}

optional<processed_transaction> 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 +1893,39 @@ std::string database_api::get_transaction_hex_without_sig(
{
return my->get_transaction_hex_without_sig(trx);
}
optional<processed_transaction> database_api_impl::get_transaction_by_txid(transaction_id_type txid)const
{
#ifdef QUERY_TXID_PLUGIN_ABLE
Copy link
Contributor

Choose a reason for hiding this comment

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

If the plugin is not enabled the method doesn't return anything. IMO it should throw.

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()) {
std::string txid_str(txid);
auto result = query_txid::query_txid_plugin::query_trx_by_id(txid_str);
if (result) {
const 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<processed_transaction> res = opt_block->transactions[trx_entry.trx_in_block];
return res;
}
return {};
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
} else {
const auto &dpo = _db.get_dynamic_global_properties();
if (itor->block_num <= dpo.last_irreversible_block_num) {
const 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<processed_transaction> res = opt_block->transactions[trx_entry.trx_in_block];
return res;
} else {
return {};
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endif
return {};
}

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<processed_transaction> 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: 3 additions & 1 deletion libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <fc/variant_object.hpp>

#include <fc/network/ip.hpp>

#include <graphene/chain/transaction_entry_object.hpp>
#include <boost/container/flat_set.hpp>

#include <functional>
Expand Down Expand Up @@ -177,6 +177,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<processed_transaction> get_transaction_by_txid(transaction_id_type txid)const;
pmconrad marked this conversation as resolved.
Show resolved Hide resolved

/**
* If the transaction has not expired, this method will return the transaction for the given ID or
Expand Down Expand Up @@ -912,6 +913,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
* 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
#include <graphene/db/object.hpp>
#include <graphene/protocol/types.hpp>
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
#include <boost/multi_index/composite_key.hpp>

namespace graphene { namespace chain {

class trx_entry_object : public abstract_object<trx_entry_object>
{
public:
static const uint8_t space_id = implementation_ids;
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
static const uint8_t type_id = impl_trx_entry_history_object_type;

trx_entry_object(){}

transaction_id_type txid;
uint32_t block_num;
uint32_t trx_in_block;
};

struct by_txid;
struct by_blocknum;

typedef multi_index_container<
trx_entry_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_txid>, member< trx_entry_object, transaction_id_type, &trx_entry_object::txid > >,
ordered_non_unique< tag<by_blocknum>, member< trx_entry_object, uint32_t, &trx_entry_object::block_num > >
>

> trx_entry_multi_index_type;

typedef generic_index<trx_entry_object, trx_entry_multi_index_type> trx_entry_index;

} } // graphene::chain

FC_REFLECT_DERIVED( graphene::chain::trx_entry_object, (graphene::chain::object),
(txid)(block_num)(trx_in_block))
3 changes: 2 additions & 1 deletion libraries/chain/include/graphene/chain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ GRAPHENE_DEFINE_IDS(chain, implementation_ids, impl_,
(special_authority)
(buyback)
(fba_accumulator)
(collateral_bid))
(collateral_bid)
(trx_entry_history))
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions libraries/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ add_subdirectory( debug_witness )
add_subdirectory( snapshot )
add_subdirectory( es_objects )
add_subdirectory( api_helper_indexes )
if(${LOAD_QUERY_TXID_PLUGIN} STREQUAL "ON")
add_subdirectory( query_txid )
endif()
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/chain/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