Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove unnecessary trait #9437

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
}
}
Loading