get network type with rpc call
This commit is contained in:
parent
d91008ecb7
commit
00569f84b5
3 changed files with 69 additions and 8 deletions
|
|
@ -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<std::string> public_keys);
|
||||
std::string combinepsbt(const vector<std::string> &psbts);
|
||||
std::string createmultisig(const uint32_t nrequired, const std::vector<std::string> public_keys);
|
||||
std::string createpsbt(const std::vector<btc_txout> &ins, const fc::flat_map<std::string, double> outs);
|
||||
std::string convertrawtopsbt(const std::string &hex);
|
||||
std::string createrawtransaction(const std::vector<btc_txout> &ins, const fc::flat_map<std::string, double> outs);
|
||||
std::string createwallet(const std::string &wallet_name);
|
||||
std::string decodepsbt(std::string const &tx_psbt);
|
||||
|
|
|
|||
|
|
@ -182,6 +182,34 @@ std::string bitcoin_rpc_client::createpsbt(const std::vector<btc_txout> &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<std::string>("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<btc_txout> &ins, const fc::flat_map<std::string, double> outs) {
|
||||
std::string body("{\"jsonrpc\": \"1.0\", \"id\":\"createrawtransaction\", "
|
||||
"\"method\": \"createrawtransaction\", \"params\": [");
|
||||
|
|
@ -688,6 +716,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<std::string>();
|
||||
}
|
||||
|
||||
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\": [] }");
|
||||
|
|
@ -1397,8 +1454,8 @@ std::string sidechain_net_handler_bitcoin::create_multisig_address(const std::ve
|
|||
std::string sidechain_net_handler_bitcoin::create_transaction(const std::vector<btc_txout> &inputs, const fc::flat_map<std::string, double> 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;
|
||||
}
|
||||
|
||||
|
|
@ -1703,7 +1760,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, bool &complete) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue