|
| 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 | +export const CalculateMinerFeeInfoRequestBody = { |
| 6 | + /** fee rate in satoshis per kilobyte, if not provided a fallback fee rate will be used */ |
| 7 | + feeRate: optional(t.number), |
| 8 | + /** number of P2SH (multisig) inputs in the transaction */ |
| 9 | + nP2shInputs: t.number, |
| 10 | + /** number of P2PKH (single sig) inputs in the transaction */ |
| 11 | + nP2pkhInputs: t.number, |
| 12 | + /** number of P2SH-P2WSH (segwit) inputs in the transaction */ |
| 13 | + nP2shP2wshInputs: t.number, |
| 14 | + /** number of outputs in the transaction */ |
| 15 | + nOutputs: t.number, |
| 16 | + /** whether the transaction contains uncompressed public keys (affects size calculation) */ |
| 17 | + containsUncompressedPublicKeys: optional(t.boolean), |
| 18 | +}; |
| 19 | + |
| 20 | +export const CalculateMinerFeeInfoResponse = t.type({ |
| 21 | + /** estimated size of the transaction in bytes */ |
| 22 | + size: t.number, |
| 23 | + /** estimated fee in satoshis for the transaction */ |
| 24 | + fee: t.number, |
| 25 | + /** fee rate that was used to estimate the fee (in satoshis per kilobyte) */ |
| 26 | + feeRate: t.number, |
| 27 | +}); |
| 28 | + |
| 29 | +/** |
| 30 | + * Calculate miner fee info |
| 31 | + * |
| 32 | + * Calculates the estimated size and fee for a transaction based on the number and types of inputs and outputs. |
| 33 | + * This is useful for estimating the fee before creating a transaction. |
| 34 | + * |
| 35 | + * The calculation takes into account: |
| 36 | + * 1. The number and types of inputs (P2SH, P2PKH, P2SH-P2WSH) |
| 37 | + * 2. The number of outputs |
| 38 | + * 3. Whether the transaction contains uncompressed public keys |
| 39 | + * 4. The fee rate (in satoshis per kilobyte) |
| 40 | + * |
| 41 | + * @operationId express.calculateminerfeeinfo |
| 42 | + */ |
| 43 | +export const PostCalculateMinerFeeInfo = httpRoute({ |
| 44 | + path: '/api/v[12]/calculateminerfeeinfo', |
| 45 | + method: 'POST', |
| 46 | + request: httpRequest({ |
| 47 | + body: CalculateMinerFeeInfoRequestBody, |
| 48 | + }), |
| 49 | + response: { |
| 50 | + 200: CalculateMinerFeeInfoResponse, |
| 51 | + 400: BitgoExpressError, |
| 52 | + 404: BitgoExpressError, |
| 53 | + }, |
| 54 | +}); |
0 commit comments