This repository was archived by the owner on Jun 1, 2026. It is now read-only.
Repository navigation
Transaction state #1104
Merged
Merged
Transaction state #1104
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e67c887
Added chain_factory
0xSou 0eea08e
Add JobConfiguration struct and export
0xSou c660f94
Add TransactionStatusClient with timeout-fail policy
0xSou 7b79707
Support swap InTransit status and status provider
0xSou 2a167cb
Undo InTransit support for now
0xSou c9d209d
Update status_provider.rs
0xSou 3430604
Add is_completed and use it in status provider
0xSou 6647585
Use milliseconds end-to-end for transaction status timeout
0xSou 8c81f2b
Replace JobConfiguration with GemJobConfiguration
0xSou a33120c
Merge branch 'main' into trans-state
0xSou 449e5e2
Centralize job configuration in primitives
0xSou 138dc21
Merge branch 'main' into trans-state
0xSou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
| use typeshare::typeshare; | ||
| use crate::Chain; | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] | ||
| #[typeshare(swift = "Sendable")] | ||
| #[serde(rename_all = "camelCase")] | ||
| const INITIAL_CAP_MS: u32 = 5_000; | ||
| const MAX_INTERVAL_MS: u32 = 15_000; | ||
| const STEP_FACTOR: f32 = 1.1; | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq)] | ||
| pub struct JobConfiguration { | ||
| pub initial_interval_ms: u32, | ||
| pub max_interval_ms: u32, | ||
| pub step_factor: f32, | ||
| } | ||
|
|
||
| impl JobConfiguration { | ||
| pub fn transaction_state(chain: Chain) -> Self { | ||
| Self { | ||
| initial_interval_ms: chain.block_time().clamp(1, INITIAL_CAP_MS), | ||
| max_interval_ms: MAX_INTERVAL_MS, | ||
| step_factor: STEP_FACTOR, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| use super::{GatewayError, GemPreferences, PreferencesWrapper}; | ||
| use crate::alien::{AlienProvider, new_alien_client}; | ||
| use crate::network::JsonRpcClient; | ||
| use chain_traits::ChainTraits; | ||
| use gem_algorand::rpc::AlgorandClientIndexer; | ||
| use gem_algorand::rpc::client::AlgorandClient; | ||
| use gem_aptos::rpc::client::AptosClient; | ||
| use gem_bitcoin::rpc::client::BitcoinClient; | ||
| use gem_cardano::rpc::client::CardanoClient; | ||
| use gem_cosmos::rpc::client::CosmosClient; | ||
| use gem_evm::rpc::EthereumClient; | ||
| use gem_hypercore::rpc::client::HyperCoreClient; | ||
| use gem_near::rpc::client::NearClient; | ||
| use gem_polkadot::rpc::client::PolkadotClient; | ||
| use gem_solana::rpc::client::SolanaClient; | ||
| use gem_stellar::rpc::client::StellarClient; | ||
| use gem_sui::rpc::client::SuiClient; | ||
| use gem_ton::rpc::client::TonClient; | ||
| use gem_tron::rpc::{client::TronClient, trongrid::client::TronGridClient}; | ||
| use gem_xrp::rpc::client::XRPClient; | ||
| use primitives::{BitcoinChain, Chain, EVMChain, chain_cosmos::CosmosChain}; | ||
| use std::sync::Arc; | ||
|
|
||
| pub struct ChainClientFactory { | ||
| alien: Arc<dyn AlienProvider>, | ||
| preferences: Arc<dyn GemPreferences>, | ||
| secure_preferences: Arc<dyn GemPreferences>, | ||
| } | ||
|
|
||
| impl ChainClientFactory { | ||
| pub fn new(alien: Arc<dyn AlienProvider>, preferences: Arc<dyn GemPreferences>, secure_preferences: Arc<dyn GemPreferences>) -> Self { | ||
| Self { | ||
| alien, | ||
| preferences, | ||
| secure_preferences, | ||
| } | ||
| } | ||
|
|
||
| pub async fn create(&self, chain: Chain) -> Result<Arc<dyn ChainTraits>, GatewayError> { | ||
| let url = self.alien.get_endpoint(chain).map_err(|e| GatewayError::PlatformError { msg: e.to_string() })?; | ||
| self.create_with_url(chain, url).await | ||
| } | ||
|
|
||
| pub async fn create_with_url(&self, chain: Chain, url: String) -> Result<Arc<dyn ChainTraits>, GatewayError> { | ||
| let alien_client = new_alien_client(url, self.alien.clone()); | ||
| match chain { | ||
| Chain::HyperCore => { | ||
| let preferences = Arc::new(PreferencesWrapper { | ||
| preferences: self.preferences.clone(), | ||
| }); | ||
| let secure_preferences = Arc::new(PreferencesWrapper { | ||
| preferences: self.secure_preferences.clone(), | ||
| }); | ||
| Ok(Arc::new(HyperCoreClient::new_with_preferences(alien_client, preferences, secure_preferences))) | ||
| } | ||
| Chain::Bitcoin | Chain::BitcoinCash | Chain::Litecoin | Chain::Doge | Chain::Zcash => { | ||
| Ok(Arc::new(BitcoinClient::new(alien_client, BitcoinChain::from_chain(chain).unwrap()))) | ||
| } | ||
| Chain::Cardano => Ok(Arc::new(CardanoClient::new(alien_client))), | ||
| Chain::Stellar => Ok(Arc::new(StellarClient::new(alien_client))), | ||
| Chain::Sui => Ok(Arc::new(SuiClient::new(JsonRpcClient::new(alien_client.clone())))), | ||
| Chain::Xrp => Ok(Arc::new(XRPClient::new(JsonRpcClient::new(alien_client.clone())))), | ||
| Chain::Algorand => Ok(Arc::new(AlgorandClient::new(alien_client.clone(), AlgorandClientIndexer::new(alien_client.clone())))), | ||
| Chain::Near => Ok(Arc::new(NearClient::new(JsonRpcClient::new(alien_client.clone())))), | ||
| Chain::Aptos => Ok(Arc::new(AptosClient::new(alien_client))), | ||
| Chain::Cosmos | Chain::Osmosis | Chain::Celestia | Chain::Thorchain | Chain::Injective | Chain::Sei | Chain::Noble => { | ||
| Ok(Arc::new(CosmosClient::new(CosmosChain::from_chain(chain).unwrap(), alien_client))) | ||
| } | ||
| Chain::Ton => Ok(Arc::new(TonClient::new(alien_client))), | ||
| Chain::Tron => Ok(Arc::new(TronClient::new(alien_client.clone(), TronGridClient::new(alien_client.clone(), String::new())))), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Chain::Polkadot => Ok(Arc::new(PolkadotClient::new(alien_client))), | ||
| Chain::Solana => Ok(Arc::new(SolanaClient::new(JsonRpcClient::new(alien_client.clone())))), | ||
| Chain::Ethereum | ||
| | Chain::Arbitrum | ||
| | Chain::SmartChain | ||
| | Chain::Polygon | ||
| | Chain::Optimism | ||
| | Chain::Base | ||
| | Chain::AvalancheC | ||
| | Chain::OpBNB | ||
| | Chain::Fantom | ||
| | Chain::Gnosis | ||
| | Chain::Manta | ||
| | Chain::Blast | ||
| | Chain::ZkSync | ||
| | Chain::Linea | ||
| | Chain::Mantle | ||
| | Chain::Celo | ||
| | Chain::World | ||
| | Chain::Sonic | ||
| | Chain::SeiEvm | ||
| | Chain::Abstract | ||
| | Chain::Berachain | ||
| | Chain::Ink | ||
| | Chain::Unichain | ||
| | Chain::Hyperliquid | ||
| | Chain::Plasma | ||
| | Chain::Monad | ||
| | Chain::XLayer | ||
| | Chain::Stable => Ok(Arc::new(EthereumClient::new(JsonRpcClient::new(alien_client), EVMChain::from_chain(chain).unwrap()))), | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
unwrap()here is risky. If a new chain is added to the match arm but is not supported byBitcoinChain::from_chain, the application will panic at runtime. It's safer to handle the potential error by returning aGatewayError::PlatformError.