LedgerHeaderFrame::pointer
LedgerHeaderFrame::loadByHash(Hash const& hash, Database& db)
{
    LedgerHeaderFrame::pointer lhf;

    string hash_s(binToHex(hash));
    string headerEncoded;

    auto prep = db.getPreparedStatement("SELECT data FROM ledgerheaders "
                                        "WHERE ledgerhash = :h");
    auto& st = prep.statement();
    st.exchange(into(headerEncoded));
    st.exchange(use(hash_s));
    st.define_and_bind();
    {
        auto timer = db.getSelectTimer("ledger-header");
        st.execute(true);
    }
    if (st.got_data())
    {
        lhf = decodeFromData(headerEncoded);
        if (lhf->getHash() != hash)
        {
            // wrong hash
            lhf.reset();
        }
    }

    return lhf;
}
Exemple #2
0
LedgerHeaderFrame::pointer
LedgerHeaderFrame::loadBySequence(uint32_t seq, Database& db,
                                  soci::session& sess)
{
    LedgerHeaderFrame::pointer lhf;

    string headerEncoded;
    {
        auto timer = db.getSelectTimer("ledger-header");
        sess << "SELECT data FROM ledgerheaders "
                "WHERE ledgerseq = :s",
            into(headerEncoded), use(seq);
    }
    if (sess.got_data())
    {
        lhf = decodeFromData(headerEncoded);

        if (lhf->mHeader.ledgerSeq != seq)
        {
            // wrong sequence number
            lhf.reset();
        }
    }

    return lhf;
}