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

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

作者: electroman | 来源:发表于2018-03-18 22:36 被阅读165次

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

处理待交易币的状态

       //处理待交易的币状态,并提示给客户

    // process prepareStatus and on errorgenerate message shown to user

    processSendCoinsReturn(prepareStatus,

       BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(),currentTransaction.getTransactionFee()));

从注释,可以看出,该函数的任务是处理待交易币的状态信息,并且如果有错误,提示给用户

函数原型如下;

voidSendCoinsDialog::processSendCoinsReturn(const WalletModel::SendCoinsReturn&sendCoinsReturn, const QString &msgArg)

{

    QPair msgParams;

    // Default to a warning message, overrideif error message is needed

    msgParams.second = CClientUIInterface::MSG_WARNING;

    // This comment is specific toSendCoinsDialog usage of WalletModel::SendCoinsReturn.

    // WalletModel::TransactionCommitFailed isused only in WalletModel::sendCoins()

    // all others are used only inWalletModel::prepareTransaction()

    switch(sendCoinsReturn.status)

    {

    case WalletModel::InvalidAddress:   //地址无效,则给出接收地址无效提示

        msgParams.first = tr("Therecipient address is not valid. Please recheck.");

        break;

    case WalletModel::InvalidAmount:  //金额无效,则给给金额必须大于0的提示

        msgParams.first = tr("The amountto pay must be larger than 0.");

        break;

    case WalletModel::AmountExceedsBalance: //金额超过了你的余额,则给出提示

        msgParams.first = tr("The amountexceeds your balance.");

        break;

    caseWalletModel::AmountWithFeeExceedsBalance: //当交易金额+交易费超过余额时,给出提示

        msgParams.first = tr("The totalexceeds your balance when the %1 transaction fee isincluded.").arg(msgArg);

        break;

    caseWalletModel::DuplicateAddress:  //每个utxo只能使用一次,因此只有一个地址,如果有重复地址,则给出提示

        msgParams.first = tr("Duplicateaddress found: addresses should only be used once each.");

        break;

    caseWalletModel::TransactionCreationFailed: //交易创建失败给出提示

        msgParams.first = tr("Transactioncreation failed!");

        msgParams.second =CClientUIInterface::MSG_ERROR;

        break;

    case WalletModel::TransactionCommitFailed: //交易错误,给出交易错误的原因

        msgParams.first = tr("Thetransaction was rejected with the following reason:%1").arg(sendCoinsReturn.reasonCommitFailed);

        msgParams.second =CClientUIInterface::MSG_ERROR;

        break;

    case WalletModel::AbsurdFee:    //交易费用太高,给出提示

        msgParams.first = tr("A fee higherthan %1 is considered an absurdly highfee.").arg(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(),maxTxFee));

        break;

    case WalletModel::PaymentRequestExpired:  交易请求过期,给出提示

        msgParams.first = tr("Paymentrequest expired.");

        msgParams.second =CClientUIInterface::MSG_ERROR;

        break;

    // included to prevent a compiler warning.

    case WalletModel::OK:

    default:

        return;

    }

今天先写这么多吧!

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

QYB地址:QVR2eUwbx43YMkWjbaAQCYdoDmpC1ohnRk


相关文章

网友评论

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

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