Added bitcoin_transaction_create_operation, evaluator; filled sidechain_net_manager::send_btc_tx
This commit is contained in:
parent
7a6fca9180
commit
0bb271a455
22 changed files with 272 additions and 50 deletions
|
|
@ -538,7 +538,9 @@ namespace detail {
|
|||
// you can help the network code out by throwing a block_older_than_undo_history exception.
|
||||
// when the net code sees that, it will stop trying to push blocks from that chain, but
|
||||
// leave that peer connected so that they can get sync blocks from us
|
||||
bool result = _chain_db->push_block(blk_msg.block, (_is_block_producer | _force_validate) ? database::skip_nothing : database::skip_transaction_signatures);
|
||||
auto skip_nothing_mode = sync_mode ? database::skip_nothing | database::skip_btc_tx_sending : database::skip_nothing;
|
||||
auto skip_transaction_signatures_mode = sync_mode ? database::skip_transaction_signatures | database::skip_btc_tx_sending : database::skip_transaction_signatures;
|
||||
bool result = _chain_db->push_block(blk_msg.block, (_is_block_producer | _force_validate) ? skip_nothing_mode : skip_transaction_signatures_mode);
|
||||
|
||||
// the block was accepted, so we now know all of the transactions contained in the block
|
||||
if (!sync_mode)
|
||||
|
|
|
|||
|
|
@ -290,6 +290,10 @@ struct get_impacted_account_visitor
|
|||
{
|
||||
_impacted.insert( op.payer );
|
||||
}
|
||||
void operator()( const bitcoin_transaction_send_operation& op )
|
||||
{
|
||||
_impacted.insert( op.payer );
|
||||
}
|
||||
};
|
||||
|
||||
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ add_library( graphene_chain
|
|||
special_authority.cpp
|
||||
buyback.cpp
|
||||
bitcoin_address_evaluator.cpp
|
||||
bitcoin_transaction_evaluator.cpp
|
||||
|
||||
account_object.cpp
|
||||
asset_object.cpp
|
||||
|
|
|
|||
49
libraries/chain/bitcoin_transaction_evaluator.cpp
Normal file
49
libraries/chain/bitcoin_transaction_evaluator.cpp
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#include <graphene/chain/bitcoin_transaction_evaluator.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/exceptions.hpp>
|
||||
#include <graphene/chain/bitcoin_transaction_object.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
void_result bitcoin_transaction_send_evaluator::do_evaluate( const bitcoin_transaction_send_operation& op )
|
||||
{
|
||||
// FC_ASSERT( db().get_sidechain_account_id() == op.payer );
|
||||
return void_result();
|
||||
}
|
||||
|
||||
object_id_type bitcoin_transaction_send_evaluator::do_apply( const bitcoin_transaction_send_operation& op )
|
||||
{
|
||||
database& d = db();
|
||||
sidechain::prev_out new_pw_vout = { "", 0, 0 };
|
||||
sidechain::bytes wit_script;
|
||||
|
||||
const bitcoin_transaction_object& btc_tx = d.create< bitcoin_transaction_object >( [&]( bitcoin_transaction_object& obj )
|
||||
{
|
||||
obj.pw_vin = op.pw_vin;
|
||||
obj.vins = op.vins;
|
||||
obj.vouts = op.vouts;
|
||||
obj.transaction = op.transaction;
|
||||
obj.transaction_id = op.transaction.get_txid();
|
||||
obj.fee_for_size = op.fee_for_size;
|
||||
obj.confirm = false;
|
||||
});
|
||||
|
||||
if( btc_tx.transaction.vout[0].is_p2wsh() && btc_tx.transaction.vout[0].scriptPubKey == wit_script )
|
||||
new_pw_vout = { btc_tx.transaction.get_txid(), 0, btc_tx.transaction.vout[0].value };
|
||||
|
||||
d.pw_vout_manager.create_new_vout( new_pw_vout );
|
||||
send_bitcoin_transaction( btc_tx );
|
||||
|
||||
return btc_tx.id;
|
||||
}
|
||||
|
||||
void bitcoin_transaction_send_evaluator::send_bitcoin_transaction( const bitcoin_transaction_object& btc_tx )
|
||||
{
|
||||
database& d = db();
|
||||
uint32_t skip = d.get_node_properties().skip_flags;
|
||||
if( !(skip & graphene::chain::database::skip_btc_tx_sending) ){
|
||||
d.send_btc_tx( btc_tx.transaction );
|
||||
}
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
@ -53,6 +53,7 @@
|
|||
#include <graphene/chain/bitcoin_address_object.hpp>
|
||||
#include <graphene/chain/primary_wallet_vout_object.hpp>
|
||||
#include <graphene/chain/sidechain_proposal_object.hpp>
|
||||
#include <graphene/chain/bitcoin_transaction_object.hpp>
|
||||
|
||||
|
||||
#include <graphene/chain/sport_object.hpp>
|
||||
|
|
@ -82,6 +83,7 @@
|
|||
#include <graphene/chain/tournament_evaluator.hpp>
|
||||
#include <graphene/chain/withdraw_pbtc_evaluator.hpp>
|
||||
#include <graphene/chain/bitcoin_address_evaluator.hpp>
|
||||
#include <graphene/chain/bitcoin_transaction_evaluator.hpp>
|
||||
|
||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||
|
||||
|
|
@ -246,6 +248,7 @@ void database::initialize_evaluators()
|
|||
register_evaluator<tournament_leave_evaluator>();
|
||||
register_evaluator<withdraw_pbtc_evaluator>();
|
||||
register_evaluator<bitcoin_address_create_evaluator>();
|
||||
register_evaluator<bitcoin_transaction_send_evaluator>();
|
||||
}
|
||||
|
||||
void database::initialize_indexes()
|
||||
|
|
@ -315,6 +318,7 @@ void database::initialize_indexes()
|
|||
add_index< primary_index<bitcoin_address_index > >();
|
||||
add_index< primary_index<primary_wallet_vout_index > >();
|
||||
add_index< primary_index<sidechain_proposal_index > >();
|
||||
add_index< primary_index<bitcoin_transaction_index > >();
|
||||
}
|
||||
|
||||
void database::init_genesis(const genesis_state_type& genesis_state)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
namespace graphene { namespace chain {
|
||||
|
||||
database::database() :
|
||||
i_w_info(*this), _random_number_generator(fc::ripemd160().data())
|
||||
i_w_info(*this), pw_vout_manager(*this), _random_number_generator(fc::ripemd160().data())
|
||||
{
|
||||
initialize_indexes();
|
||||
initialize_evaluators();
|
||||
|
|
|
|||
|
|
@ -277,6 +277,10 @@ struct get_impacted_account_visitor
|
|||
{
|
||||
_impacted.insert( op.payer );
|
||||
}
|
||||
void operator()( const bitcoin_transaction_send_operation& op )
|
||||
{
|
||||
_impacted.insert( op.payer );
|
||||
}
|
||||
};
|
||||
|
||||
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <graphene/chain/evaluator.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
class bitcoin_transaction_send_evaluator : public evaluator<bitcoin_transaction_send_evaluator>
|
||||
{
|
||||
public:
|
||||
typedef bitcoin_transaction_send_operation operation_type;
|
||||
|
||||
void_result do_evaluate( const bitcoin_transaction_send_operation& op );
|
||||
|
||||
object_id_type do_apply( const bitcoin_transaction_send_operation& op );
|
||||
|
||||
void send_bitcoin_transaction( const bitcoin_transaction_object& btc_tx );
|
||||
};
|
||||
|
||||
} } // graphene::chain
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <graphene/db/generic_index.hpp>
|
||||
#include <graphene/chain/protocol/types.hpp>
|
||||
#include <sidechain/bitcoin_transaction.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
class bitcoin_transaction_object : public abstract_object<bitcoin_transaction_object>
|
||||
{
|
||||
public:
|
||||
static const uint8_t space_id = protocol_ids;
|
||||
static const uint8_t type_id = bitcoin_transaction_object_type;
|
||||
|
||||
bitcoin_transaction_id_type get_id()const { return id; }
|
||||
|
||||
fc::sha256 pw_vin;
|
||||
|
||||
std::vector< fc::sha256 > vins;
|
||||
std::vector< info_for_vout_id_type > vouts;
|
||||
|
||||
sidechain::bitcoin_transaction transaction;
|
||||
std::string transaction_id;
|
||||
|
||||
uint64_t fee_for_size;
|
||||
|
||||
bool confirm = false;
|
||||
};
|
||||
|
||||
struct by_transaction_id;
|
||||
|
||||
typedef boost::multi_index_container<
|
||||
bitcoin_transaction_object,
|
||||
indexed_by<
|
||||
ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > >,
|
||||
ordered_unique< tag< by_transaction_id >, member< bitcoin_transaction_object, string, &bitcoin_transaction_object::transaction_id > >
|
||||
>
|
||||
> bitcoin_transaction_multi_index_container;
|
||||
typedef generic_index<bitcoin_transaction_object, bitcoin_transaction_multi_index_container> bitcoin_transaction_index;
|
||||
|
||||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::bitcoin_transaction_object, (graphene::chain::object), (pw_vin)(vins)(vouts)(transaction)(transaction_id)(fee_for_size)(confirm) )
|
||||
|
|
@ -39,7 +39,9 @@
|
|||
#include <fc/crypto/hash_ctr_rng.hpp>
|
||||
|
||||
#include <graphene/chain/protocol/protocol.hpp>
|
||||
|
||||
#include <sidechain/input_withdrawal_info.hpp>
|
||||
#include <sidechain/primary_wallet_vout_manager.hpp>
|
||||
|
||||
#include <fc/log/logger.hpp>
|
||||
|
||||
|
|
@ -79,7 +81,8 @@ namespace graphene { namespace chain {
|
|||
skip_assert_evaluation = 1 << 8, ///< used while reindexing
|
||||
skip_undo_history_check = 1 << 9, ///< used while reindexing
|
||||
skip_witness_schedule_check = 1 << 10, ///< used while reindexing
|
||||
skip_validate = 1 << 11 ///< used prior to checkpoint, skips validate() call on transaction
|
||||
skip_validate = 1 << 11, ///< used prior to checkpoint, skips validate() call on transaction
|
||||
skip_btc_tx_sending = 1 << 12
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -509,6 +512,9 @@ namespace graphene { namespace chain {
|
|||
public:
|
||||
|
||||
sidechain::input_withdrawal_info i_w_info;
|
||||
sidechain::primary_wallet_vout_manager pw_vout_manager;
|
||||
|
||||
fc::signal<void( const sidechain::bitcoin_transaction& )> send_btc_tx;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
#include <graphene/chain/protocol/base.hpp>
|
||||
#include <sidechain/bitcoin_transaction.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
struct bitcoin_transaction_send_operation : public base_operation
|
||||
{
|
||||
struct fee_parameters_type {
|
||||
uint64_t fee = 0;
|
||||
uint32_t price_per_kbyte = 0;
|
||||
};
|
||||
|
||||
asset fee;
|
||||
account_id_type payer;
|
||||
|
||||
fc::sha256 pw_vin;
|
||||
|
||||
std::vector< fc::sha256 > vins;
|
||||
std::vector< info_for_vout_id_type > vouts;
|
||||
|
||||
sidechain::bitcoin_transaction transaction;
|
||||
uint64_t fee_for_size;
|
||||
|
||||
account_id_type fee_payer()const { return payer; }
|
||||
void validate()const {}
|
||||
share_type calculate_fee( const fee_parameters_type& k )const {
|
||||
share_type fee_required = k.fee;
|
||||
fee_required += calculate_data_fee( fc::raw::pack_size(*this), k.price_per_kbyte );
|
||||
return fee_required;
|
||||
}
|
||||
};
|
||||
|
||||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT( graphene::chain::bitcoin_transaction_send_operation::fee_parameters_type, (fee)(price_per_kbyte) )
|
||||
FC_REFLECT( graphene::chain::bitcoin_transaction_send_operation, (fee)(payer)(vins)(vouts)(transaction)(fee_for_size) )
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
#include <graphene/chain/protocol/tournament.hpp>
|
||||
#include <graphene/chain/protocol/withdraw_pbtc.hpp>
|
||||
#include <graphene/chain/protocol/bitcoin_address.hpp>
|
||||
#include <graphene/chain/protocol/bitcoin_transaction.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
|
|
@ -133,7 +134,8 @@ namespace graphene { namespace chain {
|
|||
affiliate_payout_operation, // VIRTUAL
|
||||
affiliate_referral_payout_operation, // VIRTUAL
|
||||
withdraw_pbtc_operation,
|
||||
bitcoin_address_create_operation
|
||||
bitcoin_address_create_operation,
|
||||
bitcoin_transaction_send_operation
|
||||
> operation;
|
||||
|
||||
/// @} // operations group
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ namespace graphene { namespace chain {
|
|||
bitcoin_address_object_type,
|
||||
primary_wallet_vout_object_type,
|
||||
sidechain_proposal_object_type,
|
||||
bitcoin_transaction_object_type,
|
||||
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
|
||||
};
|
||||
|
||||
|
|
@ -210,36 +211,38 @@ namespace graphene { namespace chain {
|
|||
class bitcoin_address_object;
|
||||
class primary_wallet_vout_object;
|
||||
class sidechain_proposal_object;
|
||||
class bitcoin_transaction_object;
|
||||
|
||||
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
||||
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
||||
typedef object_id< protocol_ids, force_settlement_object_type, force_settlement_object> force_settlement_id_type;
|
||||
typedef object_id< protocol_ids, committee_member_object_type, committee_member_object> committee_member_id_type;
|
||||
typedef object_id< protocol_ids, witness_object_type, witness_object> witness_id_type;
|
||||
typedef object_id< protocol_ids, limit_order_object_type, limit_order_object> limit_order_id_type;
|
||||
typedef object_id< protocol_ids, call_order_object_type, call_order_object> call_order_id_type;
|
||||
typedef object_id< protocol_ids, custom_object_type, custom_object> custom_id_type;
|
||||
typedef object_id< protocol_ids, proposal_object_type, proposal_object> proposal_id_type;
|
||||
typedef object_id< protocol_ids, operation_history_object_type, operation_history_object> operation_history_id_type;
|
||||
typedef object_id< protocol_ids, withdraw_permission_object_type,withdraw_permission_object> withdraw_permission_id_type;
|
||||
typedef object_id< protocol_ids, vesting_balance_object_type, vesting_balance_object> vesting_balance_id_type;
|
||||
typedef object_id< protocol_ids, worker_object_type, worker_object> worker_id_type;
|
||||
typedef object_id< protocol_ids, balance_object_type, balance_object> balance_id_type;
|
||||
typedef object_id< protocol_ids, tournament_object_type, tournament_object> tournament_id_type;
|
||||
typedef object_id< protocol_ids, tournament_details_object_type, tournament_details_object> tournament_details_id_type;
|
||||
typedef object_id< protocol_ids, match_object_type, match_object> match_id_type;
|
||||
typedef object_id< protocol_ids, game_object_type, game_object> game_id_type;
|
||||
typedef object_id< protocol_ids, sport_object_type, sport_object> sport_id_type;
|
||||
typedef object_id< protocol_ids, event_group_object_type, event_group_object> event_group_id_type;
|
||||
typedef object_id< protocol_ids, event_object_type, event_object> event_id_type;
|
||||
typedef object_id< protocol_ids, betting_market_rules_object_type, betting_market_rules_object> betting_market_rules_id_type;
|
||||
typedef object_id< protocol_ids, betting_market_group_object_type, betting_market_group_object> betting_market_group_id_type;
|
||||
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
||||
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
||||
typedef object_id< protocol_ids, info_for_vout_object_type, info_for_vout_object> info_for_vout_id_type;
|
||||
typedef object_id< protocol_ids, bitcoin_address_object_type, bitcoin_address_object> bitcoin_address_id_type;
|
||||
typedef object_id< protocol_ids, primary_wallet_vout_object_type,primary_wallet_vout_object> primary_wallet_vout_id_type;
|
||||
typedef object_id< protocol_ids, sidechain_proposal_object_type, sidechain_proposal_object> sidechain_proposal_id_type;
|
||||
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
|
||||
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
|
||||
typedef object_id< protocol_ids, force_settlement_object_type, force_settlement_object> force_settlement_id_type;
|
||||
typedef object_id< protocol_ids, committee_member_object_type, committee_member_object> committee_member_id_type;
|
||||
typedef object_id< protocol_ids, witness_object_type, witness_object> witness_id_type;
|
||||
typedef object_id< protocol_ids, limit_order_object_type, limit_order_object> limit_order_id_type;
|
||||
typedef object_id< protocol_ids, call_order_object_type, call_order_object> call_order_id_type;
|
||||
typedef object_id< protocol_ids, custom_object_type, custom_object> custom_id_type;
|
||||
typedef object_id< protocol_ids, proposal_object_type, proposal_object> proposal_id_type;
|
||||
typedef object_id< protocol_ids, operation_history_object_type, operation_history_object> operation_history_id_type;
|
||||
typedef object_id< protocol_ids, withdraw_permission_object_type, withdraw_permission_object> withdraw_permission_id_type;
|
||||
typedef object_id< protocol_ids, vesting_balance_object_type, vesting_balance_object> vesting_balance_id_type;
|
||||
typedef object_id< protocol_ids, worker_object_type, worker_object> worker_id_type;
|
||||
typedef object_id< protocol_ids, balance_object_type, balance_object> balance_id_type;
|
||||
typedef object_id< protocol_ids, tournament_object_type, tournament_object> tournament_id_type;
|
||||
typedef object_id< protocol_ids, tournament_details_object_type, tournament_details_object> tournament_details_id_type;
|
||||
typedef object_id< protocol_ids, match_object_type, match_object> match_id_type;
|
||||
typedef object_id< protocol_ids, game_object_type, game_object> game_id_type;
|
||||
typedef object_id< protocol_ids, sport_object_type, sport_object> sport_id_type;
|
||||
typedef object_id< protocol_ids, event_group_object_type, event_group_object> event_group_id_type;
|
||||
typedef object_id< protocol_ids, event_object_type, event_object> event_id_type;
|
||||
typedef object_id< protocol_ids, betting_market_rules_object_type, betting_market_rules_object> betting_market_rules_id_type;
|
||||
typedef object_id< protocol_ids, betting_market_group_object_type, betting_market_group_object> betting_market_group_id_type;
|
||||
typedef object_id< protocol_ids, betting_market_object_type, betting_market_object> betting_market_id_type;
|
||||
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
|
||||
typedef object_id< protocol_ids, info_for_vout_object_type, info_for_vout_object> info_for_vout_id_type;
|
||||
typedef object_id< protocol_ids, bitcoin_address_object_type, bitcoin_address_object> bitcoin_address_id_type;
|
||||
typedef object_id< protocol_ids, primary_wallet_vout_object_type, primary_wallet_vout_object> primary_wallet_vout_id_type;
|
||||
typedef object_id< protocol_ids, sidechain_proposal_object_type, sidechain_proposal_object> sidechain_proposal_id_type;
|
||||
typedef object_id< protocol_ids, bitcoin_transaction_object_type, bitcoin_transaction_object> bitcoin_transaction_id_type;
|
||||
|
||||
// implementation types
|
||||
class global_property_object;
|
||||
|
|
@ -418,6 +421,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type,
|
|||
(bitcoin_address_object_type)
|
||||
(primary_wallet_vout_object_type)
|
||||
(sidechain_proposal_object_type)
|
||||
(bitcoin_transaction_object_type)
|
||||
(OBJECT_TYPE_COUNT)
|
||||
)
|
||||
FC_REFLECT_ENUM( graphene::chain::impl_object_type,
|
||||
|
|
@ -473,6 +477,7 @@ FC_REFLECT_TYPENAME( graphene::chain::info_for_vout_id_type )
|
|||
FC_REFLECT_TYPENAME( graphene::chain::bitcoin_address_id_type )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::primary_wallet_vout_id_type )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::sidechain_proposal_id_type )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::bitcoin_transaction_id_type )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::global_property_id_type )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::dynamic_global_property_id_type )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::asset_dynamic_data_id_type )
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ set(SOURCES node.cpp
|
|||
add_library( graphene_net ${SOURCES} ${HEADERS} )
|
||||
|
||||
target_link_libraries( graphene_net
|
||||
PUBLIC fc graphene_db )
|
||||
PUBLIC fc graphene_db sidechain )
|
||||
target_include_directories( graphene_net
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../chain/include"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/primary_wallet_vout_object.hpp>
|
||||
|
||||
#include <graphene/chain/protocol/types.hpp>
|
||||
#include <sidechain/types.hpp>
|
||||
#include <fc/crypto/sha256.hpp>
|
||||
|
||||
namespace graphene { namespace chain { class database; } }
|
||||
|
||||
namespace sidechain {
|
||||
|
||||
class primary_wallet_vout_manager
|
||||
|
|
@ -16,18 +17,20 @@ public:
|
|||
bool is_reach_max_unconfirmaed_vout() const;
|
||||
|
||||
fc::optional< graphene::chain::primary_wallet_vout_object > get_latest_unused_vout() const;
|
||||
|
||||
fc::optional< graphene::chain::primary_wallet_vout_object > get_vout( fc::sha256 hash_id ) const;
|
||||
|
||||
void create_new_vout( const sidechain::prev_out& out );
|
||||
|
||||
void delete_vout_with_newer( fc::uint256 hash_id );
|
||||
void delete_vout_with_newer( fc::sha256 hash_id );
|
||||
|
||||
void confirm_vout( fc::uint256 hash_id );
|
||||
void confirm_vout( fc::sha256 hash_id );
|
||||
|
||||
void use_latest_vout( fc::uint256 hash_id );
|
||||
void use_latest_vout( fc::sha256 hash_id );
|
||||
|
||||
private:
|
||||
|
||||
fc::optional< graphene::chain::primary_wallet_vout_id_type > get_vout_id( fc::uint256 hash_id ) const;
|
||||
fc::optional< graphene::chain::primary_wallet_vout_id_type > get_vout_id( fc::sha256 hash_id ) const;
|
||||
|
||||
graphene::chain::database& db;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <string>
|
||||
#include <fc/reflect/reflect.hpp>
|
||||
|
||||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/protocol/types.hpp>
|
||||
|
||||
namespace sidechain {
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ std::string bitcoin_rpc_client::send_btc_tx( const std::string& tx_hex )
|
|||
|
||||
const auto reply = send_post_request( body );
|
||||
|
||||
if( reply.body.empty() )
|
||||
if( reply.body.empty() || reply.status != 200 )
|
||||
return "";
|
||||
|
||||
std::string reply_str( reply.body.begin(), reply.body.end() );
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
void update_estimated_fee();
|
||||
|
||||
void send_btc_tx();
|
||||
void send_btc_tx( const sidechain::bitcoin_transaction& trx );
|
||||
|
||||
bool connection_is_not_defined() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <sidechain/network/sidechain_net_manager.hpp>
|
||||
#include <sidechain/serialize.hpp>
|
||||
|
||||
#include <fc/network/http/connection.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
|
|
@ -32,7 +33,11 @@ void sidechain_net_manager::initialize_manager( graphene::chain::database* _db,
|
|||
}
|
||||
|
||||
listener->block_received.connect([this]( const std::string& block_hash ) {
|
||||
std::thread( &sidechain_net_manager::handle_block, this, block_hash).detach();
|
||||
std::thread( &sidechain_net_manager::handle_block, this, block_hash ).detach();
|
||||
} );
|
||||
|
||||
db->send_btc_tx.connect([this]( const sidechain::bitcoin_transaction& trx ) {
|
||||
std::thread( &sidechain_net_manager::send_btc_tx, this, trx ).detach();
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
@ -98,9 +103,30 @@ void sidechain_net_manager::update_estimated_fee()
|
|||
auto estimated_fee = bitcoin_client->receive_estimated_fee();
|
||||
}
|
||||
|
||||
void sidechain_net_manager::send_btc_tx()
|
||||
void sidechain_net_manager::send_btc_tx( const sidechain::bitcoin_transaction& trx )
|
||||
{
|
||||
FC_ASSERT( !bitcoin_client->connection_is_not_defined() );
|
||||
const auto tx_hex = fc::to_hex( pack( trx ) );
|
||||
idump((tx_hex));
|
||||
|
||||
auto reply = bitcoin_client->send_btc_tx( tx_hex );
|
||||
|
||||
std::stringstream ss(reply);
|
||||
boost::property_tree::ptree json;
|
||||
boost::property_tree::read_json(ss, json);
|
||||
|
||||
if( !json.get_child( "error" ).empty() ) {
|
||||
wlog( "BTC tx is not sent! Reply: ${msg}", ("msg", reply) );
|
||||
const auto error_code = json.get_child( "error" ).get_child( "code" ).get_value<int>();
|
||||
|
||||
if( error_code != -27 ) // transaction already in block chain
|
||||
return;
|
||||
}
|
||||
|
||||
if( reply == "" ){
|
||||
wlog( "Don't receive successful reply status" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool sidechain_net_manager::connection_is_not_defined() const
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#include <sidechain/primary_wallet_vout_manager.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/primary_wallet_vout_object.hpp>
|
||||
#include <graphene/chain/config.hpp>
|
||||
|
||||
|
||||
namespace sidechain {
|
||||
|
||||
bool primary_wallet_vout_manager::is_reach_max_unconfirmaed_vout() const
|
||||
|
|
@ -21,6 +24,15 @@ fc::optional< graphene::chain::primary_wallet_vout_object > primary_wallet_vout_
|
|||
return fc::optional< graphene::chain::primary_wallet_vout_object > (*itr);
|
||||
}
|
||||
|
||||
fc::optional< graphene::chain::primary_wallet_vout_object > primary_wallet_vout_manager::get_vout( fc::sha256 hash_id ) const
|
||||
{
|
||||
const auto& PW_vout_by_hash_id = db.get_index_type<graphene::chain::primary_wallet_vout_index>().indices().get< graphene::chain::by_hash_id >();
|
||||
const auto& itr_hash_id = PW_vout_by_hash_id.find( hash_id );
|
||||
if( itr_hash_id == PW_vout_by_hash_id.end() )
|
||||
return fc::optional< graphene::chain::primary_wallet_vout_object >();
|
||||
return fc::optional< graphene::chain::primary_wallet_vout_object >( *itr_hash_id );
|
||||
}
|
||||
|
||||
void primary_wallet_vout_manager::create_new_vout( const sidechain::prev_out& out )
|
||||
{
|
||||
db.create<graphene::chain::primary_wallet_vout_object>([&]( graphene::chain::primary_wallet_vout_object& obj ) {
|
||||
|
|
@ -31,7 +43,7 @@ void primary_wallet_vout_manager::create_new_vout( const sidechain::prev_out& ou
|
|||
});
|
||||
}
|
||||
|
||||
void primary_wallet_vout_manager::delete_vout_with_newer( fc::uint256 hash_id )
|
||||
void primary_wallet_vout_manager::delete_vout_with_newer( fc::sha256 hash_id )
|
||||
{
|
||||
const auto& PW_vout_by_id = db.get_index_type<graphene::chain::primary_wallet_vout_index>().indices().get< graphene::chain::by_id >();
|
||||
auto vout_id = get_vout_id( hash_id );
|
||||
|
|
@ -48,7 +60,7 @@ void primary_wallet_vout_manager::delete_vout_with_newer( fc::uint256 hash_id )
|
|||
}
|
||||
}
|
||||
|
||||
void primary_wallet_vout_manager::confirm_vout( fc::uint256 hash_id )
|
||||
void primary_wallet_vout_manager::confirm_vout( fc::sha256 hash_id )
|
||||
{
|
||||
const auto& PW_vout_by_id = db.get_index_type<graphene::chain::primary_wallet_vout_index>().indices().get< graphene::chain::by_id >();
|
||||
auto vout_id = get_vout_id( hash_id );
|
||||
|
|
@ -67,7 +79,7 @@ void primary_wallet_vout_manager::confirm_vout( fc::uint256 hash_id )
|
|||
}
|
||||
}
|
||||
|
||||
void primary_wallet_vout_manager::use_latest_vout( fc::uint256 hash_id )
|
||||
void primary_wallet_vout_manager::use_latest_vout( fc::sha256 hash_id )
|
||||
{
|
||||
const auto& PW_vout_by_id = db.get_index_type<graphene::chain::primary_wallet_vout_index>().indices().get< graphene::chain::by_id >();
|
||||
auto vout_id = get_vout_id( hash_id );
|
||||
|
|
@ -85,7 +97,7 @@ void primary_wallet_vout_manager::use_latest_vout( fc::uint256 hash_id )
|
|||
}
|
||||
}
|
||||
|
||||
fc::optional< graphene::chain::primary_wallet_vout_id_type > primary_wallet_vout_manager::get_vout_id( fc::uint256 hash_id ) const
|
||||
fc::optional< graphene::chain::primary_wallet_vout_id_type > primary_wallet_vout_manager::get_vout_id( fc::sha256 hash_id ) const
|
||||
{
|
||||
const auto& PW_vout_by_hash_id = db.get_index_type<graphene::chain::primary_wallet_vout_index>().indices().get< graphene::chain::by_hash_id >();
|
||||
const auto& itr_hash_id = PW_vout_by_hash_id.find( hash_id );
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@
|
|||
#include <graphene/chain/tournament_object.hpp>
|
||||
#include <graphene/chain/match_object.hpp>
|
||||
#include <graphene/chain/game_object.hpp>
|
||||
#include <graphene/chain/info_for_vout_object.hpp>
|
||||
#include <graphene/chain/bitcoin_address_object.hpp>
|
||||
#include <graphene/chain/primary_wallet_vout_object.hpp>
|
||||
#include <graphene/chain/sidechain_proposal_object.hpp>
|
||||
|
||||
#include <fc/smart_ref_impl.hpp>
|
||||
#include <iostream>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
#include <sidechain/primary_wallet_vout_manager.hpp>
|
||||
#include <graphene/chain/primary_wallet_vout_object.hpp>
|
||||
#include "../common/database_fixture.hpp"
|
||||
#include <sidechain/types.hpp>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue