本文整理汇总了C++中TransactionFramePtr类的典型用法代码示例。如果您正苦于以下问题:C++ TransactionFramePtr类的具体用法?C++ TransactionFramePtr怎么用?C++ TransactionFramePtr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TransactionFramePtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
示例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);
}
}
}
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例14: SeqSorter
static bool
SeqSorter(TransactionFramePtr const& tx1, TransactionFramePtr const& tx2)
{
return tx1->getSeqNum() < tx2->getSeqNum();
}
示例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;
}