Skip to content

Commit 07f7e3c

Browse files
feat(mbe): fix comments
1 parent 58ae73d commit 07f7e3c

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

src/api/master/handlers/handleConsolidate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RequestTracer, KeyIndices, CustomSigningFunction } from '@bitgo/sdk-core';
1+
import { RequestTracer, KeyIndices } from '@bitgo/sdk-core';
22
import logger from '../../../logger';
33
import { MasterApiSpecRouteRequest } from '../routers/masterApiSpec';
44
import { getWalletAndSigningKeychain, makeCustomSigningFunction } from '../../../shared/coinUtils';

src/api/master/handlers/handleConsolidateUnspents.ts

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,34 @@
1-
import { RequestTracer, KeyIndices, CustomSigningFunction } from '@bitgo/sdk-core';
1+
import { RequestTracer, KeyIndices } from '@bitgo/sdk-core';
22
import logger from '../../../logger';
33
import { MasterApiSpecRouteRequest } from '../routers/masterApiSpec';
4+
import { getWalletAndSigningKeychain, makeCustomSigningFunction } from '../../../shared/coinUtils';
45

56
export async function handleConsolidateUnspents(
6-
req: MasterApiSpecRouteRequest<'v1.wallet.consolidateUnspents', 'post'>,
7+
req: MasterApiSpecRouteRequest<'v1.wallet.consolidateunspents', 'post'>,
78
) {
89
const enclavedExpressClient = req.enclavedExpressClient;
910
const reqId = new RequestTracer();
1011
const bitgo = req.bitgo;
11-
const baseCoin = bitgo.coin(req.params.coin);
1212
const params = req.decoded;
1313
const walletId = req.params.walletId;
14-
const wallet = await baseCoin.wallets().get({ id: walletId, reqId });
15-
16-
if (!wallet) {
17-
throw new Error(`Wallet ${walletId} not found`);
18-
}
19-
20-
// Get the signing keychain based on source
21-
const keyIdIndex = params.source === 'user' ? KeyIndices.USER : KeyIndices.BACKUP;
22-
const signingKeychain = await baseCoin.keychains().get({
23-
id: wallet.keyIds()[keyIdIndex],
14+
const coin = req.params.coin;
15+
16+
const { wallet, signingKeychain } = await getWalletAndSigningKeychain({
17+
bitgo,
18+
coin,
19+
walletId,
20+
params,
21+
reqId,
22+
KeyIndices,
2423
});
2524

26-
if (!signingKeychain || !signingKeychain.pub) {
27-
throw new Error(`Signing keychain for ${params.source} not found`);
28-
}
29-
30-
if (params.pubkey && params.pubkey !== signingKeychain.pub) {
31-
throw new Error(`Pub provided does not match the keychain on wallet for ${params.source}`);
32-
}
33-
3425
try {
3526
// Create custom signing function that delegates to EBE
36-
const customSigningFunction: CustomSigningFunction = async (signParams) => {
37-
const signedTx = await enclavedExpressClient.signMultisig({
38-
txPrebuild: signParams.txPrebuild,
39-
source: params.source,
40-
pub: signingKeychain.pub!,
41-
});
42-
return signedTx;
43-
};
27+
const customSigningFunction = makeCustomSigningFunction({
28+
enclavedExpressClient,
29+
source: params.source,
30+
pub: signingKeychain.pub!,
31+
});
4432

4533
// Prepare consolidation parameters
4634
const consolidationParams = {

src/api/master/routers/masterApiSpec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,21 @@ export const MasterApiSpec = apiSpec({
294294
description: 'Accelerate transaction',
295295
}),
296296
},
297+
'v1.wallet.consolidateunspents': {
298+
post: httpRoute({
299+
method: 'POST',
300+
path: '/api/{coin}/wallet/{walletId}/consolidateunspents',
301+
request: httpRequest({
302+
params: {
303+
walletId: t.string,
304+
coin: t.string,
305+
},
306+
body: ConsolidateUnspentsRequest,
307+
}),
308+
response: ConsolidateUnspentsResponse,
309+
description: 'Consolidate unspents',
310+
}),
311+
},
297312
});
298313

299314
export type MasterApiSpec = typeof MasterApiSpec;
@@ -362,5 +377,13 @@ export function createMasterApiRouter(
362377
}),
363378
]);
364379

380+
router.post('v1.wallet.consolidateunspents', [
381+
responseHandler<MasterExpressConfig>(async (req: express.Request) => {
382+
const typedReq = req as GenericMasterApiSpecRouteRequest;
383+
const result = await handleConsolidateUnspents(typedReq);
384+
return Response.ok(result);
385+
}),
386+
]);
387+
365388
return router;
366389
}

0 commit comments

Comments
 (0)