Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from torkelrogstad/2023-11-07-mainchain
Browse files Browse the repository at this point in the history
mainchain: add options for configuring connection
  • Loading branch information
CryptAxe authored Nov 10, 2023
2 parents 7813d2d + 953c6f4 commit ab696f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ std::string HelpMessage(HelpMessageMode mode)
if (showDebug)
strUsage += HelpMessageOpt("-blockversion=<n>", "Override block version to test forking scenarios");

strUsage += HelpMessageGroup(_("Mainchain connection options:"));
strUsage += HelpMessageOpt("-mainchainrpcport=<port>", strprintf(_("Connect to mainchain on <port> (default: %u)"), defaultBaseParams->RPCPort()));
strUsage += HelpMessageOpt("-mainchainrpchost=<host>", strprintf(_("Connect to mainchain on <host> (default: localhost)")));
strUsage += HelpMessageOpt("-mainchainrpcuser=<user>", strprintf(_("Connect to mainchain with username <user> (default: value of -rpcuser)")));
strUsage += HelpMessageOpt("-mainchainrpcpassword=<pw>", strprintf(_("Connect to mainchain with password <pw> (default: value of -rpcpassword)")));

strUsage += HelpMessageGroup(_("RPC server options:"));
strUsage += HelpMessageOpt("-rest", strprintf(_("Accept public REST requests (default: %u)"), DEFAULT_REST_ENABLE));
strUsage += HelpMessageOpt("-rpcallowip=<ip>", _("Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times"));
Expand Down
12 changes: 8 additions & 4 deletions src/sidechainclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,11 @@ bool SidechainClient::HaveFailedWithdrawalBundle(const uint256& hash)

bool SidechainClient::SendRequestToMainchain(const std::string& json, boost::property_tree::ptree &ptree)
{
std::string username = gArgs.GetArg("-mainchainrpcuser", gArgs.GetArg("-rpcuser", ""));
std::string password = gArgs.GetArg("-mainchainrpcpassword", gArgs.GetArg("-rpcpassword", ""));

// Format user:pass for authentication
std::string auth = gArgs.GetArg("-rpcuser", "") + ":" + gArgs.GetArg("-rpcpassword", "");
std::string auth = username + ":" + password;
if (auth == ":")
return false;

Expand All @@ -702,13 +705,14 @@ bool SidechainClient::SendRequestToMainchain(const std::string& json, boost::pro
// Regtest RPC = 18443
//
bool fRegtest = gArgs.GetBoolArg("-regtest", false);
int port = fRegtest ? 18443 : 8332;
std::string port = gArgs.GetArg("-mainchainrpcport", fRegtest ? "18443" : "8332");
std::string host = gArgs.GetArg("-mainchainrpchost", "localhost");

try {
// Setup BOOST ASIO for a synchronus call to the mainchain
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query("127.0.0.1", std::to_string(port));
tcp::resolver::query query(host, port);
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;

Expand Down Expand Up @@ -779,7 +783,7 @@ bool SidechainClient::SendRequestToMainchain(const std::string& json, boost::pro
jss << JSON;
boost::property_tree::json_parser::read_json(jss, ptree);
} catch (std::exception &exception) {
LogPrintf("ERROR Sidechain client (sendRequestToMainchain): %s\n", exception.what());
LogPrintf("ERROR Sidechain client at %s:%d (sendRequestToMainchain): %s\n", host, port, exception.what());
return false;
}
return true;
Expand Down

0 comments on commit ab696f4

Please sign in to comment.