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 350f7666..9e7b1917 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 @@ -21,10 +21,12 @@ class bitcoin_rpc_client { public: bitcoin_rpc_client(std::string _ip, uint32_t _rpc, std::string _user, std::string _password, std::string _wallet, std::string _wallet_password); + std::string getnetworktype(); std::string addmultisigaddress(const uint32_t nrequired, const std::vector public_keys); std::string combinepsbt(const vector &psbts); std::string createmultisig(const uint32_t nrequired, const std::vector public_keys); std::string createpsbt(const std::vector &ins, const fc::flat_map outs); + std::string convertrawtopsbt(const std::string &hex); std::string createrawtransaction(const std::vector &ins, const fc::flat_map outs); std::string createwallet(const std::string &wallet_name); std::string decodepsbt(std::string const &tx_psbt); diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 2fae5a13..57cd116a 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -182,6 +182,34 @@ std::string bitcoin_rpc_client::createpsbt(const std::vector &ins, co return ""; } +std::string bitcoin_rpc_client::convertrawtopsbt(const std::string &hex) { + std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"converttopsbt\", \"method\": " + "\"converttopsbt\", \"params\": [\"" + + hex + "\"] }"); + + const auto reply = send_post_request(body); + + if (reply.body.empty()) { + wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); + return ""; + } + + std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); + boost::property_tree::ptree json; + boost::property_tree::read_json(ss, json); + + if (reply.status == 200) { + if (json.find("result") != json.not_found()) { + return json.get("result"); + } + } + + if (json.count("error") && !json.get_child("error").empty()) { + wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); + } + return ""; +} + std::string bitcoin_rpc_client::createrawtransaction(const std::vector &ins, const fc::flat_map outs) { std::string body("{\"jsonrpc\": \"1.0\", \"id\":\"createrawtransaction\", " "\"method\": \"createrawtransaction\", \"params\": ["); @@ -687,6 +715,35 @@ std::string bitcoin_rpc_client::unloadwallet(const std::string &filename) { return ""; } +std::string bitcoin_rpc_client::getnetworktype() +{ + std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": " + "\"getblockchaininfo\", \"params\": [] }"); + + const auto reply = send_post_request(body); + + if (reply.body.empty()) { + wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); + return ""; + } + + std::stringstream ss(std::string(reply.body.begin(), reply.body.end())); + boost::property_tree::ptree json; + boost::property_tree::read_json(ss, json); + + if (reply.status == 200) { + auto reply = json.get_child("result"); + if (!reply.count("chain")) + return ""; + return reply.get_child("chain").get_value(); + } + + if (json.count("error") && !json.get_child("error").empty()) { + wlog("Bitcoin RPC call ${function} with body ${body} failed with reply '${msg}'", ("function", __FUNCTION__)("body", body)("msg", ss.str())); + } + return ""; +} + std::string bitcoin_rpc_client::walletlock() { std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"walletlock\", \"method\": " "\"walletlock\", \"params\": [] }"); @@ -1392,8 +1449,8 @@ std::string sidechain_net_handler_bitcoin::create_multisig_address(const std::ve std::string sidechain_net_handler_bitcoin::create_transaction(const std::vector &inputs, const fc::flat_map outputs) { std::string new_tx = ""; //new_tx = create_transaction_raw(inputs, outputs); - new_tx = create_transaction_psbt(inputs, outputs); - //new_tx = create_transaction_standalone(inputs, outputs); + //new_tx = create_transaction_psbt(inputs, outputs); + new_tx = create_transaction_standalone(inputs, outputs); return new_tx; } @@ -1696,7 +1753,7 @@ std::string sidechain_net_handler_bitcoin::create_transaction_standalone(const s } libbitcoin::data_chunk dc = tx.to_data(); - return fc::to_hex((char*)&dc[0], dc.size()); + return bitcoin_client->convertrawtopsbt(fc::to_hex((char*)&dc[0], dc.size())); } std::string sidechain_net_handler_bitcoin::sign_transaction_raw(const sidechain_transaction_object &sto) { diff --git a/programs/witness_node/genesis.json b/programs/witness_node/genesis.json index 6ed0a612..845c829b 100644 --- a/programs/witness_node/genesis.json +++ b/programs/witness_node/genesis.json @@ -1,5 +1,5 @@ { - "initial_timestamp": "2020-01-13T06:03:15", + "initial_timestamp": "2020-03-03T03:03:03", "max_core_supply": "1000000000000000", "initial_parameters": { "current_fees": { @@ -333,9 +333,9 @@ "scale": 10000 }, "block_interval": 3, - "maintenance_interval": 86400, + "maintenance_interval": 120, "maintenance_skip_slots": 3, - "committee_proposal_review_period": 1209600, + "committee_proposal_review_period": 600, "maximum_transaction_size": 2048, "maximum_block_size": 1228800000, "maximum_time_until_expiration": 86400, @@ -388,7 +388,8 @@ "son_pay_time": 86400, "son_deregister_time": 43200, "son_heartbeat_frequency": 180, - "son_down_time": 360 + "son_down_time": 360, + "son_bitcoin_min_tx_confirmations": 1 } }, "initial_bts_accounts": [], @@ -527,7 +528,8 @@ "immutable_parameters": { "min_committee_member_count": 11, "min_witness_count": 11, + "min_son_count": 5, "num_special_accounts": 0, "num_special_assets": 0 } -} +} \ No newline at end of file