Skip to content

Commit

Permalink
Merge 0ab224b into 91c50dd
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Oct 25, 2024
2 parents 91c50dd + 0ab224b commit acc208e
Showing 1 changed file with 5 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::{context::PublicContext, event::event_interface::EventInterface};
use dep::protocol_types::traits::Serialize;

fn emit<Event, let N: u32, let M: u32>(context: &mut PublicContext, event: Event)
fn emit<Event, let N: u32>(context: &mut PublicContext, event: Event)
where
Event: EventInterface<N>,
Event: Serialize<N>,
[Field; N]: LensForEventSelector<N, M>,
Event: EventInterface<N> + Serialize<N>,
{
let selector = Event::get_event_type_id();

let serialized_event = event.serialize();
let mut emitted_log = [0; M];
let mut emitted_log = [0; N + 1];

// We put the selector in the "last" place, to avoid reading or assigning to an expression in an index
for i in 0..serialized_event.len() {
Expand All @@ -22,50 +20,11 @@ where
context.emit_unencrypted_log(emitted_log);
}

pub fn encode_event<Event, let N: u32, let M: u32>(
pub fn encode_event<Event, let N: u32>(
context: &mut PublicContext,
) -> fn[(&mut PublicContext,)](Event) -> ()
where
Event: EventInterface<N>,
Event: Serialize<N>,
[Field; N]: LensForEventSelector<N, M>,
Event: EventInterface<N> + Serialize<N>,
{
|e: Event| { emit(context, e); }
}

trait LensForEventSelector<let N: u32, let M: u32> {
// N = event preimage input in fields
// M = event preimage input in fields + event selector as field
fn output(self: [Field; N]) -> [Field; M];
}

impl LensForEventSelector<1, 2> for [Field; 1] {
fn output(self) -> [Field; 2] {
[self[0] as Field; 2]
}
}
impl LensForEventSelector<2, 3> for [Field; 2] {
fn output(self) -> [Field; 3] {
[self[0] as Field; 3]
}
}
impl LensForEventSelector<3, 4> for [Field; 3] {
fn output(self) -> [Field; 4] {
[self[0] as Field; 4]
}
}
impl LensForEventSelector<4, 5> for [Field; 4] {
fn output(self) -> [Field; 5] {
[self[0] as Field; 5]
}
}
impl LensForEventSelector<5, 6> for [Field; 5] {
fn output(self) -> [Field; 6] {
[self[0] as Field; 6]
}
}
impl LensForEventSelector<6, 7> for [Field; 6] {
fn output(self) -> [Field; 7] {
[self[0] as Field; 7]
}
}

0 comments on commit acc208e

Please sign in to comment.