Skip to content

Commit

Permalink
Implement Connection OpenTry relaying (#135)
Browse files Browse the repository at this point in the history
* Initial wiring for connection open try

* Finish implementing ConnectionOpenTryMessageBuilder

* Should return ConnectionOpenTry message, not OpenInit

* Implement HasConnectionOpenTryEvent

* Implement HasConnectionOpenTryEvent

* Implement CanRelayConnectionOpenTry

* Fix cairo contracts

* Revert changes to scarb.nix

* Fix Cairo formatting
  • Loading branch information
soareschen authored Dec 13, 2024
1 parent 2054d03 commit c3b77f9
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ pub mod ConnectionHandlerComponent {
impl EventEmitter: ConnectionEventEmitterComponent::HasComponent<TContractState>,
impl ClientHandler: ClientHandlerComponent::HasComponent<TContractState>
> of IConnectionHandler<ComponentState<TContractState>> {
fn conn_open_init(ref self: ComponentState<TContractState>, msg: MsgConnOpenInit) {
fn conn_open_init(
ref self: ComponentState<TContractState>, msg: MsgConnOpenInit
) -> ConnectionId {
let connection_sequence = self.read_next_connection_sequence();
self.conn_open_init_validate(connection_sequence, msg.clone());
self.conn_open_init_execute(connection_sequence, msg);
self.conn_open_init_execute(connection_sequence, msg)
}

fn conn_open_try(ref self: ComponentState<TContractState>, msg: MsgConnOpenTry) {
fn conn_open_try(
ref self: ComponentState<TContractState>, msg: MsgConnOpenTry
) -> ConnectionId {
let connection_sequence = self.read_next_connection_sequence();
self.conn_open_try_validate(connection_sequence, msg.clone());
self.conn_open_try_execute(connection_sequence, msg);
self.conn_open_try_execute(connection_sequence, msg)
}

fn conn_open_ack(ref self: ComponentState<TContractState>, msg: MsgConnOpenAck) {
Expand Down Expand Up @@ -109,7 +113,7 @@ pub mod ConnectionHandlerComponent {

fn conn_open_init_execute(
ref self: ComponentState<TContractState>, connection_sequence: u64, msg: MsgConnOpenInit
) {
) -> ConnectionId {
let conn_end_on_a = ConnectionEndTrait::init(
msg.client_id_on_a.clone(),
msg.client_id_on_b.clone(),
Expand All @@ -129,6 +133,8 @@ pub mod ConnectionHandlerComponent {
.emit_conn_open_init_event(
msg.client_id_on_a.clone(), conn_id_on_a.clone(), msg.client_id_on_b,
);

conn_id_on_a
}
}

Expand Down Expand Up @@ -177,7 +183,7 @@ pub mod ConnectionHandlerComponent {

fn conn_open_try_execute(
ref self: ComponentState<TContractState>, connection_sequence: u64, msg: MsgConnOpenTry
) {
) -> ConnectionId {
let chan_end_on_b = ConnectionEndTrait::try_open(
msg.client_id_on_b.clone(),
msg.client_id_on_a.clone(),
Expand All @@ -201,6 +207,8 @@ pub mod ConnectionHandlerComponent {
msg.client_id_on_a.clone(),
msg.conn_id_on_a
);

conn_id_on_b
}
}

Expand Down Expand Up @@ -513,4 +521,3 @@ pub mod ConnectionHandlerComponent {
}
}
}

4 changes: 2 additions & 2 deletions cairo-contracts/packages/core/src/connection/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use starknet_ibc_core::host::ConnectionId;

#[starknet::interface]
pub trait IConnectionHandler<TContractState> {
fn conn_open_init(ref self: TContractState, msg: MsgConnOpenInit);
fn conn_open_init(ref self: TContractState, msg: MsgConnOpenInit) -> ConnectionId;

fn conn_open_try(ref self: TContractState, msg: MsgConnOpenTry);
fn conn_open_try(ref self: TContractState, msg: MsgConnOpenTry) -> ConnectionId;

fn conn_open_ack(ref self: TContractState, msg: MsgConnOpenAck);

Expand Down
4 changes: 2 additions & 2 deletions cairo-contracts/packages/testkit/src/handles/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ pub impl CoreHandleImpl of CoreHandle {
self.router_dispatcher().bind_port_id(port_id, app_address)
}

fn conn_open_init(self: @CoreContract, msg: MsgConnOpenInit) {
fn conn_open_init(self: @CoreContract, msg: MsgConnOpenInit) -> ConnectionId {
self.connecion_handler_dispatcher().conn_open_init(msg)
}

fn conn_open_try(self: @CoreContract, msg: MsgConnOpenTry) {
fn conn_open_try(self: @CoreContract, msg: MsgConnOpenTry) -> ConnectionId {
self.connecion_handler_dispatcher().conn_open_try(msg)
}

Expand Down
58 changes: 29 additions & 29 deletions relayer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c3b77f9

Please sign in to comment.