Repository navigation
Transaction state - #1104
Transaction state #1104
Conversation
Introduce a new JobConfiguration type for job backoff/timing settings. The struct (crates/primitives/src/job_configuration.rs) derives Debug/Clone/Copy/PartialEq and implements Serialize/Deserialize, uses serde camelCase and typeshare(swift = "Sendable"). Update crates/primitives/src/lib.rs to expose the new module and re-export JobConfiguration.
Add InTransit transaction status across primitives and remote swap types, and wire swap-aware status resolution into the gateway. Introduces TransactionSwapMetadata to transaction metadata, adds Swapper/SwapperProvider usage, and replaces the old TransactionStatusClient with a new StatusProvider that delegates to chain providers or the swapper as appropriate. Includes timeout handling and mapping of swap results into TransactionUpdate, plus related model and import adjustments.
There was a problem hiding this comment.
Code Review
This pull request refactors the gateway logic by introducing a ChainClientFactory and a StatusProvider to handle transaction status updates, including new support for swap-specific statuses, an InTransit state, and transaction timeout logic. Feedback includes resolving a name collision and type mismatch in the transaction state configuration, replacing risky unwrap() calls with proper error handling, and making hardcoded API keys configurable.
| @@ -0,0 +1,22 @@ | |||
| use primitives::{Chain, JobConfiguration}; | |||
There was a problem hiding this comment.
There is a name collision between the imported primitives::JobConfiguration and the local JobConfiguration struct defined on line 8. This will cause a compilation error. Since you are redefining the struct for UniFFI mapping, you should remove it from the import list.
| use primitives::{Chain, JobConfiguration}; | |
| use primitives::Chain; |
| pub fn transaction_state_config(chain: Chain) -> JobConfiguration { | ||
| let block_time_ms = chain.block_time(); | ||
| JobConfiguration { | ||
| initial_interval_ms: block_time_ms.clamp(1, INITIAL_CAP_MS), |
There was a problem hiding this comment.
This line will likely fail to compile due to a type mismatch. block_time_ms is typically an i64, while INITIAL_CAP_MS is a u32. Additionally, the result of clamp needs to be cast to u32 to match the initial_interval_ms field type.
| initial_interval_ms: block_time_ms.clamp(1, INITIAL_CAP_MS), | |
| initial_interval_ms: block_time_ms.clamp(1, INITIAL_CAP_MS as i64) as u32, |
| 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()))) |
There was a problem hiding this comment.
Using unwrap() here is risky. If a new chain is added to the match arm but is not supported by BitcoinChain::from_chain, the application will panic at runtime. It's safer to handle the potential error by returning a GatewayError::PlatformError.
| Ok(Arc::new(BitcoinClient::new(alien_client, BitcoinChain::from_chain(chain).unwrap()))) | |
| Ok(Arc::new(BitcoinClient::new(alien_client, BitcoinChain::from_chain(chain).ok_or(GatewayError::PlatformError { msg: format!("Unsupported bitcoin chain: {:?}", chain) })?))) |
| 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())))), |
| pub api_client: GemApiClient, | ||
| chain_factory: Arc<ChainClientFactory>, | ||
| yielder: Yielder, | ||
| status_provider: StatusProvider, |
There was a problem hiding this comment.
can we move status provider out of this?
| } | ||
| } | ||
|
|
||
| fn apply_timeout( |
There was a problem hiding this comment.
never use apply in the code
Introduce TransactionState::is_completed() to centralize logic for which states are terminal. Replace a manual match in gemstone/src/transaction_state/status_provider.rs with a call to is_completed(), simplifying the expired->Failed decision and improving readability while preserving existing behavior.
Switch status_provider to ms throughout: timestamp_millis() for now, no /1000 on chain_transaction_timeout, drop u64 casts. Update Hyperliquid start_time accordingly. Use existing From<GemTransactionStateRequest> for the chain provider call. Add tests for get_transaction_update and TransactionState::is_completed.
Remove the shared JobConfiguration type from crates/primitives (deleted job_configuration.rs and removed its mod/use exports). Introduce a local GemJobConfiguration in gemstone/src/transaction_state/config.rs (derive uniffi::Record) and update transaction_state_config to return GemJobConfiguration instead of the removed shared type. Logic and constants are unchanged; this decouples the uniFFI-record type from the primitives crate.
| @@ -0,0 +1,22 @@ | |||
| use primitives::Chain; | |||
There was a problem hiding this comment.
this should live in another crate, so it could be used by other services inside core, not just iOS/Android
Move job timing constants and logic into primitives::JobConfiguration and add JobConfiguration::transaction_state(chain) to compute initial_interval_ms, max_interval_ms and step_factor. Remove duplicate constants and construction from gemstone::transaction_state::config, and make gemstone build GemJobConfiguration from the shared JobConfiguration. This reduces duplication and ensures consistent transaction-state timing behavior across crates.
No description provided.