|
| 1 | +import { httpRequest, HttpResponse, httpRoute, optional } from '@api-ts/io-ts-http'; |
| 2 | +import * as t from 'io-ts'; |
| 3 | +import { ErrorResponses } from '../../../shared/errors'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Request type for the transaction acceleration endpoint. |
| 7 | + * Used to accelerate unconfirmed transactions on UTXO-based blockchains using CPFP or RBF. |
| 8 | + * |
| 9 | + * @endpoint POST /api/{coin}/wallet/{walletId}/accelerate |
| 10 | + * @description Speeds up unconfirmed transactions by creating a child transaction (CPFP) or replacing the original transaction (RBF) |
| 11 | + */ |
| 12 | +export const AccelerateRequest = { |
| 13 | + /** |
| 14 | + * Public key used for signing the acceleration transaction. |
| 15 | + * @example "xpub661MyMwAqRbcGCNnmzqt3u5KhxmXBHiC78cwAyUMaKJXpFDfHpJwNap6qpG1Kz2SPexKXy3akhPQz7GDYWpHNWkLxRLj6bDxQSf74aTAP9y" |
| 16 | + */ |
| 17 | + pubkey: t.string, |
| 18 | + |
| 19 | + /** |
| 20 | + * The key to use for signing the transaction. |
| 21 | + * @example "user" |
| 22 | + */ |
| 23 | + source: t.union([t.literal('user'), t.literal('backup')]), |
| 24 | + |
| 25 | + /** |
| 26 | + * Transaction IDs to accelerate using Child-Pays-For-Parent (CPFP). |
| 27 | + * CPFP creates a new transaction that spends an output from the original transaction. |
| 28 | + * @example ["abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234"] |
| 29 | + */ |
| 30 | + cpfpTxIds: optional(t.array(t.string)), |
| 31 | + |
| 32 | + /** |
| 33 | + * Fee rate in satoshis per byte for the CPFP transaction. |
| 34 | + * Higher fee rates result in faster confirmations but higher transaction costs. |
| 35 | + * @example 50 // 50 satoshis per byte |
| 36 | + */ |
| 37 | + cpfpFeeRate: optional(t.number), |
| 38 | + |
| 39 | + /** |
| 40 | + * Maximum fee in satoshis for the acceleration transaction. |
| 41 | + * Helps prevent overpaying for transaction acceleration. |
| 42 | + * @example 100000 // 0.001 BTC |
| 43 | + */ |
| 44 | + maxFee: optional(t.number), |
| 45 | + |
| 46 | + /** |
| 47 | + * Transaction IDs to accelerate using Replace-By-Fee (RBF). |
| 48 | + * RBF creates a new transaction that replaces the original transaction. |
| 49 | + * The original transaction must have been created with RBF enabled. |
| 50 | + * @example ["abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234"] |
| 51 | + */ |
| 52 | + rbfTxIds: optional(t.array(t.string)), |
| 53 | + |
| 54 | + /** |
| 55 | + * Fee multiplier for RBF transactions. |
| 56 | + * The new fee will be the original fee multiplied by this value. |
| 57 | + * @example 1.5 // Increase fee by 50% |
| 58 | + */ |
| 59 | + feeMultiplier: optional(t.number), |
| 60 | +}; |
| 61 | + |
| 62 | +/** |
| 63 | + * Response type for the transaction acceleration endpoint. |
| 64 | + * |
| 65 | + * @endpoint POST /api/{coin}/wallet/{walletId}/accelerate |
| 66 | + * @description Sign an acceleration transaction and send to BitGo to sign and broadcast |
| 67 | + */ |
| 68 | +const AccelerateResponse: HttpResponse = { |
| 69 | + /** |
| 70 | + * Successful acceleration response. |
| 71 | + * @returns The signed transaction and its ID |
| 72 | + * @example { "txid": "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234", "tx": "01000000000101edd7a5d948a6c79f273ce686a6a8f2e96ed8c2583b5e77b866aa2a1b3426fbed0100000000ffffffff02102700000000000017a914192f23283c2a9e6c5d11562db0eb5d4eb47f460287b9bc2c000000000017a9145c139b242ab3701f321d2399d3a11b028b3b361e870247304402206ac9477fece38d96688c6c3719cb27396c0563ead0567457e7e884b406b6da8802201992d1cfa1b55a67ce8acb482e9957812487d2555f5f54fb0286ecd3095d78e4012103c92564575197c4d6e3d9792280e7548b3ba52a432101c62de2186c4e2fa7fc580000000000" } |
| 73 | + */ |
| 74 | + 200: t.type({ |
| 75 | + /** |
| 76 | + * The transaction ID (hash) of the acceleration transaction. |
| 77 | + * This can be used to track the transaction on a block explorer. |
| 78 | + * @example "abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234" |
| 79 | + */ |
| 80 | + txid: t.string, |
| 81 | + /** |
| 82 | + * The full signed transaction in hexadecimal format. |
| 83 | + * This transaction can be broadcast to the network. |
| 84 | + * @example "01000000000101edd7a5d948a6c79f273ce686a6a8f2e96ed8c2583b5e77b866aa2a1b3426fbed0100000000ffffffff02102700000000000017a914192f23283c2a9e6c5d11562db0eb5d4eb47f460287b9bc2c000000000017a9145c139b242ab3701f321d2399d3a11b028b3b361e870247304402206ac9477fece38d96688c6c3719cb27396c0563ead0567457e7e884b406b6da8802201992d1cfa1b55a67ce8acb482e9957812487d2555f5f54fb0286ecd3095d78e4012103c92564575197c4d6e3d9792280e7548b3ba52a432101c62de2186c4e2fa7fc580000000000" |
| 85 | + */ |
| 86 | + tx: t.string, |
| 87 | + }), |
| 88 | + ...ErrorResponses, |
| 89 | +}; |
| 90 | + |
| 91 | +/** |
| 92 | + * Accelerate unconfirmed transactions on UTXO-based blockchains. |
| 93 | + * Supports Child-Pays-For-Parent (CPFP) and Replace-By-Fee (RBF) acceleration methods. |
| 94 | + */ |
| 95 | +export const AccelerateRoute = httpRoute({ |
| 96 | + method: 'POST', |
| 97 | + path: '/api/{coin}/wallet/{walletId}/accelerate', |
| 98 | + request: httpRequest({ |
| 99 | + params: { |
| 100 | + walletId: t.string, |
| 101 | + coin: t.string, |
| 102 | + }, |
| 103 | + body: AccelerateRequest, |
| 104 | + }), |
| 105 | + response: AccelerateResponse, |
| 106 | + description: 'Accelerate transaction', |
| 107 | +}); |
0 commit comments