Skip to content

Commit caec81e

Browse files
feat(mbe): final logic update
1 parent e4c82f8 commit caec81e

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

src/api/master/handlers/eddsa.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
EddsaUtils,
1010
BaseCoin,
1111
ApiKeyShare,
12+
TxRequest,
1213
} from '@bitgo/sdk-core';
1314
import { EnclavedExpressClient } from '../clients/enclavedExpressClient';
1415
import { exchangeEddsaCommitments } from '@bitgo/sdk-core/dist/src/bitgo/tss/common';

src/api/master/handlers/handleConsolidate.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import {
22
RequestTracer,
33
KeyIndices,
44
BuildConsolidationTransactionOptions,
5-
PrebuildAndSignTransactionOptions,
65
getTxRequest,
76
} from '@bitgo/sdk-core';
87
import logger from '../../../logger';
98
import { MasterApiSpecRouteRequest } from '../routers/masterApiSpec';
10-
import { getWalletAndSigningKeychain } from '../handlerUtils';
11-
import { signAndSendMultisig } from './handleSendMany';
9+
import { getWalletAndSigningKeychain, makeCustomSigningFunction } from '../handlerUtils';
1210
import { signAndSendTxRequests } from './transactionRequests';
1311

1412
export async function handleConsolidate(
@@ -55,42 +53,43 @@ export async function handleConsolidate(
5553

5654
const unsignedBuilds = await wallet.buildAccountConsolidations(consolidationParams);
5755

58-
logger.info(
56+
logger.debug(
5957
`Consolidation request for wallet ${walletId} with ${unsignedBuilds.length} unsigned builds`,
6058
);
6159

6260
if (unsignedBuilds && unsignedBuilds.length > 0) {
6361
for (const unsignedBuild of unsignedBuilds) {
64-
const unsignedBuildWithOptions: PrebuildAndSignTransactionOptions = Object.assign(
65-
{},
66-
consolidationParams,
67-
);
68-
unsignedBuildWithOptions.apiVersion = consolidationParams.apiVersion;
69-
unsignedBuildWithOptions.prebuildTx = unsignedBuild;
70-
71-
const txRequest = await getTxRequest(bitgo, wallet.id(), unsignedBuild.txRequestId!, reqId);
72-
7362
try {
74-
const sendTx = isMPC
63+
const result = isMPC
7564
? await signAndSendTxRequests(
7665
bitgo,
7766
wallet,
78-
txRequest,
67+
await getTxRequest(
68+
bitgo,
69+
wallet.id(),
70+
(() => {
71+
if (!unsignedBuild.txRequestId) {
72+
throw new Error('Missing txRequestId in unsigned build');
73+
}
74+
return unsignedBuild.txRequestId;
75+
})(),
76+
reqId,
77+
),
7978
enclavedExpressClient,
8079
signingKeychain,
8180
reqId,
8281
)
83-
: await signAndSendMultisig(
84-
wallet,
85-
params.source,
86-
unsignedBuild,
87-
unsignedBuildWithOptions,
88-
enclavedExpressClient,
89-
signingKeychain,
90-
reqId,
91-
);
92-
93-
successfulTxs.push(sendTx);
82+
: await wallet.sendAccountConsolidation({
83+
...consolidationParams,
84+
prebuildTx: unsignedBuild,
85+
customSigningFunction: makeCustomSigningFunction({
86+
enclavedExpressClient,
87+
source: params.source,
88+
pub: signingKeychain.pub!,
89+
}),
90+
});
91+
92+
successfulTxs.push(result);
9493
} catch (e) {
9594
console.dir(e);
9695
failedTxs.push(e as any);

src/api/master/handlers/handleSendMany.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,16 @@ export async function signAndSendMultisig(
214214
pub: signingKeychain.pub,
215215
});
216216

217-
console.log('Signed transaction:', JSON.stringify(signedTx, null, 2));
218-
219217
// Get extra prebuild parameters
220-
const extraParams =
221-
Array.isArray(params.recipients) && params.recipients.length > 0
222-
? await wallet.baseCoin.getExtraPrebuildParams({
223-
...params,
224-
wallet,
225-
})
226-
: {};
218+
const extraParams = await wallet.baseCoin.getExtraPrebuildParams({
219+
...params,
220+
wallet,
221+
});
227222

228223
// Combine the signed transaction with extra parameters
229224
const finalTxParams = { ...signedTx, ...extraParams };
230225

231-
console.log('Final transaction parameters:', JSON.stringify(finalTxParams, null, 2));
232226
// Submit the half signed transaction
233-
return await wallet.submitTransaction(finalTxParams, reqId);
227+
const result = (await wallet.submitTransaction(finalTxParams, reqId)) as any;
228+
return result;
234229
}

0 commit comments

Comments
 (0)