-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename public state serialisation interface structs for cla…
…rity (#1338) # Description I found some naming confusing, so have renamed things. These structs relate to Noir not yet having traits, so we need to create serialisation / deserialisation (serde) methods for any type which you wish to store as a public state. Edit: I did a git mv to rename some files, but it doesn't seem to have tracked that correctly, so unfortunately there's a deletion of a file and then a creation of a file. Sorry about that. # Checklist: - [x] I have reviewed my diff in github, line by line. - [x] Every change is related to the PR description. - [x] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to the issue(s) that it resolves. - [x] There are no unexpected formatting changes, superfluous debug logs, or commented-out code. - [x] The branch has been merged or rebased against the head of its merge target. - [x] I'm happy for the PR to be merged at the reviewer's next convenience.
- Loading branch information
1 parent
bb86205
commit cb2d210
Showing
10 changed files
with
63 additions
and
59 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
yarn-project/noir-contracts/src/contracts/child_contract/src/storage.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
use dep::aztec::state_vars::public_state::PublicState; | ||
use dep::aztec::state_vars::public_state_value::field_value::FieldValueInterface; | ||
use dep::aztec::state_vars::public_state_value::field_value::FIELD_VALUE_LEN; | ||
use dep::aztec::state_vars::type_serialisation_interface::field_serialisation_interface::FieldSerialisationInterface; | ||
use dep::aztec::state_vars::type_serialisation_interface::field_serialisation_interface::FIELD_SERIALISED_LEN; | ||
|
||
struct Storage { | ||
current_value: PublicState<Field, FIELD_VALUE_LEN>, | ||
current_value: PublicState<Field, FIELD_SERIALISED_LEN>, | ||
} | ||
|
||
impl Storage { | ||
fn init() -> Self { | ||
Storage { | ||
current_value: PublicState::new(1, FieldValueInterface), | ||
current_value: PublicState::new(1, FieldSerialisationInterface), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
yarn-project/noir-contracts/src/contracts/public_token_contract/src/storage.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
use dep::aztec::state_vars::map::Map; | ||
use dep::aztec::state_vars::public_state::PublicState; | ||
use dep::aztec::state_vars::public_state_value::field_value::FieldValueInterface; | ||
use dep::aztec::state_vars::public_state_value::field_value::FIELD_VALUE_LEN; | ||
use dep::aztec::state_vars::type_serialisation_interface::field_serialisation_interface::FieldSerialisationInterface; | ||
use dep::aztec::state_vars::type_serialisation_interface::field_serialisation_interface::FIELD_SERIALISED_LEN; | ||
|
||
struct Storage { | ||
balances: Map<PublicState<Field, FIELD_VALUE_LEN>>, | ||
balances: Map<PublicState<Field, FIELD_SERIALISED_LEN>>, | ||
} | ||
|
||
|
||
impl Storage { | ||
fn init() -> Self { | ||
Storage { | ||
balances: Map::new(1, |s| PublicState::new(s, FieldValueInterface)), | ||
balances: Map::new(1, |slot| PublicState::new(slot, FieldSerialisationInterface)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
mod immutable_singleton; | ||
mod map; | ||
mod public_state; | ||
mod public_state_value; | ||
mod type_serialisation_interface; | ||
mod set; | ||
mod singleton; |
12 changes: 6 additions & 6 deletions
12
yarn-project/noir-libs/noir-aztec/src/state_vars/public_state.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
yarn-project/noir-libs/noir-aztec/src/state_vars/public_state_value.nr
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
yarn-project/noir-libs/noir-aztec/src/state_vars/public_state_value/field_value.nr
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
yarn-project/noir-libs/noir-aztec/src/state_vars/type_serialisation_interface.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod field_serialisation_interface; | ||
|
||
/** | ||
* Before Noir supports traits, a way of specifying the serialisation and deserialisation methods for a type. | ||
*/ | ||
struct TypeSerialisationInterface<T, N> { | ||
deserialise: fn ([Field; N]) -> T, | ||
serialise: fn (T) -> [Field; N], | ||
} |
16 changes: 16 additions & 0 deletions
16
...s/noir-aztec/src/state_vars/type_serialisation_interface/field_serialisation_interface.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::state_vars::type_serialisation_interface::TypeSerialisationInterface; | ||
|
||
global FIELD_SERIALISED_LEN: Field = 1; | ||
|
||
fn deserialiseField(fields: [Field; FIELD_SERIALISED_LEN]) -> Field { | ||
fields[0] | ||
} | ||
|
||
fn serialiseField(value: Field) -> [Field; FIELD_SERIALISED_LEN] { | ||
[value] | ||
} | ||
|
||
global FieldSerialisationInterface = TypeSerialisationInterface { | ||
deserialise: deserialiseField, | ||
serialise: serialiseField, | ||
}; |