Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exposing PXE.getBlock, exporting createAztecNodeClient from aztec.js #3139

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 8 additions & 0 deletions yarn-project/aztec.js/src/pxe_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ExtendedContractData,
ExtendedNote,
ExtendedUnencryptedL2Log,
L2Block,
L2BlockL2Logs,
L2Tx,
LogId,
Expand All @@ -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<PXE>(
url,
Expand All @@ -48,6 +55,7 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], true))
AuthWitness,
L2Tx,
LogId,
L2Block,
},
{ Tx, TxReceipt, L2BlockL2Logs },
false,
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/aztec.js/src/wallet/base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ExtendedNote,
FunctionCall,
GetUnencryptedLogsResponse,
L2Block,
L2Tx,
LogFilter,
NodeInfo,
Expand Down Expand Up @@ -82,6 +83,9 @@ export abstract class BaseWallet implements Wallet {
getNoteNonces(note: ExtendedNote): Promise<Fr[]> {
return this.pxe.getNoteNonces(note);
}
getBlock(number: number): Promise<L2Block | undefined> {
return this.pxe.getBlock(number);
}
viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress | undefined): Promise<any> {
return this.pxe.viewTx(functionName, args, to, from);
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AztecNode>(
export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecNode {
return createJsonRpcClient<AztecNode>(
url,
{
AztecAddress,
Expand All @@ -47,5 +47,4 @@ export function createAztecNodeRpcClient(url: string, fetch = defaultFetch): Azt
false,
fetch,
);
return rpcClient;
}
2 changes: 1 addition & 1 deletion yarn-project/types/src/aztec_node/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './http_rpc_client.js';
export * from './aztec_node_client.js';
8 changes: 8 additions & 0 deletions yarn-project/types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ExtendedContractData,
ExtendedNote,
GetUnencryptedLogsResponse,
L2Block,
L2Tx,
LogFilter,
Tx,
Expand Down Expand Up @@ -181,6 +182,13 @@ export interface PXE {
*/
getNoteNonces(note: ExtendedNote): Promise<Fr[]>;

/**
* Get the a given block.
* @param number - The block number being requested.
* @returns The blocks requested.
*/
getBlock(number: number): Promise<L2Block | undefined>;

/**
* 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.
Expand Down