Skip to content

Commit

Permalink
chore: Rename getAccounts to getRegisteredAccounts (#2330)
Browse files Browse the repository at this point in the history
It was brought up that `getAccounts` in the RPC Server interface was
confusing, since that interface is shared with the `Wallet`, and it's
not clear if the accounts being queried correspond to all those listed
in the RPC server or just to the wallet. This rename should make it
clearer.
  • Loading branch information
spalladino authored Sep 15, 2023
1 parent aaf7f67 commit c7f3776
Show file tree
Hide file tree
Showing 24 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/docs/dev_docs/contracts/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ await aztecRpc.registerRecipient(completeAddress);
</TabItem>
</Tabs>

When you create a new account, it gets automatically registered. It can be verified by calling `aztec-cli get-accounts` OR in aztec.js by using `await aztecRpc.getAccounts()`
When you create a new account, it gets automatically registered. It can be verified by calling `aztec-cli get-accounts` OR in aztec.js by using `await aztecRpc.getRegisteredAccounts()`

> **NOTE 1**: If we didn't register owner as a recipient we could not encrypt a note for the owner and the contract deployment would fail because constructor execution would fail (we need owner's public key to encrypt a note).
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/dev_docs/getting_started/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ That might seem like a lot to digest but it can be broken down into the followin
2. We wait for the deployment of the 2 account contracts to complete.
3. We retrieve the expected account addresses from the `Account` objects and ensure that they are present in the set of account addresses registered on the Sandbox.

Note, we use the `getAccounts` api to verify that the addresses computed as part of the
Note, we use the `getRegisteredAccounts` api to verify that the addresses computed as part of the
account contract deployment have been successfully added to the Sandbox.

If you were looking at your terminal that is running the Sandbox you should hopefully have seen a lot of activity. This is because the Sandbox will have simulated the deployment of both contracts, executed the private kernel circuit for each before submitted 2 transactions to the pool. The sequencer will have picked them up and inserted them into a rollup and executed the recursive rollup circuits before publishing the rollup to Anvil. Once this has completed, the rollup is retrieved and pulled down to the internal RPC Server so that any new account state can be decrypted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class AztecRPCServer implements AztecRPC {
}
}

