diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index cf864e66..5be07693 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -153,10 +153,11 @@ class database_api_impl : public std::enable_shared_from_this uint64_t get_son_count()const; // Sidechain addresses + vector> get_all_sidechain_addresses()const; vector> get_sidechain_addresses(const vector& sidechain_address_ids)const; vector> get_sidechain_addresses_by_account(account_id_type account)const; vector> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const; - fc::optional get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const; + fc::optional get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const; uint64_t get_sidechain_addresses_count()const; // Votes @@ -1776,6 +1777,22 @@ uint64_t database_api_impl::get_son_count()const // // ////////////////////////////////////////////////////////////////////// +vector> database_api::get_all_sidechain_addresses()const +{ + return my->get_all_sidechain_addresses(); +} + +vector> database_api_impl::get_all_sidechain_addresses()const +{ + vector> result; + const auto& idx = _db.get_index_type().indices().get(); + std::for_each(idx.begin(), idx.end(), + [&result] (const sidechain_address_object& sao) { + result.push_back(sao); + }); + return result; +} + vector> database_api::get_sidechain_addresses(const vector& sidechain_address_ids)const { return my->get_sidechain_addresses( sidechain_address_ids ); @@ -1800,9 +1817,12 @@ vector> database_api::get_sidechain_addresses vector> database_api_impl::get_sidechain_addresses_by_account(account_id_type account)const { - //const auto& idx = _db.get_index_type().indices().get(); - vector> result; + const auto& sidechain_addresses_range = _db.get_index_type().indices().get().equal_range(account); + std::for_each(sidechain_addresses_range.first, sidechain_addresses_range.second, + [&result] (const sidechain_address_object& sao) { + result.push_back(sao); + }); return result; } @@ -1813,18 +1833,21 @@ vector> database_api::get_sidechain_addresses vector> database_api_impl::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const { - //const auto& idx = _db.get_index_type().indices().get(); - vector> result; + const auto& sidechain_addresses_range = _db.get_index_type().indices().get().equal_range(sidechain); + std::for_each(sidechain_addresses_range.first, sidechain_addresses_range.second, + [&result] (const sidechain_address_object& sao) { + result.push_back(sao); + }); return result; } -fc::optional database_api::get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const +fc::optional database_api::get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const { - return my->get_sidechain_addresses_by_account_and_sidechain( account, sidechain ); + return my->get_sidechain_address_by_account_and_sidechain( account, sidechain ); } -fc::optional database_api_impl::get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const +fc::optional database_api_impl::get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const { const auto& idx = _db.get_index_type().indices().get(); auto itr = idx.find( boost::make_tuple( account, sidechain ) ); diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 9f6e8c34..9ccbb2ed 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -607,9 +607,17 @@ class database_api // Sidechain Addresses // ///////////////////////// + /** + * @brief Get a list of all sidechain addresses + * @return The list of all sidechain accounts + * + * This function has semantics identical to @ref get_objects + */ + vector> get_all_sidechain_addresses()const; + /** * @brief Get a list of sidechain addresses - * @param sidechain_address_ids IDs of the sidechain accounts to retrieve + * @param sidechain_address_ids IDs of the sidechain addresses to retrieve * @return The sidechain accounts corresponding to the provided IDs * * This function has semantics identical to @ref get_objects @@ -636,7 +644,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 get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const; + fc::optional get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const; /** * @brief Get the total number of sidechain addresses registered with the blockchain @@ -856,10 +864,11 @@ FC_API(graphene::app::database_api, (get_son_count) // Sidechain addresses + (get_all_sidechain_addresses) (get_sidechain_addresses) (get_sidechain_addresses_by_account) (get_sidechain_addresses_by_sidechain) - (get_sidechain_addresses_by_account_and_sidechain) + (get_sidechain_address_by_account_and_sidechain) (get_sidechain_addresses_count) // workers diff --git a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp index 5ba00680..8c77fad2 100644 --- a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp @@ -35,16 +35,17 @@ namespace graphene { namespace chain { struct by_account; struct by_sidechain; struct by_account_and_sidechain; + struct by_sidechain_and_address; using sidechain_address_multi_index_type = multi_index_container< sidechain_address_object, indexed_by< ordered_unique< tag, member >, - ordered_unique< tag, + ordered_non_unique< tag, member >, - ordered_unique< tag, + ordered_non_unique< tag, member >, ordered_unique< tag, @@ -52,6 +53,12 @@ namespace graphene { namespace chain { member, member > + >, + ordered_unique< tag, + composite_key, + member + > > > >; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp index 556ed3e4..ad2ffdc6 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -10,12 +11,13 @@ namespace graphene { namespace peerplays_sidechain { class sidechain_net_handler { public: - sidechain_net_handler(const boost::program_options::variables_map& options); + sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map& options); virtual ~sidechain_net_handler(); - std::vector get_user_sidechain_address_mapping(); + std::vector get_sidechain_addresses(); protected: + peerplays_sidechain_plugin &plugin; graphene::peerplays_sidechain::sidechain_type sidechain; virtual std::string create_multisignature_wallet( const std::vector public_keys ) = 0; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp index 792aaf45..cbdcfbef 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp @@ -56,7 +56,7 @@ private: class sidechain_net_handler_bitcoin : public sidechain_net_handler { public: - sidechain_net_handler_bitcoin(const boost::program_options::variables_map& options); + sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map& options); virtual ~sidechain_net_handler_bitcoin(); void update_tx_infos( const std::string& block_hash ); diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp index 3eb48263..33c45ec7 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -11,12 +12,12 @@ namespace graphene { namespace peerplays_sidechain { class sidechain_net_manager { public: - sidechain_net_manager(); + 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); private: - + peerplays_sidechain_plugin &plugin; std::vector> net_handlers; }; diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 1d51a0c2..c3f4d48f 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -14,8 +14,9 @@ namespace detail class peerplays_sidechain_plugin_impl { public: - peerplays_sidechain_plugin_impl(peerplays_sidechain_plugin& _plugin) - : _self( _plugin ) + peerplays_sidechain_plugin_impl(peerplays_sidechain_plugin& _plugin) : + _self( _plugin ), + _net_manager( _plugin ) { } virtual ~peerplays_sidechain_plugin_impl(); @@ -77,9 +78,10 @@ void peerplays_sidechain_plugin::plugin_initialize(const boost::program_options: { ilog("peerplays sidechain plugin: plugin_initialize()"); - if( options.count( "bitcoin-node-ip" ) && options.count( "bitcoin-node-zmq-port" ) && options.count( "bitcoin-node-rpc-port" ) - && options.count( "bitcoin-node-rpc-user" ) && options.count( "bitcoin-node-rpc-password" ) - && options.count( "bitcoin-address" ) && options.count( "bitcoin-public-key" ) && options.count( "bitcoin-private-key" ) ) + if ( options.count( "son-id" ) && options.count( "peerplays-private-key" ) + && options.count( "bitcoin-node-ip" ) && options.count( "bitcoin-node-zmq-port" ) && options.count( "bitcoin-node-rpc-port" ) + && options.count( "bitcoin-node-rpc-user" ) && options.count( "bitcoin-node-rpc-password" ) + && options.count( "bitcoin-address" ) && options.count( "bitcoin-public-key" ) && options.count( "bitcoin-private-key" ) ) { my->_net_manager.create_handler(sidechain_type::bitcoin, options); } else { diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index 6bdd1b03..92da90b8 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -1,29 +1,31 @@ #include +#include + +#include + namespace graphene { namespace peerplays_sidechain { -sidechain_net_handler::sidechain_net_handler(const boost::program_options::variables_map& options) { +sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map& options) : + plugin( _plugin ) { } sidechain_net_handler::~sidechain_net_handler() { } -std::vector sidechain_net_handler::get_user_sidechain_address_mapping() { +std::vector sidechain_net_handler::get_sidechain_addresses() { std::vector result; switch (sidechain) { case sidechain_type::bitcoin: - result.push_back("2N5aFW5WFaYZLuJWx9RGziHBdEMj9Zf8s3J"); - result.push_back("2MxAnE469fhhdvUqUB7daU997VSearb2mn7"); - result.push_back("2NAYptFvTU8vJ1pC7CxvVA9R7D3NdBJHpwL"); - result.push_back("2N9zPaLDfaJazUmVfr3wgn8BK75tid2kkzR"); - result.push_back("2NDN7cDH3E57E1B8TwTYvBgF7CndL4FTBPL"); - //result.push_back("2MzEmSiwrRzozxE6gfZ14LAyDHZ4DYP1zVG"); - //result.push_back("2NDCdm1WVJVCMWJzRaSSy9NDvpNKiqkbrMg"); - //result.push_back("2Mu2iz3Jfqjyv3hBQGQZSGmZGZxhJp91TNX"); - //result.push_back("2N1sFbwcn4QVbvjp7yRsN4mg4mBFbvC8gKM"); - //result.push_back("2NDmxr6ufBE7Zgdgq9hShF2grx2YPEiTyNy"); - + { + const auto& sidechain_addresses_range = plugin.database().get_index_type().indices().get().equal_range(sidechain); + std::for_each(sidechain_addresses_range.first, sidechain_addresses_range.second, + [&result] (const sidechain_address_object& sao) { + result.push_back(sao.address); + }); + break; + } default: assert(false); } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index deb528b8..63f1441d 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -178,17 +178,17 @@ void zmq_listener::handle_zmq() { while ( true ) { auto msg = receive_multipart(); const auto header = std::string( static_cast( msg[0].data() ), msg[0].size() ); - const auto hash = boost::algorithm::hex( std::string( static_cast( msg[1].data() ), msg[1].size() ) ); + const auto block_hash = boost::algorithm::hex( std::string( static_cast( msg[1].data() ), msg[1].size() ) ); - event_received( hash ); + event_received( block_hash ); } } // ============================================================================= -sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(const boost::program_options::variables_map& options) : - sidechain_net_handler(options) { - sidechain = sidechain_type::bitcoin; +sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map& options) : + sidechain_net_handler(plugin, options) { + sidechain = sidechain_type::bitcoin; ip = options.at("bitcoin-node-ip").as(); zmq_port = options.at("bitcoin-node-zmq-port").as(); @@ -302,6 +302,9 @@ std::string sidechain_net_handler_bitcoin::send_transaction( const std::string& void sidechain_net_handler_bitcoin::handle_event( const std::string& event_data ) { ilog("peerplays sidechain plugin: sidechain_net_handler_bitcoin::handle_event"); ilog(" event_data: ${event_data}", ("event_data", event_data)); + + update_tx_infos( event_data ); + //update_tx_approvals(); //update_estimated_fee(); //update_tx_infos( block_hash ); @@ -315,7 +318,7 @@ std::vector sidechain_net_handler_bitcoin::extract_info_from_block std::vector result; - const auto& addr_idx = get_user_sidechain_address_mapping();// db->get_index_type().indices().get(); + const auto& addr_idx = get_sidechain_addresses();// db->get_index_type().indices().get(); for (const auto& tx_child : block.get_child("tx")) { const auto& tx = tx_child.second; @@ -327,14 +330,18 @@ std::vector sidechain_net_handler_bitcoin::extract_info_from_block for (const auto& addr : script.get_child("addresses")) { // in which cases there can be more addresses? const auto address_base58 = addr.second.get_value(); + ilog(" address_base58: ${address_base58}", ("address_base58", address_base58)); auto it = find(addr_idx.begin(), addr_idx.end(), address_base58); if (it == addr_idx.end()) continue; + ilog(" address_base58 found: ${address_base58}", ("address_base58", address_base58)); info_for_vin vin; vin.out.hash_tx = tx.get_child("txid").get_value(); vin.out.amount = parse_amount( o.second.get_child( "value" ).get_value() ); + ilog(" amount: ${amount}", ("amount", vin.out.amount)); vin.out.n_vout = o.second.get_child( "n" ).get_value(); + ilog(" n_vout: ${n_vout}", ("n_vout", vin.out.n_vout)); vin.address = address_base58; result.push_back( vin ); } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp index aa118075..382241cd 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp @@ -5,7 +5,9 @@ namespace graphene { namespace peerplays_sidechain { -sidechain_net_manager::sidechain_net_manager() { +sidechain_net_manager::sidechain_net_manager(peerplays_sidechain_plugin &_plugin) : + plugin(_plugin) +{ ilog(__FUNCTION__); } @@ -20,7 +22,7 @@ bool sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type s switch (sidechain) { case sidechain_type::bitcoin: { - std::unique_ptr h = std::unique_ptr(new sidechain_net_handler_bitcoin(options)); + std::unique_ptr h = std::unique_ptr(new sidechain_net_handler_bitcoin(plugin, options)); net_handlers.push_back(std::move(h)); ret_val = true; break; diff --git a/libraries/wallet/CMakeLists.txt b/libraries/wallet/CMakeLists.txt index 8c9f8790..382adda1 100644 --- a/libraries/wallet/CMakeLists.txt +++ b/libraries/wallet/CMakeLists.txt @@ -23,7 +23,7 @@ else() endif() add_library( graphene_wallet wallet.cpp ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp ${HEADERS} ) -target_link_libraries( graphene_wallet PRIVATE graphene_app graphene_net graphene_chain graphene_utilities fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) +target_link_libraries( graphene_wallet PRIVATE graphene_app graphene_net graphene_chain graphene_utilities fc peerplays_sidechain ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) target_include_directories( graphene_db PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) if(MSVC) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 6a78d8d3..e42c1108 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1368,6 +1368,89 @@ class wallet_api */ map list_active_sons(); + /** Adds sidechain address owned by the given account for a given sidechain. + * + * An account can have at most one sidechain address for one sidechain. + * + * @param account the name or id of the account who owns the address + * @param sidechain a sidechain to whom address belongs + * @param address sidechain address + * @param private_key private key for sidechain address + * @param public_key public key for sidechain address + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction adding sidechain address + */ + signed_transaction add_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + string address, + string private_key, + string public_key, + bool broadcast = false); + + /** Updates existing sidechain address owned by the given account for a given sidechain. + * + * Only address, private key and public key might be updated. + * + * @param account the name or id of the account who owns the address + * @param sidechain a sidechain to whom address belongs + * @param address sidechain address + * @param private_key private key for sidechain address + * @param public_key public key for sidechain address + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction updating sidechain address + */ + signed_transaction update_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + string address, + string private_key, + string public_key, + bool broadcast = false); + + /** Deletes existing sidechain address owned by the given account for a given sidechain. + * + * @param account the name or id of the account who owns the address + * @param sidechain a sidechain to whom address belongs + * @param broadcast true to broadcast the transaction on the network + * @returns the signed transaction updating sidechain address + */ + signed_transaction delete_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + bool broadcast = false); + + /** Retrieves all sidechain addresses registered in the system. + * + * @returns the list of all sidechain addresses registered in the system + */ + vector> get_all_sidechain_addresses (); + + /** Retrieves all sidechain addresses owned by given account. + * + * @param account the name or id of the account who owns the address + * @returns the list of all sidechain addresses owned by given account. + */ + vector> get_sidechain_addresses_by_account(string account); + + /** Retrieves all sidechain addresses registered for a given sidechain. + * + * @param sidechain the name of the sidechain + * @returns the list of all sidechain addresses registered for a given sidechain. + */ + vector> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain); + + /** Retrieves sidechain address owned by given account for a given sidechain. + * + * @param account the name or id of the account who owns the address + * @param sidechain the name of the sidechain + * @returns the sidechain address owned by given account for a given sidechain. + */ + fc::optional get_sidechain_address_by_account_and_sidechain(string account, peerplays_sidechain::sidechain_type sidechain); + + /** Retrieves the total number of sidechain addresses registered in the system. + * + * @returns the total number of sidechain addresses registered in the system. + */ + uint64_t get_sidechain_addresses_count(); + /** Creates a witness object owned by the given account. * * An account can have at most one witness object. @@ -2121,6 +2204,14 @@ FC_API( graphene::wallet::wallet_api, (update_son) (delete_son) (list_sons) + (add_sidechain_address) + (update_sidechain_address) + (delete_sidechain_address) + (get_all_sidechain_addresses) + (get_sidechain_addresses_by_account) + (get_sidechain_addresses_by_sidechain) + (get_sidechain_address_by_account_and_sidechain) + (get_sidechain_addresses_count) (create_witness) (update_witness) (create_worker) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index f7cc2a51..620304be 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -73,6 +73,7 @@ #include #include +#include #include #include @@ -1954,6 +1955,73 @@ public: return result; } FC_CAPTURE_AND_RETHROW() } + signed_transaction add_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + string address, + string private_key, + string public_key, + bool broadcast /* = false */) + { try { + account_id_type sidechain_address_account_id = get_account_id(account); + + sidechain_address_add_operation op; + op.sidechain_address_account = sidechain_address_account_id; + op.sidechain = sidechain; + op.address = address; + op.private_key = private_key; + op.public_key = public_key; + + signed_transaction tx; + tx.operations.push_back( op ); + set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); + tx.validate(); + + return sign_transaction( tx, broadcast ); + } FC_CAPTURE_AND_RETHROW() } + + signed_transaction update_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + string address, + string private_key, + string public_key, + bool broadcast /* = false */) + { try { + account_id_type sidechain_address_account_id = get_account_id(account); + + sidechain_address_update_operation op; + op.sidechain_address_account = sidechain_address_account_id; + op.sidechain = sidechain; + op.address = address; + op.private_key = private_key; + op.public_key = public_key; + + signed_transaction tx; + tx.operations.push_back( op ); + set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); + tx.validate(); + + return sign_transaction( tx, broadcast ); + } FC_CAPTURE_AND_RETHROW() } + + signed_transaction delete_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + bool broadcast /* = false */) + { try { + account_id_type sidechain_address_account_id = get_account_id(account); + + sidechain_address_delete_operation op; + op.sidechain_address_account = sidechain_address_account_id; + op.sidechain = sidechain; + + signed_transaction tx; + tx.operations.push_back( op ); + set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees); + tx.validate(); + + return sign_transaction( tx, broadcast ); + + } FC_CAPTURE_AND_RETHROW() } + signed_transaction create_witness(string owner_account, string url, bool broadcast /* = false */) @@ -4330,6 +4398,60 @@ map wallet_api::list_active_sons() return my->list_active_sons(); } +signed_transaction wallet_api::add_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + string address, + string private_key, + string public_key, + bool broadcast /* = false */) +{ + return my->add_sidechain_address(account, sidechain, address, private_key, public_key, broadcast); +} + +signed_transaction wallet_api::update_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + string address, + string private_key, + string public_key, + bool broadcast /* = false */) +{ + return my->update_sidechain_address(account, sidechain, address, private_key, public_key, broadcast); +} + +signed_transaction wallet_api::delete_sidechain_address(string account, + peerplays_sidechain::sidechain_type sidechain, + bool broadcast /* = false */) +{ + return my->delete_sidechain_address(account, sidechain, broadcast); +} + +vector> wallet_api::get_all_sidechain_addresses () +{ + return my->_remote_db->get_all_sidechain_addresses(); +} + +vector> wallet_api::get_sidechain_addresses_by_account(string account) +{ + account_id_type account_id = get_account_id(account); + return my->_remote_db->get_sidechain_addresses_by_account(account_id); +} + +vector> wallet_api::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain) +{ + return my->_remote_db->get_sidechain_addresses_by_sidechain(sidechain); +} + +fc::optional wallet_api::get_sidechain_address_by_account_and_sidechain(string account, peerplays_sidechain::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); +} + +uint64_t wallet_api::get_sidechain_addresses_count() +{ + return my->_remote_db->get_sidechain_addresses_count(); +} + signed_transaction wallet_api::create_witness(string owner_account, string url, bool broadcast /* = false */)