Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Oct 29, 2024
1 parent 469f863 commit 9b9129e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 29 deletions.
11 changes: 7 additions & 4 deletions boxes/boxes/react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use dep::aztec::macros::aztec;
contract BoxReact {
use dep::aztec::{
protocol_types::public_keys::OvpkM,
keys::getters::get_public_keys,
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
macros::{storage::storage, functions::{private, public, initializer}}
Expand All @@ -19,22 +20,24 @@ contract BoxReact {
#[initializer]
fn constructor(
number: Field,
owner: AztecAddress,
owner_ovpk_m: OvpkM
owner: AztecAddress
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

#[private]
fn setNumber(
number: Field,
owner: AztecAddress,
owner_ovpk_m: OvpkM
owner: AztecAddress
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

Expand Down
4 changes: 1 addition & 3 deletions boxes/boxes/react/src/hooks/useContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ export function useContract() {
setWait(true);
const wallet = await deployerEnv.getWallet();
const salt = Fr.random();
const { masterOutgoingViewingPublicKey } =
wallet.getCompleteAddress().publicKeys;

const tx = await BoxReactContract.deploy(
wallet,
Fr.random(),
wallet.getCompleteAddress().address,
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
).send({
contractAddressSalt: salt,
});
Expand Down
4 changes: 1 addition & 3 deletions boxes/boxes/react/src/hooks/useNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ export function useNumber({ contract }: { contract: Contract }) {

const value = BigInt(el.value);
const deployerWallet = await deployerEnv.getWallet();
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
deployerWallet.getCompleteAddress().publicKeys;

await toast.promise(
contract!.methods
.setNumber(
value,
deployerWallet.getCompleteAddress().address,
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
)
.send()
.wait(),
Expand Down
12 changes: 4 additions & 8 deletions boxes/boxes/react/tests/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ describe('BoxReact Contract Tests', () => {
wallet = await deployerEnv.getWallet();
accountCompleteAddress = wallet.getCompleteAddress();
const salt = Fr.random();
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
accountCompleteAddress.publicKeys;

contract = await BoxReactContract.deploy(
wallet,
Fr.random(),
accountCompleteAddress.address,
masterOutgoingViewingPublicKey.toWrappedNoirStruct()
accountCompleteAddress.address
)
.send({ contractAddressSalt: salt })
.deployed();
Expand All @@ -30,13 +28,11 @@ describe('BoxReact Contract Tests', () => {

test('Can set a number', async () => {
logger.info(`${await wallet.getRegisteredAccounts()}`);
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
accountCompleteAddress.publicKeys;

await contract.methods
.setNumber(
numberToSet,
accountCompleteAddress.address,
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
accountCompleteAddress.address
)
.send()
.wait();
Expand Down
11 changes: 7 additions & 4 deletions boxes/boxes/vanilla/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use dep::aztec::macros::aztec;
contract Vanilla {
use dep::aztec::{
protocol_types::public_keys::OvpkM,
keys::getters::get_public_keys,
prelude::{AztecAddress, PrivateMutable, Map, NoteInterface, NoteHeader, Point},
encrypted_logs::encrypted_note_emission::encode_and_encrypt_note,
macros::{storage::storage, functions::{private, public, initializer}}
Expand All @@ -19,22 +20,24 @@ contract Vanilla {
#[initializer]
fn constructor(
number: Field,
owner: AztecAddress,
owner_ovpk_m: OvpkM
owner: AztecAddress
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).initialize(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

#[private]
fn setNumber(
number: Field,
owner: AztecAddress,
owner_ovpk_m: OvpkM
owner: AztecAddress
) {
let numbers = storage.numbers;
let mut new_number = ValueNote::new(number, owner);

let owner_ovpk_m = get_public_keys(owner).ovpk_m;
numbers.at(owner).replace(&mut new_number).emit(encode_and_encrypt_note(&mut context, owner_ovpk_m, owner));
}

Expand Down
10 changes: 3 additions & 7 deletions boxes/boxes/vanilla/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ const setWait = (state: boolean): void =>
document.querySelector('#deploy').addEventListener('click', async ({ target }: any) => {
setWait(true);
wallet = await account.register();
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } =
wallet.getCompleteAddress().publicKeys;

contract = await VanillaContract.deploy(
wallet,
Fr.random(),
wallet.getCompleteAddress().address,
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
wallet.getCompleteAddress().address
)
.send({ contractAddressSalt: Fr.random() })
.deployed();
Expand All @@ -42,13 +40,11 @@ document.querySelector('#set').addEventListener('submit', async (e: Event) => {
setWait(true);

const { value } = document.querySelector('#number') as HTMLInputElement;
const { address: owner, publicKeys } = wallet.getCompleteAddress();
const { masterNullifierPublicKey, masterOutgoingViewingPublicKey } = publicKeys;
const { address: owner } = wallet.getCompleteAddress();
await contract.methods
.setNumber(
parseInt(value),
owner,
masterOutgoingViewingPublicKey.toWrappedNoirStruct(),
)
.send()
.wait();
Expand Down

0 comments on commit 9b9129e

Please sign in to comment.