pot_o_extensions/
chain_bridge.rs1use async_trait::async_trait;
2use pot_o_core::TribeResult;
3use pot_o_mining::ProofPayload;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct TxSignature(pub String);
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct MinerAccount {
11 pub pubkey: String,
12 pub total_proofs: u64,
13 pub total_rewards: u64,
14 pub pending_rewards: u64,
15 pub reputation_score: f64,
16 pub last_proof_slot: u64,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
20pub enum Token {
21 SOL,
22 PTtC,
23 NMTC,
24}
25
26#[allow(clippy::double_must_use)]
27#[async_trait]
28pub trait ChainBridge: Send + Sync {
29 async fn submit_proof(&self, proof: &ProofPayload) -> TribeResult<TxSignature>;
30 async fn query_miner(&self, pubkey: &str) -> TribeResult<Option<MinerAccount>>;
31 async fn register_miner(&self, miner_pubkey: &str) -> TribeResult<TxSignature>;
32 async fn get_current_difficulty(&self) -> TribeResult<u64>;
33 async fn request_swap(
34 &self,
35 from_token: Token,
36 to_token: Token,
37 amount: u64,
38 ) -> TribeResult<TxSignature>;
39}
40
41#[derive(Default)]
42pub struct TribechainBridge;
43
44impl TribechainBridge {
45 pub fn new() -> Self {
46 Self
47 }
48}
49
50#[async_trait]
51impl ChainBridge for TribechainBridge {
52 async fn submit_proof(&self, proof: &ProofPayload) -> TribeResult<TxSignature> {
53 tracing::info!(
54 challenge = %proof.proof.challenge_id,
55 miner = %proof.proof.miner_pubkey,
56 "TribechainBridge: submit_proof (no-op, always succeeds)"
57 );
58 let sig = TxSignature(format!(
59 "tribechain_{}",
60 &proof.proof.computation_hash[..proof.proof.computation_hash.len().min(16)]
61 ));
62 Ok(sig)
63 }
64
65 async fn query_miner(&self, pubkey: &str) -> TribeResult<Option<MinerAccount>> {
66 tracing::debug!(
67 pubkey,
68 "TribechainBridge: query_miner (no-op, returning None)"
69 );
70 Ok(None)
71 }
72
73 async fn register_miner(&self, miner_pubkey: &str) -> TribeResult<TxSignature> {
74 tracing::info!(
75 miner = %miner_pubkey,
76 "TribechainBridge: register_miner (no-op, always succeeds)"
77 );
78 Ok(TxSignature(format!("registered_{}", miner_pubkey)))
79 }
80
81 async fn get_current_difficulty(&self) -> TribeResult<u64> {
82 tracing::debug!("TribechainBridge: get_current_difficulty (returning default 2)");
83 Ok(2)
84 }
85
86 async fn request_swap(
87 &self,
88 _from_token: Token,
89 _to_token: Token,
90 _amount: u64,
91 ) -> TribeResult<TxSignature> {
92 tracing::info!("TribechainBridge: request_swap (no-op, returning stub)");
93 Ok(TxSignature("tribechain_swap_stub".to_string()))
94 }
95}