The credential issuance and verification handlers used Handle::block_on() directly inside the tokio runtime, causing a deadlock. Wrapped with block_in_place() to properly yield the runtime thread. Also completed full feature verification across all 25 test groups (~175 checks) on live server. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
3.6 KiB
Rust
107 lines
3.6 KiB
Rust
use super::RpcHandler;
|
|
use crate::wallet::{ecash, profits};
|
|
use anyhow::Result;
|
|
|
|
impl RpcHandler {
|
|
pub(super) async fn handle_wallet_ecash_balance(
|
|
&self,
|
|
) -> Result<serde_json::Value> {
|
|
let wallet = ecash::load_wallet(&self.config.data_dir).await?;
|
|
Ok(serde_json::json!({
|
|
"balance_sats": wallet.balance(),
|
|
"token_count": wallet.tokens.iter().filter(|t| !t.spent).count(),
|
|
}))
|
|
}
|
|
|
|
pub(super) async fn handle_wallet_ecash_mint(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let amount_sats = params
|
|
.get("amount_sats")
|
|
.and_then(|v| v.as_u64())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing amount_sats"))?;
|
|
|
|
if amount_sats == 0 || amount_sats > 1_000_000 {
|
|
return Err(anyhow::anyhow!("Amount must be between 1 and 1,000,000 sats"));
|
|
}
|
|
|
|
let token = ecash::mint_tokens(&self.config.data_dir, amount_sats).await?;
|
|
Ok(serde_json::json!({
|
|
"token_id": token.id,
|
|
"amount_sats": token.amount_sats,
|
|
}))
|
|
}
|
|
|
|
pub(super) async fn handle_wallet_ecash_melt(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let token_id = params
|
|
.get("token_id")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing token_id"))?;
|
|
|
|
let amount = ecash::melt_tokens(&self.config.data_dir, token_id).await?;
|
|
Ok(serde_json::json!({
|
|
"melted_sats": amount,
|
|
}))
|
|
}
|
|
|
|
pub(super) async fn handle_wallet_ecash_send(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let amount_sats = params
|
|
.get("amount_sats")
|
|
.and_then(|v| v.as_u64())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing amount_sats"))?;
|
|
|
|
let token_str = ecash::send_token(&self.config.data_dir, amount_sats).await?;
|
|
Ok(serde_json::json!({
|
|
"token": token_str,
|
|
"amount_sats": amount_sats,
|
|
}))
|
|
}
|
|
|
|
pub(super) async fn handle_wallet_ecash_receive(
|
|
&self,
|
|
params: Option<serde_json::Value>,
|
|
) -> Result<serde_json::Value> {
|
|
let params = params.ok_or_else(|| anyhow::anyhow!("Missing params"))?;
|
|
let token = params
|
|
.get("token")
|
|
.and_then(|v| v.as_str())
|
|
.ok_or_else(|| anyhow::anyhow!("Missing token"))?;
|
|
|
|
let amount = ecash::receive_token(&self.config.data_dir, token).await?;
|
|
Ok(serde_json::json!({
|
|
"received_sats": amount,
|
|
}))
|
|
}
|
|
|
|
pub(super) async fn handle_wallet_ecash_history(
|
|
&self,
|
|
) -> Result<serde_json::Value> {
|
|
let wallet = ecash::load_wallet(&self.config.data_dir).await?;
|
|
Ok(serde_json::json!({
|
|
"transactions": wallet.transactions,
|
|
}))
|
|
}
|
|
|
|
pub(super) async fn handle_wallet_networking_profits(
|
|
&self,
|
|
) -> Result<serde_json::Value> {
|
|
let summary = profits::get_networking_profits(&self.config.data_dir).await?;
|
|
Ok(serde_json::json!({
|
|
"total_sats": summary.total_sats,
|
|
"content_sales_sats": summary.content_sales_sats,
|
|
"routing_fees_sats": summary.routing_fees_sats,
|
|
"recent": summary.recent,
|
|
}))
|
|
}
|
|
}
|