Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 27, 2025
1 parent 84c4552 commit 39d8f7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,9 @@
use dep::aztec::{macros::aztec, protocol_types::traits::{Deserialize, Packable, Serialize}};

// I tried using #[derive(Serialize, Deserialize)] macro here but for whatever reason it fails to compile.
pub struct Note {
a: Field,
b: Field,
}

impl Serialize<2> for Note {
fn serialize(self) -> [Field; 2] {
[self.a, self.b]
}
}

impl Deserialize<2> for Note {
fn deserialize(wire: [Field; 2]) -> Note {
Note { a: wire[0], b: wire[1] }
}
}

/// We implement the Packable trait for Note because it can be stored in contract's storage (and there
/// the implementation of Packable is required).
impl Packable<2> for Note {
fn pack(self) -> [Field; 2] {
self.serialize()
}

fn unpack(fields: [Field; 2]) -> Self {
Self::deserialize(fields)
}
}
mod note;
use dep::aztec::macros::aztec;

#[aztec]
contract AvmTest {
use crate::Note;
use crate::note::Note;

global big_field_128_bits: Field = 0x001234567890abcdef1234567890abcdef;
global big_field_136_bits: Field = 0x991234567890abcdef1234567890abcdef;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use dep::aztec::protocol_types::traits::{Deserialize, Packable, Serialize};
use std::meta::derive;

#[derive(Deserialize, Packable, Serialize)]
pub struct Note {
a: Field,
b: Field,
}
29 changes: 2 additions & 27 deletions noir-projects/noir-contracts/contracts/fpc_contract/src/config.nr
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
use dep::aztec::protocol_types::{address::AztecAddress, traits::{Deserialize, Packable, Serialize}};
use std::meta::derive;

global CONFIG_LENGTH: u32 = 2;

#[derive(Deserialize, Packable, Serialize)]
pub struct Config {
pub accepted_asset: AztecAddress, // Asset the FPC accepts (denoted as AA below)
pub admin: AztecAddress, // Address to which AA is sent during the private fee payment flow
}

impl Serialize<CONFIG_LENGTH> for Config {
fn serialize(self: Self) -> [Field; CONFIG_LENGTH] {
[self.accepted_asset.to_field(), self.admin.to_field()]
}
}

impl Deserialize<CONFIG_LENGTH> for Config {
fn deserialize(fields: [Field; CONFIG_LENGTH]) -> Self {
Config {
accepted_asset: AztecAddress::from_field(fields[0]),
admin: AztecAddress::from_field(fields[1]),
}
}
}

impl Packable<CONFIG_LENGTH> for Config {
fn pack(self) -> [Field; CONFIG_LENGTH] {
self.serialize()
}

fn unpack(fields: [Field; CONFIG_LENGTH]) -> Self {
Self::deserialize(fields)
}
}

0 comments on commit 39d8f7e

Please sign in to comment.