|
| 1 | +//! Protocol logic specific to processing ICS2 messages of type `MsgProvideCouterparty`. |
| 2 | +
|
| 3 | +use ibc_eureka_core_client_context::prelude::*; |
| 4 | +use ibc_eureka_core_client_types::error::ClientError; |
| 5 | +use ibc_eureka_core_client_types::msgs::MsgProvideCouterparty; |
| 6 | +use ibc_eureka_core_host::{ExecutionContext, ValidationContext}; |
| 7 | +use ibc_primitives::prelude::*; |
| 8 | + |
| 9 | +pub fn validate<Ctx>(ctx: &Ctx, msg: MsgProvideCouterparty) -> Result<(), ClientError> |
| 10 | +where |
| 11 | + Ctx: ValidationContext, |
| 12 | +{ |
| 13 | + let MsgProvideCouterparty { |
| 14 | + client_id, signer, .. |
| 15 | + } = &msg; |
| 16 | + |
| 17 | + ctx.validate_message_signer(signer)?; |
| 18 | + |
| 19 | + let client_val_ctx = ctx.get_client_validation_context(); |
| 20 | + |
| 21 | + // Read client state from the host chain store. The client should already exist. |
| 22 | + let client_state = client_val_ctx.client_state(client_id)?; |
| 23 | + |
| 24 | + client_state |
| 25 | + .status(client_val_ctx, client_id)? |
| 26 | + .verify_is_active()?; |
| 27 | + |
| 28 | + if client_val_ctx.counterparty_meta(client_id)?.is_some() { |
| 29 | + return Err(ClientError::ClientSpecific { |
| 30 | + description: "counterparty is already provided".into(), |
| 31 | + }); |
| 32 | + } |
| 33 | + |
| 34 | + Ok(()) |
| 35 | +} |
| 36 | + |
| 37 | +pub fn execute<Ctx>(ctx: &mut Ctx, msg: MsgProvideCouterparty) -> Result<(), ClientError> |
| 38 | +where |
| 39 | + Ctx: ExecutionContext, |
| 40 | +{ |
| 41 | + let MsgProvideCouterparty { |
| 42 | + client_id, |
| 43 | + counterparty_client_id, |
| 44 | + counterparty_commitment_prefix, |
| 45 | + .. |
| 46 | + } = &msg; |
| 47 | + |
| 48 | + let client_exec_ctx = ctx.get_client_execution_context(); |
| 49 | + |
| 50 | + client_exec_ctx.store_counterparty_meta( |
| 51 | + client_id, |
| 52 | + counterparty_client_id, |
| 53 | + counterparty_commitment_prefix, |
| 54 | + )?; |
| 55 | + |
| 56 | + Ok(()) |
| 57 | +} |
0 commit comments