Skip to content

Commit

Permalink
refactor: use highest mempool.space fee estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Jul 22, 2023
1 parent fbd6403 commit 7c38088
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/chain/MempoolSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ class MempoolSpace {
};

public latestFee = (): number | undefined => {
for (const api of this.apis) {
if (api.latestFee !== undefined) {
return api.latestFee;
}
const fees = this.apis
.map((c) => c.latestFee)
.filter((val): val is number => val !== undefined);

if (fees.length === 0) {
this.logger.warn(`All ${this.symbol} MempoolSpace endpoints failed`);
return undefined;
}

this.logger.warn(`All ${this.symbol} MempoolSpace endpoints failed`);
return undefined;
return Math.max(...fees);
};

public stop = () => {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/chain/MempoolSpace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ describe('MempoolSpace', () => {
expect(mempool.latestFee()).not.toBeUndefined();
});

test('should pick results in order', async () => {
test('should pick highest returned fee', async () => {
mempool.stop();

const expectedFee = 42;

mempool['apis'][0]['latestFee'] = expectedFee;
mempool['apis'][1]['latestFee'] = expectedFee - 12;
mempool['apis'][0]['latestFee'] = expectedFee - 12;
mempool['apis'][1]['latestFee'] = expectedFee;
expect(mempool.latestFee()).toEqual(expectedFee);

mempool['apis'][0]['latestFee'] = undefined;
Expand Down

0 comments on commit 7c38088

Please sign in to comment.