openzeppelin_relayer/domain/transaction/solana/
solana_transaction.rs

1use async_trait::async_trait;
2use eyre::Result;
3use log::info;
4use std::sync::Arc;
5
6use crate::{
7    domain::transaction::Transaction,
8    jobs::JobProducer,
9    models::{NetworkTransactionRequest, RelayerRepoModel, TransactionError, TransactionRepoModel},
10    repositories::{
11        InMemoryRelayerRepository, InMemoryTransactionRepository, RelayerRepositoryStorage,
12    },
13    services::SolanaProvider,
14};
15
16#[allow(dead_code)]
17pub struct SolanaRelayerTransaction {
18    relayer: RelayerRepoModel,
19    provider: Arc<SolanaProvider>,
20    relayer_repository: Arc<RelayerRepositoryStorage<InMemoryRelayerRepository>>,
21    transaction_repository: Arc<InMemoryTransactionRepository>,
22    job_producer: Arc<JobProducer>,
23}
24
25#[allow(dead_code)]
26impl SolanaRelayerTransaction {
27    pub fn new(
28        relayer: RelayerRepoModel,
29        relayer_repository: Arc<RelayerRepositoryStorage<InMemoryRelayerRepository>>,
30        provider: Arc<SolanaProvider>,
31        transaction_repository: Arc<InMemoryTransactionRepository>,
32        job_producer: Arc<JobProducer>,
33    ) -> Result<Self, TransactionError> {
34        Ok(Self {
35            relayer_repository,
36            provider,
37            transaction_repository,
38            relayer,
39            job_producer,
40        })
41    }
42}
43
44#[async_trait]
45impl Transaction for SolanaRelayerTransaction {
46    async fn prepare_transaction(
47        &self,
48        tx: TransactionRepoModel,
49    ) -> Result<TransactionRepoModel, TransactionError> {
50        info!("preparing transaction");
51        Ok(tx)
52    }
53
54    async fn submit_transaction(
55        &self,
56        tx: TransactionRepoModel,
57    ) -> Result<TransactionRepoModel, TransactionError> {
58        info!("submitting transaction");
59        Ok(tx)
60    }
61
62    async fn resubmit_transaction(
63        &self,
64        tx: TransactionRepoModel,
65    ) -> Result<TransactionRepoModel, TransactionError> {
66        info!("resubmitting transaction");
67        // For now, just call submit_transaction as Solana implementation is a stub
68        self.submit_transaction(tx).await
69    }
70
71    async fn handle_transaction_status(
72        &self,
73        tx: TransactionRepoModel,
74    ) -> Result<TransactionRepoModel, TransactionError> {
75        Ok(tx)
76    }
77
78    async fn cancel_transaction(
79        &self,
80        tx: TransactionRepoModel,
81    ) -> Result<TransactionRepoModel, TransactionError> {
82        Ok(tx)
83    }
84
85    async fn replace_transaction(
86        &self,
87        _old_tx: TransactionRepoModel,
88        _new_tx_request: NetworkTransactionRequest,
89    ) -> Result<TransactionRepoModel, TransactionError> {
90        Ok(_old_tx)
91    }
92
93    async fn sign_transaction(
94        &self,
95        tx: TransactionRepoModel,
96    ) -> Result<TransactionRepoModel, TransactionError> {
97        Ok(tx)
98    }
99
100    async fn validate_transaction(
101        &self,
102        _tx: TransactionRepoModel,
103    ) -> Result<bool, TransactionError> {
104        Ok(true)
105    }
106}