|
| 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 | + * Path parameters for account resources endpoint |
| 7 | + */ |
| 8 | +export const AccountResourcesParams = { |
| 9 | + /** Coin identifier (e.g., 'trx', 'ttrx') */ |
| 10 | + coin: t.string, |
| 11 | + /** Wallet ID */ |
| 12 | + id: t.string, |
| 13 | +} as const; |
| 14 | + |
| 15 | +/** |
| 16 | + * Body parameters for account resources endpoint |
| 17 | + */ |
| 18 | +export const AccountResourcesBody = { |
| 19 | + /** On-chain addresses to query resources for */ |
| 20 | + addresses: t.array(t.string), |
| 21 | + /** Optional destination address to calculate energy deficit for token transfers */ |
| 22 | + destinationAddress: optional(t.string), |
| 23 | +} as const; |
| 24 | + |
| 25 | +/** |
| 26 | + * Account resource information for a single address |
| 27 | + */ |
| 28 | +export const AccountResourceInfo = t.intersection([ |
| 29 | + t.type({ |
| 30 | + address: t.string, |
| 31 | + free_bandwidth_available: t.number, |
| 32 | + free_bandwidth_used: t.number, |
| 33 | + staked_bandwidth_available: t.number, |
| 34 | + staked_bandwidth_used: t.number, |
| 35 | + energy_available: t.number, |
| 36 | + energy_used: t.number, |
| 37 | + }), |
| 38 | + t.partial({ |
| 39 | + resourceDeficitForAssetTransfer: t.intersection([ |
| 40 | + t.type({ |
| 41 | + bandwidthDeficit: t.number, |
| 42 | + bandwidthSunRequired: t.string, |
| 43 | + }), |
| 44 | + t.partial({ |
| 45 | + energyDeficit: t.number, |
| 46 | + energySunRequired: t.string, |
| 47 | + }), |
| 48 | + ]), |
| 49 | + maxResourcesDelegatable: t.type({ |
| 50 | + bandwidthSun: t.string, |
| 51 | + energySun: t.string, |
| 52 | + }), |
| 53 | + }), |
| 54 | +]); |
| 55 | + |
| 56 | +/** |
| 57 | + * Failed address information |
| 58 | + */ |
| 59 | +export const FailedAddressInfo = t.type({ |
| 60 | + address: t.string, |
| 61 | + error: t.string, |
| 62 | +}); |
| 63 | + |
| 64 | +/** |
| 65 | + * Response for account resources |
| 66 | + */ |
| 67 | +export const AccountResourcesResponse = { |
| 68 | + /** Account resources for the queried addresses */ |
| 69 | + 200: t.type({ |
| 70 | + resources: t.array(AccountResourceInfo), |
| 71 | + failedAddresses: t.array(FailedAddressInfo), |
| 72 | + }), |
| 73 | + /** Invalid request */ |
| 74 | + 400: BitgoExpressError, |
| 75 | +} as const; |
| 76 | + |
| 77 | +/** |
| 78 | + * Get Account Resources |
| 79 | + * |
| 80 | + * Query BANDWIDTH and ENERGY resource information for TRX wallet addresses. |
| 81 | + * Returns resource availability, usage, and optional deficit calculations |
| 82 | + * for token transfers. |
| 83 | + * |
| 84 | + * @operationId express.v2.wallet.getaccountresources |
| 85 | + * @tag express |
| 86 | + */ |
| 87 | +export const GetAccountResources = httpRoute({ |
| 88 | + path: '/api/v2/{coin}/wallet/{id}/getaccountresources', |
| 89 | + method: 'POST', |
| 90 | + request: httpRequest({ |
| 91 | + params: AccountResourcesParams, |
| 92 | + body: AccountResourcesBody, |
| 93 | + }), |
| 94 | + response: AccountResourcesResponse, |
| 95 | +}); |
0 commit comments