-
Notifications
You must be signed in to change notification settings - Fork 236
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
refactor: storing &mut context
in state vars
#1926
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
10b1679
WIP
benesjan 36665a5
WIP
benesjan a294e68
using Option
benesjan 5b7ece0
non native token
benesjan 55fbdb3
child
benesjan 4154ea6
escrow
benesjan cef297a
public token
benesjan 50591cf
child
benesjan d84ddb2
price feed
benesjan ff0bbf0
private token fix
benesjan 078a3b4
WIP
benesjan f956a3f
ecdsa
benesjan f06ea56
schnorr account
benesjan 179aece
schnorr
benesjan 719be2a
WIP
benesjan 4726622
pokeable
benesjan 4e098e0
pending commitments
benesjan 8a727b6
private token airdrop
benesjan 248e171
native token
benesjan 7eae394
WIP
benesjan 3754c87
cleanup
benesjan ae0df88
Merge branch 'master' into janb/storing-context-in-state-vars
benesjan 66b9eb6
WIP
benesjan 4e71326
fix
benesjan ba53c99
formatting
benesjan f8edcbf
fix
benesjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
16 changes: 13 additions & 3 deletions
16
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,25 @@ | ||
use dep::aztec::context::{PrivateContext, PublicContext}; | ||
use dep::aztec::state_vars::public_state::PublicState; | ||
use dep::aztec::types::type_serialisation::field_serialisation::FieldSerialisationMethods; | ||
use dep::aztec::types::type_serialisation::field_serialisation::FIELD_SERIALISED_LEN; | ||
use dep::std::option::Option; | ||
|
||
struct Storage { | ||
current_value: PublicState<Field, FIELD_SERIALISED_LEN>, | ||
} | ||
|
||
impl Storage { | ||
fn init() -> Self { | ||
fn init( | ||
private_context: Option<&mut PrivateContext>, | ||
public_context: Option<&mut PublicContext>, | ||
) -> Self { | ||
Storage { | ||
current_value: PublicState::new(1, FieldSerialisationMethods), | ||
current_value: PublicState::new( | ||
private_context, | ||
public_context, | ||
1, | ||
FieldSerialisationMethods, | ||
), | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you run a code formatter or something? If so, how? We should get it into the CI so we ensure all our code gets formatted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
rustfmt
but it was a semi-manual process becauserustfmt
fails on unconstrained methods and global vars. How I made it work is that I first renamedunconstrained get_balance
toget_balance_unconstrained
and removed the global vars and then reverted the changes. The formatting became too ugly so it was worth the hassle but this makes it impossible to use in CI without bigger modifications ofrustfmt
.But this actually makes me curious whether to create
noirfmt
it would be sufficient to create some simple pre and post processors which would make and revert the changes I did manually... 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I found a tracking issue in Noir, which doesn't seem prioritised atm: noir-lang/noir#1580
As for using rustfmt, it's an interesting idea, but I'm worried that it'll keep diverging as we add more non-rust features to Noir. Also, removing noir-specific keywords is easy, but adding them back is not, given the file changes introduced by rustfmt. I think we should probably wait.