Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 3, 2024
1 parent fd09f90 commit 9cc4ffa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion boxes/token/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ contract Token {

storage.balances.at(from).sub(SafeU120::new(amount));

let selector = compute_selector("_increase_public_balance((Field),Field)");
let selector = FunctionSelector::from_signature("_increase_public_balance((Field),Field)");
let _void = context.call_public_function(context.this_address(), selector, [to.to_field(), amount]);
}
// docs:end:unshield
Expand Down
1 change: 0 additions & 1 deletion docs/docs/dev_docs/contracts/syntax/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ Oracles introduce **non-determinism** into a circuit, and thus are `unconstraine

### A few useful inbuilt oracles

- [`compute_selector`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/selector.nr) - Computes the selector of a function. This is useful for when you want to call a function from within a circuit, but don't have an interface at hand and don't want to hardcode the selector in hex.
- [`debug_log`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/debug_log.nr) - Provides a couple of debug functions that can be used to log information to the console.
- [`auth_witness`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/authwit/src/auth_witness.nr) - Provides a way to fetch the authentication witness for a given address. This is useful when building account contracts to support approve-like functionality.
- [`get_l1_to_l2_message`](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/aztec-nr/aztec/src/oracle/get_l1_to_l2_message.nr) - Useful for application that receive messages from L1 to be consumed on L2, such as token bridges or other cross-chain applications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ We are using various utils within the Aztec library:

* `context` - exposes things such as the contract address, msg_sender, etc
* `oracle::get_secret_key` - get your secret key to help us create a randomized nullifier
* `selector::compute_selector` - compute a function selector so we can call functions from other functions
* `FunctionSelector::from_signature` - compute a function selector from signature so we can call functions from other functions
* `state_vars::{ map::Map, public_state::PublicState, }` - we will use a Map to store the votes (key = voteId, value = number of votes), and PublicState to hold our public values that we mentioned earlier
* `types::type_serialization::{..}` - various serialization methods for defining how to use these types
* `types::address::{AztecAddress},` - our admin will be held as an address
Expand Down Expand Up @@ -113,7 +113,7 @@ Therefore our constructor must call a public function by using `context.call_pub

`context.call_public_function()` takes three arguments:
1. The contract address whose method we want to call
2. The selector of the function to call (we can use `compute_selector()` for this)
2. The selector of the function to call (we can use `FunctionSelector::from_signature(...)` for this)
3. The arguments of the function (we pass the `admin`)

We now need to write the `_initialize()` function:
Expand Down
5 changes: 3 additions & 2 deletions noir/tooling/nargo_fmt/tests/expected/contract.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
// Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
contract Benchmarking {
use dep::protocol_types::abis::function_selector::FunctionSelector;

use dep::value_note::{
utils::{increment, decrement},
value_note::{VALUE_NOTE_LEN, ValueNote, ValueNoteMethods},
Expand All @@ -11,7 +13,6 @@ contract Benchmarking {
use dep::aztec::{
context::{Context},
note::{utils as note_utils, note_getter_options::NoteGetterOptions, note_header::NoteHeader},
selector::compute_selector,
log::emit_unencrypted_log,
state_vars::{map::Map, public_state::PublicState, set::Set},
types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN},
Expand Down Expand Up @@ -59,7 +60,7 @@ contract Benchmarking {
storage.balances.at(owner).write(current + value);
let _callStackItem1 = context.call_public_function(
context.this_address(),
compute_selector("broadcast(Field)"),
FunctionSelector::from_signature("broadcast(Field)"),
[owner]
);
}
Expand Down
5 changes: 3 additions & 2 deletions noir/tooling/nargo_fmt/tests/input/contract.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
// Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
contract Benchmarking {
use dep::protocol_types::abis::function_selector::FunctionSelector;

use dep::value_note::{
utils::{increment, decrement},
value_note::{VALUE_NOTE_LEN, ValueNote, ValueNoteMethods},
Expand All @@ -11,7 +13,6 @@ contract Benchmarking {
use dep::aztec::{
context::{Context},
note::{utils as note_utils, note_getter_options::NoteGetterOptions, note_header::NoteHeader},
selector::compute_selector,
log::emit_unencrypted_log,
state_vars::{map::Map, public_state::PublicState, set::Set},
types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN},
Expand Down Expand Up @@ -57,7 +58,7 @@ contract Benchmarking {
fn increment_balance(owner: Field, value: Field) {
let current = storage.balances.at(owner).read();
storage.balances.at(owner).write(current + value);
let _callStackItem1 = context.call_public_function(context.this_address(), compute_selector("broadcast(Field)"), [owner]);
let _callStackItem1 = context.call_public_function(context.this_address(), FunctionSelector::from_signature("broadcast(Field)"), [owner]);
}

// Est ultricies integer quis auctor elit sed. In nibh mauris cursus mattis molestie a iaculis.
Expand Down

0 comments on commit 9cc4ffa

Please sign in to comment.