Skip to content

Commit de4eddd

Browse files
authored
feat(express): migrated prebuildAndSignTransaction as type route
2 parents a604c23 + fbc0e56 commit de4eddd

File tree

5 files changed

+1307
-15
lines changed

5 files changed

+1307
-15
lines changed

modules/express/src/clientRoutes.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,11 +968,13 @@ async function handleV2SendMany(req: express.Request) {
968968
* - send/broadcast transaction
969969
* @param req where req.body is {@link PrebuildAndSignTransactionOptions}
970970
*/
971-
export async function handleV2PrebuildAndSignTransaction(req: express.Request): Promise<SignedTransactionRequest> {
971+
export async function handleV2PrebuildAndSignTransaction(
972+
req: ExpressApiRouteRequest<'express.v2.wallet.prebuildandsigntransaction', 'post'>
973+
): Promise<SignedTransactionRequest> {
972974
const bitgo = req.bitgo;
973-
const coin = bitgo.coin(req.params.coin);
975+
const coin = bitgo.coin(req.decoded.coin);
974976
const reqId = new RequestTracer();
975-
const wallet = await coin.wallets().get({ id: req.params.id, reqId });
977+
const wallet = await coin.wallets().get({ id: req.decoded.id, reqId });
976978
req.body.reqId = reqId;
977979
let result;
978980
try {
@@ -1640,12 +1642,10 @@ export function setupAPIRoutes(app: express.Application, config: Config): void {
16401642
// send transaction
16411643
app.post('/api/v2/:coin/wallet/:id/sendcoins', parseBody, prepareBitGo(config), promiseWrapper(handleV2SendOne));
16421644
app.post('/api/v2/:coin/wallet/:id/sendmany', parseBody, prepareBitGo(config), promiseWrapper(handleV2SendMany));
1643-
app.post(
1644-
'/api/v2/:coin/wallet/:id/prebuildAndSignTransaction',
1645-
parseBody,
1645+
router.post('express.v2.wallet.prebuildandsigntransaction', [
16461646
prepareBitGo(config),
1647-
promiseWrapper(handleV2PrebuildAndSignTransaction)
1648-
);
1647+
typedPromiseWrapper(handleV2PrebuildAndSignTransaction),
1648+
]);
16491649

16501650
// token enablement
16511651
app.post(

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { PostShareWallet } from './v2/shareWallet';
3535
import { PutExpressWalletUpdate } from './v2/expressWalletUpdate';
3636
import { PostFanoutUnspents } from './v2/fanoutUnspents';
3737
import { PostConsolidateUnspents } from './v2/consolidateunspents';
38+
import { PostPrebuildAndSignTransaction } from './v2/prebuildAndSignTransaction';
3839
import { PostCoinSign } from './v2/coinSign';
3940

4041
// Too large types can cause the following error
@@ -109,10 +110,13 @@ export const ExpressV1PendingApprovalsApiSpec = apiSpec({
109110
},
110111
});
111112

112-
export const ExpressV1WalletSignTransactionApiSpec = apiSpec({
113+
export const ExpressWalletSignTransactionApiSpec = apiSpec({
113114
'express.v1.wallet.signTransaction': {
114115
post: PostSignTransaction,
115116
},
117+
'express.v2.wallet.prebuildandsigntransaction': {
118+
post: PostPrebuildAndSignTransaction,
119+
},
116120
});
117121

118122
export const ExpressV1KeychainDeriveApiSpec = apiSpec({
@@ -240,7 +244,7 @@ export type ExpressApi = typeof ExpressPingApiSpec &
240244
typeof ExpressV1WalletAcceptShareApiSpec &
241245
typeof ExpressV1WalletSimpleCreateApiSpec &
242246
typeof ExpressV1PendingApprovalsApiSpec &
243-
typeof ExpressV1WalletSignTransactionApiSpec &
247+
typeof ExpressWalletSignTransactionApiSpec &
244248
typeof ExpressV1KeychainDeriveApiSpec &
245249
typeof ExpressV1KeychainLocalApiSpec &
246250
typeof ExpressV1PendingApprovalConstructTxApiSpec &
@@ -270,7 +274,7 @@ export const ExpressApi: ExpressApi = {
270274
...ExpressV1WalletAcceptShareApiSpec,
271275
...ExpressV1WalletSimpleCreateApiSpec,
272276
...ExpressV1PendingApprovalsApiSpec,
273-
...ExpressV1WalletSignTransactionApiSpec,
277+
...ExpressWalletSignTransactionApiSpec,
274278
...ExpressV1KeychainDeriveApiSpec,
275279
...ExpressV1KeychainLocalApiSpec,
276280
...ExpressV1PendingApprovalConstructTxApiSpec,

0 commit comments

Comments
 (0)