Spaces:
Sleeping
Sleeping
| use crate::cli::{Asset, Network, OutputFormat}; | |
| use serde::{Deserialize, Serialize}; | |
| use serde_json::Value; | |
| pub const DEVNET_RPC_URL: &str = "https://api.devnet.solana.com"; | |
| pub const MAINNET_RPC_URL: &str = "https://api.mainnet-beta.solana.com"; | |
| pub const DEVNET_USDC_MINT: &str = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"; | |
| pub const COINBASE_API_URL: &str = "https://api.coinbase.com"; | |
| pub struct Config { | |
| pub network: Network, | |
| pub format: OutputFormat, | |
| pub quiet: bool, | |
| pub rpc_url: Option<String>, | |
| pub stripe_base_url: Option<String>, | |
| pub coinbase_base_url: Option<String>, | |
| pub solana_private_key_base58: Option<String>, | |
| pub fee_program_id: Option<String>, | |
| pub onchain_fee_collection_enabled: bool, | |
| pub fee_fixed_cents: u64, | |
| pub fee_variable_bps: u16, | |
| pub sol_price_usd: String, | |
| pub cardholder_name: String, | |
| pub cardholder_email: String, | |
| } | |
| impl Default for Config { | |
| fn default() -> Self { | |
| Self { | |
| network: Network::Devnet, | |
| format: OutputFormat::Json, | |
| quiet: false, | |
| rpc_url: None, | |
| stripe_base_url: None, | |
| coinbase_base_url: None, | |
| solana_private_key_base58: None, | |
| fee_program_id: None, | |
| onchain_fee_collection_enabled: false, | |
| fee_fixed_cents: 10, | |
| fee_variable_bps: 20, | |
| sol_price_usd: "100.00".to_string(), | |
| cardholder_name: "CardCLI Demo User".to_string(), | |
| cardholder_email: "demo@cardcli.dev".to_string(), | |
| } | |
| } | |
| } | |
| impl Config { | |
| pub fn rpc_url(&self) -> &str { | |
| self.rpc_url.as_deref().unwrap_or(match self.network { | |
| Network::Devnet => DEVNET_RPC_URL, | |
| Network::Mainnet => MAINNET_RPC_URL, | |
| }) | |
| } | |
| pub fn stripe_base_url(&self) -> &str { | |
| self.stripe_base_url | |
| .as_deref() | |
| .unwrap_or("https://api.stripe.com") | |
| } | |
| pub fn coinbase_base_url(&self) -> &str { | |
| self.coinbase_base_url | |
| .as_deref() | |
| .unwrap_or(COINBASE_API_URL) | |
| } | |
| } | |
| pub struct Credentials { | |
| pub api_key: String, | |
| pub created_at: String, | |
| } | |
| pub struct State { | |
| pub stripe_cardholder_id: Option<String>, | |
| pub deposits: Vec<Deposit>, | |
| pub cards: Vec<CardRecord>, | |
| pub fee_payments: Vec<FeePayment>, | |
| pub audit_log: Vec<AuditEntry>, | |
| pub idempotency_keys: Vec<IdempotencyRecord>, | |
| } | |
| pub struct Deposit { | |
| pub id: String, | |
| pub asset: Asset, | |
| pub network: Network, | |
| pub address: String, | |
| pub token_mint: Option<String>, | |
| pub token_address: Option<String>, | |
| pub secret_key_base58: String, | |
| pub created_at: String, | |
| pub status: DepositState, | |
| pub amount_native: String, | |
| pub amount_usd: String, | |
| pub fee_paid_lamports: u64, | |
| pub confirmed_at: Option<String>, | |
| pub last_signature: Option<String>, | |
| } | |
| pub enum DepositState { | |
| Pending, | |
| Confirmed, | |
| Expired, | |
| } | |
| pub struct CardRecord { | |
| pub id: String, | |
| pub stripe_card_id: String, | |
| pub stripe_cardholder_id: String, | |
| pub amount_usd: String, | |
| pub currency: String, | |
| pub status: CardState, | |
| pub last4: Option<String>, | |
| pub brand: Option<String>, | |
| pub exp_month: Option<u32>, | |
| pub exp_year: Option<u32>, | |
| pub fee_fixed_usd: String, | |
| pub fee_variable_usd: String, | |
| pub fee_total_usd: String, | |
| pub total_debited_usd: String, | |
| pub fee_lamports: u64, | |
| pub fee_transaction_signature: Option<String>, | |
| pub fee_reference: Option<String>, | |
| pub number: Option<String>, | |
| pub cvc: Option<String>, | |
| pub reveal_unavailable_reason: Option<String>, | |
| pub created_at: String, | |
| pub frozen_at: Option<String>, | |
| } | |
| pub struct FeePayment { | |
| pub id: String, | |
| pub source_deposit_id: String, | |
| pub program_id: String, | |
| pub treasury_vault: String, | |
| pub fee_signature: String, | |
| pub fee_usd: String, | |
| pub fee_lamports: u64, | |
| pub card_amount_usd: String, | |
| pub sol_price_usd: String, | |
| pub created_at: String, | |
| } | |
| pub enum CardState { | |
| Pending, | |
| Active, | |
| Frozen, | |
| Canceled, | |
| } | |
| pub struct AuditEntry { | |
| pub timestamp: String, | |
| pub action: String, | |
| pub resource_type: String, | |
| pub resource_id: String, | |
| pub details: Value, | |
| } | |
| pub struct IdempotencyRecord { | |
| pub key: String, | |
| pub operation: String, | |
| pub resource_id: String, | |
| pub created_at: String, | |
| } | |