|
| 1 | +// Copyright 2020 Kodebox, Inc. |
| 2 | +// This file is part of CodeChain. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as |
| 6 | +// published by the Free Software Foundation, either version 3 of the |
| 7 | +// License, or (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +use super::types::{CommitmentPrefix, Identifier}; |
| 18 | +use super::{client_connections_path, path as connection_path}; |
| 19 | +use crate::ibc; |
| 20 | +use crate::ibc::client_02::ConsensusState; |
| 21 | +use crate::ibc::connection_03::types::{ConnectionEnd, ConnectionState}; |
| 22 | +use ibc::commitment_23::Prefix; |
| 23 | +use rlp::Encodable; |
| 24 | + |
| 25 | +#[derive(Default)] |
| 26 | +pub struct Manager {} |
| 27 | + |
| 28 | +impl Manager { |
| 29 | + pub fn new() -> Self { |
| 30 | + Manager {} |
| 31 | + } |
| 32 | + |
| 33 | + pub fn handle_open_init( |
| 34 | + ctx: &mut dyn ibc::Context, |
| 35 | + identifier: Identifier, |
| 36 | + desired_counterparty_connection_identifier: Identifier, |
| 37 | + counterparty_prefix: CommitmentPrefix, |
| 38 | + client_identifier: Identifier, |
| 39 | + counterparty_client_identifier: Identifier, |
| 40 | + ) -> Result<(), String> { |
| 41 | + let kv_store = ctx.get_kv_store(); |
| 42 | + if kv_store.has(&connection_path(&identifier)) { |
| 43 | + return Err("Connection exist".to_owned()) |
| 44 | + } |
| 45 | + let state = ConnectionState::INIT; |
| 46 | + let connection = ConnectionEnd { |
| 47 | + state, |
| 48 | + counterparty_connection_identifier: desired_counterparty_connection_identifier, |
| 49 | + counterparty_prefix, |
| 50 | + client_identifier, |
| 51 | + counterparty_client_identifier, |
| 52 | + }; |
| 53 | + kv_store.set(&connection_path(&identifier), &connection.rlp_bytes()); |
| 54 | + // add connection to client |
| 55 | + Ok(()) |
| 56 | + } |
| 57 | +} |
0 commit comments