Augment "submit" command response:

If merged, this commit will report additional information in the
response to the submit command; this will make it easier for developers
to accurately track the status of transaction submission.

Fixes #2851
This commit is contained in:
p2peer
2019-10-13 00:27:23 +03:00
committed by Nik Bougalis
parent 14f0234a26
commit 79e9085dd1
6 changed files with 237 additions and 2 deletions

View File

@@ -1393,6 +1393,41 @@ TxQ::getMetrics(OpenView const& view) const
return result;
}
TxQ::FeeAndSeq
TxQ::getTxRequiredFeeAndSeq(OpenView const& view,
std::shared_ptr<STTx const> const& tx) const
{
auto const account = (*tx)[sfAccount];
std::lock_guard lock(mutex_);
auto const snapshot = feeMetrics_.getSnapshot();
auto const baseFee = calculateBaseFee(view, *tx);
auto const fee = FeeMetrics::scaleFeeLevel(snapshot, view);
auto const accountSeq = [&view, &account]() -> std::uint32_t {
auto const sle = view.read(keylet::account(account));
if (sle)
return (*sle)[sfSequence];
return 0;
}();
auto availableSeq = accountSeq;
if (auto iter {byAccount_.find(account)}; iter != byAccount_.end())
{
auto& txQAcct = iter->second;
for (auto const& [seq, _] : txQAcct.transactions)
{
(void)_;
if (seq >= availableSeq)
availableSeq = seq + 1;
}
}
return {fee * baseFee / baseLevel, accountSeq, availableSeq};
}
auto
TxQ::getAccountTxs(AccountID const& account, ReadView const& view) const
-> std::map<TxSeq, AccountTxDetails const>