Skip to content

feat: Add --of-principal to icp token/cycles balance#536

Merged
adamspofford-dfinity merged 4 commits intomainfrom
spofford/balance-of
May 1, 2026
Merged

feat: Add --of-principal to icp token/cycles balance#536
adamspofford-dfinity merged 4 commits intomainfrom
spofford/balance-of

Conversation

@adamspofford-dfinity
Copy link
Copy Markdown
Contributor

No description provided.

@adamspofford-dfinity adamspofford-dfinity requested a review from a team as a code owner April 27, 2026 22:35
///
/// # Returns
///
pub async fn get_balance(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

isn't it simpler if get_balance takes:

  • principal
  • Option
  • token

And you get the balance for that principal.
Seems like a clearer api than maybe maybe of_principal otherwise the principal of the agent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, the agent should typically be an input to functions like this. The reason is that we do not want to create more than one HTTP client for keep-alive reasons.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes - I didn't mean to drop the agent.
I meant

Suggested change
pub async fn get_balance(
agent: &Agent,
of_principal: Principal,
subaccount: Option<[u8; 32]>,
token: &str,
) -> Result<TokenAmount, GetBalanceError> {

This way you're always getting the balance of_principal not falling back on the principal in the agent and it's clearer what the function is doing.

Otherwise - at the very least add a comment to explain the arguments

@adamspofford-dfinity adamspofford-dfinity enabled auto-merge (squash) May 1, 2026 15:39
@adamspofford-dfinity adamspofford-dfinity merged commit a2c112e into main May 1, 2026
156 of 158 checks passed
@adamspofford-dfinity adamspofford-dfinity deleted the spofford/balance-of branch May 1, 2026 16:16
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.

2 participants