Skip to content

Commit

Permalink
wallet: add getBlockHeader method to node and nullclients.
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Sep 10, 2024
1 parent 66ebb3b commit 46f099f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/wallet/nodeclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,24 @@ class NodeClient extends AsyncEmitter {
async getCoin(hash, index) {
return this.node.getCoin(hash, index);
}

/**
* Get block header.
* @param {Hash|Number} block
* @returns {Promise<ChainEntry>}
*/

async getBlockHeader(block) {
if (typeof block === 'string')
block = Buffer.from(block, 'hex');

const entry = await this.node.chain.getEntry(block);

if (!entry)
return null;

return entry;
}
}

/*
Expand Down
10 changes: 10 additions & 0 deletions lib/wallet/nullclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ class NullClient extends EventEmitter {
async getNameStatus(nameHash) {
return new NameState();
}

/**
* Get block header.
* @param {Hash|Number} block
* @returns {Promise<ChainEntry?>}
*/

async getBlockHeader(block) {
return null;
}
}

/*
Expand Down

0 comments on commit 46f099f

Please sign in to comment.