美文网首页比特币源码学习笔记
比特币源码阅读(HTTPReq_JSONRPC的注册和实现)

比特币源码阅读(HTTPReq_JSONRPC的注册和实现)

作者: 坠叶飘香 | 来源:发表于2018-08-11 17:03 被阅读0次

    1.注册处理RPC请求的函数的堆栈

    1.1.AppInit函数

    src/bitcoind.cpp

    static bool AppInit(int argc, char* argv[])
    {
      fRet = AppInitMain();
    }
    
    1.2.AppInitMain函数

    src/init.cpp

    bool AppInitMain()
    {
       RegisterAllCoreRPCCommands(tableRPC);
       if (!AppInitServers())
                return InitError(_("Unable to start HTTP server. See debug log for details."));
    }
    
    1.3.AppInitServers函数

    src/init.cpp

    static bool AppInitServers()
    {
        if (!StartHTTPRPC())
            return false;
    }
    
    1.4.注册处理RPC请求的函数

    src/httprpc.cpp

    bool StartHTTPRPC()
    {
        LogPrint(BCLog::RPC, "Starting HTTP RPC server\n");
        if (!InitRPCAuthentication())
            return false;
    
        RegisterHTTPHandler("/", true, HTTPReq_JSONRPC);  //注册处理RPC请求的函数
    #ifdef ENABLE_WALLET
        // ifdef can be removed once we switch to better endpoint support and API versioning
        RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC);
    #endif
        assert(EventBase());
        httpRPCTimerInterface = MakeUnique<HTTPRPCTimerInterface>(EventBase());
        RPCSetTimerInterface(httpRPCTimerInterface.get());
        return true;
    }
    

    2.对RPC命令的处理

    src/httprpc.cpp

    static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
    {
      jreq.parse(valRequest);
      UniValue result = tableRPC.execute(jreq);  //执行CRPCTable的execute函数
    }
    

    相关文章

      网友评论

        本文标题:比特币源码阅读(HTTPReq_JSONRPC的注册和实现)

        本文链接:https://www.haomeiwen.com/subject/wcvdbftx.html