Skip to content

Add getAccountResources method to Wallet class#8173

Open
Copilot wants to merge 1 commit intomasterfrom
copilot/add-get-account-resources-method
Open

Add getAccountResources method to Wallet class#8173
Copilot wants to merge 1 commit intomasterfrom
copilot/add-get-account-resources-method

Conversation

Copy link

Copilot AI commented Feb 18, 2026

Adds getAccountResources() method to Wallet class for querying account resources from the WP API endpoint.

Changes

  • Interface (iWallet.ts): Added GetAccountResourcesOptions interface and method signature to IWallet interface
  • Implementation (wallet.ts): Implemented method with options object pattern, array validation and query parameter handling in Wallet class
  • Tests (wallet/getAccountResources.ts): Added unit tests covering success paths and error cases

Method Signature

async getAccountResources(params: GetAccountResourcesOptions): Promise<any>

Where GetAccountResourcesOptions is defined as:

export interface GetAccountResourcesOptions {
  addresses: string[];
  destinationAddress?: string;
}

Calls GET /accountResources with addresses as a required parameter and optional destinationAddress for computing resource deficits needed for an asset transfer.

Usage

// Access via wallet instance
const resources = await wallet.getAccountResources({ 
  addresses: ['addr1', 'addr2'] 
});

// Query with destination address to get resource deficit for a token transfer
const resources = await wallet.getAccountResources({ 
  addresses: ['TWpHQPy2CBwJ5opNF1ugRY357vMDPNLEGK'],
  destinationAddress: 'TUXzc3sUuTqNDeKCbhiKtcVUfSvgTtRpzz'
});

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).

Copilot AI changed the title [WIP] Add getAccountResources method to wallet class Add getAccountResources method to Wallet class Feb 18, 2026
Copilot AI requested a review from bhavidhingra February 18, 2026 16:44
Copy link
Contributor

@bhavidhingra bhavidhingra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot We have to change the implementation a bit, this operation will not belong to a wallet. It is agnostic of a wallet.

Copy link
Author

Copilot AI commented Feb 19, 2026

@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 Wallet class to BaseCoin class since this operation is wallet-agnostic. The method now works at the coin level and can be accessed via coin.getAccountResources(addresses, assetName) instead of wallet.getAccountResources(). Changes in commit 215fa80.

Copilot AI changed the title Add getAccountResources method to Wallet class Add getAccountResources method to BaseCoin class Feb 19, 2026
Copilot AI requested a review from bhavidhingra February 19, 2026 11:37
Copy link
Contributor

@bhavidhingra bhavidhingra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Sorry, we have to pivot back to using the wallet specific API. Please revert back to using it as was done earlier.

Copy link
Author

Copilot AI commented Feb 19, 2026

@copilot Sorry, we have to pivot back to using the wallet specific API. Please revert back to using it as was done earlier.

Reverted back to Wallet class implementation with assetName parameter. The method is now in the Wallet class as originally implemented. Changes in commit bce0ac4.

Copilot AI changed the title Add getAccountResources method to BaseCoin class Add getAccountResources method to Wallet class Feb 19, 2026
Copilot AI requested a review from bhavidhingra February 19, 2026 12:17
Copilot AI requested a review from bhavidhingra February 19, 2026 13:35
@bhavidhingra bhavidhingra force-pushed the copilot/add-get-account-resources-method branch 5 times, most recently from ca445f8 to 2c533ce Compare February 19, 2026 14:28
@bhavidhingra bhavidhingra force-pushed the copilot/add-get-account-resources-method branch 3 times, most recently from 5c2716d to 6d7e006 Compare March 5, 2026 12:35
@bhavidhingra bhavidhingra marked this pull request as ready for review March 5, 2026 13:17
@bhavidhingra bhavidhingra requested review from a team as code owners March 5, 2026 13:17
@bhavidhingra bhavidhingra force-pushed the copilot/add-get-account-resources-method branch from 6d7e006 to 7038a4f Compare March 5, 2026 14:15
* @param params - options object containing addresses and optional destinationAddress
* @returns {Promise<any>} - response from WP API
*/
async getAccountResources(params: GetAccountResourcesOptions): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we type the response instead of any?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@bhavidhingra bhavidhingra force-pushed the copilot/add-get-account-resources-method branch from 7038a4f to d286299 Compare March 6, 2026 10:19
@bhavidhingra bhavidhingra requested a review from ravibitgo March 6, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants