[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/superstacked/sidecoin/master/src/rpcserver.cpp [Back]  [Original]

// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Copyright (c) 2014 Joey Krug and Jack Peterson
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "rpcserver.h"

#include "base58.h"
#include "init.h"
#include 
#include "main.h"
#include "ui_interface.h"
#include "util.h"
#ifdef ENABLE_WALLET
#include "wallet.h"
#endif
#ifdef _WIN32
    #include 
    #include 
#endif
#include "unistd.h"

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "json/json_spirit_writer_template.h"

using namespace std;
using namespace boost;
using namespace boost::asio;
using namespace json_spirit;

static std::string strRPCUserColonPass;

// These are created by StartRPCThreads, destroyed in StopRPCThreads
static asio::io_service* rpc_io_service = NULL;
static map deadlineTimers;
static ssl::context* rpc_ssl_context = NULL;
static boost::thread_group* rpc_worker_group = NULL;
static boost::asio::io_service::work *rpc_dummy_work = NULL;

void RPCTypeCheck(const Array& params,
                  const list& typesExpected,
                  bool fAllowNull)
{
    unsigned int i = 0;
    BOOST_FOREACH(Value_type t, typesExpected)
    {
        if (params.size() second;
        string strMethod = mi->first;
        // We already filter duplicates, but these deprecated screw up the sort order
        if (strMethod.find("label") != string::npos)
            continue;
        if (strCommand != "" && strMethod != strCommand)
            continue;
#ifdef ENABLE_WALLET
        if (pcmd->reqWallet && !pwalletMain)
            continue;
#endif

        try
        {
            Array params;
            rpcfn_type pfn = pcmd->actor;
            if (setDone.insert(pfn).second)
                (*pfn)(params, true);
        }
        catch (std::exception& e)
        {
            // Help text is returned in an exception
            string strHelp = string(e.what());
            if (strCommand == "")
                if (strHelp.find('\n') != string::npos)
                    strHelp = strHelp.substr(0, strHelp.find('\n'));
            strRet += strHelp + "\n";
        }
    }
    if (strRet == "")
        strRet = strprintf("help: unknown command: %s\n", strCommand);
    strRet = strRet.substr(0,strRet.size()-1);
    return strRet;
}

Value help(const Array& params, bool fHelp)
{
    if (fHelp || params.size() > 1)
        throw runtime_error(
            "help ( \"command\" )\n"
            "\nList all commands, or get help for a specified command.\n"
            "\nArguments:\n"
            "1. \"command\"     (string, optional) The command to get help on\n"
            "\nResult:\n"
            "\"text\"     (string) The help text\n"
        );

    string strCommand;
    if (params.size() > 0)
        strCommand = params[0].get_str();

    return tableRPC.help(strCommand);
}

Value claimtx(const Array& params, bool fHelp)
{
    if (fHelp || params.size() < 1)
        throw runtime_error(
            "claimtx \"bitcoin address\"\n"
            "\nArguments:\n"
            "1. \"address\"          (string, required) The bitcoin address you want to use to claim your coins\n"
            "\nResult :\n"
            "{\n"
            "  \"rawtx\" : \"hash\",     (string) execute signrawtransaction with your bitcoin client, then type sendrawtransaction and the result that bitcoinqt gave you \n"
            "  \"autoSuccess\" : true or false,   (boolean) True if we successfully automate this claim process if you have bitcoinqt already installed on your computer\n"
            "}\n"
            "\"data\"             (string) A raw transaction ready to be signed'.\n"
            "\nExamples:\n"
            + HelpExampleCli("claimtx", "\"1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX\"")
            + HelpExampleRpc("claimtx", "\"12DL1vZrJVphm8PXcV9GNCtBYo3PCMn2No\"")
        );

    CTransaction prevTx;
    CBlock block;
    bool defined = false;
    std::string btcHash160Str;
    std::string address;
    std::string scriptPubKeyString;

    uint256 prevTxid;
    uint64_t txAmt = 0;

    if (params.size() > 0) {
     address = params[0].get_str();
    }


    std::ifstream snapfile;

    #ifdef _WIN32
        char username[UNLEN+1];
        DWORD username_len = UNLEN+1;
        GetUserName(username, &username_len);
        std::string userString(username);
        std::string str(getlogin());
        std::string SNAPSHOT_FILE = "C:\Users\\" + userString + "\Appdata\Roaming\Sidecoin\balances\snapshotToImport.txt";
    #elif __APPLE__
        std::string str(getlogin());
        std::string SNAPSHOT_FILE = "/users/" + str + "/Library/Application Support/Sidecoin/balances/snapshotToImport.txt";
    #elif __linux
        std::string str(getlogin());
        std::string SNAPSHOT_FILE = "/home/" + str + "/.sidecoin/balances/snapshotToImport.txt";
    #elif __unix
        std::string str(getlogin());
        std::string SNAPSHOT_FILE = "/home/" + str + "/.sidecoin/balances/snapshotToImport.txt";
    #endif


    //printf("path: %s\n", SNAPSHOT_FILE.c_str());
    snapfile.open(SNAPSHOT_FILE.c_str());
    if (snapfile.good()) {
        while (!snapfile.eof()) {
            char buffer[1024];
            const char* btcBalance = 0;
            const char* btcHash160 = 0;
            const char* btcAddress = 0;
            snapfile.getline(buffer, 1024);
            btcBalance = strtok(buffer, "\t");
            if (btcBalance) {
                btcHash160 = strtok(0, "\t");
                if (btcHash160) {
                    btcAddress = strtok(0, "\n");
                    if(btcAddress==address) {
                        btcHash160Str = btcHash160;
                        std::cout  sidecoin-cli " + methodname + " " + args + "\n";
}

std::string HelpExampleRpc(string methodname, string args){
    return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", "
        "\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
}

const CRPCTable tableRPC;

Web Proxy Viewer  |  New URL  |  Original Page