From 95267a1d03619b020a6739d73b9f1744798ab53a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 12 Mar 2015 20:59:28 +0100 Subject: [PATCH] Minor fix for block getting. --- libethereum/BlockChain.cpp | 8 ++++---- libethereum/BlockChain.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index e781be8f5..19a16d193 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -65,7 +65,7 @@ std::ostream& dev::eth::operator<<(std::ostream& _out, BlockChain const& _bc) ldb::Slice dev::eth::toSlice(h256 _h, unsigned _sub) { #if ALL_COMPILERS_ARE_CPP11_COMPLIANT - static thread_local h256 h = _h ^ h256(u256(_sub)); + static thread_local h256 h = _h ^ sha3(h256(u256(_sub))); return ldb::Slice((char const*)&h, 32); #else static boost::thread_specific_ptr t_h; @@ -140,7 +140,7 @@ void BlockChain::open(std::string _path, bool _killExisting) // Insert details of genesis block. m_details[m_genesisHash] = BlockDetails(0, c_genesisDifficulty, h256(), {}); auto r = m_details[m_genesisHash].rlp(); - m_extrasDB->Put(m_writeOptions, ldb::Slice((char const*)&m_genesisHash, 32), (ldb::Slice)dev::ref(r)); + m_extrasDB->Put(m_writeOptions, toSlice(m_genesisHash, ExtraDetails), (ldb::Slice)dev::ref(r)); } checkConsistency(); @@ -703,7 +703,7 @@ bool BlockChain::isKnown(h256 _hash) const return true; } string d; - m_blocksDB->Get(m_readOptions, ldb::Slice((char const*)&_hash, 32), &d); + m_blocksDB->Get(m_readOptions, toSlice(_hash), &d); return !!d.size(); } @@ -720,7 +720,7 @@ bytes BlockChain::block(h256 _hash) const } string d; - m_blocksDB->Get(m_readOptions, ldb::Slice((char const*)&_hash, 32), &d); + m_blocksDB->Get(m_readOptions, toSlice(_hash), &d); if (!d.size()) { diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index a6760a3f6..9676b4a78 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -155,6 +155,7 @@ public: /// Get a transaction from its hash. Thread-safe. bytes transaction(h256 _transactionHash) const { TransactionAddress ta = queryExtras(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytes(); return transaction(ta.blockHash, ta.index); } + std::pair transactionLocation(h256 _transactionHash) const { TransactionAddress ta = queryExtras(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return std::pair(h256(), 0); return std::make_pair(ta.blockHash, ta.index); } /// Get a block's transaction (RLP format) for the given block hash (or the most recent mined if none given) & index. Thread-safe. bytes transaction(h256 _blockHash, unsigned _i) const { bytes b = block(_blockHash); return RLP(b)[1][_i].data().toBytes(); }