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


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

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


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

示例1: updateLabels


//.........这里部分代码省略.........
    double dPriorityInputs      = 0;
    unsigned int nQuantity      = 0;

    vector<COutPoint> vCoinControl;
    vector<COutput>   vOutputs;
    coinControl->ListSelected(vCoinControl);
    model->getOutputs(vCoinControl, vOutputs);

    nPayFee = nTransactionFee;
    loop
    {
        txDummy.vin.clear();
        txDummy.vout.clear();
        nQuantity = 0;
        nAmount = 0;
        dPriorityInputs = 0;
        nBytesInputs = 0;

        // Inputs
        BOOST_FOREACH(const COutput& out, vOutputs)
        {
            // Quantity
            nQuantity++;

            // Amount
            nAmount += out.tx->vout[out.i].nValue;

            // Priority
            dPriorityInputs += (double)out.tx->vout[out.i].nValue * (out.nDepth+1);

            // Bytes
            txDummy.vin.push_back(CTxIn(out.tx->vout[out.i].GetHash(), out.tx->vout[out.i].nValue));
            nBytesInputs += 73; // Future ECDSA signature in DER format
        }

        // Outputs
        BOOST_FOREACH(const PAIRTYPE(QString, qint64) &payee, CoinControlDialog::payAddresses)
        {
            QString address = payee.first;
            qint64 amount = payee.second;
            CScript scriptPubKey;
            scriptPubKey.SetDestination(CBitcoinAddress(address.toStdString()).Get());
            CTxOut txout(amount, scriptPubKey);
            txDummy.vout.push_back(txout);
        }

        // calculation
        if (nQuantity > 0)
        {
            nChange = nAmount - nPayAmount - nPayFee;
            // if sub-cent change is required, the fee must be raised to at least MIN_TX_FEE
            // or until nChange becomes zero
            // NOTE: this depends on the exact behaviour of GetMinFee
            if (nPayFee < MIN_TX_FEE && nChange > 0 && nChange < CENT)
            {
                int64 nMoveToFee = min(nChange, MIN_TX_FEE - nPayFee);
                nChange -= nMoveToFee;
                nPayFee += nMoveToFee;
            }

            // Tamcoin: sub-cent change is moved to fee
            if (nChange > 0 && nChange < MIN_TXOUT_AMOUNT)
            {
                nPayFee += nChange;
                nChange = 0;
            }

            if (nChange > 0)
            {
                // Add a change address in the outputs
                CTxOut txout(0, (CScript)vector<unsigned char>(24, 0));
                txDummy.vout.push_back(txout);
            }

            // Bytes
            nBytes = nBytesInputs + GetSerializeSize(*(CTransaction*)&txDummy, SER_NETWORK, PROTOCOL_VERSION);

            // Priority
            dPriority = dPriorityInputs / nBytes;
            sPriorityLabel = CoinControlDialog::getPriorityLabel(dPriority);

            // Fee
            int64 nFee = nTransactionFee * (1 + (int64)nBytes / 1000);

            // Min Fee
            int64 nMinFee = txDummy.GetMinFee(1, false, GMF_SEND, nBytes);

            if (nPayFee < max(nFee, nMinFee))
            {
                nPayFee = max(nFee, nMinFee);
                continue;
            }

            // after fee
            nAfterFee = nAmount - nPayFee;
            if (nAfterFee < 0)
                nAfterFee = 0;
        }
        break;
    }
开发者ID:Bitspender,项目名称:Tamcoin-v2,代码行数:101,代码来源:coincontroldialog.cpp


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