2013-10-11 23:09:59 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
|
|
// Copyright (c) 2009-2013 The Bitcoin developers
|
2015-03-18 00:06:58 +01:00
|
|
|
// Copyright (c) 2009-2013 The Dash developers
|
2013-10-11 23:09:59 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "init.h"
|
2013-11-20 14:18:57 +01:00
|
|
|
#include "rpcclient.h"
|
2014-02-24 14:08:56 +01:00
|
|
|
#include "rpcprotocol.h"
|
2013-10-11 23:09:59 +02:00
|
|
|
#include "ui_interface.h" /* for _(...) */
|
2013-11-28 17:28:27 +01:00
|
|
|
#include "chainparams.h"
|
2013-10-11 23:09:59 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
|
2013-10-11 23:09:59 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Start
|
|
|
|
//
|
|
|
|
static bool AppInitRPC(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Parameters
|
|
|
|
//
|
|
|
|
ParseParameters(argc, argv);
|
|
|
|
if (!boost::filesystem::is_directory(GetDataDir(false)))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-07 10:10:01 +02:00
|
|
|
try {
|
|
|
|
ReadConfigFile(mapArgs, mapMultiArgs);
|
|
|
|
} catch(std::exception &e) {
|
|
|
|
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-28 17:28:27 +01:00
|
|
|
// Check for -testnet or -regtest parameter (TestNet() calls are only valid after this clause)
|
|
|
|
if (!SelectParamsFromCommandLine()) {
|
|
|
|
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-11 23:09:59 +02:00
|
|
|
|
|
|
|
if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help"))
|
|
|
|
{
|
|
|
|
// First part of help message is specific to RPC client
|
2015-03-18 00:06:58 +01:00
|
|
|
std::string strUsage = _("Dash Core RPC client version") + " " + FormatFullVersion() + "\n\n" +
|
2013-10-11 23:09:59 +02:00
|
|
|
_("Usage:") + "\n" +
|
2015-03-19 15:15:08 +01:00
|
|
|
" dash-cli [options] <command> [params] " + _("Send command to Dash Core") + "\n" +
|
|
|
|
" dash-cli [options] help " + _("List commands") + "\n" +
|
|
|
|
" dash-cli [options] help <command> " + _("Get help for a command") + "\n";
|
2013-10-11 23:09:59 +02:00
|
|
|
|
2013-11-27 15:41:12 +01:00
|
|
|
strUsage += "\n" + HelpMessageCli(true);
|
2013-10-11 23:09:59 +02:00
|
|
|
|
|
|
|
fprintf(stdout, "%s", strUsage.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2014-05-13 12:15:00 +02:00
|
|
|
SetupEnvironment();
|
|
|
|
|
2013-10-11 23:09:59 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(!AppInitRPC(argc, argv))
|
2014-02-24 14:08:56 +01:00
|
|
|
return abs(RPC_MISC_ERROR);
|
2013-10-11 23:09:59 +02:00
|
|
|
}
|
|
|
|
catch (std::exception& e) {
|
|
|
|
PrintExceptionContinue(&e, "AppInitRPC()");
|
2014-02-24 14:08:56 +01:00
|
|
|
return abs(RPC_MISC_ERROR);
|
2013-10-11 23:09:59 +02:00
|
|
|
} catch (...) {
|
|
|
|
PrintExceptionContinue(NULL, "AppInitRPC()");
|
2014-02-24 14:08:56 +01:00
|
|
|
return abs(RPC_MISC_ERROR);
|
2013-10-11 23:09:59 +02:00
|
|
|
}
|
|
|
|
|
2014-02-24 14:08:56 +01:00
|
|
|
int ret = abs(RPC_MISC_ERROR);
|
2013-10-11 23:09:59 +02:00
|
|
|
try
|
|
|
|
{
|
2014-02-24 14:08:56 +01:00
|
|
|
ret = CommandLineRPC(argc, argv);
|
2013-10-11 23:09:59 +02:00
|
|
|
}
|
|
|
|
catch (std::exception& e) {
|
|
|
|
PrintExceptionContinue(&e, "CommandLineRPC()");
|
|
|
|
} catch (...) {
|
|
|
|
PrintExceptionContinue(NULL, "CommandLineRPC()");
|
|
|
|
}
|
2014-02-24 14:08:56 +01:00
|
|
|
return ret;
|
2013-10-11 23:09:59 +02:00
|
|
|
}
|