Skip to content

Commit

Permalink
update core docs and code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Dec 20, 2023
1 parent 2740475 commit 68d107f
Show file tree
Hide file tree
Showing 6 changed files with 8,997 additions and 12,264 deletions.
Binary file removed bun.lockb
Binary file not shown.
27 changes: 23 additions & 4 deletions packages/core/src/provider/DojoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@ import { LOCAL_KATANA } from "../constants";
import { getContractByName } from "../utils";

/**
* RpcProvider class: Extends the generic Provider to handle RPC interactions with Dojo World.
* DojoProvider: The DojoProvider is an execution provider for dojo worlds. It allows you to easily interact with a dojo world via the Starknet.js library.
* ```ts
* import { DojoProvider } from "@dojoengine/core";
*
* const provider = new DojoProvider(
* VITE_PUBLIC_WORLD_ADDRESS,
* manifest,
* VITE_PUBLIC_NODE_URL
* );
*
* await provider.execute(signer, contract, system, call_data);
* ```
*/
export class DojoProvider extends Provider {
public provider: RpcProvider;
public contract: Contract;
public manifest: any;

/**
* Constructor: Initializes the RPCProvider with the given world address and URL.
* Constructor: Initializes the DojoProvider with the given world address, manifest and URL.
*
* @param {string} world_address - Address of the world.
* @param {string} [url=LOCAL_KATANA] - RPC URL (defaults to LOCAL_KATANA).
Expand Down Expand Up @@ -125,7 +136,11 @@ export class DojoProvider extends Provider {

/**
* Executes a function with the given parameters.
* This function is a wrapper around the Starknet.js Account.execute function, but is more convenient to use.
*
* ```ts
* await provider.execute(signer, contract, system, call_data);
* ```
* @param {Account} account - The account to use.
* @param {string} contract - The contract to execute.
* @param {string} call - The function to call.
Expand Down Expand Up @@ -165,8 +180,12 @@ export class DojoProvider extends Provider {
}

/**
* Executes a function with the given parameters.
* Executes a multicall.
* This function is a wrapper around the Starknet.js Account.execute function, but allows for executing multiple calls at once.
*
* ```ts
* await provider.executeMulti(account, calls);
* ```
* @param {Account} account - The account to use.
* @param {AllowArray<Call>} calls - The calls to execute.
* @param {InvocationsDetails | undefined} transactionDetails - The transactionDetails allow to override maxFee & version
Expand All @@ -191,7 +210,7 @@ export class DojoProvider extends Provider {
}

/**
* Retrieves current uuid from the world contract
* Retrieves current uuid from the world contract.
*
* @returns {Promise<number>} - A promise that resolves to the world uuid
* @throws {Error} - Throws an error if the call fails.
Expand Down
46 changes: 0 additions & 46 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
import { shortString } from "starknet";

/**
* Extracts the names of all components from a manifest.
*
* @param {any} manifest - The input manifest containing component details.
* @returns {any} - An array containing the names of all components.
*/
export function getAllComponentNames(manifest: any): any {
return manifest.components.map((component: any) => component.name);
}

/**
* Extracts the names of all components from a manifest and converts them to `felt252` representation.
*
* @param {any} manifest - The input manifest containing component details.
* @returns {any} - An array containing the `felt252` representation of component names.
*/
export function getAllComponentNamesAsFelt(manifest: any): any {
return manifest.components.map((component: any) =>
shortString.encodeShortString(component.name)
);
}

/**
* Extracts the names of all systems from a manifest.
*
* @param {any} manifest - The input manifest containing system details.
* @returns {any} - An array containing the names of all systems.
*/
export function getAllSystemNames(manifest: any): any {
return manifest.systems.map((system: any) => system.name);
}

/**
* Extracts the names of all systems from a manifest and converts them to `felt252` representation.
*
* @param {any} manifest - The input manifest containing system details.
* @returns {any} - An array containing the `felt252` representation of system names.
*/
export function getAllSystemNamesAsFelt(manifest: any): any {
return manifest.systems.map((system: any) =>
shortString.encodeShortString(system.name)
);
}

/**
* Gets a contract from a manifest by name.
*
Expand Down
140 changes: 68 additions & 72 deletions packages/create-dojo/bin/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 68d107f

Please sign in to comment.