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 17 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
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ 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

- wget https://github.com/google/leveldb/archive/v1.20.tar.gz
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
- tar xvf v1.20.tar.gz
- rm -f v1.20.tar.gz
- cd leveldb-1.20
- make
- sudo cp -r out-static/lib* out-shared/lib* "/usr/local/lib"
- cd include
- sudo cp -r leveldb /usr/local/include
- sudo ldconfig
- git clone https://github.com/google/snappy.git
- cd snappy
- mkdir build
- cd build && cmake ../
- sudo make install
- cd /home/travis/build/bitshares/bitshares-core
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()

option(LOAD_QUERY_TXID_PLUGIN "Build with query_txid plugin." ON)
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
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 "" )
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ RUN \
fish \
&& \
apt-get clean && \
wget https://github.com/google/leveldb/archive/v1.20.tar.gz && \
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
tar xvf v1.20.tar.gz && \
rm -f v1.20.tar.gz && \
cd leveldb-1.20 && \
make && \
sudo cp -r out-static/lib* out-shared/lib* "/usr/local/lib" && \
cd include && \
sudo cp -r leveldb /usr/local/include && \
sudo ldconfig && \
git clone https://github.com/google/snappy.git && \
cd snappy && \
mkdir build && \
cd build && cmake ../ && \
sudo make install && \
cd /bitshares-core && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD . /bitshares-core
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
31 changes: 29 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<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 +1893,28 @@ 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
{
#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);
auto trx_entry = *itor;
Copy link
Contributor

Choose a reason for hiding this comment

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

*itor is undefined if itor == txid_index.end()

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) {
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
}

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
6 changes: 5 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,9 @@
#include <fc/variant_object.hpp>

#include <fc/network/ip.hpp>

#ifdef QUERY_TXID_PLUGIN_ABLE
#include <graphene/query_txid/transaction_entry_object.hpp>
#endif
#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
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()
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/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
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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>
#include <boost/multi_index/composite_key.hpp>

namespace graphene { namespace chain {

struct query_trx_info : public graphene::protocol::processed_transaction
{
query_trx_info( const signed_transaction& trx = signed_transaction())
: processed_transaction(trx){}

virtual ~query_trx_info() = default;

uint64_t query_txid_block_number = 0;
uint64_t query_txid_trx_in_block = 0;
};
#ifndef QUERY_TXID_SPACE_ID
#define QUERY_TXID_SPACE_ID 8
#endif
enum query_txid_object_type
{
transaction_position_object_type = 0
};
class trx_entry_object : public abstract_object<trx_entry_object>
{
public:
static const uint8_t space_id = QUERY_TXID_SPACE_ID;
static const uint8_t type_id = transaction_position_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))
FC_REFLECT_DERIVED( graphene::chain::query_trx_info, (graphene::protocol::processed_transaction),
(query_txid_block_number)(query_txid_trx_in_block))
Loading