Browse Source

Minor fix for block getting.

cl-refactor
Gav Wood 10 years ago
parent
commit
95267a1d03
  1. 8
      libethereum/BlockChain.cpp
  2. 1
      libethereum/BlockChain.h

8
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<h256> 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())
{

1
libethereum/BlockChain.h

@ -155,6 +155,7 @@ public:
/// Get a transaction from its hash. Thread-safe.
bytes transaction(h256 _transactionHash) const { TransactionAddress ta = queryExtras<TransactionAddress, ExtraTransactionAddress>(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return bytes(); return transaction(ta.blockHash, ta.index); }
std::pair<h256, unsigned> transactionLocation(h256 _transactionHash) const { TransactionAddress ta = queryExtras<TransactionAddress, ExtraTransactionAddress>(_transactionHash, m_transactionAddresses, x_transactionAddresses, NullTransactionAddress); if (!ta) return std::pair<h256, unsigned>(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(); }

Loading…
Cancel
Save