本文整理汇总了C++中TransactionFramePtr类的典型用法代码示例。如果您正苦于以下问题:C++ TransactionFramePtr类的具体用法?C++ TransactionFramePtr怎么用?C++ TransactionFramePtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TransactionFramePtr类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: HashTxSorter
static bool
HashTxSorter(TransactionFramePtr const& tx1, TransactionFramePtr const& tx2)
{
// need to use the hash of whole tx here since multiple txs could have
// the same Contents
return tx1->getFullHash() < tx2->getFullHash();
}
开发者ID:nullstyle,项目名称:stellar-core,代码行数:7,代码来源:TxSetFrame.cpp
示例2: operator
bool operator()(TransactionFramePtr const& tx1,
TransactionFramePtr const& tx2) const
{
// need to use the hash of whole tx here since multiple txs could have
// the same Contents
return lessThanXored(tx1->getFullHash(), tx2->getFullHash(), mSetHash);
}
开发者ID:AnthonyAkentiev,项目名称:stellar-core,代码行数:7,代码来源:TxSetFrame.cpp
示例3: sqltx
// TODO.3 this and checkValid share a lot of code
void
TxSetFrame::trimInvalid(Application& app,
std::vector<TransactionFramePtr>& trimmed)
{
soci::transaction sqltx(app.getDatabase().getSession());
app.getDatabase().setCurrentTransactionReadOnly();
sortForHash();
map<AccountID, vector<TransactionFramePtr>> accountTxMap;
for (auto tx : mTransactions)
{
accountTxMap[tx->getSourceID()].push_back(tx);
}
for (auto& item : accountTxMap)
{
// order by sequence number
std::sort(item.second.begin(), item.second.end(), SeqSorter);
TransactionFramePtr lastTx;
SequenceNumber lastSeq = 0;
int64_t totFee = 0;
for (auto& tx : item.second)
{
if (!tx->checkValid(app, lastSeq))
{
trimmed.push_back(tx);
removeTx(tx);
continue;
}
totFee += tx->getFee();
lastTx = tx;
lastSeq = tx->getSeqNum();
}
if (lastTx)
{
// make sure account can pay the fee for all these tx
int64_t newBalance =
lastTx->getSourceAccount().getBalance() - totFee;
if (newBalance < lastTx->getSourceAccount().getMinimumBalance(
app.getLedgerManager()))
{
for (auto& tx : item.second)
{
trimmed.push_back(tx);
removeTx(tx);
}
}
}
}
}
开发者ID:nullstyle,项目名称:stellar-core,代码行数:55,代码来源:TxSetFrame.cpp
示例4: txm
Herder::TransactionSubmitStatus
LoadGenerator::TxInfo::execute(Application& app, bool isCreate,
TransactionResultCode& code, int32_t batchSize)
{
auto seqNum = mFrom->getLastSequenceNumber();
mFrom->setSequenceNumber(seqNum + 1);
TransactionFramePtr txf =
transactionFromOperations(app, mFrom->getSecretKey(), seqNum + 1, mOps);
TxMetrics txm(app.getMetrics());
// Record tx metrics.
if (isCreate)
{
while (batchSize--)
{
txm.mAccountCreated.Mark();
}
}
else
{
txm.mPayment.Mark();
txm.mNativePayment.Mark();
}
txm.mTxnAttempted.Mark();
StellarMessage msg;
msg.type(TRANSACTION);
msg.transaction() = txf->getEnvelope();
txm.mTxnBytes.Mark(xdr::xdr_argpack_size(msg));
auto status = app.getHerder().recvTransaction(txf);
if (status != Herder::TX_STATUS_PENDING)
{
CLOG(INFO, "LoadGen")
<< "tx rejected '" << Herder::TX_STATUS_STRING[status]
<< "': " << xdr::xdr_to_string(txf->getEnvelope()) << " ===> "
<< xdr::xdr_to_string(txf->getResult());
if (status == Herder::TX_STATUS_ERROR)
{
code = txf->getResultCode();
}
txm.mTxnRejected.Mark();
}
else
{
app.getOverlayManager().broadcastMessage(msg);
}
return status;
}
开发者ID:charwliu,项目名称:stellar-core,代码行数:51,代码来源:LoadGenerator.cpp
示例5: applyAllowTrust
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);
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:15,代码来源:TxTests.cpp
示例6: applyChangeTrust
void
applyChangeTrust(Application& app, SecretKey& from, SecretKey& to,
SequenceNumber seq, std::string const& currencyCode,
int64_t limit, ChangeTrustResultCode result)
{
TransactionFramePtr txFrame;
txFrame = createChangeTrust(from, to, seq, currencyCode, limit);
LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
txFrame->apply(delta, app);
checkTransaction(*txFrame);
REQUIRE(ChangeTrustOpFrame::getInnerCode(
txFrame->getResult().result.results()[0]) == result);
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:16,代码来源:TxTests.cpp
示例7: operator
bool operator()(TransactionFramePtr const& tx1,
TransactionFramePtr const& tx2) const
{
// need to use the hash of whole tx here since multiple txs could have
// the same Contents
Hash h1 = tx1->getFullHash();
Hash h2 = tx2->getFullHash();
Hash v1, v2;
for (int n = 0; n < 32; n++)
{
v1[n] = mSetHash[n] ^ h1[n];
v2[n] = mSetHash[n] ^ h2[n];
}
return v1 < v2;
}
开发者ID:nullstyle,项目名称:stellar-core,代码行数:16,代码来源:TxSetFrame.cpp
示例8: applySetOptions
void
applySetOptions(Application& app, SecretKey& source, AccountID* inflationDest,
uint32_t* setFlags, uint32_t* clearFlags, Thresholds* thrs,
Signer* signer, SequenceNumber seq, SetOptionsResultCode result)
{
TransactionFramePtr txFrame;
txFrame = createSetOptions(source, inflationDest, setFlags, clearFlags,
thrs, signer, seq);
LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
txFrame->apply(delta, app);
checkTransaction(*txFrame);
REQUIRE(SetOptionsOpFrame::getInnerCode(
txFrame->getResult().result.results()[0]) == result);
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:17,代码来源:TxTests.cpp
示例9: applyPaymentTx
void
applyPaymentTx(Application& app, SecretKey& from, SecretKey& to,
SequenceNumber seq, int64_t amount, PaymentResultCode result)
{
TransactionFramePtr txFrame;
AccountFrame fromAccount;
AccountFrame toAccount;
bool beforeToExists = AccountFrame::loadAccount(
to.getPublicKey(), toAccount, app.getDatabase());
REQUIRE(AccountFrame::loadAccount(from.getPublicKey(), fromAccount,
app.getDatabase()));
txFrame = createPaymentTx(from, to, seq, amount);
LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
txFrame->apply(delta, app);
checkTransaction(*txFrame);
auto txResult = txFrame->getResult();
auto innerCode = PaymentOpFrame::getInnerCode(txResult.result.results()[0]);
REQUIRE(innerCode == result);
REQUIRE(txResult.feeCharged == app.getLedgerManager().getTxFee());
AccountFrame toAccountAfter;
bool afterToExists = AccountFrame::loadAccount(
to.getPublicKey(), toAccountAfter, app.getDatabase());
if (!(innerCode == PAYMENT_SUCCESS || innerCode == PAYMENT_SUCCESS_MULTI))
{
// check that the target account didn't change
REQUIRE(beforeToExists == afterToExists);
if (beforeToExists && afterToExists)
{
REQUIRE(memcmp(&toAccount.getAccount(),
&toAccountAfter.getAccount(),
sizeof(AccountEntry)) == 0);
}
}
else
{
REQUIRE(afterToExists);
}
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:46,代码来源:TxTests.cpp
示例10: applyInflation
OperationResult
applyInflation(Application& app, SecretKey& from, SequenceNumber seq,
InflationResultCode result)
{
TransactionFramePtr txFrame = createInflation(from, seq);
LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
bool res = txFrame->apply(delta, app);
checkTransaction(*txFrame);
REQUIRE(InflationOpFrame::getInnerCode(
txFrame->getResult().result.results()[0]) == result);
if (res)
{
delta.commit();
}
return getFirstResult(*txFrame);
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:18,代码来源:TxTests.cpp
示例11: transactionFromOperation
TransactionFramePtr
transactionFromOperation(SecretKey& from, SequenceNumber seq,
Operation const& op)
{
TransactionEnvelope e;
e.tx.sourceAccount = from.getPublicKey();
e.tx.maxLedger = UINT32_MAX;
e.tx.minLedger = 0;
e.tx.fee = 10;
e.tx.seqNum = seq;
e.tx.operations.push_back(op);
TransactionFramePtr res = TransactionFrame::makeTransactionFromWire(e);
res->addSignature(from);
return res;
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:19,代码来源:TxTests.cpp
示例12: applyCreditPaymentTx
PaymentResult
applyCreditPaymentTx(Application& app, SecretKey& from, SecretKey& to,
Currency& ci, SequenceNumber seq, int64_t amount,
PaymentResultCode result, std::vector<Currency>* path)
{
TransactionFramePtr txFrame;
txFrame = createCreditPaymentTx(from, to, ci, seq, amount, path);
LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader());
txFrame->apply(delta, app);
checkTransaction(*txFrame);
auto& firstResult = getFirstResult(*txFrame);
PaymentResult res = firstResult.tr().paymentResult();
auto resCode = res.code();
REQUIRE(resCode == result);
return res;
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:21,代码来源:TxTests.cpp
示例13: getRoot
void
CommandHandler::testTx(std::string const& params, std::string& retStr)
{
std::map<std::string, std::string> retMap;
http::server::server::parseParams(params, retMap);
auto to = retMap.find("to");
auto from = retMap.find("from");
auto amount = retMap.find("amount");
auto create = retMap.find("create");
Json::Value root;
if (to != retMap.end() && from != retMap.end() && amount != retMap.end())
{
Hash const& networkID = mApp.getNetworkID();
SecretKey toKey, fromKey;
if (to->second == "root")
{
toKey = getRoot(networkID);
}
else
{
toKey = getAccount(to->second.c_str());
}
if (from->second == "root")
{
fromKey = getRoot(networkID);
}
else
{
fromKey = getAccount(from->second.c_str());
}
uint64_t paymentAmount = 0;
std::istringstream iss(amount->second);
iss >> paymentAmount;
root["from_name"] = from->second;
root["to_name"] = to->second;
root["from_id"] = PubKeyUtils::toStrKey(fromKey.getPublicKey());
root["to_id"] = PubKeyUtils::toStrKey(toKey.getPublicKey());
;
root["amount"] = (Json::UInt64)paymentAmount;
SequenceNumber fromSeq = getSeq(fromKey, mApp) + 1;
TransactionFramePtr txFrame;
if (create != retMap.end() && create->second == "true")
{
txFrame = createCreateAccountTx(networkID, fromKey, toKey, fromSeq,
paymentAmount);
}
else
{
txFrame = createPaymentTx(networkID, fromKey, toKey, fromSeq,
paymentAmount);
}
switch (mApp.getHerder().recvTransaction(txFrame))
{
case Herder::TX_STATUS_PENDING:
root["status"] = "pending";
break;
case Herder::TX_STATUS_DUPLICATE:
root["status"] = "duplicate";
break;
case Herder::TX_STATUS_ERROR:
root["status"] = "error";
root["detail"] =
xdr::xdr_to_string(txFrame->getResult().result.code());
break;
default:
assert(false);
}
}
开发者ID:Samx2015,项目名称:stellar-core,代码行数:78,代码来源:CommandHandler.cpp
示例14: SeqSorter
static bool
SeqSorter(TransactionFramePtr const& tx1, TransactionFramePtr const& tx2)
{
return tx1->getSeqNum() < tx2->getSeqNum();
}
开发者ID:nullstyle,项目名称:stellar-core,代码行数:5,代码来源:TxSetFrame.cpp
示例15: assert
size_t
TransactionFrame::copyTransactionsToStream(Database& db, soci::session& sess,
uint32_t ledgerSeq,
uint32_t ledgerCount,
XDROutputFileStream& txOut,
XDROutputFileStream& txResultOut)
{
auto timer = db.getSelectTimer("txhistory");
std::string txBody, txResult, txMeta;
uint32_t begin = ledgerSeq, end = ledgerSeq + ledgerCount;
size_t n = 0;
TransactionEnvelope tx;
uint32_t curLedgerSeq;
assert(begin <= end);
soci::statement st =
(sess.prepare << "SELECT ledgerseq, txbody, txresult FROM txhistory "
"WHERE ledgerseq >= :begin AND ledgerseq < :end ORDER "
"BY ledgerseq ASC, txindex ASC",
soci::into(curLedgerSeq), soci::into(txBody), soci::into(txResult),
soci::use(begin), soci::use(end));
Hash h;
TxSetFrame txSet(h); // we're setting the hash later
TransactionHistoryResultEntry results;
st.execute(true);
uint32_t lastLedgerSeq = curLedgerSeq;
results.ledgerSeq = curLedgerSeq;
while (st.got_data())
{
if (curLedgerSeq != lastLedgerSeq)
{
saveTransactionHelper(db, sess, lastLedgerSeq, txSet, results,
txOut, txResultOut);
// reset state
txSet.mTransactions.clear();
results.ledgerSeq = ledgerSeq;
results.txResultSet.results.clear();
lastLedgerSeq = curLedgerSeq;
}
std::string body = base64::decode(txBody);
std::string result = base64::decode(txResult);
xdr::xdr_get g1(body.data(), body.data() + body.size());
xdr_argpack_archive(g1, tx);
TransactionFramePtr txFrame = make_shared<TransactionFrame>(tx);
txSet.add(txFrame);
xdr::xdr_get g2(result.data(), result.data() + result.size());
results.txResultSet.results.emplace_back();
TransactionResultPair& p = results.txResultSet.results.back();
xdr_argpack_archive(g2, p);
if (p.transactionHash != txFrame->getContentsHash())
{
throw std::runtime_error("transaction mismatch");
}
++n;
st.fetch();
}
if (n != 0)
{
saveTransactionHelper(db, sess, lastLedgerSeq, txSet, results, txOut,
txResultOut);
}
return n;
}
开发者ID:thejollyrogers,项目名称:stellar-core,代码行数:75,代码来源:TransactionFrame.cpp
示例16: operator
bool operator()(TransactionFramePtr const& tx1,
TransactionFramePtr const& tx2)
{
return tx1->getFeeRatio(mApp) < tx2->getFeeRatio(mApp);
}
开发者ID:ligthyear,项目名称:stellar-core,代码行数:5,代码来源:TxSetFrame.cpp
示例17: applyCreateOfferHelper
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;
}
开发者ID:gmarceau,项目名称:stellar-core,代码行数:61,代码来源:TxTests.cpp
示例18: CLOG
bool
TxSetFrame::checkOrTrim(
Application& app,
std::function<bool(TransactionFramePtr, SequenceNumber)>
processInvalidTxLambda,
std::function<bool(std::vector<TransactionFramePtr> const&)>
processInsufficientBalance)
{
map<AccountID, vector<TransactionFramePtr>> accountTxMap;
Hash lastHash;
for (auto& tx : mTransactions)
{
if (tx->getFullHash() < lastHash)
{
CLOG(DEBUG, "Herder")
<< "bad txSet: " << hexAbbrev(mPreviousLedgerHash)
<< " not sorted correctly";
return false;
}
accountTxMap[tx->getSourceID()].push_back(tx);
lastHash = tx->getFullHash();
}
for (auto& item : accountTxMap)
{
// order by sequence number
std::sort(item.second.begin(), item.second.end(), SeqSorter);
TransactionFramePtr lastTx;
SequenceNumber lastSeq = 0;
int64_t totFee = 0;
for (auto& tx : item.second)
{
if (!tx->checkValid(app, lastSeq))
{
if (processInvalidTxLambda(tx, lastSeq))
continue;
return false;
}
totFee += tx->getFee();
lastTx = tx;
lastSeq = tx->getSeqNum();
}
if (lastTx)
{
// make sure account can pay the fee for all these tx
int64_t newBalance =
lastTx->getSourceAccount().getBalance() - totFee;
if (newBalance < lastTx->getSourceAccount().getMinimumBalance(
app.getLedgerManager()))
{
if (!processInsufficientBalance(item.second))
return false;
}
}
}
return true;
}
开发者ID:hanxueming126,项目名称:stellar-core,代码行数:62,代码来源:TxSetFrame.cpp
示例19: doInflation
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)
{
//.........这里部分代码省略.........
开发者ID:gmarceau,项目名称:stellar-core,代码行数:101,代码来源:InflationTests.cpp
注:本文中的TransactionFramePtr类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论