美文网首页
比特币源码研读(19)-交易(5)交易流程分析

比特币源码研读(19)-交易(5)交易流程分析

作者: electroman | 来源:发表于2018-03-11 23:26 被阅读186次

3 更新交易特征

       //更新交易币的特征

        // Always use a CCoinControl instance, usethe CoinControlDialog instance if CoinControl has been enabled

    CCoinControl ctrl;

    if(model->getOptionsModel()->getCoinControlFeatures())

        ctrl = *CoinControlDialog::coinControl;

    updateCoinControlState(ctrl);

    prepareStatus =model->prepareTransaction(currentTransaction, ctrl);

第一句代码:

CoinControl和CoinControlDialog是币的状态控制信息类,从注释可以看出,如果CoinControl类已经使用了,则ctrl使用类CoinControlDialog

第二句代码

 updateCoinControlState(ctrl);   函数用于更新币的控制状态信息,该函数定义在sendcoinsdialog.cpp中,

函数原型如下:

voidSendCoinsDialog::updateCoinControlState(CCoinControl& ctrl)

{

    if (ui->radioCustomFee->isChecked()){

        ctrl.m_feerate =CFeeRate(ui->customFee->value());

    } else {

        ctrl.m_feerate.reset();

    }

    // Avoid using global defaults when sendingmoney from the GUI

    // Either custom fee will be used or if notselected, the confirmation target from dropdown box

    ctrl.m_confirm_target =getConfTargetForIndex(ui->confTargetSelector->currentIndex());

    ctrl.signalRbf =ui->optInRBF->isChecked();

}

if (ui->radioCustomFee->isChecked())该语句表示:

如果用户自定义了交易费,则选择自定义交一份,否则选择默认交易费。既下图的custom

ctrl.m_confirm_target= getConfTargetForIndex(ui->confTargetSelector->currentIndex())

这段代码用于需要多少个确认块,如果不设置,则用默认的确认块,否则按照用户的设置选择默认块。默认块的选择只能从列表中选择

getConfTargetForIndex()函数的原型是

static conststd::array confTargets = { {2, 4, 6, 12, 24, 48, 144, 504, 1008}};

intgetConfTargetForIndex(int index) {

    if (index+1 >static_cast(confTargets.size())) {

        return confTargets.back();

    }

    if (index < 0) {

        return confTargets[0];

    }

    return confTargets[index];

}

既下图中的确认区块的时间

prepareStatus =model->prepareTransaction(currentTransaction, ctrl);

将需要发送的币的状态写入参数prepareStatus中

下次,我们将分析如何处理待交易的币的状态

本文由【区块链研习社】优质内容计划支持,更多关于区块链的深度好文,请点击[区块链研习社](http://www.jianshu.com/c/b17f09dc2831)

区块链研习社比特币源码研读班  electroman

有QYB的伙伴们,打赏点呗!

QYB地址:QVR2eUwbx43YMkWjbaAQCYdoDmpC1ohnRk

相关文章

网友评论

      本文标题:比特币源码研读(19)-交易(5)交易流程分析

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