Partial signing functional for deposit and withdrawal

This commit is contained in:
Srdjan Obucina 2020-03-19 16:06:58 +01:00
parent 5897442112
commit 23c4eba59b
42 changed files with 484 additions and 365 deletions

View file

@ -160,8 +160,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// Sidechain addresses
vector<optional<sidechain_address_object>> get_sidechain_addresses(const vector<sidechain_address_id_type>& sidechain_address_ids)const;
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_account(account_id_type account)const;
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const;
fc::optional<sidechain_address_object> get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const;
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const;
fc::optional<sidechain_address_object> get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const;
uint64_t get_sidechain_addresses_count()const;
// Votes
@ -1865,12 +1865,12 @@ vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addr
return result;
}
vector<optional<sidechain_address_object>> database_api::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const
vector<optional<sidechain_address_object>> database_api::get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const
{
return my->get_sidechain_addresses_by_sidechain( sidechain );
}
vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const
vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const
{
vector<optional<sidechain_address_object>> result;
const auto& sidechain_addresses_range = _db.get_index_type<sidechain_address_index>().indices().get<by_sidechain>().equal_range(sidechain);
@ -1881,12 +1881,12 @@ vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addr
return result;
}
fc::optional<sidechain_address_object> database_api::get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const
fc::optional<sidechain_address_object> database_api::get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const
{
return my->get_sidechain_address_by_account_and_sidechain( account, sidechain );
}
fc::optional<sidechain_address_object> database_api_impl::get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const
fc::optional<sidechain_address_object> database_api_impl::get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const
{
const auto& idx = _db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
auto itr = idx.find( boost::make_tuple( account, sidechain ) );

View file

@ -346,12 +346,12 @@ struct get_impacted_account_visitor
void operator()( const sidechain_transaction_create_operation& op ){
_impacted.insert( op.payer );
}
// void operator()( const sidechain_transaction_sign_operation& op ){
// _impacted.insert( op.payer );
// }
// void operator()( const sidechain_transaction_send_operation& op ){
// _impacted.insert( op.payer );
// }
void operator()( const sidechain_transaction_sign_operation& op ){
_impacted.insert( op.payer );
}
void operator()( const sidechain_transaction_send_operation& op ){
_impacted.insert( op.payer );
}
};
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )

View file

