Skip to content

Commit b20c900

Browse files
authored
Merge pull request #11 from AztecProtocol/fixing-starter-token-reference
fix: starter token reference
2 parents f5e24c7 + aed0bc6 commit b20c900

File tree

5 files changed

+84
-86
lines changed

5 files changed

+84
-86
lines changed

starter-token/reference/contract/src/main.nr

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,84 @@ use aztec::macros::aztec;
22

33
#[aztec]
44
pub contract StarterToken {
5-
use aztec::macros::{
6-
functions::{initializer, private, public, utility, internal},
7-
storage::storage,
8-
};
9-
use aztec::state_vars::{PublicMutable, Map};
10-
use aztec::protocol_types::address::AztecAddress;
11-
12-
use easy_private_state::EasyPrivateUint;
13-
14-
#[storage]
15-
struct Storage<Context> {
16-
owner: PublicMutable<AztecAddress, Context>,
17-
balances: Map<AztecAddress, PublicMutable<u128, Context>, Context>,
18-
// ===============
19-
private_balances: Map<AztecAddress, EasyPrivateUint<Context>, Context>
20-
}
21-
22-
#[initializer]
23-
#[public]
24-
fn setup() {
25-
// The deployer becomes the owner
26-
storage.owner.write(context.msg_sender());
27-
}
28-
29-
#[public]
30-
fn mint(to: AztecAddress, amount: u128) {
31-
assert_eq(context.msg_sender(), storage.owner.read());
32-
33-
let recipient_balance = storage.balances.at(to).read();
34-
storage.balances.at(to).write(recipient_balance + amount);
35-
}
36-
37-
#[public]
38-
fn transfer(to: AztecAddress, amount: u128) {
39-
let sender = context.msg_sender();
40-
let sender_balance = storage.balances.at(sender).read();
5+
use aztec::macros::{
6+
functions::{initializer, private, public, utility, internal},
7+
storage::storage,
8+
};
9+
use aztec::state_vars::{PublicMutable, Map};
10+
use aztec::protocol_types::address::AztecAddress;
11+
12+
use easy_private_state::EasyPrivateUint;
13+
14+
#[storage]
15+
struct Storage<Context> {
16+
owner: PublicMutable<AztecAddress, Context>,
17+
balances: Map<AztecAddress, PublicMutable<u128, Context>, Context>,
18+
// ===============
19+
private_balances: Map<AztecAddress, EasyPrivateUint<Context>, Context>
20+
}
21+
22+
#[initializer]
23+
#[public]
24+
fn setup() {
25+
// The deployer becomes the owner
26+
storage.owner.write(context.msg_sender());
27+
}
28+
29+
#[public]
30+
fn mint(to: AztecAddress, amount: u128) {
31+
assert_eq(context.msg_sender(), storage.owner.read());
32+
33+
let recipient_balance = storage.balances.at(to).read();
34+
storage.balances.at(to).write(recipient_balance + amount);
35+
}
36+
37+
#[public]
38+
fn transfer(to: AztecAddress, amount: u128) {
39+
let sender = context.msg_sender();
40+
let sender_balance = storage.balances.at(sender).read();
41+
42+
assert(sender_balance >= amount, "Insufficient balance");
43+
44+
storage.balances.at(sender).write(sender_balance - amount);
45+
46+
let recipient_balance = storage.balances.at(to).read();
47+
storage.balances.at(to).write(recipient_balance + amount);
48+
}
49+
50+
#[public]
51+
fn transfer_ownership(new_owner: AztecAddress) {
52+
assert_eq(context.msg_sender(), storage.owner.read());
53+
storage.owner.write(new_owner);
54+
}
4155

42-
assert(sender_balance >= amount, "Insufficient balance");
43-
44-
storage.balances.at(sender).write(sender_balance - amount);
45-
46-
let recipient_balance = storage.balances.at(to).read();
47-
storage.balances.at(to).write(recipient_balance + amount);
48-
}
49-
50-
#[public]
51-
fn transfer_ownership(new_owner: AztecAddress) {
52-
assert_eq(context.msg_sender(), storage.owner.read());
53-
storage.owner.write(new_owner);
54-
}
55-
56-
// ===============
56+
// ===============
5757

58-
#[private]
59-
fn mint_private(to: AztecAddress, amount: u64) {
60-
// Enqueue public validation
61-
StarterToken::at(context.this_address())._assert_is_owner(context.msg_sender()).enqueue(&mut context);
58+
#[private]
59+
fn mint_private(to: AztecAddress, amount: u64) {
60+
// Enqueue public validation
61+
StarterToken::at(context.this_address())._assert_is_owner(context.msg_sender()).enqueue(&mut context);
6262

63-
storage.private_balances.at(to).add(amount, to);
64-
}
63+
storage.private_balances.at(to).add(amount, to);
64+
}
6565

66-
#[private]
67-
fn transfer_private(to: AztecAddress, amount: u64) {
68-
let sender = context.msg_sender();
66+
#[private]
67+
fn transfer_private(to: AztecAddress, amount: u64) {
68+
let sender = context.msg_sender();
6969

70-
storage.private_balances.at(sender).sub(amount, sender);
70+
storage.private_balances.at(sender).sub(amount, sender);
7171

72-
storage.private_balances.at(to).add(amount, to);
73-
}
72+
storage.private_balances.at(to).add(amount, to);
73+
}
7474

75-
#[utility]
76-
unconstrained fn view_private_balance(owner: AztecAddress) -> Field {
77-
storage.private_balances.at(owner).get_value()
78-
}
75+
#[utility]
76+
unconstrained fn view_private_balance(owner: AztecAddress) -> Field {
77+
storage.private_balances.at(owner).get_value()
78+
}
7979

80-
#[public]
81-
#[internal]
82-
fn _assert_is_owner(maybe_owner: AztecAddress) {
83-
assert_eq(maybe_owner, storage.owner.read());
84-
}
80+
#[public]
81+
#[internal]
82+
fn _assert_is_owner(maybe_owner: AztecAddress) {
83+
assert_eq(maybe_owner, storage.owner.read());
84+
}
8585
}

