Skip to content

Commit 238a956

Browse files
committed
Implementing ConnOpenConfirm datagram
1 parent d3ee77c commit 238a956

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

core/src/ibc/connection_03/manager.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,31 @@ impl<'a> Manager<'a> {
161161
Ok(())
162162
}
163163

164+
pub fn handle_open_confirm(
165+
&mut self,
166+
identifier: Identifier,
167+
proof_ack: CommitmentProof,
168+
proof_height: u64,
169+
) -> Result<(), String> {
170+
let connection = self
171+
.query(&identifier)
172+
.ok_or_else(|| format!("Cannot find connection with the identifier: {}", identifier))?;
173+
if connection.state != ConnectionState::TRYOPEN {
174+
return Err(format!("Invalid connection state expected TRYOPEN but found {:?}", connection.state))
175+
}
176+
177+
let expected = ConnectionEnd {
178+
state: ConnectionState::OPEN,
179+
counterparty_connection_identifier: identifier.clone(),
180+
counterparty_prefix: get_commiment_prefix(),
181+
client_identifier: connection.counterparty_client_identifier.clone(),
182+
counterparty_client_identifier: connection.client_identifier.clone(),
183+
};
184+
185+
self.verify_connection_state(&connection, proof_height, proof_ack, )
186+
unimplemented!()
187+
}
188+
164189
fn query(&mut self, identifier: &str) -> Option<ConnectionEnd> {
165190
let kv_store = self.ctx.get_kv_store();
166191

core/src/ibc/transaction_handler/datagrams.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum DatagramTag {
2424
ConnOpenInit = 3,
2525
ConnOpenTry = 4,
2626
ConnOpenAck = 5,
27+
ConnOpenConfirm = 6,
2728
}
2829

2930
impl Encodable for DatagramTag {
@@ -41,6 +42,7 @@ impl Decodable for DatagramTag {
4142
3 => Ok(DatagramTag::ConnOpenInit),
4243
4 => Ok(DatagramTag::ConnOpenTry),
4344
5 => Ok(DatagramTag::ConnOpenAck),
45+
6 => Ok(DatagramTag::ConnOpenConfirm),
4446
_ => Err(DecoderError::Custom("Unexpected DatagramTag Value")),
4547
}
4648
}
@@ -82,6 +84,11 @@ pub enum Datagram {
8284
proof_height: u64,
8385
consensus_height: u64,
8486
},
87+
ConnOpenConfirm {
88+
identifier: String,
89+
proof_ack: String,
90+
proof_height: u64,
91+
},
8592
}
8693

8794
impl Encodable for Datagram {
@@ -153,6 +160,14 @@ impl Encodable for Datagram {
153160
.append(proof_height)
154161
.append(consensus_height);
155162
}
163+
Datagram::ConnOpenConfirm {
164+
identifier,
165+
proof_ack,
166+
proof_height,
167+
} => {
168+
s.begin_list(4);
169+
s.append(&DatagramTag::ConnOpenConfirm).append(identifier).append(proof_ack).append(proof_height)
170+
}
156171
};
157172
}
158173
}
@@ -240,6 +255,20 @@ impl Decodable for Datagram {
240255
consensus_height: rlp.val_at(5)?,
241256
})
242257
}
258+
DatagramTag::ConnOpenConfirm => {
259+
let item_count = rlp.item_count()?;
260+
if item_count != 4 {
261+
return Err(DecoderError::RlpInvalidLength {
262+
expected: 4,
263+
got: item_count,
264+
})
265+
}
266+
Ok(Datagram::ConnOpenConfirm {
267+
identifier: rlp.val_at(1)?,
268+
proof_ack: rlp.val_at(2)?,
269+
proof_height: rlp.val_at(3)?,
270+
})
271+
}
243272
}
244273
}
245274
}
@@ -288,4 +317,14 @@ mod tests {
288317
};
289318
rlp_encode_and_decode_test!(conn_open_ack);
290319
}
320+
321+
#[test]
322+
fn conn_open_confirm() {
323+
let conn_open_confirm = Datagram::ConnOpenConfirm {
324+
identifier: "identifier".to_owned(),
325+
proof_ack: "proof_ack".to_owned(),
326+
proof_height: 1,
327+
};
328+
rlp_encode_and_decode_test!(conn_open_confirm);
329+
}
291330
}

core/src/ibc/transaction_handler/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ pub fn execute(
102102
.handle_open_ack(identifier, proof_try, proof_consensus, proof_height, consensus_height)
103103
.map_err(|err| RuntimeError::IBC(format!("ConnOpenAck: {}", err)).into())
104104
}
105+
Datagram::ConnOpenConfirm {
106+
identifier,
107+
proof_ack,
108+
proof_height,
109+
} => unimplemented!(),
105110
}
106111
}
107112

0 commit comments

Comments
 (0)