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


C++ pointer::getBalanceAboveReserve方法代码示例

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


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

示例1: runtime_error

OfferExchange::CrossOfferResult
OfferExchange::crossOffer(OfferFrame& sellingWheatOffer,
                          int64_t maxWheatReceived, int64_t& numWheatReceived,
                          int64_t maxSheepSend, int64_t& numSheepSend)
{
    Asset& sheep = sellingWheatOffer.getOffer().buying;
    Asset& wheat = sellingWheatOffer.getOffer().selling;
    AccountID& accountBID = sellingWheatOffer.getOffer().sellerID;

    Database& db = mLedgerManager.getDatabase();

    AccountFrame::pointer accountB;
    accountB = AccountFrame::loadAccount(accountBID, db);
    if (!accountB)
    {
        throw std::runtime_error(
            "invalid database state: offer must have matching account");
    }

    TrustFrame::pointer wheatLineAccountB;
    if (wheat.type() != ASSET_TYPE_NATIVE)
    {
        wheatLineAccountB = TrustFrame::loadTrustLine(accountBID, wheat, db);
        if (!wheatLineAccountB)
        {
            throw std::runtime_error(
                "invalid database state: offer must have matching trust line");
        }
    }

    TrustFrame::pointer sheepLineAccountB;

    if (sheep.type() == ASSET_TYPE_NATIVE)
    {
        numWheatReceived = INT64_MAX;
    }
    else
    {
        sheepLineAccountB = TrustFrame::loadTrustLine(accountBID, sheep, db);
        if (!sheepLineAccountB)
        {
            throw std::runtime_error(
                "invalid database state: offer must have matching trust line");
        }

        // compute numWheatReceived based on what the account can receive
        int64_t sellerMaxSheep = sheepLineAccountB->getMaxAmountReceive();

        if (!bigDivide(numWheatReceived, sellerMaxSheep,
                       sellingWheatOffer.getOffer().price.d,
                       sellingWheatOffer.getOffer().price.n))
        {
            numWheatReceived = INT64_MAX;
        }
    }

    // adjust numWheatReceived with what the seller has
    {
        int64_t wheatCanSell;
        if (wheat.type() == ASSET_TYPE_NATIVE)
        {
            // can only send above the minimum balance
            wheatCanSell = accountB->getBalanceAboveReserve(mLedgerManager);
        }
        else
        {
            if (wheatLineAccountB->isAuthorized())
            {
                wheatCanSell = wheatLineAccountB->getBalance();
            }
            else
            {
                wheatCanSell = 0;
            }
        }
        if (numWheatReceived > wheatCanSell)
        {
            numWheatReceived = wheatCanSell;
        }
    }
    // you can receive the lesser of the amount of wheat offered or
    // the amount the guy has

    if (numWheatReceived >= sellingWheatOffer.getOffer().amount)
    {
        numWheatReceived = sellingWheatOffer.getOffer().amount;
    }
    else
    {
        // update the offer based on the balance (to determine if it should be
        // deleted or not)
        // note that we don't need to write into the db at this point as the
        // actual update
        // is done further down
        sellingWheatOffer.getOffer().amount = numWheatReceived;
    }

    bool reducedOffer = false;

    if (numWheatReceived > maxWheatReceived)
//.........这里部分代码省略.........
开发者ID:paladin226,项目名称:stellar-core,代码行数:101,代码来源:OfferExchange.cpp


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