Skip to content

Commit 52751f1

Browse files
committed
Add ConnOpenInit datagram
1 parent 7a153ce commit 52751f1

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

core/src/ibc/connection_03/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ pub fn path(id: &str) -> String {
2424
pub fn client_connections_path(client_id: &str) -> String {
2525
format!("clients/{}/connections", client_id)
2626
}
27+
28+
pub use manager::Manager;

core/src/ibc/transaction_handler/datagrams.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream};
2121
enum DatagramTag {
2222
CreateClient = 1,
2323
UpdateClient = 2,
24+
ConnOpenInit = 3,
2425
}
2526

2627
impl Encodable for DatagramTag {
@@ -35,6 +36,7 @@ impl Decodable for DatagramTag {
3536
match byte {
3637
1 => Ok(DatagramTag::CreateClient),
3738
2 => Ok(DatagramTag::UpdateClient),
39+
3 => Ok(DatagramTag::ConnOpenInit),
3840
_ => Err(DecoderError::Custom("Unexpected DatagramTag Value")),
3941
}
4042
}
@@ -51,6 +53,13 @@ pub enum Datagram {
5153
id: String,
5254
header: Vec<u8>,
5355
},
56+
ConnOpenInit {
57+
identifier: String,
58+
desired_counterparty_connection_identifier: String,
59+
counterparty_prefix: String,
60+
client_identifier: String,
61+
counterparty_client_identifier: String,
62+
},
5463
}
5564

5665
impl Encodable for Datagram {
@@ -69,6 +78,21 @@ impl Encodable for Datagram {
6978
} => {
7079
s.begin_list(3).append(&DatagramTag::UpdateClient).append(id).append(header);
7180
}
81+
Datagram::ConnOpenInit {
82+
identifier,
83+
desired_counterparty_connection_identifier,
84+
counterparty_prefix,
85+
client_identifier,
86+
counterparty_client_identifier,
87+
} => {
88+
s.begin_list(6);
89+
s.append(&DatagramTag::ConnOpenInit)
90+
.append(identifier)
91+
.append(desired_counterparty_connection_identifier)
92+
.append(counterparty_prefix)
93+
.append(client_identifier)
94+
.append(counterparty_client_identifier);
95+
}
7296
};
7397
}
7498
}
@@ -104,6 +128,22 @@ impl Decodable for Datagram {
104128
header: rlp.val_at(2)?,
105129
})
106130
}
131+
DatagramTag::ConnOpenInit => {
132+
let item_count = rlp.item_count()?;
133+
if item_count != 6 {
134+
return Err(DecoderError::RlpInvalidLength {
135+
expected: 6,
136+
got: item_count,
137+
})
138+
}
139+
Ok(Datagram::ConnOpenInit {
140+
identifier: rlp.val_at(1)?,
141+
desired_counterparty_connection_identifier: rlp.val_at(2)?,
142+
counterparty_prefix: rlp.val_at(3)?,
143+
client_identifier: rlp.val_at(4)?,
144+
counterparty_client_identifier: rlp.val_at(5)?,
145+
})
146+
}
107147
}
108148
}
109149
}

core/src/ibc/transaction_handler/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use cstate::{StateResult, TopLevelState};
2323
use ctypes::errors::RuntimeError;
2424
use ibc::client_02 as ibc_client;
2525
use ibc::client_02::foundry as ibc_foundry;
26+
use ibc::connection_03 as ibc_connection;
2627
use ibc::context as ibc_context;
2728
use rlp::{Decodable, Rlp};
2829

@@ -43,6 +44,26 @@ pub fn execute(
4344
id,
4445
header,
4546
} => update_client(state, &id, &header),
47+
Datagram::ConnOpenInit {
48+
identifier,
49+
desired_counterparty_connection_identifier,
50+
counterparty_prefix,
51+
client_identifier,
52+
counterparty_client_identifier,
53+
} => {
54+
let mut context = ibc_context::TopLevelContext::new(state);
55+
let connection_manager = ibc_connection::Manager::new();
56+
connection_manager
57+
.handle_open_init(
58+
&mut context,
59+
identifier,
60+
desired_counterparty_connection_identifier,
61+
counterparty_prefix,
62+
client_identifier,
63+
counterparty_client_identifier,
64+
)
65+
.map_err(|err| RuntimeError::IBC(format!("ConnOpenInit: {}", err)).into())
66+
}
4667
}
4768
}
4869

0 commit comments

Comments
 (0)