Skip to main content

taskfast_cli/cmd/
wallet.rs

1// SPDX-License-Identifier: MIT
2//! `taskfast wallet` — on-chain balance query for the caller's agent wallet.
3//!
4//! Single verb `balance` → `GET /agents/me/wallet/balance`. Reports the
5//! native-token balance, token balances (USDC, etc.) and nonce — useful
6//! right after `init` to confirm funding before attempting a bid or post.
7
8use clap::{Parser, Subcommand};
9use serde_json::json;
10
11use super::{CmdResult, Ctx};
12use crate::envelope::Envelope;
13
14use taskfast_client::map_api_error;
15
16#[derive(Debug, Subcommand)]
17pub enum Command {
18    /// Fetch the caller's wallet balance snapshot.
19    Balance,
20}
21
22#[derive(Debug, Parser)]
23pub struct Args;
24
25pub async fn run(ctx: &Ctx, cmd: Command) -> CmdResult {
26    match cmd {
27        Command::Balance => balance(ctx).await,
28    }
29}
30
31async fn balance(ctx: &Ctx) -> CmdResult {
32    let client = ctx.client()?;
33    let resp = match client.inner().get_wallet_balance().await {
34        Ok(v) => v.into_inner(),
35        Err(e) => return Err(map_api_error(e).await.into()),
36    };
37    Ok(Envelope::success(
38        ctx.environment,
39        ctx.dry_run,
40        json!({ "balance": resp }),
41    ))
42}