|
| 1 | +import * as t from 'io-ts'; |
| 2 | +import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; |
| 3 | +import { BitgoExpressError } from '../../schemas/error'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Request parameters for constructing a pending approval transaction |
| 7 | + */ |
| 8 | +export const ConstructPendingApprovalTxRequestParams = { |
| 9 | + /** The ID of the pending approval */ |
| 10 | + id: t.string, |
| 11 | +}; |
| 12 | + |
| 13 | +/** |
| 14 | + * Request body for constructing a pending approval transaction |
| 15 | + */ |
| 16 | +export const ConstructPendingApprovalTxRequestBody = { |
| 17 | + /** The wallet passphrase to decrypt the user key (either walletPassphrase or xprv must be provided for transactionRequest type) */ |
| 18 | + walletPassphrase: optional(t.string), |
| 19 | + /** The extended private key (alternative to walletPassphrase) */ |
| 20 | + xprv: optional(t.string), |
| 21 | + /** Whether to use the original fee from the transaction request (cannot be used with fee, feeRate, or feeTxConfirmTarget) */ |
| 22 | + useOriginalFee: optional(t.boolean), |
| 23 | + /** Custom fee amount in satoshis (cannot be used with useOriginalFee) */ |
| 24 | + fee: optional(t.number), |
| 25 | + /** Custom fee rate in satoshis per kilobyte (cannot be used with useOriginalFee) */ |
| 26 | + feeRate: optional(t.number), |
| 27 | + /** Custom fee confirmation target in blocks (cannot be used with useOriginalFee) */ |
| 28 | + feeTxConfirmTarget: optional(t.number), |
| 29 | +}; |
| 30 | + |
| 31 | +/** |
| 32 | + * Response for constructing a pending approval transaction |
| 33 | + */ |
| 34 | +export const ConstructPendingApprovalTxResponse = t.type({ |
| 35 | + /** The signed transaction hex */ |
| 36 | + tx: t.string, |
| 37 | + /** The fee amount in satoshis */ |
| 38 | + fee: optional(t.number), |
| 39 | + /** The fee rate in satoshis per kilobyte */ |
| 40 | + feeRate: optional(t.number), |
| 41 | + /** Whether the transaction is instant */ |
| 42 | + instant: optional(t.boolean), |
| 43 | + /** The BitGo fee amount */ |
| 44 | + bitgoFee: optional(t.unknown), |
| 45 | + /** Travel information */ |
| 46 | + travelInfos: optional(t.unknown), |
| 47 | + /** Estimated transaction size in bytes */ |
| 48 | + estimatedSize: optional(t.number), |
| 49 | + /** Unspent transaction outputs used */ |
| 50 | + unspents: optional(t.array(t.unknown)), |
| 51 | +}); |
| 52 | + |
| 53 | +/** |
| 54 | + * Construct a pending approval transaction |
| 55 | + * |
| 56 | + * This endpoint constructs and signs a transaction for a pending approval, returning the transaction hex |
| 57 | + * but not sending it to the network. This is useful for reviewing the transaction before approving it. |
| 58 | + * |
| 59 | + * For transaction request type approvals, either a wallet passphrase or xprv must be provided to sign the transaction. |
| 60 | + * You can optionally specify fee-related parameters to customize the transaction fee. |
| 61 | + * |
| 62 | + * @operationId express.v1.pendingapproval.constructTx |
| 63 | + */ |
| 64 | +export const PutConstructPendingApprovalTx = httpRoute({ |
| 65 | + path: '/api/v1/pendingapprovals/:id/constructTx', |
| 66 | + method: 'PUT', |
| 67 | + request: httpRequest({ |
| 68 | + params: ConstructPendingApprovalTxRequestParams, |
| 69 | + body: ConstructPendingApprovalTxRequestBody, |
| 70 | + }), |
| 71 | + response: { |
| 72 | + /** Successfully constructed transaction */ |
| 73 | + 200: ConstructPendingApprovalTxResponse, |
| 74 | + /** Invalid request or construction fails */ |
| 75 | + 400: BitgoExpressError, |
| 76 | + }, |
| 77 | +}); |
0 commit comments