Skip to content

Commit

Permalink
wallet: fix getBlockHeader for NodeClient.
Browse files Browse the repository at this point in the history
node-client: remove getMedianTime (not used).
  • Loading branch information
nodech committed Nov 19, 2024
1 parent 0d0cc1f commit 6558b45
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 72 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ process and allows parallel rescans.
- Add `getMempoolRejectionFilter` and `checkMempoolRejectionFilter` NodeClient
aliases.
- Add `getFee`, an HTTP alternative to estimateFee socket call.
- Adds `getMedianTime(blockhash)` that returns median time past of the block.
- Adds `getEntries(start, end)` that returns encoded chain entries.

### Wallet Changes
Expand Down
10 changes: 0 additions & 10 deletions lib/client/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,6 @@ class NodeClient extends Client {
return this.call('get entry', blockhash);
}

/**
* Get median time past.
* @param {Hash} blockhash
* @returns {Promise<Number>}
*/

getMedianTime(blockhash) {
return this.call('get median time', blockhash);
}

/**
* Get hashes.
* @param {Number} [start=-1]
Expand Down
17 changes: 1 addition & 16 deletions lib/wallet/nodeclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,6 @@ class NodeClient extends AsyncEmitter {
return entry;
}

/**
* Get median time past.
* @param {Hash} blockhash
* @returns {Promise<Number>}
*/

async getMedianTime(blockhash) {
const entry = await this.node.chain.getEntry(blockhash);

if (!entry)
return null;

return this.node.chain.getMedianTime(entry);
}

/**
* Send a transaction. Do not wait for promise.
* @param {TX} tx
Expand Down Expand Up @@ -358,7 +343,7 @@ class NodeClient extends AsyncEmitter {
if (!entry)
return null;

return entry;
return entry.toJSON();
}
}

Expand Down
11 changes: 0 additions & 11 deletions lib/wallet/nullclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const assert = require('bsert');
const EventEmitter = require('events');
const NameState = require('../covenants/namestate');
const Block = require('../primitives/block');
const util = require('../utils/util');

/**
* Null Client
Expand Down Expand Up @@ -94,16 +93,6 @@ class NullClient extends EventEmitter {
return { hash, height: 0, time: 0 };
}

/**
* Get median time past.
* @param {Hash} blockhash
* @returns {Promise<Number>}
*/

async getMedianTime(blockhash) {
return util.now();
}

/**
* Send a transaction. Do not wait for promise.
* @param {TX} tx
Expand Down
35 changes: 1 addition & 34 deletions test/node-http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const mnemonics = require('./data/mnemonic-english.json');
const consensus = require('../lib/protocol/consensus');
const Outpoint = require('../lib/primitives/outpoint');
const ChainEntry = require('../lib/blockchain/chainentry');
const util = require('../lib/utils/util');
const {ZERO_HASH} = consensus;

// Commonly used test mnemonic
Expand Down Expand Up @@ -434,7 +433,7 @@ describe('Node HTTP', function() {
describe('Websockets', function() {
this.timeout(15000);

describe('Get entry and mtp', function() {
describe('Get entry', function() {
const nodeCtx = new NodeContext({
wallet: true
});
Expand Down Expand Up @@ -463,11 +462,6 @@ describe('Node HTTP', function() {
assert.strictEqual(entry.height, 0);
});

it('should get genesis mtp by height', async () => {
const mtp = await nclient.getMedianTime(0);
assert(mtp);
});

it('should get last entry by height', async () => {
const rawTip = await nclient.getTip();
assert(rawTip);
Expand All @@ -483,14 +477,6 @@ describe('Node HTTP', function() {
assert.bufferEqual(entry.hash, tip.hash);
});

it('should get last mtp by height', async () => {
const tip = ChainEntry.decode(await nclient.getTip());
assert(tip);

const mtp = await nclient.getMedianTime(tip.height);
assert(mtp);
});

it('should get all entries by hash', async () => {
const tip = ChainEntry.decode(await nclient.getTip());
assert(tip);
Expand All @@ -508,25 +494,6 @@ describe('Node HTTP', function() {
hash = entry.prevBlock;
} while (entry.height > 0);
});

it('should get all mtps by hash', async () => {
const tip = ChainEntry.decode(await nclient.getTip());

let entry;
let hash = tip.hash;
let lastMTP = util.now() + 1e8;
do {
entry = ChainEntry.decode(await nclient.getEntry(hash));
assert(entry);

const mtp = await nclient.getMedianTime(entry.hash);
assert(mtp);
assert(mtp <= lastMTP);
lastMTP = mtp;

hash = entry.prevBlock;
} while (entry.height > 0);
});
});

describe('get hashes and entries', function() {
Expand Down

0 comments on commit 6558b45

Please sign in to comment.