예제 #1
0
AccountFrame::pointer
AccountFrame::loadAccount(AccountID const& accountID, Database& db)
{
    LedgerKey key;
    key.type(ACCOUNT);
    key.account().accountID = accountID;
    if (cachedEntryExists(key, db))
    {
        auto p = getCachedEntry(key, db);
        return p ? std::make_shared<AccountFrame>(*p) : nullptr;
    }

    std::string actIDStrKey = PubKeyUtils::toStrKey(accountID);

    std::string publicKey, inflationDest, creditAuthKey;
    std::string homeDomain, thresholds;
    soci::indicator inflationDestInd;

    AccountFrame::pointer res = make_shared<AccountFrame>(accountID);
    AccountEntry& account = res->getAccount();

    auto prep =
        db.getPreparedStatement("SELECT balance, seqnum, numsubentries, "
                                "inflationdest, homedomain, thresholds, "
                                "flags, lastmodified "
                                "FROM accounts WHERE accountid=:v1");
    auto& st = prep.statement();
    st.exchange(into(account.balance));
    st.exchange(into(account.seqNum));
    st.exchange(into(account.numSubEntries));
    st.exchange(into(inflationDest, inflationDestInd));
    st.exchange(into(homeDomain));
    st.exchange(into(thresholds));
    st.exchange(into(account.flags));
    st.exchange(into(res->getLastModified()));
    st.exchange(use(actIDStrKey));
    st.define_and_bind();
    {
        auto timer = db.getSelectTimer("account");
        st.execute(true);
    }

    if (!st.got_data())
    {
        putCachedEntry(key, nullptr, db);
        return nullptr;
    }

    account.homeDomain = homeDomain;

    bn::decode_b64(thresholds.begin(), thresholds.end(),
                   res->mAccountEntry.thresholds.begin());

    if (inflationDestInd == soci::i_ok)
    {
        account.inflationDest.activate() =
            PubKeyUtils::fromStrKey(inflationDest);
    }

    account.signers.clear();

    if (account.numSubEntries != 0)
    {
        auto signers = loadSigners(db, actIDStrKey);
        account.signers.insert(account.signers.begin(), signers.begin(),
                               signers.end());
    }

    res->normalize();
    res->mUpdateSigners = false;
    assert(res->isValid());
    res->mKeyCalculated = false;
    res->putCachedEntry(db);
    return res;
}
예제 #2
0
AccountFrame::pointer
AccountFrame::loadAccount(AccountID const& accountID, Database& db)
{
    LedgerKey key;
    key.type(ACCOUNT);
    key.account().accountID = accountID;
    if (cachedEntryExists(key, db))
    {
        auto p = getCachedEntry(key, db);
        return p ? std::make_shared<AccountFrame>(*p) : nullptr;
    }

    std::string actIDStrKey = PubKeyUtils::toStrKey(accountID);

    std::string publicKey, inflationDest, creditAuthKey;
    std::string homeDomain, thresholds;
    soci::indicator inflationDestInd, homeDomainInd, thresholdsInd;

    soci::session& session = db.getSession();

    AccountFrame::pointer res = make_shared<AccountFrame>(accountID);
    AccountEntry& account = res->getAccount();
    {
        auto timer = db.getSelectTimer("account");
        session << "SELECT balance, seqnum, numsubentries, "
                   "inflationdest, homedomain, thresholds,  flags "
                   "FROM accounts WHERE accountid=:v1",
            into(account.balance), into(account.seqNum),
            into(account.numSubEntries), into(inflationDest, inflationDestInd),
            into(homeDomain, homeDomainInd), into(thresholds, thresholdsInd),
            into(account.flags), use(actIDStrKey);
    }

    if (!session.got_data())
    {
        putCachedEntry(key, nullptr, db);
        return nullptr;
    }

    if (homeDomainInd == soci::i_ok)
    {
        account.homeDomain = homeDomain;
    }

    if (thresholdsInd == soci::i_ok)
    {
        bn::decode_b64(thresholds.begin(), thresholds.end(),
                       res->mAccountEntry.thresholds.begin());
    }

    if (inflationDestInd == soci::i_ok)
    {
        account.inflationDest.activate() =
            PubKeyUtils::fromStrKey(inflationDest);
    }

    account.signers.clear();

    if (account.numSubEntries != 0)
    {
        string pubKey;
        Signer signer;

        auto prep = db.getPreparedStatement("SELECT publickey, weight from "
                                            "signers where accountid =:id");
        auto& st = prep.statement();
        st.exchange(use(actIDStrKey));
        st.exchange(into(pubKey));
        st.exchange(into(signer.weight));
        st.define_and_bind();
        {
            auto timer = db.getSelectTimer("signer");
            st.execute(true);
        }
        while (st.got_data())
        {
            signer.pubKey = PubKeyUtils::fromStrKey(pubKey);

            account.signers.push_back(signer);

            st.fetch();
        }
    }

    res->normalize();
    res->mUpdateSigners = false;

    res->mKeyCalculated = false;
    res->putCachedEntry(db);
    return res;
}