Skip to content

Commit

Permalink
fix: eth relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Orlando committed Aug 22, 2023
1 parent d0c2ea8 commit e1eb4e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions starknet/src/execution_strategies.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod vanilla;

mod simple_quorum;

mod eth_relayer;
34 changes: 23 additions & 11 deletions starknet/src/execution_strategies/eth_relayer.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#[starknet::contract]
mod EthRelayerExecutionStrategy {
use array::ArrayTrait;
use option::OptionTrait;
use traits::TryInto;
use serde::Serde;
use starknet::syscalls::send_message_to_l1_syscall;
use starknet::info::get_caller_address;
use sx::interfaces::IExecutionStrategy;
use sx::types::{Proposal};

#[storage]
struct Storage {}

#[external(v0)]
impl EthRelayerExecutionStrategy of IExecutionStrategy<ContractState> {
fn execute(
Expand All @@ -18,19 +25,24 @@ mod EthRelayerExecutionStrategy {
let space = get_caller_address();

// Decode payload
let l1_destination = payload[0];
// keccak hash of the proposal execution payload
let execution_hash = u256 { low: payload[2], high: payload[1] };
let mut payload = payload;
// L1 destination contract address
let l1_destination = payload.pop_front().unwrap();
// keccak hash of the L1 proposal execution payload
let l1_execution_hash = u256 {
low: payload.pop_front().unwrap().try_into().unwrap(),
high: payload.pop_front().unwrap().try_into().unwrap()
};

let mut message_payload = array![];
space.serialize(mut message_payload);
proposal.serialize(mut message_payload);
votes_for.serialize(mut message_payload);
votes_against.serialize(mut message_payload);
votes_abstain.serialize(mut message_payload);
execution_hash.serialize(mut message_payload);
let mut l1_payload = array![];
space.serialize(ref l1_payload);
proposal.serialize(ref l1_payload);
votes_for.serialize(ref l1_payload);
votes_against.serialize(ref l1_payload);
votes_abstain.serialize(ref l1_payload);
l1_execution_hash.serialize(ref l1_payload);

send_message_to_l1_syscall(l1_destination, message_payload);
send_message_to_l1_syscall(l1_destination, l1_payload.span());
}
}
}

0 comments on commit e1eb4e5

Please sign in to comment.