use crate::{errors::AppError, state::AppState}; use axum::{Json, extract::State}; use serde::{Deserialize, Serialize}; use solana_sdk::{signature::Signature, transaction::Transaction}; #[derive(Debug, Deserialize)] pub struct SubmitTransactionRequest { /// Base64 encoded signed transaction pub transaction_base64: String, } #[derive(Debug, Serialize)] pub struct SubmitTransactionResponse { /// Transaction signature pub signature: String, /// Confirmation message pub message: String, } /// Handler for submitting signed transactions to Solana pub async fn submit_transaction( State(state): State, Json(payload): Json, ) -> Result, AppError> { // Decode base64 transaction let tx_bytes = base64::decode(&payload.transaction_base64).map_err(|e| { AppError::InvalidInput(format!("Failed to decode base64 transaction: {}", e)) })?; println!("we decode tx"); // Deserialize transaction using bincode let transaction: Transaction = bincode::deserialize(&tx_bytes) .map_err(|e| AppError::InvalidInput(format!("Failed to deserialize transaction: {}", e)))?; println!("we deserialize tx"); // Send and confirm transaction let signature = state .rpc_client .send_and_confirm_transaction_with_spinner(&transaction) // .send_and_confirm_transaction(&transaction) .map_err(|e| AppError::TransactionFailed(format!("Transaction failed: {}", e)))?; println!("we send and confirm tx"); Ok(Json(SubmitTransactionResponse { signature: signature.to_string(), message: "Transaction submitted and confirmed successfully".to_string(), })) }