@@ -2,13 +2,11 @@ import {
22 RequestTracer ,
33 KeyIndices ,
44 BuildConsolidationTransactionOptions ,
5- PrebuildAndSignTransactionOptions ,
65 getTxRequest ,
76} from '@bitgo/sdk-core' ;
87import logger from '../../../logger' ;
98import { MasterApiSpecRouteRequest } from '../routers/masterApiSpec' ;
10- import { getWalletAndSigningKeychain } from '../handlerUtils' ;
11- import { signAndSendMultisig } from './handleSendMany' ;
9+ import { getWalletAndSigningKeychain , makeCustomSigningFunction } from '../handlerUtils' ;
1210import { signAndSendTxRequests } from './transactionRequests' ;
1311
1412export 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 ) ;
0 commit comments