starter-token/reference/external-call-contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub contract ExternalCall {
1010
use dep::starter_token::StarterToken;
1111

1212
#[private]
13-
fn call_mint_on_other_contract(contract_address: AztecAddress, to: AztecAddress, amount: u128) {
13+
fn call_mint_on_other_contract(contract_address: AztecAddress, to: AztecAddress, amount: u64) {
1414
StarterToken::at(contract_address).mint_private(to, amount).call(&mut context);
1515
}
1616
}

starter-token/reference/ts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"start": "npm run build && node dist/src/index.js"
1111
},
1212
"dependencies": {
13-
"@aztec/accounts": "^1.2.0",
14-
"@aztec/aztec.js": "^1.2.0"
13+
"@aztec/accounts": "2.0.2",
14+
"@aztec/aztec.js": "2.0.2"
1515
},
1616
"devDependencies": {
1717
"typescript": "^5.8.3"
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import { GettingStartedContract } from '../artifacts/GettingStarted.js';
2-
import {
3-
Fr,
4-
createPXEClient,
5-
waitForPXE,
6-
} from '@aztec/aztec.js';
1+
import { createPXEClient, waitForPXE } from '@aztec/aztec.js';
2+
import { StarterTokenContract } from '../artifacts/StarterToken.js';
73
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
84

95
const pxe = createPXEClient('http://localhost:8080');
106
await waitForPXE(pxe);
117

128
const wallets = await getInitialTestAccountsWallets(pxe);
139
const deployerWallet = wallets[0];
10+
const deployerAddress = deployerWallet.getAddress();
1411

15-
const contractDeploymentSalt = Fr.random();
16-
const gettingStartedContract = await GettingStartedContract
12+
const starterTokenContract = await StarterTokenContract
1713
.deploy(deployerWallet)
18-
.send({ contractAddressSalt: contractDeploymentSalt }).wait();
14+
.send({
15+
from: deployerAddress
16+
}).wait();
1917

20-
console.log('Contract Address', gettingStartedContract.contract.address);
18+
console.log(starterTokenContract.contract.address);

starter-token/start-here/external-call-contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub contract ExternalCall {
1010
use dep::starter_token::StarterToken;
1111

1212
#[private]
13-
fn call_mint_on_other_contract(contract_address: AztecAddress, to: AztecAddress, amount: u128) {
13+
fn call_mint_on_other_contract(contract_address: AztecAddress, to: AztecAddress, amount: u64) {
1414
StarterToken::at(contract_address).mint_private(to, amount).call(&mut context);
1515
}
1616
}

0 commit comments

Comments
 (0)