-
Notifications
You must be signed in to change notification settings - Fork 302
feat(express): add typed routes for TRX delegation APIs #8344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
modules/express/src/typedRoutes/api/v2/accountResources.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import * as t from 'io-ts'; | ||
| import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; | ||
| import { BitgoExpressError } from '../../schemas/error'; | ||
|
|
||
| /** | ||
| * Path parameters for account resources endpoint | ||
| */ | ||
| export const AccountResourcesParams = { | ||
| /** Coin identifier (e.g., 'trx', 'ttrx') */ | ||
| coin: t.string, | ||
| /** Wallet ID */ | ||
| id: t.string, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Body parameters for account resources endpoint | ||
| */ | ||
| export const AccountResourcesBody = { | ||
| /** On-chain addresses to query resources for */ | ||
| addresses: t.array(t.string), | ||
| /** Optional destination address to calculate energy deficit for token transfers */ | ||
| destinationAddress: optional(t.string), | ||
| } as const; | ||
|
|
||
| /** | ||
| * Account resource information for a single address | ||
| */ | ||
| export const AccountResourceInfo = t.intersection([ | ||
| t.type({ | ||
| address: t.string, | ||
| free_bandwidth_available: t.number, | ||
| free_bandwidth_used: t.number, | ||
| staked_bandwidth_available: t.number, | ||
| staked_bandwidth_used: t.number, | ||
| energy_available: t.number, | ||
| energy_used: t.number, | ||
| }), | ||
| t.partial({ | ||
| resourceDeficitForAssetTransfer: t.intersection([ | ||
| t.type({ | ||
| bandwidthDeficit: t.number, | ||
| bandwidthSunRequired: t.string, | ||
| }), | ||
| t.partial({ | ||
| energyDeficit: t.number, | ||
| energySunRequired: t.string, | ||
| }), | ||
| ]), | ||
| maxResourcesDelegatable: t.type({ | ||
| bandwidthSun: t.string, | ||
| energySun: t.string, | ||
| }), | ||
| }), | ||
| ]); | ||
|
|
||
| /** | ||
| * Failed address information | ||
| */ | ||
| export const FailedAddressInfo = t.type({ | ||
| address: t.string, | ||
| error: t.string, | ||
| }); | ||
|
|
||
| /** | ||
| * Response for account resources | ||
| */ | ||
| export const AccountResourcesResponse = { | ||
| /** Account resources for the queried addresses */ | ||
| 200: t.type({ | ||
| resources: t.array(AccountResourceInfo), | ||
| failedAddresses: t.array(FailedAddressInfo), | ||
| }), | ||
| /** Invalid request */ | ||
| 400: BitgoExpressError, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Get Account Resources | ||
| * | ||
| * Query BANDWIDTH and ENERGY resource information for TRX wallet addresses. | ||
| * Returns resource availability, usage, and optional deficit calculations | ||
| * for token transfers. | ||
| * | ||
| * @operationId express.v2.wallet.getaccountresources | ||
| * @tag express | ||
| */ | ||
| export const GetAccountResources = httpRoute({ | ||
bhavidhingra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| path: '/api/v2/{coin}/wallet/{id}/getaccountresources', | ||
| method: 'POST', | ||
| request: httpRequest({ | ||
| params: AccountResourcesParams, | ||
| body: AccountResourcesBody, | ||
| }), | ||
bhavidhingra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| response: AccountResourcesResponse, | ||
| }); | ||
82 changes: 82 additions & 0 deletions
82
modules/express/src/typedRoutes/api/v2/resourceDelegations.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import * as t from 'io-ts'; | ||
| import { NumberFromString } from 'io-ts-types'; | ||
| import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; | ||
| import { BitgoExpressError } from '../../schemas/error'; | ||
|
|
||
| /** | ||
| * Path parameters for resource delegations endpoint | ||
| */ | ||
| export const ResourceDelegationsParams = { | ||
| /** Coin identifier (e.g., 'trx', 'ttrx') */ | ||
| coin: t.string, | ||
| /** Wallet ID */ | ||
| id: t.string, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Query parameters for resource delegations endpoint | ||
| */ | ||
| export const ResourceDelegationsQuery = { | ||
| /** Filter by delegation direction: 'outgoing' for delegations from this address, 'incoming' for delegations to this address; omit to fetch both */ | ||
| type: optional(t.union([t.literal('outgoing'), t.literal('incoming')])), | ||
| /** Filter by resource type (case-insensitive: ENERGY, energy, BANDWIDTH, bandwidth) */ | ||
| resource: optional(t.string), | ||
parasgarg-bitgo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** Maximum number of results to return */ | ||
| limit: optional(NumberFromString), | ||
| /** Pagination cursor from previous response */ | ||
| nextBatchPrevId: optional(t.string), | ||
bhavidhingra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } as const; | ||
|
|
||
| /** | ||
| * A single delegation record | ||
| */ | ||
| export const DelegationRecord = t.type({ | ||
| id: t.string, | ||
| coin: t.string, | ||
| ownerAddress: t.string, | ||
| receiverAddress: t.string, | ||
| resource: t.union([t.literal('ENERGY'), t.literal('BANDWIDTH')]), | ||
| balance: t.string, | ||
| updatedAt: t.string, | ||
| }); | ||
|
|
||
| /** | ||
| * Response for resource delegations | ||
| */ | ||
| export const ResourceDelegationsResponse = { | ||
| /** Resource delegations for the wallet */ | ||
| 200: t.type({ | ||
| address: t.string, | ||
| coin: t.string, | ||
| delegations: t.intersection([ | ||
| t.type({ | ||
| outgoing: t.array(DelegationRecord), | ||
| incoming: t.array(DelegationRecord), | ||
| }), | ||
| t.partial({ | ||
| nextBatchPrevId: t.string, | ||
| }), | ||
| ]), | ||
| }), | ||
| /** Invalid request */ | ||
| 400: BitgoExpressError, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Get Resource Delegations | ||
| * | ||
| * Query active outgoing and incoming ENERGY/BANDWIDTH resource delegations | ||
| * for a TRX wallet. | ||
| * | ||
| * @operationId express.v2.wallet.resourcedelegations | ||
| * @tag express | ||
| */ | ||
| export const GetResourceDelegations = httpRoute({ | ||
| path: '/api/v2/{coin}/wallet/{id}/resourcedelegations', | ||
| method: 'GET', | ||
| request: httpRequest({ | ||
| params: ResourceDelegationsParams, | ||
| query: ResourceDelegationsQuery, | ||
| }), | ||
bhavidhingra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| response: ResourceDelegationsResponse, | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.