@ -653,7 +653,7 @@ class database_api
* @param sidechain Sidechain for which addresses should be retrieved
* @return The sidechain addresses objects, or null if the sidechain does not have any addresses
*/
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const;
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const;
/**
* @brief Get the sidechain addresses for a given account and sidechain
@ -661,7 +661,7 @@ class database_api
* @param sidechain Sidechain for which address should be retrieved
* @return The sidechain addresses objects, or null if the account does not have a sidechain addresses for a given sidechain
*/
fc::optional<sidechain_address_object> get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const;
fc::optional<sidechain_address_object> get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const;
/**
* @brief Get the total number of sidechain addresses registered with the blockchain

View file

@ -130,7 +130,7 @@ add_library( graphene_chain
)
add_dependencies( graphene_chain build_hardfork_hpp )
target_link_libraries( graphene_chain fc graphene_db peerplays_sidechain )
target_link_libraries( graphene_chain fc graphene_db )
target_include_directories( graphene_chain
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )

View file

@ -270,8 +270,8 @@ void database::initialize_evaluators()
register_evaluator<update_sidechain_address_evaluator>();
register_evaluator<delete_sidechain_address_evaluator>();
register_evaluator<sidechain_transaction_create_evaluator>();
// register_evaluator<sidechain_transaction_sign_evaluator>();
// register_evaluator<sidechain_transaction_send_evaluator>();
register_evaluator<sidechain_transaction_sign_evaluator>();
register_evaluator<sidechain_transaction_send_evaluator>();
}
void database::initialize_indexes()

View file

@ -333,12 +333,12 @@ struct get_impacted_account_visitor
void operator()( const sidechain_transaction_create_operation& op ) {
_impacted.insert( op.payer );
}
// void operator()( const sidechain_transaction_sign_operation& op ) {
// _impacted.insert( op.payer );
// }
// void operator()( const sidechain_transaction_send_operation& op ) {
// _impacted.insert( op.payer );
// }
void operator()( const sidechain_transaction_sign_operation& op ) {
_impacted.insert( op.payer );
}
void operator()( const sidechain_transaction_send_operation& op ) {
_impacted.insert( op.payer );
}
};
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
@ -443,6 +443,8 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
assert( aobj != nullptr );
accounts.insert( aobj->sidechain_address_account );
break;
} case sidechain_transaction_object_type:{
break;
}
}
}

View file

@ -40,7 +40,7 @@
#include <graphene/chain/protocol/protocol.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
#include <fc/log/logger.hpp>

View file

@ -157,9 +157,9 @@ namespace graphene { namespace chain {
sidechain_address_add_operation,
sidechain_address_update_operation,
sidechain_address_delete_operation,
sidechain_transaction_create_operation//,
//sidechain_transaction_sign_operation,
//sidechain_transaction_send_operation
sidechain_transaction_create_operation,
sidechain_transaction_sign_operation,
sidechain_transaction_send_operation
> operation;
/// @} // operations group

View file

@ -1,7 +1,7 @@
#pragma once
#include <graphene/chain/protocol/base.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
@ -11,7 +11,7 @@ namespace graphene { namespace chain {
asset fee;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
string deposit_address;
string withdraw_address;
@ -26,7 +26,7 @@ namespace graphene { namespace chain {
asset fee;
sidechain_address_id_type sidechain_address_id;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
optional<string> deposit_address;
optional<string> withdraw_address;
@ -41,7 +41,7 @@ namespace graphene { namespace chain {
asset fee;
sidechain_address_id_type sidechain_address_id;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
account_id_type fee_payer()const { return sidechain_address_account; }
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }

View file

@ -1,7 +1,7 @@
#pragma once
#include <graphene/chain/protocol/base.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
@ -9,48 +9,47 @@ namespace graphene { namespace chain {
{
struct fee_parameters_type { uint64_t fee = 0; };
asset fee;
account_id_type payer;
asset fee;
account_id_type payer;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
optional<son_wallet_id_type> son_wallet_id;
optional<son_wallet_deposit_id_type> son_wallet_deposit_id;
optional<son_wallet_withdraw_id_type> son_wallet_withdraw_id;
std::string transaction;
std::vector<std::pair<son_id_type, bool>> signatures;
std::vector<son_id_type> signers;
account_id_type fee_payer()const { return payer; }
void validate()const {}
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
};
// struct sidechain_transaction_sign_operation : public base_operation
// {
// struct fee_parameters_type { uint64_t fee = 0; };
//
// asset fee;
// account_id_type payer;
// proposal_id_type proposal_id;
// std::vector<peerplays_sidechain::bytes> signatures;
//
// account_id_type fee_payer()const { return payer; }
// void validate()const {}
// share_type calculate_fee( const fee_parameters_type& k )const { return 0; }
// };
//
// struct sidechain_transaction_send_operation : public base_operation
// {
// struct fee_parameters_type { uint64_t fee = 0; };
//
// asset fee;
// account_id_type payer;
//
// sidechain_transaction_id_type sidechain_transaction_id;
//
// account_id_type fee_payer()const { return payer; }
// void validate()const {}
// share_type calculate_fee( const fee_parameters_type& k )const { return 0; }
// };
struct sidechain_transaction_sign_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = 0; };
asset fee;
account_id_type payer;
sidechain_transaction_id_type sidechain_transaction_id;
std::string transaction;
bool complete;
account_id_type fee_payer()const { return payer; }
share_type calculate_fee( const fee_parameters_type& k )const { return 0; }
};
struct sidechain_transaction_send_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = 0; };
asset fee;
account_id_type payer;
sidechain_transaction_id_type sidechain_transaction_id;
account_id_type fee_payer()const { return payer; }
share_type calculate_fee( const fee_parameters_type& k )const { return 0; }
};
} } // graphene::chain
@ -61,10 +60,13 @@ FC_REFLECT( graphene::chain::sidechain_transaction_create_operation, (fee)(payer
(son_wallet_deposit_id)
(son_wallet_withdraw_id)
(transaction)
(signatures) )
(signers) )
//FC_REFLECT( graphene::chain::sidechain_transaction_sign_operation::fee_parameters_type, (fee) )
//FC_REFLECT( graphene::chain::sidechain_transaction_sign_operation, (fee)(payer)(proposal_id)(signatures) )
//
//FC_REFLECT( graphene::chain::sidechain_transaction_send_operation::fee_parameters_type, (fee) )
//FC_REFLECT( graphene::chain::sidechain_transaction_send_operation, (fee)(payer)(sidechain_transaction_id) )
FC_REFLECT( graphene::chain::sidechain_transaction_sign_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::sidechain_transaction_sign_operation, (fee)(payer)
(sidechain_transaction_id)
(transaction) )
FC_REFLECT( graphene::chain::sidechain_transaction_send_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::sidechain_transaction_send_operation, (fee)(payer)
(sidechain_transaction_id) )

View file

@ -1,6 +1,6 @@
#pragma once
#include <graphene/chain/protocol/base.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
@ -13,7 +13,7 @@ namespace graphene { namespace chain {
std::string url;
vesting_balance_id_type deposit;
public_key_type signing_key;
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
vesting_balance_id_type pay_vb;
account_id_type fee_payer()const { return owner_account; }
@ -30,7 +30,7 @@ namespace graphene { namespace chain {
optional<std::string> new_url;
optional<vesting_balance_id_type> new_deposit;
optional<public_key_type> new_signing_key;
optional<flat_map<peerplays_sidechain::sidechain_type, string>> new_sidechain_public_keys;
optional<flat_map<sidechain_type, string>> new_sidechain_public_keys;
optional<vesting_balance_id_type> new_pay_vb;
account_id_type fee_payer()const { return owner_account; }

View file

@ -25,7 +25,7 @@ namespace graphene { namespace chain {
account_id_type payer;
son_wallet_id_type son_wallet_id;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
string address;
account_id_type fee_payer()const { return payer; }

View file

@ -14,7 +14,7 @@ namespace graphene { namespace chain {
son_id_type son_id;
fc::time_point_sec timestamp;
peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
std::string sidechain_uid;
std::string sidechain_transaction_id;
std::string sidechain_from;

View file

@ -14,12 +14,12 @@ namespace graphene { namespace chain {
son_id_type son_id;
fc::time_point_sec timestamp;
peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
std::string peerplays_uid;
std::string peerplays_transaction_id;
chain::account_id_type peerplays_from;
chain::asset peerplays_asset;
peerplays_sidechain::sidechain_type withdraw_sidechain;
sidechain_type withdraw_sidechain;
std::string withdraw_address;
std::string withdraw_currency;
safe<int64_t> withdraw_amount;

View file

@ -3,7 +3,7 @@
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
@ -20,12 +20,12 @@ namespace graphene { namespace chain {
static const uint8_t type_id = sidechain_address_object_type;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
string deposit_address;
string withdraw_address;
sidechain_address_object() :
sidechain(graphene::peerplays_sidechain::sidechain_type::bitcoin),
sidechain(sidechain_type::bitcoin),
deposit_address(""),
withdraw_address("") {}
};
@ -44,17 +44,17 @@ namespace graphene { namespace chain {
member<sidechain_address_object, account_id_type, &sidechain_address_object::sidechain_address_account>
>,
ordered_non_unique< tag<by_sidechain>,
member<sidechain_address_object, peerplays_sidechain::sidechain_type, &sidechain_address_object::sidechain>
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>
>,
ordered_unique< tag<by_account_and_sidechain>,
composite_key<sidechain_address_object,
member<sidechain_address_object, account_id_type, &sidechain_address_object::sidechain_address_account>,
member<sidechain_address_object, peerplays_sidechain::sidechain_type, &sidechain_address_object::sidechain>
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>
>
>,
ordered_unique< tag<by_sidechain_and_deposit_address>,
composite_key<sidechain_address_object,
member<sidechain_address_object, peerplays_sidechain::sidechain_type, &sidechain_address_object::sidechain>,
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
member<sidechain_address_object, std::string, &sidechain_address_object::deposit_address>
>
>

View file

@ -0,0 +1,20 @@
#pragma once
#include <fc/reflect/reflect.hpp>
namespace graphene { namespace chain {
enum class sidechain_type {
bitcoin,
ethereum,
eos,
peerplays
};
} }
FC_REFLECT_ENUM(graphene::chain::sidechain_type,
(bitcoin)
(ethereum)
(eos)
(peerplays) )

View file

@ -13,23 +13,22 @@ public:
object_id_type do_apply(const sidechain_transaction_create_operation& o);
};
//class sidechain_transaction_sign_evaluator : public evaluator<sidechain_transaction_sign_evaluator>
//{
//public:
// typedef sidechain_transaction_sign_operation operation_type;
//
// void_result do_evaluate(const sidechain_transaction_sign_operation& o);
// object_id_type do_apply(const sidechain_transaction_sign_operation& o);
// void update_proposal( const sidechain_transaction_sign_operation& o );
//};
//
//class sidechain_transaction_send_evaluator : public evaluator<sidechain_transaction_send_evaluator>
//{
//public:
// typedef sidechain_transaction_send_operation operation_type;
//
// void_result do_evaluate(const sidechain_transaction_send_operation& o);
// object_id_type do_apply(const sidechain_transaction_send_operation& o);
//};
class sidechain_transaction_sign_evaluator : public evaluator<sidechain_transaction_sign_evaluator>
{
public:
typedef sidechain_transaction_sign_operation operation_type;
void_result do_evaluate(const sidechain_transaction_sign_operation& o);
object_id_type do_apply(const sidechain_transaction_sign_operation& o);
};
class sidechain_transaction_send_evaluator : public evaluator<sidechain_transaction_send_evaluator>
{
public:
typedef sidechain_transaction_send_operation operation_type;
void_result do_evaluate(const sidechain_transaction_send_operation& o);
object_id_type do_apply(const sidechain_transaction_send_operation& o);
};
} } // namespace graphene::chain

View file

@ -1,6 +1,6 @@
#pragma once
#include <graphene/chain/protocol/types.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
@ -16,35 +16,36 @@ namespace graphene { namespace chain {
static const uint8_t space_id = protocol_ids;
static const uint8_t type_id = sidechain_transaction_object_type;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
optional<son_wallet_id_type> son_wallet_id;
optional<son_wallet_deposit_id_type> son_wallet_deposit_id;
optional<son_wallet_withdraw_id_type> son_wallet_withdraw_id;
std::string transaction;
std::vector<std::pair<son_id_type, bool>> signatures;
std::vector<std::pair<son_id_type, bool>> signers;
bool valid = false;
bool completed = false;
bool complete = false;
bool sent = false;
};
struct by_sidechain_and_completed;
struct by_sidechain_and_sent;
struct by_sidechain_and_complete;
struct by_sidechain_and_complete_and_sent;
using sidechain_transaction_multi_index_type = multi_index_container<
sidechain_transaction_object,
indexed_by<
ordered_unique< tag<by_id>,
member<object, object_id_type, &object::id>
>,
ordered_non_unique< tag<by_sidechain_and_completed>,
ordered_non_unique< tag<by_sidechain_and_complete>,
composite_key<sidechain_transaction_object,
member<sidechain_transaction_object, peerplays_sidechain::sidechain_type, &sidechain_transaction_object::sidechain>,
member<sidechain_transaction_object, bool, &sidechain_transaction_object::completed>
member<sidechain_transaction_object, sidechain_type, &sidechain_transaction_object::sidechain>,
member<sidechain_transaction_object, bool, &sidechain_transaction_object::complete>
>
>,
ordered_non_unique< tag<by_sidechain_and_sent>,
ordered_non_unique< tag<by_sidechain_and_complete_and_sent>,
composite_key<sidechain_transaction_object,
member<sidechain_transaction_object, peerplays_sidechain::sidechain_type, &sidechain_transaction_object::sidechain>,
member<sidechain_transaction_object, sidechain_type, &sidechain_transaction_object::sidechain>,
member<sidechain_transaction_object, bool, &sidechain_transaction_object::complete>,
member<sidechain_transaction_object, bool, &sidechain_transaction_object::sent>
>
>
@ -59,7 +60,7 @@ FC_REFLECT_DERIVED( graphene::chain::sidechain_transaction_object, (graphene::db
(son_wallet_deposit_id)
(son_wallet_withdraw_id)
(transaction)
(signatures)
(signers)
(valid)
(completed)
(complete)
(sent) )

View file

@ -1,6 +1,6 @@
#pragma once
#include <graphene/chain/protocol/types.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
@ -14,7 +14,7 @@ namespace graphene { namespace chain {
son_id_type son_id;
uint64_t total_votes = 0;
public_key_type signing_key;
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
bool operator==(const son_info& rhs) {
bool son_sets_equal =

View file

@ -2,7 +2,7 @@
#include <graphene/chain/protocol/types.hpp>
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
@ -68,7 +68,7 @@ namespace graphene { namespace chain {
vesting_balance_id_type pay_vb;
son_statistics_id_type statistics;
son_status status = son_status::inactive;
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
void pay_son_fee(share_type pay, database& db);
};

View file

@ -1,6 +1,6 @@
#pragma once
#include <graphene/chain/protocol/types.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
@ -17,7 +17,7 @@ namespace graphene { namespace chain {
static const uint8_t type_id = son_wallet_deposit_object_type;
time_point_sec timestamp;
peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
std::string sidechain_uid;
std::string sidechain_transaction_id;
std::string sidechain_from;
@ -45,7 +45,7 @@ namespace graphene { namespace chain {
member<object, object_id_type, &object::id>
>,
ordered_non_unique< tag<by_sidechain>,
member<son_wallet_deposit_object, peerplays_sidechain::sidechain_type, &son_wallet_deposit_object::sidechain>
member<son_wallet_deposit_object, sidechain_type, &son_wallet_deposit_object::sidechain>
>,
ordered_unique< tag<by_sidechain_uid>,
member<son_wallet_deposit_object, std::string, &son_wallet_deposit_object::sidechain_uid>
@ -55,7 +55,7 @@ namespace graphene { namespace chain {
>,
ordered_non_unique< tag<by_sidechain_and_processed>,
composite_key<son_wallet_deposit_object,
member<son_wallet_deposit_object, peerplays_sidechain::sidechain_type, &son_wallet_deposit_object::sidechain>,
member<son_wallet_deposit_object, sidechain_type, &son_wallet_deposit_object::sidechain>,
member<son_wallet_deposit_object, bool, &son_wallet_deposit_object::processed>
>
>

View file

@ -1,7 +1,7 @@
#pragma once
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/son_info.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
@ -20,7 +20,7 @@ namespace graphene { namespace chain {
time_point_sec valid_from;
time_point_sec expires;
flat_map<peerplays_sidechain::sidechain_type, string> addresses;
flat_map<sidechain_type, string> addresses;
vector<son_info> sons;
};

View file

@ -1,6 +1,6 @@
#pragma once
#include <graphene/chain/protocol/types.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
@ -17,12 +17,12 @@ namespace graphene { namespace chain {
static const uint8_t type_id = son_wallet_withdraw_object_type;
time_point_sec timestamp;
peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
std::string peerplays_uid;
std::string peerplays_transaction_id;
chain::account_id_type peerplays_from;
chain::asset peerplays_asset;
peerplays_sidechain::sidechain_type withdraw_sidechain;
sidechain_type withdraw_sidechain;
std::string withdraw_address;
std::string withdraw_currency;
safe<int64_t> withdraw_amount;
@ -47,14 +47,14 @@ namespace graphene { namespace chain {
member<son_wallet_withdraw_object, std::string, &son_wallet_withdraw_object::peerplays_uid>
>,
ordered_non_unique< tag<by_withdraw_sidechain>,
member<son_wallet_withdraw_object, peerplays_sidechain::sidechain_type, &son_wallet_withdraw_object::withdraw_sidechain>
member<son_wallet_withdraw_object, sidechain_type, &son_wallet_withdraw_object::withdraw_sidechain>
>,
ordered_non_unique< tag<by_processed>,
member<son_wallet_withdraw_object, bool, &son_wallet_withdraw_object::processed>
>,
ordered_non_unique< tag<by_withdraw_sidechain_and_processed>,
composite_key<son_wallet_withdraw_object,
member<son_wallet_withdraw_object, peerplays_sidechain::sidechain_type, &son_wallet_withdraw_object::withdraw_sidechain>,
member<son_wallet_withdraw_object, sidechain_type, &son_wallet_withdraw_object::withdraw_sidechain>,
member<son_wallet_withdraw_object, bool, &son_wallet_withdraw_object::processed>
>
>

View file

@ -1,10 +1,10 @@
#include <graphene/chain/sidechain_transaction_evaluator.hpp>
#include <graphene/chain/hardfork.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/hardfork.hpp>
namespace graphene { namespace chain {
@ -30,114 +30,94 @@ object_id_type sidechain_transaction_create_evaluator::do_apply(const sidechain_
sto.son_wallet_deposit_id = op.son_wallet_deposit_id;
sto.son_wallet_withdraw_id = op.son_wallet_withdraw_id;
sto.transaction = op.transaction;
sto.signatures = op.signatures;
std::transform(op.signers.begin(), op.signers.end(), std::inserter(sto.signers, sto.signers.end()), [](const son_id_type son_id) {
return std::make_pair(son_id, false);
});
sto.valid = true;
sto.completed = false;
sto.complete = false;
sto.sent = false;
});
return new_sidechain_transaction_object.id;
} FC_CAPTURE_AND_RETHROW( ( op ) ) }
//void_result sidechain_transaction_sign_evaluator::do_evaluate(const sidechain_transaction_sign_operation &op)
//{
// try
// {
// FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); // can be removed after HF date pass
// const auto &proposal_idx = db().get_index_type<proposal_index>().indices().get<by_id>();
// const auto &proposal_itr = proposal_idx.find(op.proposal_id);
// FC_ASSERT(proposal_idx.end() != proposal_itr, "proposal not found");
// // Checks can this SON approve this proposal
// auto can_this_son_approve_this_proposal = [&]() {
// const auto &sidx = db().get_index_type<son_index>().indices().get<graphene::chain::by_account>();
// auto son_obj = sidx.find(op.payer);
// if (son_obj == sidx.end())
// {
// return false;
// }
// // TODO: Check if the SON is included in the PW script.
// return true;
// };
//
// FC_ASSERT(can_this_son_approve_this_proposal(), "Invalid approval received");
// return void_result();
// }
// FC_CAPTURE_AND_RETHROW((op))
//}
//
//object_id_type sidechain_transaction_sign_evaluator::do_apply(const sidechain_transaction_sign_operation &op)
//{
// try
// {
// const auto &proposal = op.proposal_id(db());
// const auto &sidx = db().get_index_type<son_index>().indices().get<graphene::chain::by_account>();
// auto son_obj = sidx.find(op.payer);
//
// db().modify(proposal, [&](proposal_object &po) {
// auto sidechain_transaction_send_op = po.proposed_transaction.operations[0].get<sidechain_transaction_create_operation>();
// sidechain_transaction_send_op.signatures[son_obj->id] = op.signatures;
// po.proposed_transaction.operations[0] = sidechain_transaction_send_op;
// });
//
// db().modify( son_obj->statistics( db() ), [&]( son_statistics_object& sso ) {
// sso.txs_signed += 1;
// } );
//
// update_proposal(op);
// }
// FC_CAPTURE_AND_RETHROW((op))
//}
//
//void sidechain_transaction_sign_evaluator::update_proposal(const sidechain_transaction_sign_operation &op)
//{
// database &d = db();
// proposal_update_operation update_op;
//
// update_op.fee_paying_account = op.payer;
// update_op.proposal = op.proposal_id;
// update_op.active_approvals_to_add = {op.payer};
//
// bool skip_fee_old = trx_state->skip_fee;
// bool skip_fee_schedule_check_old = trx_state->skip_fee_schedule_check;
// trx_state->skip_fee = true;
// trx_state->skip_fee_schedule_check = true;
//
// d.apply_operation(*trx_state, update_op);
//
// trx_state->skip_fee = skip_fee_old;
// trx_state->skip_fee_schedule_check = skip_fee_schedule_check_old;
//}
//
//void_result sidechain_transaction_send_evaluator::do_evaluate(const sidechain_transaction_send_operation &op)
//{
// try
// {
// FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
// FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." );
// const auto& btidx = db().get_index_type<sidechain_transaction_index>().indices().get<by_id>();
// const auto btobj = btidx.find(op.sidechain_transaction_id);
// FC_ASSERT(btobj != btidx.end(), "Bitcoin Transaction Object not found");
// FC_ASSERT(btobj->processed == false, "Bitcoin Transaction already processed");
// return void_result();
// }
// FC_CAPTURE_AND_RETHROW((op))
//}
//
//object_id_type sidechain_transaction_send_evaluator::do_apply(const sidechain_transaction_send_operation &op)
//{
// try
// {
// const auto &btidx = db().get_index_type<sidechain_transaction_index>().indices().get<by_id>();
// auto btobj = btidx.find(op.sidechain_transaction_id);
// if (btobj != btidx.end())
// {
// db().modify(*btobj, [&op](sidechain_transaction_object &bto) {
// bto.processed = true;
// });
// }
// return op.sidechain_transaction_id;
// }
// FC_CAPTURE_AND_RETHROW((op))
//}
void_result sidechain_transaction_sign_evaluator::do_evaluate(const sidechain_transaction_sign_operation &op)
{ try {
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); // can be removed after HF date pass
const auto &sto_idx = db().get_index_type<sidechain_transaction_index>().indices().get<by_id>();
const auto &sto_obj = sto_idx.find(op.sidechain_transaction_id);
FC_ASSERT(sto_obj != sto_idx.end(), "Sidechain transaction object not found");
const auto &son_idx = db().get_index_type<son_index>().indices().get<by_account>();
const auto &son_obj = son_idx.find(op.payer);
FC_ASSERT(son_obj != son_idx.end(), "SON object not found");
bool expected = false;
for (auto signer : sto_obj->signers) {
if (signer.first == son_obj->id) {
expected = !signer.second;
}
}
FC_ASSERT(expected, "Signer not expected");
FC_ASSERT(sto_obj->valid, "Transaction not valid");
FC_ASSERT(!sto_obj->complete, "Transaction signing completed");
FC_ASSERT(!sto_obj->sent, "Transaction already sent");
return void_result();
} FC_CAPTURE_AND_RETHROW( ( op ) ) }
object_id_type sidechain_transaction_sign_evaluator::do_apply(const sidechain_transaction_sign_operation &op)
{ try {
const auto &sto_idx = db().get_index_type<sidechain_transaction_index>().indices().get<by_id>();
auto sto_obj = sto_idx.find(op.sidechain_transaction_id);
const auto &son_idx = db().get_index_type<son_index>().indices().get<by_account>();
auto son_obj = son_idx.find(op.payer);
db().modify(*sto_obj, [&](sidechain_transaction_object &sto) {
sto.transaction = op.transaction;
sto.complete = op.complete;
for (size_t i = 0; i < sto.signers.size(); i++) {
if (sto.signers.at(i).first == son_obj->id) {
sto.signers.at(i).second = true;
}
}
});
db().modify(son_obj->statistics(db()), [&](son_statistics_object& sso) {
sso.txs_signed += 1;
});
return op.sidechain_transaction_id;
} FC_CAPTURE_AND_RETHROW( ( op ) ) }
void_result sidechain_transaction_send_evaluator::do_evaluate(const sidechain_transaction_send_operation &op)
{ try {
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); // can be removed after HF date pass
const auto &sto_idx = db().get_index_type<sidechain_transaction_index>().indices().get<by_id>();
const auto &sto_obj = sto_idx.find(op.sidechain_transaction_id);
FC_ASSERT(sto_obj != sto_idx.end(), "Sidechain transaction object not found");
FC_ASSERT(sto_obj->valid, "Transaction not valid");
FC_ASSERT(sto_obj->complete, "Transaction signing not complete");
FC_ASSERT(!sto_obj->sent, "Transaction already sent");
return void_result();
} FC_CAPTURE_AND_RETHROW( ( op ) ) }
object_id_type sidechain_transaction_send_evaluator::do_apply(const sidechain_transaction_send_operation &op)
{ try {
const auto &sto_idx = db().get_index_type<sidechain_transaction_index>().indices().get<by_id>();
auto sto_obj = sto_idx.find(op.sidechain_transaction_id);
db().modify(*sto_obj, [&](sidechain_transaction_object &sto) {
sto.sent = true;
});
return op.sidechain_transaction_id;
} FC_CAPTURE_AND_RETHROW( ( op ) ) }
} // namespace chain
} // namespace graphene

View file

@ -10,16 +10,10 @@
#include <graphene/chain/protocol/asset.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace peerplays_sidechain {
enum class sidechain_type {
bitcoin,
ethereum,
eos,
peerplays
};
using bytes = std::vector<unsigned char>;
struct prev_out {
@ -63,7 +57,7 @@ struct info_for_vin {
struct sidechain_event_data {
fc::time_point_sec timestamp;
sidechain_type sidechain;
chain::sidechain_type sidechain;
std::string sidechain_uid;
std::string sidechain_transaction_id;
std::string sidechain_from;
@ -76,5 +70,3 @@ struct sidechain_event_data {
};
}} // namespace graphene::peerplays_sidechain
FC_REFLECT_ENUM(graphene::peerplays_sidechain::sidechain_type, (bitcoin)(ethereum)(eos)(peerplays))

View file

@ -5,6 +5,7 @@
#include <graphene/chain/son_object.hpp>
namespace graphene { namespace peerplays_sidechain {
using namespace chain;
namespace detail {

View file

@ -15,7 +15,7 @@ public:
sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
virtual ~sidechain_net_handler();
graphene::peerplays_sidechain::sidechain_type get_sidechain();
sidechain_type get_sidechain();
std::vector<std::string> get_sidechain_deposit_addresses();
std::vector<std::string> get_sidechain_withdraw_addresses();
std::string get_private_key(std::string public_key);
@ -23,16 +23,21 @@ public:
void sidechain_event_data_received(const sidechain_event_data &sed);
void process_deposits();
void process_withdrawals();
void process_sidechain_transactions();
void send_sidechain_transactions();
void save_transaction();
virtual std::string recreate_primary_wallet() = 0;
virtual std::string process_deposit(const son_wallet_deposit_object &swdo) = 0;
virtual std::string process_withdrawal(const son_wallet_withdraw_object &swwo) = 0;
virtual std::string process_sidechain_transaction(const sidechain_transaction_object &sto, bool &complete) = 0;
virtual bool send_sidechain_transaction(const sidechain_transaction_object &sto) = 0;
protected:
peerplays_sidechain_plugin &plugin;
graphene::chain::database &database;
graphene::peerplays_sidechain::sidechain_type sidechain;
sidechain_type sidechain;
std::map<std::string, std::string> private_keys;

View file

@ -37,7 +37,7 @@ public:
std::vector<btc_txout> listunspent();
std::vector<btc_txout> listunspent_by_address_and_amount(const std::string &address, double transfer_amount);
std::string loadwallet(const std::string &filename);
void sendrawtransaction(const std::string &tx_hex);
bool sendrawtransaction(const std::string &tx_hex);
std::string signrawtransactionwithkey(const std::string &tx_hash, const std::string &private_key);
std::string signrawtransactionwithwallet(const std::string &tx_hash);
std::string unloadwallet(const std::string &filename);
@ -87,6 +87,8 @@ public:
std::string recreate_primary_wallet();
std::string process_deposit(const son_wallet_deposit_object &swdo);
std::string process_withdrawal(const son_wallet_withdraw_object &swwo);
std::string process_sidechain_transaction(const sidechain_transaction_object &sto, bool &complete);
bool send_sidechain_transaction(const sidechain_transaction_object &sto);
private:
std::string ip;
@ -101,16 +103,16 @@ private:
std::unique_ptr<zmq_listener> listener;
std::string create_transaction(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs);
std::string sign_transaction(const std::string &tx);
void send_transaction(const std::string &tx);
std::string sign_transaction(const std::string &tx, bool &complete);
bool send_transaction(const std::string &tx);
std::string create_transaction_raw(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs);
std::string create_transaction_psbt(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs);
std::string create_transaction_standalone(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs);
std::string sign_transaction_raw(const std::string &tx);
std::string sign_transaction_psbt(const std::string &tx);
std::string sign_transaction_standalone(const std::string &tx);
std::string sign_transaction_raw(const std::string &tx, bool &complete);
std::string sign_transaction_psbt(const std::string &tx, bool &complete);
std::string sign_transaction_standalone(const std::string &tx, bool &complete);
std::string transfer_all_btc(const std::string &from_address, const std::string &to_address);
std::string transfer_deposit_to_primary_wallet(const son_wallet_deposit_object &swdo);

View file

@ -16,6 +16,8 @@ public:
std::string recreate_primary_wallet();
std::string process_deposit(const son_wallet_deposit_object &swdo);
std::string process_withdrawal(const son_wallet_withdraw_object &swwo);
std::string process_sidechain_transaction(const sidechain_transaction_object &sto, bool &complete);
bool send_sidechain_transaction(const sidechain_transaction_object &sto);
private:
void on_applied_block(const signed_block &b);

View file

@ -1,6 +1,6 @@
#pragma once
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
#include <graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp>
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
@ -15,10 +15,12 @@ public:
sidechain_net_manager(peerplays_sidechain_plugin &_plugin);
virtual ~sidechain_net_manager();
bool create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map &options);
bool create_handler(sidechain_type sidechain, const boost::program_options::variables_map &options);
void recreate_primary_wallet();
void process_deposits();
void process_withdrawals();
void process_sidechain_transactions();
void send_sidechain_transactions();
private:
peerplays_sidechain_plugin &plugin;

View file

@ -49,6 +49,8 @@ public:
void recreate_primary_wallet();
void process_deposits();
void process_withdrawals();
void process_sidechain_transactions();
void send_sidechain_transactions();
private:
peerplays_sidechain_plugin &plugin;
@ -347,6 +349,8 @@ void peerplays_sidechain_plugin_impl::son_processing() {
process_deposits();
process_withdrawals();
process_sidechain_transactions();
}
}
@ -538,6 +542,14 @@ void peerplays_sidechain_plugin_impl::process_withdrawals() {
net_manager->process_withdrawals();
}
void peerplays_sidechain_plugin_impl::process_sidechain_transactions() {
net_manager->process_sidechain_transactions();
}
void peerplays_sidechain_plugin_impl::send_sidechain_transactions() {
net_manager->send_sidechain_transactions();
}
void peerplays_sidechain_plugin_impl::on_applied_block(const signed_block &b) {
if (first_block_skipped) {
schedule_son_processing();

View file

@ -1,13 +1,13 @@
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdraw_object.hpp>
#include <fc/log/logger.hpp>
namespace graphene {
namespace peerplays_sidechain {
namespace graphene { namespace peerplays_sidechain {
sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
plugin(_plugin),
@ -17,7 +17,7 @@ sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin
sidechain_net_handler::~sidechain_net_handler() {
}
graphene::peerplays_sidechain::sidechain_type sidechain_net_handler::get_sidechain() {
sidechain_type sidechain_net_handler::get_sidechain() {
return sidechain;
}
@ -178,9 +178,9 @@ void sidechain_net_handler::process_deposits() {
const chain::global_property_object &gpo = database.get_global_properties();
auto active_sons = gpo.active_sons;
std::vector<std::pair<son_id_type, bool>> signatures;
std::vector<son_id_type> signers;
for (const son_info &si : active_sons) {
signatures.push_back(std::make_pair(si.son_id, false));
signers.push_back(si.son_id);
}
sidechain_transaction_create_operation stc_op;
@ -190,7 +190,7 @@ void sidechain_net_handler::process_deposits() {
//stc_op.son_wallet_withdraw_id = ; // not set, not needed
stc_op.sidechain = sidechain;
stc_op.transaction = sidechain_tx;
stc_op.signatures = signatures;
stc_op.signers = signers;
son_wallet_deposit_process_operation swdp_op;
swdp_op.payer = GRAPHENE_SON_ACCOUNT;
@ -232,9 +232,9 @@ void sidechain_net_handler::process_withdrawals() {
const chain::global_property_object &gpo = database.get_global_properties();
auto active_sons = gpo.active_sons;
std::vector<std::pair<son_id_type, bool>> signatures;
std::vector<son_id_type> signers;
for (const son_info &si : active_sons) {
signatures.push_back(std::make_pair(si.son_id, false));
signers.push_back(si.son_id);
}
sidechain_transaction_create_operation stc_op;
@ -244,7 +244,7 @@ void sidechain_net_handler::process_withdrawals() {
stc_op.son_wallet_withdraw_id = swwo.id;
stc_op.sidechain = sidechain;
stc_op.transaction = sidechain_tx;
stc_op.signatures = signatures;
stc_op.signers = signers;
son_wallet_withdraw_process_operation swwp_op;
swwp_op.payer = GRAPHENE_SON_ACCOUNT;
@ -269,6 +269,69 @@ void sidechain_net_handler::process_withdrawals() {
});
}
void sidechain_net_handler::process_sidechain_transactions() {
const auto &idx = plugin.database().get_index_type<sidechain_transaction_index>().indices().get<by_sidechain_and_complete>();
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, false));
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
ilog("Sidechain transaction to process: ${sto}", ("sto", sto));
bool complete = false;
std::string processed_sidechain_tx = process_sidechain_transaction(sto, complete);
if (processed_sidechain_tx.empty()) {
ilog("Sidechain transaction not processed: ${sto}", ("sto", sto));
return;
}
sidechain_transaction_sign_operation sts_op;
sts_op.payer = plugin.get_son_object(plugin.get_current_son_id()).son_account;
sts_op.sidechain_transaction_id = sto.id;
sts_op.transaction = processed_sidechain_tx;
sts_op.complete = complete;
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), sts_op);
trx.validate();
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if (plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch (fc::exception e) {
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}", ("e", e.what()));
}
});
}
void sidechain_net_handler::send_sidechain_transactions() {
const auto &idx = plugin.database().get_index_type<sidechain_transaction_index>().indices().get<by_sidechain_and_complete_and_sent>();
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, true, false));
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
ilog("Sidechain transaction to send: ${sto}", ("sto", sto));
bool sent = send_sidechain_transaction(sto);
if (!sent) {
ilog("Sidechain transaction not sent: ${sto}", ("sto", sto));
return;
}
sidechain_transaction_send_operation sts_op;
sts_op.payer = plugin.get_son_object(plugin.get_current_son_id()).son_account;
sts_op.sidechain_transaction_id = sto.id;
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), sts_op);
trx.validate();
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if (plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch (fc::exception e) {
ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}", ("e", e.what()));
}
});
}
std::string sidechain_net_handler::recreate_primary_wallet() {
FC_ASSERT(false, "recreate_primary_wallet not implemented");
}
@ -280,5 +343,13 @@ std::string sidechain_net_handler::process_deposit(const son_wallet_deposit_obje
std::string sidechain_net_handler::process_withdrawal(const son_wallet_withdraw_object &swwo) {
FC_ASSERT(false, "process_withdrawal not implemented");
}
std::string sidechain_net_handler::process_sidechain_transaction(const sidechain_transaction_object &sto, bool &complete) {
FC_ASSERT(false, "process_sidechain_transaction not implemented");
}
} // namespace graphene::peerplays_sidechain
bool sidechain_net_handler::send_sidechain_transaction(const sidechain_transaction_object &sto) {
FC_ASSERT(false, "send_sidechain_transaction not implemented");
}
}} // namespace graphene::peerplays_sidechain

View file

@ -15,6 +15,7 @@
#include <graphene/chain/protocol/sidechain_transaction.hpp>
#include <graphene/chain/protocol/son_wallet.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_info.hpp>
#include <graphene/chain/son_wallet_object.hpp>
@ -483,7 +484,7 @@ std::string bitcoin_rpc_client::loadwallet(const std::string &filename) {
return "";
}
void bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) {
bool bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) {
const auto body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"sendrawtransaction\", "
"\"method\": \"sendrawtransaction\", \"params\": [") +
std::string("\"") + tx_hex + std::string("\"") + std::string("] }");
@ -492,7 +493,7 @@ void bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) {
if (reply.body.empty()) {
wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));
return;
return false;
}
std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
@ -500,14 +501,14 @@ void bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) {
boost::property_tree::read_json(ss, json);
if (reply.status == 200) {
return;
return true;
} else if (json.count("error") && !json.get_child("error").empty()) {
const auto error_code = json.get_child("error").get_child("code").get_value<int>();
if (error_code == -27) // transaction already in block chain
return;
return true;
wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str()));
}
return false;
}
std::string bitcoin_rpc_client::signrawtransactionwithkey(const std::string &tx_hash, const std::string &private_key) {
@ -830,7 +831,8 @@ std::string sidechain_net_handler_bitcoin::recreate_primary_wallet() {
std::string prev_pw_address = prev_sw_pt.get<std::string>("address");
tx = transfer_all_btc(prev_pw_address, active_pw_address);
sign_transaction(tx);
bool complete = false;
sign_transaction(tx, complete);
}
}
}
@ -839,15 +841,19 @@ std::string sidechain_net_handler_bitcoin::recreate_primary_wallet() {
}
std::string sidechain_net_handler_bitcoin::process_deposit(const son_wallet_deposit_object &swdo) {
std::string tx = transfer_deposit_to_primary_wallet(swdo);
sign_transaction(tx);
return tx;
return transfer_deposit_to_primary_wallet(swdo);
}
std::string sidechain_net_handler_bitcoin::process_withdrawal(const son_wallet_withdraw_object &swwo) {
std::string tx = transfer_withdrawal_from_primary_wallet(swwo);
sign_transaction(tx);
return tx;
return transfer_withdrawal_from_primary_wallet(swwo);
}
std::string sidechain_net_handler_bitcoin::process_sidechain_transaction(const sidechain_transaction_object &sto, bool &complete) {
return sign_transaction(sto.transaction, complete);
}
bool sidechain_net_handler_bitcoin::send_sidechain_transaction(const sidechain_transaction_object &sto) {
return send_transaction(sto.transaction);
}
// Creates transaction in any format
@ -862,16 +868,16 @@ std::string sidechain_net_handler_bitcoin::create_transaction(const std::vector<
// Adds signature to transaction
// Function to actually add signature should return transaction with added signature string, or empty string in case of failure
std::string sidechain_net_handler_bitcoin::sign_transaction(const std::string &tx) {
std::string sidechain_net_handler_bitcoin::sign_transaction(const std::string &tx, bool &complete) {
std::string new_tx = "";
//new_tx = sign_transaction_raw(tx);
new_tx = sign_transaction_psbt(tx);
//new_tx = sign_transaction_standalone(tx);
//new_tx = sign_transaction_raw(tx, complete);
new_tx = sign_transaction_psbt(tx, complete);
//new_tx = sign_transaction_standalone(tx, complete);
return new_tx;
}
void sidechain_net_handler_bitcoin::send_transaction(const std::string &tx) {
bitcoin_client->sendrawtransaction(tx);
bool sidechain_net_handler_bitcoin::send_transaction(const std::string &tx) {
return bitcoin_client->sendrawtransaction(tx);
}
std::string sidechain_net_handler_bitcoin::create_transaction_raw(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> outputs) {
@ -943,7 +949,7 @@ std::string sidechain_net_handler_bitcoin::create_transaction_standalone(const s
return "";
}
std::string sidechain_net_handler_bitcoin::sign_transaction_raw(const std::string &tx) {
std::string sidechain_net_handler_bitcoin::sign_transaction_raw(const std::string &tx, bool &complete) {
if (tx.empty()) {
wlog("Signing failed, tx string is empty");
return "";
@ -970,13 +976,13 @@ std::string sidechain_net_handler_bitcoin::sign_transaction_raw(const std::strin
if (complete_raw) {
std::string decoded_raw = bitcoin_client->decoderawtransaction(new_tx_raw);
send_transaction(new_tx_raw);
return "";
complete = true;
return new_tx_raw;
}
return new_tx_raw;
}
std::string sidechain_net_handler_bitcoin::sign_transaction_psbt(const std::string &tx) {
std::string sidechain_net_handler_bitcoin::sign_transaction_psbt(const std::string &tx, bool &complete) {
if (tx.empty()) {
wlog("Signing failed, tx string is empty");
return "";
@ -1019,14 +1025,15 @@ std::string sidechain_net_handler_bitcoin::sign_transaction_psbt(const std::stri
if (complete_raw) {
std::string decoded_raw = bitcoin_client->decoderawtransaction(new_tx_raw);
send_transaction(new_tx_raw);
return "";
complete = true;
return new_tx_raw;
}
}
return new_tx_psbt;
}
std::string sidechain_net_handler_bitcoin::sign_transaction_standalone(const std::string &tx) {
std::string sidechain_net_handler_bitcoin::sign_transaction_standalone(const std::string &tx, bool &complete) {
complete = true;
return "";
}

View file

@ -42,6 +42,15 @@ std::string sidechain_net_handler_peerplays::process_withdrawal(const son_wallet
return "";
}
std::string sidechain_net_handler_peerplays::process_sidechain_transaction(const sidechain_transaction_object &sto, bool &complete) {
complete = true;
return "";
}
bool sidechain_net_handler_peerplays::send_sidechain_transaction(const sidechain_transaction_object &sto) {
return true;
}
void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) {
for (const auto &trx : b.transactions) {
size_t operation_index = -1;

View file

@ -15,7 +15,7 @@ sidechain_net_manager::sidechain_net_manager(peerplays_sidechain_plugin &_plugin
sidechain_net_manager::~sidechain_net_manager() {
}
bool sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map &options) {
bool sidechain_net_manager::create_handler(sidechain_type sidechain, const boost::program_options::variables_map &options) {
bool ret_val = false;
@ -57,4 +57,16 @@ void sidechain_net_manager::process_withdrawals() {
}
}
void sidechain_net_manager::process_sidechain_transactions() {
for (size_t i = 0; i < net_handlers.size(); i++) {
net_handlers.at(i)->process_sidechain_transactions();
}
}
void sidechain_net_manager::send_sidechain_transactions() {
for (size_t i = 0; i < net_handlers.size(); i++) {
net_handlers.at(i)->send_sidechain_transactions();
}
}
}} // namespace graphene::peerplays_sidechain

View file

@ -1320,7 +1320,7 @@ class wallet_api
string url,
vesting_balance_id_type deposit_id,
vesting_balance_id_type pay_vb_id,
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast = false);
/**
@ -1335,7 +1335,7 @@ class wallet_api
signed_transaction update_son(string owner_account,
string url,
string block_signing_key,
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast = false);
@ -1422,7 +1422,7 @@ class wallet_api
* @returns the signed transaction adding sidechain address
*/
signed_transaction add_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
string deposit_address,
string withdraw_address,
bool broadcast = false);
@ -1439,7 +1439,7 @@ class wallet_api
* @returns the signed transaction updating sidechain address
*/
signed_transaction update_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
string deposit_address,
string withdraw_address,
bool broadcast = false);
@ -1452,7 +1452,7 @@ class wallet_api
* @returns the signed transaction updating sidechain address
*/
signed_transaction delete_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
bool broadcast = false);
/** Retrieves all sidechain addresses owned by given account.
@ -1467,7 +1467,7 @@ class wallet_api
* @param sidechain the name of the sidechain
* @returns the list of all sidechain addresses registered for a given sidechain.
*/
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain);
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_sidechain(sidechain_type sidechain);
/** Retrieves sidechain address owned by given account for a given sidechain.
*
@ -1475,7 +1475,7 @@ class wallet_api
* @param sidechain the name of the sidechain
* @returns the sidechain address owned by given account for a given sidechain.
*/
fc::optional<sidechain_address_object> get_sidechain_address_by_account_and_sidechain(string account, peerplays_sidechain::sidechain_type sidechain);
fc::optional<sidechain_address_object> get_sidechain_address_by_account_and_sidechain(string account, sidechain_type sidechain);
/** Retrieves the total number of sidechain addresses registered in the system.
*

View file

@ -73,7 +73,7 @@
#include <graphene/chain/rock_paper_scissors.hpp>
#include <graphene/bookie/bookie_api.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
#include <graphene/utilities/git_revision.hpp>
@ -1865,7 +1865,7 @@ public:
string url,
vesting_balance_id_type deposit_id,
vesting_balance_id_type pay_vb_id,
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast /* = false */)
{ try {
fc::scoped_lock<fc::mutex> lock(_resync_mutex);
@ -1899,7 +1899,7 @@ public:
signed_transaction update_son(string owner_account,
string url,
string block_signing_key,
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast /* = false */)
{ try {
son_object son = get_son(owner_account);
@ -2026,7 +2026,7 @@ public:
} FC_CAPTURE_AND_RETHROW() }
signed_transaction add_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
string deposit_address,
string withdraw_address,
bool broadcast /* = false */)
@ -2048,7 +2048,7 @@ public:
} FC_CAPTURE_AND_RETHROW() }
signed_transaction update_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
string deposit_address,
string withdraw_address,
bool broadcast /* = false */)
@ -2074,7 +2074,7 @@ public:
} FC_CAPTURE_AND_RETHROW() }
signed_transaction delete_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
bool broadcast /* = false */)
{ try {
account_id_type sidechain_address_account_id = get_account_id(account);
@ -4444,7 +4444,7 @@ signed_transaction wallet_api::create_son(string owner_account,
string url,
vesting_balance_id_type deposit_id,
vesting_balance_id_type pay_vb_id,
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast /* = false */)
{
return my->create_son(owner_account, url, deposit_id, pay_vb_id, sidechain_public_keys, broadcast);
@ -4453,7 +4453,7 @@ signed_transaction wallet_api::create_son(string owner_account,
signed_transaction wallet_api::update_son(string owner_account,
string url,
string block_signing_key,
flat_map<peerplays_sidechain::sidechain_type, string> sidechain_public_keys,
flat_map<sidechain_type, string> sidechain_public_keys,
bool broadcast /* = false */)
{
return my->update_son(owner_account, url, block_signing_key, sidechain_public_keys, broadcast);
@ -4501,7 +4501,7 @@ vector<optional<son_wallet_object>> wallet_api::get_son_wallets(uint32_t limit)
}
signed_transaction wallet_api::add_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
string deposit_address,
string withdraw_address,
bool broadcast /* = false */)
@ -4510,7 +4510,7 @@ signed_transaction wallet_api::add_sidechain_address(string account,
}
signed_transaction wallet_api::update_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
string deposit_address,
string withdraw_address,
bool broadcast /* = false */)
@ -4519,7 +4519,7 @@ signed_transaction wallet_api::update_sidechain_address(string account,
}
signed_transaction wallet_api::delete_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
sidechain_type sidechain,
bool broadcast /* = false */)
{
return my->delete_sidechain_address(account, sidechain, broadcast);
@ -4531,12 +4531,12 @@ vector<optional<sidechain_address_object>> wallet_api::get_sidechain_addresses_b
return my->_remote_db->get_sidechain_addresses_by_account(account_id);
}
vector<optional<sidechain_address_object>> wallet_api::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)
vector<optional<sidechain_address_object>> wallet_api::get_sidechain_addresses_by_sidechain(sidechain_type sidechain)
{
return my->_remote_db->get_sidechain_addresses_by_sidechain(sidechain);
}
fc::optional<sidechain_address_object> wallet_api::get_sidechain_address_by_account_and_sidechain(string account, peerplays_sidechain::sidechain_type sidechain)
fc::optional<sidechain_address_object> wallet_api::get_sidechain_address_by_account_and_sidechain(string account, sidechain_type sidechain)
{
account_id_type account_id = get_account_id(account);
return my->_remote_db->get_sidechain_address_by_account_and_sidechain(account_id, sidechain);

View file

@ -40,7 +40,7 @@ public:
}
void create_son(const std::string& account_name, const std::string& son_url,
flat_map<graphene::peerplays_sidechain::sidechain_type, string>& sidechain_public_keys,
flat_map<sidechain_type, string>& sidechain_public_keys,
bool generate_maintenance = true)
{
graphene::wallet::brain_key_info bki;
@ -112,16 +112,16 @@ BOOST_AUTO_TEST_CASE( create_sons )
BOOST_TEST_MESSAGE("SON cli wallet tests begin");
try
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
son_test_helper sth(*this);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1";
sth.create_son("son1account", "http://son1", sidechain_public_keys);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys);
auto son1_obj = con.wallet_api_ptr->get_son("son1account");
@ -146,10 +146,10 @@ BOOST_AUTO_TEST_CASE( cli_update_son )
{
BOOST_TEST_MESSAGE("Cli get_son and update_son Test");
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1";
son_test_helper sth(*this);
sth.create_son("sonmember", "http://sonmember", sidechain_public_keys);
@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE( cli_update_son )
// update SON
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2";
con.wallet_api_ptr->update_son("sonmember", "http://sonmember_updated", "", sidechain_public_keys, true);
son_data = con.wallet_api_ptr->get_son("sonmember");
@ -187,16 +187,16 @@ BOOST_AUTO_TEST_CASE( son_voting )
BOOST_TEST_MESSAGE("SON Vote cli wallet tests begin");
try
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
son_test_helper sth(*this);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1";
sth.create_son("son1account", "http://son1", sidechain_public_keys);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys);
BOOST_TEST_MESSAGE("Voting for SONs");
@ -266,16 +266,16 @@ BOOST_AUTO_TEST_CASE( delete_son )
BOOST_TEST_MESSAGE("SON delete cli wallet tests begin");
try
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
son_test_helper sth(*this);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1";
sth.create_son("son1account", "http://son1", sidechain_public_keys);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys);
BOOST_TEST_MESSAGE("Deleting SONs");
@ -314,13 +314,13 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture )
gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count;
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
// create son accounts
for(unsigned int i = 0; i < son_number + 1; i++)
{
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i);
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i);
sth.create_son("sonaccount" + fc::to_pretty_string(i),
"http://son" + fc::to_pretty_string(i),
sidechain_public_keys,
@ -385,16 +385,16 @@ BOOST_AUTO_TEST_CASE( list_son )
BOOST_TEST_MESSAGE("List SONs cli wallet tests begin");
try
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
son_test_helper sth(*this);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1";
sth.create_son("son1account", "http://son1", sidechain_public_keys);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys);
auto res = con.wallet_api_ptr->list_sons("", 100);
@ -415,16 +415,16 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests begin");
try
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
son_test_helper sth(*this);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1";
sth.create_son("son1account", "http://son1", sidechain_public_keys);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys);
BOOST_TEST_MESSAGE("Vote for 2 accounts with update_son_votes");
@ -572,16 +572,16 @@ BOOST_AUTO_TEST_CASE( related_functions )
global_property_object gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons.size() == 0);
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
son_test_helper sth(*this);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1";
sth.create_son("son1account", "http://son1", sidechain_public_keys);
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2";
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys);
gpo = con.wallet_api_ptr->get_global_properties();
@ -608,13 +608,13 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count;
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
// create son accounts
for(unsigned int i = 0; i < son_number + 1; i++)
{
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i);
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i);
sth.create_son("sonaccount" + fc::to_pretty_string(i),
"http://son" + fc::to_pretty_string(i),
sidechain_public_keys,
@ -674,13 +674,13 @@ BOOST_AUTO_TEST_CASE( maintenance_test )
gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count;
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
flat_map<sidechain_type, string> sidechain_public_keys;
// create son accounts
for(unsigned int i = 0; i < son_number + 1; i++)
{
sidechain_public_keys.clear();
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i);
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i);
sth.create_son("sonaccount" + fc::to_pretty_string(i),
"http://son" + fc::to_pretty_string(i),
sidechain_public_keys,

View file

@ -4,7 +4,7 @@
#include <graphene/chain/hardfork.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
using namespace graphene::chain;
using namespace graphene::chain::test;
@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) {
sidechain_address_add_operation op;
op.sidechain_address_account = alice_id;
op.sidechain = graphene::peerplays_sidechain::sidechain_type::bitcoin;
op.sidechain = sidechain_type::bitcoin;
op.deposit_address = "deposit_address";
op.withdraw_address = "withdraw_address";
@ -43,10 +43,10 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) {
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
BOOST_CHECK( obj->sidechain_address_account == alice_id );
BOOST_CHECK( obj->sidechain == graphene::peerplays_sidechain::sidechain_type::bitcoin );
BOOST_CHECK( obj->sidechain == sidechain_type::bitcoin );
BOOST_CHECK( obj->deposit_address == "deposit_address" );
BOOST_CHECK( obj->withdraw_address == "withdraw_address" );
}
@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) {
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
std::string new_deposit_address = "new_deposit_address";
@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) {
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
BOOST_CHECK( obj->sidechain_address_account == obj->sidechain_address_account );
BOOST_CHECK( obj->sidechain == obj->sidechain );
@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_delete_test ) {
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj != idx.end() );
{
@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_delete_test ) {
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
BOOST_REQUIRE( idx.size() == 0 );
auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) );
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
BOOST_REQUIRE( obj == idx.end() );
}
}

