From 4c09059265a02f87da7c212e573be08a754e2735 Mon Sep 17 00:00:00 2001 From: ByteYue Date: Thu, 30 Jul 2026 15:48:02 +0800 Subject: [PATCH] refactor(oracle): expose fixed-size source progress --- .../src/on_chain_config/oracle_state.rs | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/crates/api-types/src/on_chain_config/oracle_state.rs b/crates/api-types/src/on_chain_config/oracle_state.rs index f1c0dad05cc..a4afde0b95b 100644 --- a/crates/api-types/src/on_chain_config/oracle_state.rs +++ b/crates/api-types/src/on_chain_config/oracle_state.rs @@ -9,17 +9,31 @@ pub struct OracleSourceState { pub source_id: u64, /// Latest nonce for this source pub latest_nonce: u128, - /// The latest DataRecord (None if nonce is 0) - pub latest_record: Option, + /// Latest successfully delivered source-defined restart position + pub latest_position: u128, } -/// Rust representation of the on-chain DataRecord -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct LatestDataRecord { - /// Timestamp when this was recorded - pub recorded_at: u64, - /// Source block number - pub block_number: u64, - /// Payload data - pub data: Vec, -} \ No newline at end of file +#[cfg(test)] +mod tests { + use super::OracleSourceState; + + #[test] + fn bcs_round_trip_has_fixed_size() { + let state = OracleSourceState { + source_type: 6, + source_id: 137, + latest_nonce: u128::MAX, + latest_position: u128::MAX - 1, + }; + + let encoded = bcs::to_bytes(&state).expect("OracleSourceState should serialize"); + assert_eq!(encoded.len(), 44); + + let decoded: OracleSourceState = + bcs::from_bytes(&encoded).expect("OracleSourceState should deserialize"); + assert_eq!(decoded.source_type, state.source_type); + assert_eq!(decoded.source_id, state.source_id); + assert_eq!(decoded.latest_nonce, state.latest_nonce); + assert_eq!(decoded.latest_position, state.latest_position); + } +}