diff --git a/libraries/plugins/peerplays_sidechain/bitcoin_utils.cpp b/libraries/plugins/peerplays_sidechain/bitcoin_utils.cpp index 7064ebc9..c330263c 100644 --- a/libraries/plugins/peerplays_sidechain/bitcoin_utils.cpp +++ b/libraries/plugins/peerplays_sidechain/bitcoin_utils.cpp @@ -89,4 +89,9 @@ std::string p2sh_address_from_redeem_script(const bytes& script, bitcoin_network return fc::to_base58(reinterpret_cast(&data[0]), data.size()); } +bytes sign_raw_transaction(const bytes& unsigned_tx, const fc::ecc::private_key& priv_key) +{ + return bytes(); +} + }} diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin_utils.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin_utils.hpp index 4b69ff44..e9f2bfdb 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin_utils.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/bitcoin_utils.hpp @@ -11,5 +11,6 @@ enum bitcoin_network { bytes generate_redeem_script(fc::flat_map key_data); std::string p2sh_address_from_redeem_script(const bytes& script, bitcoin_network network = mainnet); +bytes sign_raw_transaction(const bytes& unsigned_tx, const fc::ecc::private_key& priv_key); }} 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 46a680be..9768066b 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 @@ -31,6 +31,7 @@ public: bool connection_is_not_defined() const; void import_address( const std::string& address_or_script); std::vector list_unspent(); + std::string prepare_tx(const std::vector& ins, const fc::flat_map outs); private: diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 1c6c446f..87327991 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -238,6 +238,55 @@ std::vector bitcoin_rpc_client::list_unspent() return result; } +std::string bitcoin_rpc_client::prepare_tx(const std::vector &ins, const fc::flat_map outs) +{ + std::string body("{\"jsonrpc\": \"1.0\", \"id\":\"pp_plugin\", \"method\": \"createrawtransaction\", \"params\": ["); + body += "["; + bool first = true; + for(const auto& entry: ins) + { + if(!first) + body += ","; + body += "{\"txid\":\"" + entry.txid_ + "\",\"vout\":\"" + fc::to_string(entry.out_num_) + "\"}"; + first = false; + } + body += "]"; + first = true; + body += "{"; + for(const auto& entry: outs) + { + if(!first) + body += ","; + body += "\"" + entry.first + "\":\"" + fc::to_string(entry.second) + "\""; + first = false; + } + body += "}"; + body += std::string("] }"); + + const auto reply = send_post_request( body ); + + if( reply.body.empty() ) + { + wlog("Failed to create raw transaction: [${body}]", ("body", body)); + return std::string(); + } + + std::string reply_str( reply.body.begin(), reply.body.end() ); + + std::stringstream ss(reply_str); + boost::property_tree::ptree json; + boost::property_tree::read_json( ss, json ); + + if( reply.status == 200 ) { + idump((reply_str)); + if( json.count( "result" ) ) + return json.get_child("result").get_value(); + } else if( json.count( "error" ) && !json.get_child( "error" ).empty() ) { + wlog( "Failed to create raw transaction: [${body}]! Reply: ${msg}", ("body", body)("msg", reply_str) ); + } + return std::string(); +} + fc::http::reply bitcoin_rpc_client::send_post_request( std::string body ) { fc::http::connection conn;