Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ ui/translations.qrc
beam_version.gen
keykeeper/wasm-key-keeper.*

out/
wmake.sh
out/
wmake.sh
.cache
13 changes: 13 additions & 0 deletions explorer/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,19 @@ class Adapter : public Node::IObserver, public IAdapter {
return get_block_not_found(h);
}

json get_block_by_hash(const Blob& key) override
{
Height h = _nodeBackend.get_DB().FindBlockByHash(key);
if (h)
{
NodeDB::StateID sid;
Block::SystemState::Full s;
if (FindBlockByHeight(sid, s, h))
return extract_block_from_row(sid, s, h);
}
return get_block_not_found(0);
}

json get_blocks(Height startHeight, uint64_t n) override {

json result = json::array();
Expand Down
1 change: 1 addition & 0 deletions explorer/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct IAdapter {
virtual json get_status() = 0;
virtual json get_block(Height height, int adj) = 0;
virtual json get_block_by_kernel(const Blob& key) = 0;
virtual json get_block_by_hash(const Blob& key) = 0;
virtual json get_blocks(Height startHeight, uint64_t n) = 0;
virtual json get_hdrs(Height hMax, uint64_t nMax, uint64_t dn, const TotalsCol* pCols, uint32_t nCols) = 0;
virtual json get_peers() = 0;
Expand Down
4 changes: 2 additions & 2 deletions explorer/htm/BeamExplorer.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3348,8 +3348,8 @@ <h2 class="title">About</h2>
function submitSearch() {
// Get search string
let query = document.getElementById('SearchField').value;
// Simplistic test to check if search string is rather block height or kernel id
let key = query.length < 10 ? '&height=' : '&kernel=';
// Simplistic test to check if search string is rather block height or hash/kernel id
let key = query.length < 10 ? '&height=' : '&id=';
// Load the corresponding URL
window.location.href = UrlSelf('block', key + query);
}
Expand Down
19 changes: 18 additions & 1 deletion explorer/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,28 @@ bool get_UrlHexArg(const HttpUrl& url, const std::string_view& name, uintBig_t<n

OnRequest(block)
{

ECC::Hash::Value hv;
if (get_UrlHexArg(_currentUrl, "hash", hv))
return _backend.get_block_by_hash(hv);

if (get_UrlHexArg(_currentUrl, "kernel", hv))
return _backend.get_block_by_kernel(hv);

auto idArg = _currentUrl.args.find("id");
if (_currentUrl.args.end() != idArg)
{
const auto& val = idArg->second;
if (val.find_first_not_of("0123456789") == std::string_view::npos)
return _backend.get_block(static_cast<Height>(_currentUrl.get_int_arg("id", 0)), 0);
if (get_UrlHexArg(_currentUrl, "id", hv))
{
auto res = _backend.get_block_by_kernel(hv);
if (res.value("found", true))
return res;
return _backend.get_block_by_hash(hv);
}
}

auto height = _currentUrl.get_int_arg("height", 0);
auto adj = _currentUrl.get_int_arg("adj", 0);
return _backend.get_block(height, static_cast<int>(adj));
Expand Down
19 changes: 18 additions & 1 deletion node/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void NodeDB::Open(const char* szPath)
bCreate = !rs.Step();
}

const uint64_t nVersionTop = 38;
const uint64_t nVersionTop = 39;


Transaction t(*this);
Expand Down Expand Up @@ -499,6 +499,10 @@ void NodeDB::Open(const char* szPath)
CreateTables37();
// no break;

case 38: // block hash index
ExecQuick("CREATE INDEX IF NOT EXISTS [Idx" TblStates "Hash] ON [" TblStates "] ([" TblStates_Hash "]);");
// no break;

ParamIntSet(ParamID::DbVer, nVersionTop);
// no break;

Expand Down Expand Up @@ -559,6 +563,7 @@ void NodeDB::Create()

ExecQuick("CREATE INDEX [Idx" TblStates "Wrk] ON [" TblStates "] ([" TblStates_ChainWork "]);");
ExecQuick("CREATE INDEX [Idx" TblStates TblStates_Txos "] ON [" TblStates "] ([" TblStates_Txos "]);");
ExecQuick("CREATE INDEX [Idx" TblStates "Hash] ON [" TblStates "] ([" TblStates_Hash "]);");

ExecQuick("CREATE TABLE [" TblTips "] ("
"[" TblTips_Number "] INTEGER NOT NULL,"
Expand Down Expand Up @@ -2381,6 +2386,18 @@ Height NodeDB::FindKernel(const Blob& key)
return h;
}

Height NodeDB::FindBlockByHash(const Blob& hash)
{
Recordset rs(*this, Query::StateFindByHash, "SELECT " TblStates_Number " FROM " TblStates " WHERE " TblStates_Hash "=? LIMIT 1");
rs.put(0, hash);
if (!rs.Step())
return 0;

Height h;
rs.get(0, h);
return h;
}

void NodeDB::TxoAdd(TxoID id, const Blob& b)
{
Recordset rs(*this, Query::TxoAdd, "INSERT INTO " TblTxo "(" TblTxo_ID "," TblTxo_Value ") VALUES(?,?)");
Expand Down
2 changes: 2 additions & 0 deletions node/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class NodeDB
StateSetRB,
StateGetTxos,
StateFindByTxos,
StateFindByHash,
TipAdd,
TipDel,
TipReachableAdd,
Expand Down Expand Up @@ -577,6 +578,7 @@ class NodeDB
void InsertKernel(const Blob&, Height h);
void DeleteKernel(const Blob&, Height h);
Height FindKernel(const Blob&); // in case of duplicates - returning the one with the largest Height
Height FindBlockByHash(const Blob& hash);

uint64_t FindStateWorkGreater(const Difficulty::Raw&);

Expand Down
Loading