diff --git a/src/ic-solana/src/rpc_client.rs b/src/ic-solana/src/rpc_client.rs index 494a987..021a3ea 100644 --- a/src/ic-solana/src/rpc_client.rs +++ b/src/ic-solana/src/rpc_client.rs @@ -339,6 +339,10 @@ impl RpcClient { /// Method relies on the `getBlock` RPC call to get the block: /// https://solana.com/docs/rpc/http/getBlock pub async fn get_block(&self, slot: Slot, config: Option) -> RpcResult { + if let Some(commitment) = config.as_ref().and_then(|c| c.commitment) { + ensure_at_least_confirmed(commitment.into())?; + } + self.call( RpcRequest::GetBlock, (slot, config.unwrap_or_default()), @@ -415,6 +419,10 @@ impl RpcClient { json!([start_slot, commitment_config]) }; + if let Some(commitment_config) = commitment_config { + ensure_at_least_confirmed(commitment_config)?; + } + let end_slot = end_slot.unwrap_or(start_slot + MAX_GET_BLOCKS_RANGE); let limit = end_slot.saturating_sub(start_slot); @@ -451,6 +459,10 @@ impl RpcClient { ))); } + if let Some(commitment_config) = commitment_config { + ensure_at_least_confirmed(commitment_config)?; + } + self.call( RpcRequest::GetBlocksWithLimit, (start_slot, limit, commitment_config), @@ -997,6 +1009,10 @@ impl RpcClient { signature: &Signature, config: Option, ) -> RpcResult> { + if let Some(commitment) = config.as_ref().and_then(|c| c.commitment) { + ensure_at_least_confirmed(commitment.into())?; + } + self.call( RpcRequest::GetTransaction, (signature.to_string(), config.unwrap_or_default()), @@ -1163,6 +1179,17 @@ impl RpcClient { } } +/// Ensures that the provided commitment configuration meets the minimum required level of +/// 'confirmed'. +fn ensure_at_least_confirmed(commitment_config: CommitmentConfig) -> RpcResult<()> { + if !commitment_config.is_at_least_confirmed() { + return Err(RpcError::ValidationError( + "This method requires a commitment level of 'confirmed' or higher.".to_string(), + )); + } + Ok(()) +} + // TODO: // pub fn is_response_too_large(code: &RejectionCode, message: &str) -> bool { // code == &RejectionCode::SysFatal && (message.contains("size limit") ||