Skip to content

Commit 1dd6497

Browse files
committed
refactor(express): splits calculateMinerFeeInfo into v1 and v2
Ticket: WP-7409
1 parent 096819c commit 1dd6497

5 files changed

Lines changed: 76 additions & 24 deletions

File tree

modules/express/src/clientRoutes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,10 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
16561656
router.post('express.decrypt', [prepareBitGo(config), typedPromiseWrapper(handleDecrypt)]);
16571657
router.post('express.encrypt', [prepareBitGo(config), typedPromiseWrapper(handleEncrypt)]);
16581658
router.post('express.verifyaddress', [prepareBitGo(config), typedPromiseWrapper(handleVerifyAddress)]);
1659+
router.post('express.v1.calculateminerfeeinfo', [
1660+
prepareBitGo(config),
1661+
typedPromiseWrapper(handleCalculateMinerFeeInfo),
1662+
]);
16591663
router.post('express.calculateminerfeeinfo', [
16601664
prepareBitGo(config),
16611665
typedPromiseWrapper(handleCalculateMinerFeeInfo),

modules/express/src/typedRoutes/api/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { PostLogin } from './common/login';
88
import { PostDecrypt } from './common/decrypt';
99
import { PostEncrypt } from './common/encrypt';
1010
import { PostVerifyAddress } from './common/verifyAddress';
11-
import { PostCalculateMinerFeeInfo } from './common/calculateMinerFeeInfo';
11+
import { PostV1CalculateMinerFeeInfo } from './v1/calculateMinerFeeInfo';
12+
import { PostV2CalculateMinerFeeInfo } from './v2/calculateMinerFeeInfo';
1213
import { PostAcceptShare } from './v1/acceptShare';
1314
import { PostSimpleCreate } from './v1/simpleCreate';
1415
import { PutPendingApproval } from './v1/pendingApproval';
@@ -101,8 +102,11 @@ export const ExpressVerifyCoinAddressApiSpec = apiSpec({
101102
});
102103

103104
export const ExpressCalculateMinerFeeInfoApiSpec = apiSpec({
105+
'express.v1.calculateminerfeeinfo': {
106+
post: PostV1CalculateMinerFeeInfo,
107+
},
104108
'express.calculateminerfeeinfo': {
105-
post: PostCalculateMinerFeeInfo,
109+
post: PostV2CalculateMinerFeeInfo,
106110
},
107111
});
108112

modules/express/src/typedRoutes/api/common/calculateMinerFeeInfo.ts renamed to modules/express/src/typedRoutes/api/v1/calculateMinerFeeInfo.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,16 @@ export const CalculateMinerFeeInfoResponse = t.type({
2727
});
2828

2929
/**
30-
* Calculate miner fee info
30+
* Calculate miner fee info (v1)
3131
*
3232
* Calculates the estimated size and fee for a transaction based on the number and types of inputs and outputs.
3333
* This is useful for estimating the fee before creating a transaction.
3434
*
35-
* The calculation takes into account:
36-
* 1. The number and types of inputs (P2SH, P2PKH, P2SH-P2WSH)
37-
* 2. The number of outputs
38-
* 3. Whether the transaction contains uncompressed public keys
39-
* 4. The fee rate (in satoshis per kilobyte)
40-
*
41-
* @operationId express.calculateminerfeeinfo
35+
* @operationId express.v1.calculateminerfeeinfo
4236
* @tag express
4337
*/
44-
export const PostCalculateMinerFeeInfo = httpRoute({
45-
path: '/api/v[12]/calculateminerfeeinfo',
38+
export const PostV1CalculateMinerFeeInfo = httpRoute({
39+
path: '/api/v1/calculateminerfeeinfo',
4640
method: 'POST',
4741
request: httpRequest({
4842
body: CalculateMinerFeeInfoRequestBody,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { httpRoute, httpRequest } from '@api-ts/io-ts-http';
2+
import { BitgoExpressError } from '../../schemas/error';
3+
import { CalculateMinerFeeInfoRequestBody, CalculateMinerFeeInfoResponse } from '../v1/calculateMinerFeeInfo';
4+
5+
/**
6+
* Calculate miner fee info
7+
*
8+
* Calculates the estimated size and fee for a transaction based on the number and types of inputs and outputs.
9+
* This is useful for estimating the fee before creating a transaction.
10+
*
11+
* The calculation takes into account:
12+
* 1. The number and types of inputs (P2SH, P2PKH, P2SH-P2WSH)
13+
* 2. The number of outputs
14+
* 3. Whether the transaction contains uncompressed public keys
15+
* 4. The fee rate (in satoshis per kilobyte)
16+
*
17+
* @operationId express.calculateminerfeeinfo
18+
* @tag express
19+
*/
20+
export const PostV2CalculateMinerFeeInfo = httpRoute({
21+
path: '/api/v2/calculateminerfeeinfo',
22+
method: 'POST',
23+
request: httpRequest({
24+
body: CalculateMinerFeeInfoRequestBody,
25+
}),
26+
response: {
27+
200: CalculateMinerFeeInfoResponse,
28+
400: BitgoExpressError,
29+
404: BitgoExpressError,
30+
},
31+
});

modules/express/test/unit/typedRoutes/calculateMinerFeeInfo.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import * as t from 'io-ts';
33
import {
44
CalculateMinerFeeInfoRequestBody,
55
CalculateMinerFeeInfoResponse,
6-
PostCalculateMinerFeeInfo,
7-
} from '../../../src/typedRoutes/api/common/calculateMinerFeeInfo';
6+
PostV1CalculateMinerFeeInfo,
7+
} from '../../../src/typedRoutes/api/v1/calculateMinerFeeInfo';
8+
import { PostV2CalculateMinerFeeInfo } from '../../../src/typedRoutes/api/v2/calculateMinerFeeInfo';
89
import { assertDecode } from './common';
910
import 'should';
1011
import 'should-http';
@@ -301,25 +302,43 @@ describe('CalculateMinerFeeInfo codec tests', function () {
301302
});
302303
});
303304

304-
describe('PostCalculateMinerFeeInfo route definition', function () {
305-
it('should have the correct path', function () {
306-
assert.strictEqual(PostCalculateMinerFeeInfo.path, '/api/v[12]/calculateminerfeeinfo');
305+
describe('PostV1CalculateMinerFeeInfo route definition', function () {
306+
it('should have the correct path for v1', function () {
307+
assert.strictEqual(PostV1CalculateMinerFeeInfo.path, '/api/v1/calculateminerfeeinfo');
307308
});
308309

309310
it('should have the correct HTTP method', function () {
310-
assert.strictEqual(PostCalculateMinerFeeInfo.method, 'POST');
311+
assert.strictEqual(PostV1CalculateMinerFeeInfo.method, 'POST');
311312
});
312313

313314
it('should have the correct request configuration', function () {
314-
// Verify the route is configured with a request property
315-
assert.ok(PostCalculateMinerFeeInfo.request);
315+
assert.ok(PostV1CalculateMinerFeeInfo.request);
316316
});
317317

318318
it('should have the correct response types', function () {
319-
// Check that the response object has the expected status codes
320-
assert.ok(PostCalculateMinerFeeInfo.response[200]);
321-
assert.ok(PostCalculateMinerFeeInfo.response[400]);
322-
assert.ok(PostCalculateMinerFeeInfo.response[404]);
319+
assert.ok(PostV1CalculateMinerFeeInfo.response[200]);
320+
assert.ok(PostV1CalculateMinerFeeInfo.response[400]);
321+
assert.ok(PostV1CalculateMinerFeeInfo.response[404]);
322+
});
323+
});
324+
325+
describe('PostV2CalculateMinerFeeInfo route definition', function () {
326+
it('should have the correct path for v2', function () {
327+
assert.strictEqual(PostV2CalculateMinerFeeInfo.path, '/api/v2/calculateminerfeeinfo');
328+
});
329+
330+
it('should have the correct HTTP method', function () {
331+
assert.strictEqual(PostV2CalculateMinerFeeInfo.method, 'POST');
332+
});
333+
334+
it('should have the correct request configuration', function () {
335+
assert.ok(PostV2CalculateMinerFeeInfo.request);
336+
});
337+
338+
it('should have the correct response types', function () {
339+
assert.ok(PostV2CalculateMinerFeeInfo.response[200]);
340+
assert.ok(PostV2CalculateMinerFeeInfo.response[400]);
341+
assert.ok(PostV2CalculateMinerFeeInfo.response[404]);
323342
});
324343
});
325344

0 commit comments

Comments
 (0)