Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMinkov committed Mar 2, 2023
1 parent f718457 commit 75cfa2b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added a new feature to the library: `fetchEvents` can now be used to fetch events for a specified zkApp from a GraphQL endpoint that implements the schema specified [here](https://github.com/o1-labs/Archive-Node-API/blob/efebc9fd3cfc028f536ae2125e0d2676e2b86cd2/src/schema.ts#L1).
- Added a new feature to the library: `fetchEvents` can now be used to fetch events for a specified zkApp from a GraphQL endpoint that implements the schema specified [here](https://github.com/o1-labs/Archive-Node-API/blob/efebc9fd3cfc028f536ae2125e0d2676e2b86cd2/src/schema.ts#L1). `Mina.Network` now accepts an additional endpoint to configure, which points to a GraphQL server running the mentioned schema. The default used enpoint is now specified by the `mina` property in the input.

## [0.9.2](https://github.com/o1-labs/snarkyjs/compare/9c44b9c2...1abdfb70)

Expand Down
16 changes: 8 additions & 8 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function setGraphqlEndpoint(graphqlEndpoint: string) {
/**
* Sets up a GraphQL endpoint to be used for fetching information from an Archive Node.
*
* @param {string} - A GraphQL endpoint.
* @param A GraphQL endpoint.
*/
function setArchiveGraphqlEndpoint(graphqlEndpoint: string) {
archiveGraphqlEndpoint = graphqlEndpoint;
Expand Down Expand Up @@ -502,13 +502,13 @@ type EventActionFilterOptions = {
/**
Asynchronously fetches event data for an account from the Mina Archive Node GraphQL API.
@async
@param {object} accountInfo - The account information object.
@param {string} accountInfo.publicKey - The account public key.
@param {string} [accountInfo.tokenId] - The optional token ID for the account.
@param {string} [graphqlEndpoint=archiveGraphqlEndpoint] - The GraphQL endpoint to query. Defaults to the Archive Node GraphQL API.
@param {object} [filterOptions={}] - The optional filter options object.
@returns {Promise<Array>} A promise that resolves to an array of objects containing event data and block height for the account.
@throws {Error} If the GraphQL request fails or the response is invalid.
@param accountInfo - The account information object.
@param accountInfo.publicKey - The account public key.
@param [accountInfo.tokenId] - The optional token ID for the account.
@param [graphqlEndpoint=archiveGraphqlEndpoint] - The GraphQL endpoint to query. Defaults to the Archive Node GraphQL API.
@param [filterOptions={}] - The optional filter options object.
@returns A promise that resolves to an array of objects containing event data and block height for the account.
@throws If the GraphQL request fails or the response is invalid.
@example
const accountInfo = { publicKey: 'B62qiwmXrWn7Cok5VhhB3KvCwyZ7NHHstFGbiU5n7m8s2RqqNW1p1wF' };
const events = await fetchEvents(accountInfo);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/mina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,18 @@ function Network(input: { mina: string; archive: string } | string): Mina {
let graphqlEndpoint: string;
let archiveEndpoint: string;

if (typeof input === 'string') {
if (input && typeof input === 'string') {
graphqlEndpoint = input;
Fetch.setGraphqlEndpoint(graphqlEndpoint);
} else {
} else if (input && typeof input === 'object') {
graphqlEndpoint = input.mina;
archiveEndpoint = input.archive;
Fetch.setGraphqlEndpoint(graphqlEndpoint);
Fetch.setArchiveGraphqlEndpoint(archiveEndpoint);
} else {
throw new Error(
"Network: malformed input. Please provide a string or an object with 'mina' and 'archive' endpoints."
);
}

// copied from mina/genesis_ledgers/berkeley.json
Expand Down
8 changes: 4 additions & 4 deletions src/lib/zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,10 @@ super.init();
/**
Asynchronously fetches events emitted by this {@link SmartContract} and returns an array of events with their corresponding types.
@async
@param {UInt32} [start=UInt32.from(0)] - The start height of the events to fetch.
@param {UInt32} [end] - The end height of the events to fetch. If not provided, fetches events up to the latest height.
@returns {Promise<Array>} A promise that resolves to an array of objects, each containing the event type and event data for the specified range.
@throws {Error} If there is an error fetching events from the Mina network.
@param [start=UInt32.from(0)] - The start height of the events to fetch.
@param end - The end height of the events to fetch. If not provided, fetches events up to the latest height.
@returns A promise that resolves to an array of objects, each containing the event type and event data for the specified range.
@throws If there is an error fetching events from the Mina network.
@example
const startHeight = UInt32.from(1000);
const endHeight = UInt32.from(2000);
Expand Down

0 comments on commit 75cfa2b

Please sign in to comment.