Add getAccountResources method to Wallet class#8173
Conversation
bhavidhingra
left a comment
There was a problem hiding this comment.
@copilot We have to change the implementation a bit, this operation will not belong to a wallet. It is agnostic of a wallet.
Moved the method from |
bhavidhingra
left a comment
There was a problem hiding this comment.
@copilot Sorry, we have to pivot back to using the wallet specific API. Please revert back to using it as was done earlier.
ca445f8 to
2c533ce
Compare
5c2716d to
6d7e006
Compare
6d7e006 to
7038a4f
Compare
| * @param params - options object containing addresses and optional destinationAddress | ||
| * @returns {Promise<any>} - response from WP API | ||
| */ | ||
| async getAccountResources(params: GetAccountResourcesOptions): Promise<any> { |
There was a problem hiding this comment.
can we type the response instead of any?
TICKET: CHALO-206
7038a4f to
d286299
Compare
Adds
getAccountResources()method to Wallet class for querying account resources from the WP API endpoint.Changes
iWallet.ts): AddedGetAccountResourcesOptionsinterface and method signature toIWalletinterfacewallet.ts): Implemented method with options object pattern, array validation and query parameter handling inWalletclasswallet/getAccountResources.ts): Added unit tests covering success paths and error casesMethod Signature
Where
GetAccountResourcesOptionsis defined as:Calls
GET /accountResourceswith addresses as a required parameter and optionaldestinationAddressfor computing resource deficits needed for an asset transfer.Usage
Example Output
Running against a testnet USDT wallet (
ttrx:usdt):{ "resources": [ { "address": "TWpHQPy2CBwJ5opNF1ugRY357vMDPNLEGK", "free_bandwidth_available": 600, "free_bandwidth_used": 0, "staked_bandwidth_available": 0, "staked_bandwidth_used": 0, "energy_available": 0, "energy_used": 0, "resourceDeficitForAssetTransfer": { "bandwidthDeficit": 0, "bandwidthSunRequired": "0", "energyDeficit": 28045, "energySunRequired": "1993" }, "maxResourcesDelegatable": { "bandwidthWeight": "0", "energyWeight": "0" } } ], "failedAddresses": [] }Key fields explained:
free_bandwidth_available/staked_bandwidth_available: Bandwidth from free daily allocation and TRX staking respectively.energy_available: Energy the address currently has (from staking or delegation).resourceDeficitForAssetTransfer: The shortfall in bandwidth and energy needed for a token transfer to the destination address. Here the address needs 28,045 energy (costing 1,993 SUN ≈ 0.001993 TRX) to perform a USDT transfer, but has no bandwidth deficit.maxResourcesDelegatable: The maximum bandwidth/energy weight this address can delegate to others (zero here since nothing is staked).