本文整理汇总了C++中TransactionFramePtr::apply方法的典型用法代码示例。如果您正苦于以下问题:C++ TransactionFramePtr::apply方法的具体用法?C++ TransactionFramePtr::apply怎么用?C++ TransactionFramePtr::apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TransactionFramePtr
的用法示例。
在下文中一共展示了TransactionFramePtr::apply方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: delta
void
applyAllowTrust(Application& app, SecretKey& from, SecretKey& trustor,
SequenceNumber seq, std::string const& currencyCode,
bool authorize, AllowTrustResultCode result)
{
TransactionFramePtr txFrame;
txFrame = createAllowTrust(from, trustor, seq, currencyCode, authorize);
LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
txFrame->apply(delta, app);
checkTransaction(*txFrame);
REQUIRE(AllowTrustOpFrame::getInnerCode(
txFrame->getResult().result.results()[0]) == result);
}
示例2: delta
static void
doInflation(Application& app, int nbAccounts,
std::function<int64(int)> getBalance,
std::function<int(int)> getVote, int expectedWinnerCount)
{
// simulate the expected inflation based off the current ledger state
std::map<int, int64> balances;
// load account balances
for (int i = 0; i < nbAccounts; i++)
{
AccountFrame act;
if (getBalance(i) < 0)
{
balances[i] = -1;
REQUIRE(!AccountFrame::loadAccount(getTestAccount(i).getPublicKey(),
act, app.getDatabase()));
}
else
{
REQUIRE(AccountFrame::loadAccount(getTestAccount(i).getPublicKey(),
act, app.getDatabase()));
balances[i] = act.getBalance();
// double check that inflationDest is setup properly
if (act.getAccount().inflationDest)
{
REQUIRE(getTestAccount(getVote(i)).getPublicKey() ==
*act.getAccount().inflationDest);
}
else
{
REQUIRE(getVote(i) < 0);
}
}
}
LedgerManager& lm = app.getLedgerManager();
LedgerHeader& cur = lm.getCurrentLedgerHeader();
cur.feePool = 10000;
int64 expectedTotcoins = cur.totalCoins;
int64 expectedFees = cur.feePool;
std::vector<int64> expectedBalances;
auto root = getRoot();
TransactionFramePtr txFrame =
createInflation(root, getAccountSeqNum(root, app) + 1);
expectedFees += txFrame->getFee(app);
expectedBalances =
simulateInflation(nbAccounts, expectedTotcoins, expectedFees,
[&](int i)
{
return balances[i];
},
getVote);
// perform actual inflation
{
LedgerDelta delta(lm.getCurrentLedgerHeader());
REQUIRE(txFrame->apply(delta, app));
delta.commit();
}
// verify ledger state
LedgerHeader& cur2 = lm.getCurrentLedgerHeader();
REQUIRE(cur2.totalCoins == expectedTotcoins);
REQUIRE(cur2.feePool == expectedFees);
// verify balances
InflationResult const& infResult =
getFirstResult(*txFrame).tr().inflationResult();
auto const& payouts = infResult.payouts();
int actualChanges = 0;
for (int i = 0; i < nbAccounts; i++)
{
AccountFrame act;
auto const& pk = getTestAccount(i).getPublicKey();
if (expectedBalances[i] < 0)
{
REQUIRE(!AccountFrame::loadAccount(pk, act, app.getDatabase()));
REQUIRE(balances[i] < 0); // account didn't get deleted
}
else
{
REQUIRE(AccountFrame::loadAccount(pk, act, app.getDatabase()));
REQUIRE(expectedBalances[i] == act.getBalance());
if (expectedBalances[i] != balances[i])
{
REQUIRE(balances[i] >= 0);
actualChanges++;
bool found = false;
for (auto const& p : payouts)
{
if (p.destination == pk)
{
//.........这里部分代码省略.........
示例3: createOfferOp
static CreateOfferResult
applyCreateOfferHelper(Application& app, LedgerDelta& delta, uint64 offerId,
SecretKey& source, Currency& takerGets,
Currency& takerPays, Price const& price, int64_t amount,
SequenceNumber seq)
{
uint64_t expectedOfferID = delta.getHeaderFrame().getLastGeneratedID() + 1;
if (offerId != 0)
{
expectedOfferID = offerId;
}
TransactionFramePtr txFrame;
txFrame = createOfferOp(offerId, source, takerGets, takerPays, price,
amount, seq);
txFrame->apply(delta, app);
checkTransaction(*txFrame);
auto& results = txFrame->getResult().result.results();
REQUIRE(results.size() == 1);
auto& createOfferResult = results[0].tr().createOfferResult();
if (createOfferResult.code() == CREATE_OFFER_SUCCESS)
{
OfferFrame offer;
auto& offerResult = createOfferResult.success().offer;
auto& offerEntry = offer.getOffer();
switch (offerResult.effect())
{
case CREATE_OFFER_CREATED:
case CREATE_OFFER_UPDATED:
REQUIRE(OfferFrame::loadOffer(source.getPublicKey(),
expectedOfferID, offer,
app.getDatabase()));
REQUIRE(memcmp(&offerEntry, &offerResult.offer(),
sizeof(OfferEntry)) == 0);
REQUIRE(offerEntry.price == price);
REQUIRE(memcmp(&offerEntry.takerGets, &takerGets,
sizeof(Currency)) == 0);
REQUIRE(memcmp(&offerEntry.takerPays, &takerPays,
sizeof(Currency)) == 0);
break;
case CREATE_OFFER_DELETED:
REQUIRE(!OfferFrame::loadOffer(source.getPublicKey(),
expectedOfferID, offer,
app.getDatabase()));
break;
default:
abort();
}
}
return createOfferResult;
}