From 22719851c70f4481037b0092ff36f1fe409c1ec2 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 31 Oct 2023 09:39:30 +0000 Subject: [PATCH 1/3] exposing getBlock on PXE --- yarn-project/aztec.js/src/pxe_client.ts | 8 ++++++++ yarn-project/aztec.js/src/wallet/base_wallet.ts | 4 ++++ yarn-project/types/src/interfaces/pxe.ts | 10 +++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/yarn-project/aztec.js/src/pxe_client.ts b/yarn-project/aztec.js/src/pxe_client.ts index c50cdc848de..5e7cd3a3822 100644 --- a/yarn-project/aztec.js/src/pxe_client.ts +++ b/yarn-project/aztec.js/src/pxe_client.ts @@ -14,6 +14,7 @@ import { ExtendedContractData, ExtendedNote, ExtendedUnencryptedL2Log, + L2Block, L2BlockL2Logs, L2Tx, LogId, @@ -27,6 +28,12 @@ import { export { makeFetch } from '@aztec/foundation/json-rpc/client'; +/** + * Creates a JSON-RPC client to remotely talk to PXE. + * @param url - The URL of the PXE. + * @param fetch - The fetch implementation to use. + * @returns A JSON-RPC client of PXE. + */ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], true)): PXE => createJsonRpcClient( url, @@ -48,6 +55,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], true)) AuthWitness, L2Tx, LogId, + L2Block, }, { Tx, TxReceipt, L2BlockL2Logs }, false, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 6003bdb2496..2a1f5235b4e 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -7,6 +7,7 @@ import { ExtendedNote, FunctionCall, GetUnencryptedLogsResponse, + L2Block, L2Tx, LogFilter, NodeInfo, @@ -82,6 +83,9 @@ export abstract class BaseWallet implements Wallet { getNoteNonces(note: ExtendedNote): Promise { return this.pxe.getNoteNonces(note); } + getBlock(number: number): Promise { + return this.pxe.getBlock(number); + } viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress | undefined): Promise { return this.pxe.viewTx(functionName, args, to, from); } diff --git a/yarn-project/types/src/interfaces/pxe.ts b/yarn-project/types/src/interfaces/pxe.ts index f52eb27273a..d189fddd609 100644 --- a/yarn-project/types/src/interfaces/pxe.ts +++ b/yarn-project/types/src/interfaces/pxe.ts @@ -6,6 +6,7 @@ import { ExtendedContractData, ExtendedNote, GetUnencryptedLogsResponse, + L2Block, L2Tx, LogFilter, Tx, @@ -160,7 +161,7 @@ export interface PXE { getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise; /** - * Gets notes based on the provided filter. + * Gets notes OF ACCOUNTS REGISTERED IN THIS PXE based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */ @@ -181,6 +182,13 @@ export interface PXE { */ getNoteNonces(note: ExtendedNote): Promise; + /** + * Get the a given block. + * @param number - The block number being requested. + * @returns The blocks requested. + */ + getBlock(number: number): Promise; + /** * Simulate the execution of a view (read-only) function on a deployed contract without actually modifying state. * This is useful to inspect contract state, for example fetching a variable value or calling a getter function. From 53ea59d19a1e4bdd9500ab086df0b60f0df4403c Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 31 Oct 2023 09:43:13 +0000 Subject: [PATCH 2/3] consistent naming + exposing createAztecNodeClient --- yarn-project/aztec.js/src/index.ts | 1 + yarn-project/end-to-end/src/fixtures/utils.ts | 4 ++-- yarn-project/pxe/src/bin/index.ts | 4 ++-- .../{http_rpc_client.ts => aztec_node_client.ts} | 13 ++++++------- yarn-project/types/src/aztec_node/rpc/index.ts | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) rename yarn-project/types/src/aztec_node/rpc/{http_rpc_client.ts => aztec_node_client.ts} (72%) diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 4f315d036fb..351b350fb19 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -32,6 +32,7 @@ export { TxStatus, UnencryptedL2Log, emptyFunctionCall, + createAztecNodeClient, } from '@aztec/types'; export { ContractArtifact } from '@aztec/foundation/abi'; export { createDebugLogger, DebugLogger } from '@aztec/foundation/log'; diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index c4f63723ce6..6b405775ad3 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -29,7 +29,7 @@ import { } from '@aztec/l1-artifacts'; import { PXEService, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; import { SequencerClient } from '@aztec/sequencer-client'; -import { AztecNode, L2BlockL2Logs, LogType, PXE, createAztecNodeRpcClient } from '@aztec/types'; +import { AztecNode, L2BlockL2Logs, LogType, PXE, createAztecNodeClient } from '@aztec/types'; import * as path from 'path'; import { @@ -166,7 +166,7 @@ async function setupWithSandbox(account: Account, config: AztecNodeConfig, logge // we are setting up against the sandbox, l1 contracts are already deployed const aztecNodeUrl = getAztecNodeUrl(); logger(`Creating Aztec Node client to remote host ${aztecNodeUrl}`); - const aztecNode = createAztecNodeRpcClient(aztecNodeUrl); + const aztecNode = createAztecNodeClient(aztecNodeUrl); logger(`Creating PXE client to remote host ${PXE_URL}`); const pxeClient = createPXEClient(PXE_URL); await waitForPXE(pxeClient, logger); diff --git a/yarn-project/pxe/src/bin/index.ts b/yarn-project/pxe/src/bin/index.ts index 21de0ee64dd..de9e3684ed2 100644 --- a/yarn-project/pxe/src/bin/index.ts +++ b/yarn-project/pxe/src/bin/index.ts @@ -1,6 +1,6 @@ #!/usr/bin/env -S node --no-warnings import { createDebugLogger } from '@aztec/foundation/log'; -import { createAztecNodeRpcClient } from '@aztec/types'; +import { createAztecNodeClient } from '@aztec/types'; import { getPXEServiceConfig } from '../config/index.js'; import { startPXEHttpServer } from '../pxe_http/index.js'; @@ -17,7 +17,7 @@ async function main() { logger.info(`Setting up PXE...`); const pxeConfig = getPXEServiceConfig(); - const nodeRpcClient = createAztecNodeRpcClient(AZTEC_NODE_URL); + const nodeRpcClient = createAztecNodeClient(AZTEC_NODE_URL); const pxeService = await createPXEService(nodeRpcClient, pxeConfig); const shutdown = async () => { diff --git a/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts b/yarn-project/types/src/aztec_node/rpc/aztec_node_client.ts similarity index 72% rename from yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts rename to yarn-project/types/src/aztec_node/rpc/aztec_node_client.ts index 0dd96e503a7..1c312302357 100644 --- a/yarn-project/types/src/aztec_node/rpc/http_rpc_client.ts +++ b/yarn-project/types/src/aztec_node/rpc/aztec_node_client.ts @@ -19,13 +19,13 @@ import { } from '@aztec/types'; /** - * Creates a JSON-RPC client to remotely talk to an AztecNode. - * @param url - The URL of the AztecNode - * @param fetch - The fetch implementation to use - * @returns A JSON-RPC client + * Creates a JSON-RPC client to remotely talk to an Aztec Node. + * @param url - The URL of the Aztec Node. + * @param fetch - The fetch implementation to use. + * @returns A JSON-RPC client of Aztec Node. */ -export function createAztecNodeRpcClient(url: string, fetch = defaultFetch): AztecNode { - const rpcClient = createJsonRpcClient( +export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecNode { + return createJsonRpcClient( url, { AztecAddress, @@ -47,5 +47,4 @@ export function createAztecNodeRpcClient(url: string, fetch = defaultFetch): Azt false, fetch, ); - return rpcClient; } diff --git a/yarn-project/types/src/aztec_node/rpc/index.ts b/yarn-project/types/src/aztec_node/rpc/index.ts index e8ecf164fef..9b73b528764 100644 --- a/yarn-project/types/src/aztec_node/rpc/index.ts +++ b/yarn-project/types/src/aztec_node/rpc/index.ts @@ -1 +1 @@ -export * from './http_rpc_client.js'; +export * from './aztec_node_client.js'; From 61359e9ee7dc0d1ab515faf448486d2d79798749 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 31 Oct 2023 09:46:05 +0000 Subject: [PATCH 3/3] cleanup --- yarn-project/types/src/interfaces/pxe.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/types/src/interfaces/pxe.ts b/yarn-project/types/src/interfaces/pxe.ts index d189fddd609..b6e7bd0e3cd 100644 --- a/yarn-project/types/src/interfaces/pxe.ts +++ b/yarn-project/types/src/interfaces/pxe.ts @@ -161,7 +161,7 @@ export interface PXE { getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise; /** - * Gets notes OF ACCOUNTS REGISTERED IN THIS PXE based on the provided filter. + * Gets notes based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */