vector<bool> GetCoinsByTxHash(const HashValue& hash) override { DbDataReader dr = m_cmdTxFindCoins.Bind(1, ReducedHashValue(hash)).ExecuteVector(); vector<bool> vec; if (!dr.IsDBNull(0)) { CMemReadStream stm(dr.GetBytes(0)); for (int v; (v=stm.ReadByte())!=-1;) { for (int i=0; i<8; ++i) vec.push_back(v & (1 << i)); } } return vec; }
pair<int, int> FindPrevTxCoords(DbWriter& wr, int height, const HashValue& hash) override { //!!! ASSERT(!MtxSqlite.try_lock()); DbDataReader dr = m_cmdTxHashToBlockordIdx .Bind(1, ReducedHashValue(hash)) .ExecuteVector(); int heightOut = dr.GetInt32(0); wr.Write7BitEncoded(height-heightOut+1); pair<int, int> pp = TxHashesOutNums(dr.GetBytes(1)).StartingTxOutIdx(hash); if (pp.second < 0) Throw(E_COIN_InconsistentDatabase); return pp; }
bool FindTx(const HashValue& hash, Tx *ptx) override { EXT_LOCK (MtxSqlite) { DbDataReader dr = m_cmdFindTx.Bind(1, ReducedHashValue(hash)).ExecuteReader(); if (!dr.Read()) return false; if (ptx) { ptx->EnsureCreate(); ptx->SetHash(hash); LoadFromDb(*ptx, dr); } } return true; }
bool FindTxById(const ConstBuf& txid, Tx *ptx) override { EXT_LOCK (MtxSqlite) { DbDataReader dr = m_cmdFindTx.Bind(1, *(Int64*)txid.P).ExecuteReader(); if (!dr.Read()) return false; if (ptx) { ptx->EnsureCreate(); ptx->SetReducedHash(txid); LoadFromDb(*ptx, dr); } } return true; }
DomainData Resolve(RCString domain) override { if (!ResolverMode) Throw(E_NOTIMPL); DomainData r; EXT_LOCK (MtxSqlite) { DbDataReader dr = m_cmdFindDomain.Bind(1, domain).ExecuteReader(); if (dr.Read()) { r.AddressData = dr.GetString(0); r.Height = dr.GetInt32(1); } } return r; }
vector<Block> GetBlocks(const LocatorHashes& locators, const HashValue& hashStop) override { vector<Block> r; int idx = locators.FindIndexInMainChain(); EXT_LOCK (MtxSqlite) { SqliteCommand cmd(EXT_STR("SELECT id, hash, data, txhashes FROM blocks WHERE id>" << idx << " ORDER BY id LIMIT " << 2000 + locators.DistanceBack), m_db); for (DbDataReader dr = cmd.ExecuteReader(); dr.Read();) { Block block = LoadBlock(dr); r.push_back(block); if (Hash(block) == hashStop) break; } } return r; }
DbDataReader SqliteCommand::ExecuteVector() { DbDataReader r = SqliteCommand::ExecuteReader(); if (!r.Read()) Throw(ExtErr::DB_NoRecord); return r; }
Blob FindPubkey(Int64 id) override { EXT_LOCK (MtxSqlite) { DbDataReader dr = CmdPubkeyIdToData.Bind(1, id).ExecuteReader(); return dr.Read() ? Blob(dr.GetBytes(0)) : Blob(nullptr); } }
Block FindBlock(const HashValue& hash) override { EXT_LOCK (MtxSqlite) { DbDataReader dr = m_cmdFindBlock.Bind(1, ReducedBlockHash(hash)).ExecuteReader(); return dr.Read() ? LoadBlock(dr) : Block(nullptr); } }
int GetNameHeight(const ConstBuf& cbufName, int heightExpired) override { DbDataReader dr = m_cmdNameHeight.Bind(1, ToStringName(cbufName)).ExecuteReader(); return dr.Read() ? dr.GetInt32(0) : -1; }