John Freeman
John Freeman

Reputation: 2692

How can I apply a transaction to a ledger?

I have an STTx and a Ledger. How can I get a new Ledger with the transaction applied (or even just a ReadView such that .info().accountHash is up-to-date)?

Upvotes: 0

Views: 75

Answers (1)

John Freeman
John Freeman

Reputation: 2692

# include <ripple/app/ledger/BuildLedger.h>
# include <ripple/app/misc/CanonicalTXSet.h>
# include <ripple/consensus/LedgerTiming.h> // ledgerDefaultTimeResolution

// Start with what you have.
Application const& app = ...
beast::Journal journal = ...
std::shared_ptr<Ledger const> const& parent = ...
std::shared_ptr<STTx const> const& transaction = ...

// Massage them into parameters for buildLedger.
NetClock::time_point const closeTime = app.timeKeeper().closeTime();
bool const closeTimeCorrect = false;
NetClock::duration closeTimeResolution = ledgerDefaultTimeResolution;
CanonicalTXSet const transactions{parent->info().hash};
transactions.insert(transaction);
std::set<TXID> failedTransactions; // Leave empty.

std::shared_ptr<Ledger> child = buildLedger(
    parent,
    closeTime,
    closeTimeCorrect ,
    closeTimeResolution,
    app,
    transactions,
    failedTransactions,
    journal);

Upvotes: 0

Related Questions