public async getAccounts(): Promise<CompleteAddress[]> {
public async getRegisteredAccounts(): Promise<CompleteAddress[]> {
// Get complete addresses of both the recipients and the accounts
const addresses = await this.db.getCompleteAddresses();
// Filter out the addresses not corresponding to accounts
Expand All @@ -126,8 +126,8 @@ export class AztecRPCServer implements AztecRPC {
return accounts;
}

public async getAccount(address: AztecAddress): Promise<CompleteAddress | undefined> {
const result = await this.getAccounts();
public async getRegisteredAccount(address: AztecAddress): Promise<CompleteAddress | undefined> {
const result = await this.getRegisteredAccounts();
const account = result.find(r => r.address.equals(address));
return Promise.resolve(account);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ export const aztecRpcTestSuite = (testName: string, aztecRpcSetup: () => Promise
await rpc.registerAccount(await keyPair.getPrivateKey(), completeAddress.partialAddress);

// Check that the account is correctly registered using the getAccounts and getRecipients methods
const accounts = await rpc.getAccounts();
const accounts = await rpc.getRegisteredAccounts();
const recipients = await rpc.getRecipients();
expect(accounts).toContainEqual(completeAddress);
expect(recipients).not.toContainEqual(completeAddress);

// Check that the account is correctly registered using the getAccount and getRecipient methods
const account = await rpc.getAccount(completeAddress.address);
const account = await rpc.getRegisteredAccount(completeAddress.address);
const recipient = await rpc.getRecipient(completeAddress.address);
expect(account).toEqual(completeAddress);
expect(recipient).toBeUndefined();
Expand All @@ -45,13 +45,13 @@ export const aztecRpcTestSuite = (testName: string, aztecRpcSetup: () => Promise
await rpc.registerRecipient(completeAddress);

// Check that the recipient is correctly registered using the getAccounts and getRecipients methods
const accounts = await rpc.getAccounts();
const accounts = await rpc.getRegisteredAccounts();
const recipients = await rpc.getRecipients();
expect(accounts).not.toContainEqual(completeAddress);
expect(recipients).toContainEqual(completeAddress);

// Check that the recipient is correctly registered using the getAccount and getRecipient methods
const account = await rpc.getAccount(completeAddress.address);
const account = await rpc.getRegisteredAccount(completeAddress.address);
const recipient = await rpc.getRecipient(completeAddress.address);
expect(account).toBeUndefined();
expect(recipient).toEqual(completeAddress);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-sandbox/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function main() {
logger.info(`Debug logs will be written to ${logPath}`);
const accountStrings = [`Initial Accounts:\n\n`];

const registeredAccounts = await rpcServer.getAccounts();
const registeredAccounts = await rpcServer.getRegisteredAccounts();
for (const account of accounts) {
const completeAddress = await account.account.getCompleteAddress();
if (registeredAccounts.find(a => a.equals(completeAddress))) {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function getWallet(
address: AztecAddress,
accountContract: AccountContract,
): Promise<AccountWallet> {
const completeAddress = await rpc.getAccount(address);
const completeAddress = await rpc.getRegisteredAccount(address);
if (!completeAddress) {
throw new Error(`Account ${address} not found`);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Contract Class', () => {
wallet.getTxReceipt.mockResolvedValue(mockTxReceipt);
wallet.getNodeInfo.mockResolvedValue(mockNodeInfo);
wallet.simulateTx.mockResolvedValue(mockTx);
wallet.getAccounts.mockResolvedValue([account]);
wallet.getRegisteredAccounts.mockResolvedValue([account]);
});

it('should create and send a contract method tx', async () => {
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export abstract class BaseWallet implements Wallet {
registerRecipient(account: CompleteAddress): Promise<void> {
return this.rpc.registerRecipient(account);
}
getAccounts(): Promise<CompleteAddress[]> {
return this.rpc.getAccounts();
getRegisteredAccounts(): Promise<CompleteAddress[]> {
return this.rpc.getRegisteredAccounts();
}
getAccount(address: AztecAddress): Promise<CompleteAddress | undefined> {
return this.rpc.getAccount(address);
getRegisteredAccount(address: AztecAddress): Promise<CompleteAddress | undefined> {
return this.rpc.getRegisteredAccount(address);
}
getRecipients(): Promise<CompleteAddress[]> {
return this.rpc.getRecipients();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function WalletDropdown({ selected, onSelectChange, onError }: Props) {
return;
}
const loadOptions = async () => {
const fetchedOptions = await rpcClient.getAccounts();
const fetchedOptions = await rpcClient.getRegisteredAccounts();
setOptions(fetchedOptions);
onSelectChange(fetchedOptions[0]);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('ZK Contract Tests', () => {

beforeAll(async () => {
rpcClient = await setupSandbox();
const accounts = await rpcClient.getAccounts();
const accounts = await rpcClient.getRegisteredAccounts();
[owner, account2, _account3] = accounts;

wallet = await getWallet(owner, rpcClient);
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/canary/src/aztec_js_browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
SANDBOX_URL,
privKey.toString(),
);
const accounts = await testClient.getAccounts();
const accounts = await testClient.getRegisteredAccounts();
const stringAccounts = accounts.map(acc => acc.address.toString());
expect(stringAccounts.includes(result)).toBeTruthy();
}, 15_000);
Expand All @@ -134,7 +134,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
async (rpcUrl, contractAddress, PrivateTokenContractAbi) => {
const { Contract, AztecAddress, createAztecRpcClient, makeFetch } = window.AztecJs;
const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true));
const owner = (await client.getAccounts())[0].address;
const owner = (await client.getRegisteredAccounts())[0].address;
const [wallet] = await AztecJs.getSandboxAccountsWallets(client);
const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet);
const balance = await contract.methods.getBalance(owner).view({ from: owner });
Expand All @@ -155,7 +155,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
console.log(`Starting transfer tx`);
const { AztecAddress, Contract, createAztecRpcClient, makeFetch } = window.AztecJs;
const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true));
const accounts = await client.getAccounts();
const accounts = await client.getRegisteredAccounts();
const owner = accounts[0].address;
const receiver = accounts[1].address;
const [wallet] = await AztecJs.getSandboxAccountsWallets(client);
Expand All @@ -182,12 +182,12 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
const { GrumpkinScalar, DeployMethod, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } =
window.AztecJs;
const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true));
let accounts = await client.getAccounts();
let accounts = await client.getRegisteredAccounts();
if (accounts.length === 0) {
// This test needs an account for deployment. We create one in case there is none available in the RPC server.
const privateKey = GrumpkinScalar.fromString(privateKeyString);
await getUnsafeSchnorrAccount(client, privateKey).waitDeploy();
accounts = await client.getAccounts();
accounts = await client.getRegisteredAccounts();
}
const owner = accounts[0];
const tx = new DeployMethod(owner.publicKey, client, PrivateTokenContractAbi, [
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/canary/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ describe('CLI canary', () => {
};

it('creates & retrieves an account', async () => {
existingAccounts = await aztecRpcClient.getAccounts();
existingAccounts = await aztecRpcClient.getRegisteredAccounts();
debug('Create an account');
await run(`create-account`);
const foundAddress = findInLogs(/Address:\s+(?<address>0x[a-fA-F0-9]+)/)?.groups?.address;
expect(foundAddress).toBeDefined();
const newAddress = AztecAddress.fromString(foundAddress!);

const accountsAfter = await aztecRpcClient.getAccounts();
const accountsAfter = await aztecRpcClient.getRegisteredAccounts();
const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress];
expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts);
const newCompleteAddress = accountsAfter[accountsAfter.length - 1];
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('CLI canary', () => {
expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`);

debug('Transfer some tokens');
const existingAccounts = await aztecRpcClient.getAccounts();
const existingAccounts = await aztecRpcClient.getRegisteredAccounts();
// ensure we pick a different acc
const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('uniswap_trade_on_l1_from_l2', () => {
logger('Running L1/L2 messaging test on HTTP interface.');

[wallet] = await getSandboxAccountsWallets(aztecRpcClient);
const accounts = await wallet.getAccounts();
const accounts = await wallet.getRegisteredAccounts();
const owner = accounts[0].address;
const receiver = accounts[1].address;

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
.option('-u, --rpc-url <string>', 'URL of the Aztec RPC', AZTEC_RPC_HOST || 'http://localhost:8080')
.action(async (options: any) => {
const client = await createCompatibleClient(options.rpcUrl, debugLogger);
const accounts = await client.getAccounts();
const accounts = await client.getRegisteredAccounts();
if (!accounts.length) {
log('No accounts found.');
} else {
Expand All @@ -311,7 +311,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
.action(async (_address, options) => {
const client = await createCompatibleClient(options.rpcUrl, debugLogger);
const address = AztecAddress.fromString(_address);
const account = await client.getAccount(address);
const account = await client.getRegisteredAccount(address);

if (!account) {
log(`Unknown account ${_address}`);
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/cli/src/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ describe('CLI Utils', () => {
// returns a parsed Aztec Address
const aztecAddress = AztecAddress.random();
const result = await getTxSender(client, aztecAddress.toString());
expect(client.getAccounts).toHaveBeenCalledTimes(0);
expect(client.getRegisteredAccounts).toHaveBeenCalledTimes(0);
expect(result).toEqual(aztecAddress);

// returns an address found in the aztec client
const completeAddress = await CompleteAddress.random();
client.getAccounts.mockResolvedValueOnce([completeAddress]);
client.getRegisteredAccounts.mockResolvedValueOnce([completeAddress]);
const resultWithoutString = await getTxSender(client);
expect(client.getAccounts).toHaveBeenCalled();
expect(client.getRegisteredAccounts).toHaveBeenCalled();
expect(resultWithoutString).toEqual(completeAddress.address);

// throws when invalid parameter passed
Expand All @@ -47,7 +47,7 @@ describe('CLI Utils', () => {
).rejects.toThrow(`Invalid option 'from' passed: ${errorAddr}`);

// Throws error when no string is passed & no accounts found in RPC
client.getAccounts.mockResolvedValueOnce([]);
client.getRegisteredAccounts.mockResolvedValueOnce([]);
await expect(
(async () => {
await getTxSender(client);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function getTxSender(client: AztecRPC, _from?: string) {
throw new Error(`Invalid option 'from' passed: ${_from}`);
}
} else {
const accounts = await client.getAccounts();
const accounts = await client.getRegisteredAccounts();
if (!accounts.length) {
throw new Error('No accounts found in Aztec RPC instance.');
}
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/end-to-end/src/e2e_aztec_js_browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
SANDBOX_URL,
privKey.toString(),
);
const accounts = await testClient.getAccounts();
const accounts = await testClient.getRegisteredAccounts();
const stringAccounts = accounts.map(acc => acc.address.toString());
expect(stringAccounts.includes(result)).toBeTruthy();
}, 15_000);
Expand All @@ -137,7 +137,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
async (rpcUrl, contractAddress, PrivateTokenContractAbi) => {
const { Contract, AztecAddress, createAztecRpcClient, makeFetch } = window.AztecJs;
const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true));
const owner = (await client.getAccounts())[0].address;
const owner = (await client.getRegisteredAccounts())[0].address;
const [wallet] = await AztecJs.getSandboxAccountsWallets(client);
const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet);
const balance = await contract.methods.getBalance(owner).view({ from: owner });
Expand All @@ -157,7 +157,7 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
console.log(`Starting transfer tx`);
const { AztecAddress, Contract, createAztecRpcClient, makeFetch } = window.AztecJs;
const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true));
const accounts = await client.getAccounts();
const accounts = await client.getRegisteredAccounts();
const receiver = accounts[1].address;
const [wallet] = await AztecJs.getSandboxAccountsWallets(client);
const contract = await Contract.at(AztecAddress.fromString(contractAddress), PrivateTokenContractAbi, wallet);
Expand All @@ -179,12 +179,12 @@ conditionalDescribe()('e2e_aztec.js_browser', () => {
const { GrumpkinScalar, DeployMethod, createAztecRpcClient, makeFetch, getUnsafeSchnorrAccount } =
window.AztecJs;
const client = createAztecRpcClient(rpcUrl!, makeFetch([1, 2, 3], true));
let accounts = await client.getAccounts();
let accounts = await client.getRegisteredAccounts();
if (accounts.length === 0) {
// This test needs an account for deployment. We create one in case there is none available in the RPC server.
const privateKey = GrumpkinScalar.fromString(privateKeyString);
await getUnsafeSchnorrAccount(client, privateKey).waitDeploy();
accounts = await client.getAccounts();
accounts = await client.getRegisteredAccounts();
}
const owner = accounts[0];
const tx = new DeployMethod(owner.publicKey, client, PrivateTokenContractAbi, [
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/end-to-end/src/e2e_cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ describe('CLI e2e test', () => {
};

it('creates & retrieves an account', async () => {
existingAccounts = await aztecRpcClient.getAccounts();
existingAccounts = await aztecRpcClient.getRegisteredAccounts();
debug('Create an account');
await run(`create-account`);
const foundAddress = findInLogs(/Address:\s+(?<address>0x[a-fA-F0-9]+)/)?.groups?.address;
expect(foundAddress).toBeDefined();
const newAddress = AztecAddress.fromString(foundAddress!);

const accountsAfter = await aztecRpcClient.getAccounts();
const accountsAfter = await aztecRpcClient.getRegisteredAccounts();
const expectedAccounts = [...existingAccounts.map(a => a.address), newAddress];
expect(accountsAfter.map(a => a.address)).toEqual(expectedAccounts);
const newCompleteAddress = accountsAfter[accountsAfter.length - 1];
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('CLI e2e test', () => {
expect(balance!).toEqual(`${BigInt(INITIAL_BALANCE).toString()}n`);

debug('Transfer some tokens');
const existingAccounts = await aztecRpcClient.getAccounts();
const existingAccounts = await aztecRpcClient.getRegisteredAccounts();
// ensure we pick a different acc
const receiver = existingAccounts.find(acc => acc.address.toString() !== ownerAddress.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('e2e_multiple_accounts_1_enc_key', () => {

// Verify that all accounts use the same encryption key
const encryptionPublicKey = await generatePublicKey(encryptionPrivateKey);
for (const account of await aztecRpcServer.getAccounts()) {
for (const account of await aztecRpcServer.getRegisteredAccounts()) {
expect(account.publicKey).toEqual(encryptionPublicKey);
}

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_sandbox_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('e2e_sandbox_example', () => {
const [alice, bob] = (await Promise.all(accounts.map(x => x.getCompleteAddress()))).map(x => x.address);

// Verify that the accounts were deployed
const registeredAccounts = (await aztecRpc.getAccounts()).map(x => x.address);
const registeredAccounts = (await aztecRpc.getRegisteredAccounts()).map(x => x.address);
for (const [account, name] of [
[alice, 'Alice'],
[bob, 'Bob'],
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export async function setupAztecRPCServer(

return {
aztecRpcServer: rpc!,
accounts: await rpc!.getAccounts(),
accounts: await rpc!.getRegisteredAccounts(),
wallets,
logger,
};
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/sample-dapp/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { SANDBOX_URL = 'http://localhost:8080' } = process.env;

async function main() {
const client = createAztecRpcClient(SANDBOX_URL);
const [owner] = await client.getAccounts();
const [owner] = await client.getRegisteredAccounts();

const privateTokenDeployer = new ContractDeployer(PrivateTokenArtifact, client);
const { contractAddress: privateTokenAddress } = await privateTokenDeployer.deploy(100n, owner.address).send().wait();
Expand Down
Loading

0 comments on commit c7f3776

Please sign in to comment.