当前位置: 首页>>代码示例>>C++>>正文


C++ CTransaction::IsPeggyBase方法代码示例

本文整理汇总了C++中CTransaction::IsPeggyBase方法的典型用法代码示例。如果您正苦于以下问题:C++ CTransaction::IsPeggyBase方法的具体用法?C++ CTransaction::IsPeggyBase怎么用?C++ CTransaction::IsPeggyBase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CTransaction的用法示例。


在下文中一共展示了CTransaction::IsPeggyBase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runtime_error

extern "C" char* GetPeggyByBlock(CBlock *pblock, CBlockIndex *pindex)
{
    cJSON *array, *arrayObj, *header, *peggybase, *peggypayments, *peggytx;
    header = cJSON_CreateObject();
    peggybase = cJSON_CreateObject();
    peggypayments = cJSON_CreateArray();
    peggytx = cJSON_CreateArray();
    array = cJSON_CreateArray();
    arrayObj = cJSON_CreateObject();
    //header
    jaddnum(header, "blocknum", pindex->nHeight);
    jaddnum(header, "blocktimestamp", pblock->nTime);
    jaddstr(header, "blockhash", (char*)pindex->GetBlockHash().ToString().c_str());

    jadd(arrayObj, "header", header);

    if(pindex->nHeight >= nMinPeggyHeight){
        if(!pblock->vtx[2].IsPeggyBase())
            throw runtime_error(
                "Block Does not contain a peggybase transaction!\n"
            );
    }
    else{
        return "Not a peggy block\n";
    }


    int index, vouts;

    //peggypayments
    char bits[4096];
    char hex[4096];

    bool fPeggy = false;
    uint64_t nPeggyPayments = 0;

    for(index=0; index<pblock->vtx.size(); index++){
        fPeggy = false;
        const CTransaction tempTx = pblock->vtx[index];
        if(tempTx.IsCoinBase() || tempTx.IsCoinStake())
            continue;

        if(tempTx.IsPeggyBase()){
            const CTxOut peggyOut = tempTx.vout[0];
            const CScript priceFeed = peggyOut.scriptPubKey;

            char peggybits[4096];
            strcpy(peggybits, (char*)HexStr(priceFeed.begin(), priceFeed.end(), false).c_str()+2);

            jaddstr(peggybase, "txid", (char*)tempTx.GetHash().ToString().c_str());
            jaddstr(peggybase, "peggybase", peggybits);
            jaddnum(peggybase, "time", tempTx.nTime);
            jaddnum(peggybase, "txind", 2);
            jaddnum(peggybase, "voutind", 0);
            jaddstr(peggybase, "address", "peggypayments");
            fPeggy = true;
        }

        for(vouts=0; vouts<tempTx.vout.size(); vouts++){

            const CTxOut tempVout = tempTx.vout[vouts];

            const CScript tempScriptPubKey = tempVout.scriptPubKey;
            CTxDestination destAddress;
            strcpy(hex, (char*)HexStr(tempScriptPubKey.begin(), tempScriptPubKey.end(), false).c_str());
            sprintf(hex, "%s", hex);

            if(fPeggy && (vouts != 0)){
                cJSON *peggyOut = cJSON_CreateObject();


                jaddstr(peggyOut, "txid", (char*)tempTx.GetHash().ToString().c_str());
                jaddnum(peggyOut, "time", tempTx.nTime);
                jaddnum(peggyOut, "txind", index);
                jaddnum(peggyOut, "amount", tempVout.nValue);
                jaddnum(peggyOut, "voutind", vouts);
                jaddstr(peggyOut, "scriptPubKey", hex);

                if(ExtractDestination(tempScriptPubKey, destAddress)){
                    jaddstr(peggyOut, "address", (char*)CBitcoinAddress(destAddress).ToString().c_str());
                }
                else{
                    jaddstr(peggyOut, "address", "null");
                }

                nPeggyPayments += (uint64_t)tempVout.nValue;

                jaddi(peggypayments, peggyOut);
            }

            else if(!fPeggy && (isOpReturn(hex) == 0)){ //peggy lock found
                cJSON *lockVout = cJSON_CreateObject();

                jaddstr(lockVout, "txid", (char*)tempTx.GetHash().ToString().c_str());
                jaddnum(lockVout, "time", tempTx.nTime);
                jaddnum(lockVout, "txind", index);
                jaddnum(lockVout, "voutind", vouts);
                jaddstr(lockVout, "scriptPubKey", hex);

                if(ExtractDestination(tempScriptPubKey, destAddress)){
//.........这里部分代码省略.........
开发者ID:destenson,项目名称:jl777--btcd,代码行数:101,代码来源:rpcpeggy.cpp


注:本文中的CTransaction::IsPeggyBase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。