Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node/http: get block header by hash/height #808

Merged
merged 5 commits into from
Aug 1, 2019
Merged
Changes from 2 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
17 changes: 17 additions & 0 deletions lib/node/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,23 @@ class HTTP extends Server {
res.json(200, block.getJSON(this.network, view, height, depth));
});

// Block Header by hash/height
this.get('/header/:block', async (req, res) => {
const valid = Validator.fromRequest(req);
const hash = valid.uintbrhash('block');

enforce(hash != null, 'Hash or height required.');

const entry = await this.chain.getEntry(hash);

if (!entry) {
res.json(404);
return;
}

res.json(200, entry.toJSON());
tynes marked this conversation as resolved.
Show resolved Hide resolved
});

// Mempool snapshot
this.get('/mempool', async (req, res) => {
enforce(this.mempool, 'No mempool available.');
Expand Down