Rework CallRPC, use bitcoind cookie auth

This commit is contained in:
instagibbs 2016-06-03 09:12:39 -04:00 committed by Gregory Sanders
parent f1878a4462
commit bab5e9ef7c
5 changed files with 60 additions and 11 deletions

View file

@ -75,6 +75,16 @@ boost::filesystem::path GetAuthCookieFile()
return path;
}
boost::filesystem::path GetMainchainAuthCookieFile()
{
boost::filesystem::path path(GetArg("-mainchainrpccookiefile", COOKIEAUTH_FILE));
//Change to default false for live network
if (!path.is_complete() && GetBoolArg("-testnet", true)) path = "testnet3" / path;
if (!path.is_complete() && GetBoolArg("-regtest", false)) path = "regtest" / path;
if (!path.is_complete()) path = GetDataDir(false) / path;
return path;
}
bool GenerateAuthCookie(std::string *cookie_out)
{
const size_t COOKIE_SIZE = 32;
@ -117,6 +127,23 @@ bool GetAuthCookie(std::string *cookie_out)
return true;
}
bool GetMainchainAuthCookie(std::string *cookie_out)
{
std::ifstream file;
std::string cookie;
boost::filesystem::path filepath = GetMainchainAuthCookieFile();
file.open(filepath.string().c_str());
if (!file.is_open())
return false;
std::getline(file, cookie);
file.close();
if (cookie_out)
*cookie_out = cookie;
return true;
}
void DeleteAuthCookie()
{
try {