View file

@ -6,7 +6,7 @@
//#include <graphene/chain/sidechain_transaction_object.hpp>
//#include <graphene/chain/proposal_object.hpp>
//#include <graphene/chain/son_object.hpp>
//#include <graphene/peerplays_sidechain/defs.hpp>
//#include <graphene/chain/sidechain_defs.hpp>
//
//using namespace graphene;
//using namespace graphene::chain;
@ -76,8 +76,8 @@
//
// // alice becomes son
// {
// flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
// sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address";
// flat_map<sidechain_type, string> sidechain_public_keys;
// sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address";
//
// son_create_operation op;
// op.owner_account = alice_id;
@ -131,8 +131,8 @@
//
// // bob becomes son
// {
// flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
// sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address";
// flat_map<sidechain_type, string> sidechain_public_keys;
// sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address";
//
// son_create_operation op;
// op.owner_account = bob_id;

View file

@ -83,8 +83,8 @@ BOOST_AUTO_TEST_CASE( create_son_test ) {
// alice became son
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address";
flat_map<sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address";
son_create_operation op;
op.owner_account = alice_id;
@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE( create_son_test ) {
BOOST_REQUIRE( obj != idx.end() );
BOOST_CHECK( obj->url == test_url );
BOOST_CHECK( obj->signing_key == alice_public_key );
BOOST_CHECK( obj->sidechain_public_keys.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "bitcoin address" );
BOOST_CHECK( obj->sidechain_public_keys.at(sidechain_type::bitcoin) == "bitcoin address" );
BOOST_CHECK( obj->deposit.instance == deposit.instance.value );
BOOST_CHECK( obj->pay_vb.instance == payment.instance.value );
}
@ -118,8 +118,8 @@ BOOST_AUTO_TEST_CASE( update_son_test ) {
std::string new_url = "https://anewurl.com";
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "new bitcoin address";
flat_map<sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[sidechain_type::bitcoin] = "new bitcoin address";
son_update_operation op;
op.son_id = son_id_type(0);
@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE( update_son_test ) {
auto obj = idx.find( alice_id );
BOOST_REQUIRE( obj != idx.end() );
BOOST_CHECK( obj->url == new_url );
BOOST_CHECK( obj->sidechain_public_keys.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "new bitcoin address" );
BOOST_CHECK( obj->sidechain_public_keys.at(sidechain_type::bitcoin) == "new bitcoin address" );
}
BOOST_AUTO_TEST_CASE( delete_son_test ) {

View file

@ -4,7 +4,7 @@
#include <graphene/chain/hardfork.hpp>
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/chain/sidechain_defs.hpp>
using namespace graphene;
using namespace graphene::chain;
@ -71,8 +71,8 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
// alice becomes son
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address";
flat_map<sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address";
son_create_operation op;
op.owner_account = alice_id;
@ -126,8 +126,8 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
// bob becomes son
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address";
flat_map<sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address";
son_create_operation op;
op.owner_account = bob_id;
@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
si.son_id = son_id_type(0);
si.total_votes = 1000;
si.signing_key = alice_public_key;
si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = "";
si.sidechain_public_keys[sidechain_type::bitcoin] = "";
op.sons.push_back(si);
}
@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
si.son_id = son_id_type(1);
si.total_votes = 1000;
si.signing_key = bob_public_key;
si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = "";
si.sidechain_public_keys[sidechain_type::bitcoin] = "";
op.sons.push_back(si);
}
@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_update_test ) {
op.payer = GRAPHENE_SON_ACCOUNT;
op.son_wallet_id = son_wallet_id_type(0);
op.sidechain = graphene::peerplays_sidechain::sidechain_type::bitcoin;
op.sidechain = sidechain_type::bitcoin;
op.address = "bitcoin address";
trx.operations.push_back(op);
@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_update_test ) {
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find(son_wallet_id_type(0));
BOOST_REQUIRE( obj != idx.end() );
BOOST_REQUIRE( obj->addresses.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "bitcoin address" );
BOOST_REQUIRE( obj->addresses.at(sidechain_type::bitcoin) == "bitcoin address" );
}
}