Skip to content

Commit

Permalink
Merge pull request #86 from dojoengine/core-updates
Browse files Browse the repository at this point in the history
Core updates
  • Loading branch information
ponderingdemocritus authored Dec 19, 2023
2 parents 5f5b21e + fb26471 commit 7d13b3c
Show file tree
Hide file tree
Showing 13 changed files with 667 additions and 124 deletions.
Binary file added bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/react-app/src/dojo/setupNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineContractComponents } from "./contractComponents";
import { world } from "./world";
import { RPCProvider } from "@dojoengine/core";
import { DojoProvider } from "@dojoengine/core";
import { Account, num } from "starknet";
import manifest from "../../../dojo-starter/target/dev/manifest.json";
import * as torii from "@dojoengine/torii-client";
Expand All @@ -16,7 +16,7 @@ export async function setupNetwork() {
} = import.meta.env;

// Create a new RPCProvider instance.
const provider = new RPCProvider(
const provider = new DojoProvider(
VITE_PUBLIC_WORLD_ADDRESS,
manifest,
VITE_PUBLIC_NODE_URL
Expand Down
4 changes: 2 additions & 2 deletions examples/react-phaser-example/src/dojo/setupNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineContractComponents } from "./contractComponents";
import { world } from "./world";
import { RPCProvider } from "@dojoengine/core";
import { DojoProvider } from "@dojoengine/core";
import { Account, num } from "starknet";
import dev_manifest from "../../../dojo-starter/target/dev/manifest.json";
import * as torii from "@dojoengine/torii-client";
Expand All @@ -15,7 +15,7 @@ export async function setupNetwork() {
VITE_PUBLIC_TORII,
} = import.meta.env;

const provider = new RPCProvider(
const provider = new DojoProvider(
VITE_PUBLIC_WORLD_ADDRESS,
dev_manifest,
VITE_PUBLIC_NODE_URL
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "dojo-packages",
"name": "dojo.js",
"version": "0.1.61",
"workspaces": [
"examples/react-app",
Expand Down Expand Up @@ -30,7 +30,8 @@
"build": "bun run build-core && bun run build-create-burner && bun run build-create-dojo && bun run build-utils && bun run build-torii-wasm && bun run build-torii-client && bun run build-react",
"clean": "rm -rf node_modules packages/create-burner/node_modules node_modules packages/create-dojo/node_modules packages/core/node_modules packages/utils/node_modules packages/torii-client/node_modules packages/torii-wasm/node_modules packages/react/node_modules bun.lockb packages/create-burner/bun.lockb packages/core/bun.lockb packages/utils/bun.lockb packages/torii-client/bun.lockb packages/torii-wasm/bun.lockb packages/react/bun.lockb && rm -rf examples/react-app/node_modules examples/react-app/bun.lockb examples/react-phaser-example/node_modules examples/react-phaser-example/bun.lockb",
"prettier-check": "bun x prettier --check .",
"prettier": "bun x prettier --write ."
"prettier": "bun x prettier --write .",
"release": "bun run build && bun run prettier && npx lerna publish --no-private --force-publish"
},
"dependencies": {}
}
5 changes: 0 additions & 5 deletions packages/core/jest.config.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "tsup",
"postbuild": "cp -R bin dist/",
"test": "jest"
"test": "vitest"
},
"exports": {
".": {
Expand All @@ -26,10 +26,10 @@
"@types/mocha": "^10.0.1",
"bun-types": "^1.0.1",
"fetch-mock": "^9.11.0",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"tsup": "^8.0.1",
"typescript": "^5.0.3"
"typescript": "^5.0.3",
"vitest": "^1.1.0"
},
"bin": {
"create-components": "./dist/bin/generateComponents.cjs"
Expand Down
8 changes: 0 additions & 8 deletions packages/core/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
export const KATANA_ACCOUNT_1_ADDRESS =
"0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973";
export const KATANA_ACCOUNT_1_PRIVATEKEY =
"0x1800000000300000180000000000030000000000003006001800006600";
export const LOCAL_KATANA = "http://127.0.0.1:5050";
export const LOCAL_TORII = "http://localhost:8080";
export const DOJO_STARTER_WORLD =
"0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84";
export const ACCOUNT_CLASS_HASH =
"0x04d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f";
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import {
CallContractResponse,
} from "starknet";
import { Provider } from "./provider";
import { Query, WorldEntryPoints } from "../types";
import { WorldEntryPoints } from "../types";
import { LOCAL_KATANA } from "../constants";
import { getContractByName } from "../utils";

/**
* RPCProvider class: Extends the generic Provider to handle RPC interactions.
* RpcProvider class: Extends the generic Provider to handle RPC interactions with Dojo World.
*/
export class RPCProvider extends Provider {
export class DojoProvider extends Provider {
public provider: RpcProvider;
public contract: Contract;
public manifest: any;
Expand Down Expand Up @@ -51,24 +51,27 @@ export class RPCProvider extends Provider {
* Retrieves a single entity's details.
*
* @param {string} model - The component to query.
* @param {Query} query - The query details.
* @param {Array<string>} keys - The keys to query.
* @param {number} [offset=0] - Starting offset (defaults to 0).
* @param {number} [length=0] - Length to retrieve (defaults to 0).
* @returns {Promise<Array<bigint>>} - A promise that resolves to an array of bigints representing the entity's details.
*/
public async entity(
model: string,
query: Query,
keys: Array<string>,
offset: number = 0,
length: number = 0
length: number = 0,
layout: Array<number>
): Promise<Array<bigint>> {
try {
return (await this.contract.call(WorldEntryPoints.get, [
shortString.encodeShortString(model),
query.keys.length,
...(query.keys as any),
keys.length,
...(keys as any),
offset,
length,
layout.length,
layout,
])) as unknown as Array<bigint>;
} catch (error) {
throw error;
Expand All @@ -78,39 +81,48 @@ export class RPCProvider extends Provider {
/**
* Retrieves multiple entities' details.
*
* @param {string} component - The component to query.
* @param {number} length - Number of entities to retrieve.
* @returns {Promise<Array<bigint>>} - A promise that resolves to an array of bigints representing the entities' details.
* @param {string} model - The component to query.
* @param {number} index - The index to query.
* @param {Array<string>} values - The values to query.
* @param {number} valuesLength - The values length to query.
* @param {Array<number>} valuesLayout - The values layout to query.
*/
public async entities(
model: string,
length: number
): Promise<Array<bigint>> {
index: string,
values: Array<string>,
valuesLength: number,
valuesLayout: Array<number>
): Promise<Array<Array<bigint>>> {
try {
return (await this.contract.call(WorldEntryPoints.entities, [
shortString.encodeShortString(model),
length,
])) as unknown as Array<bigint>;
index,
values,
valuesLength,
valuesLayout,
])) as unknown as Promise<Array<Array<bigint>>>;
} catch (error) {
throw error;
}
}

/**
* Retrieves a component's details.
* Retrieves a models
*
* @param {string} name - Name of the component.
* @returns {Promise<bigint>} - A promise that resolves to a bigint representing the component's details.
* @param {string} name - Name of the model.
* @returns {Promise<bigint>} - A promise that resolves to a bigint representing the model's details.
*/
public async component(name: string): Promise<bigint> {
public async model(name: string): Promise<bigint> {
try {
return (await this.contract.call(WorldEntryPoints.component, [
return (await this.contract.call(WorldEntryPoints.model, [
shortString.encodeShortString(name),
])) as unknown as bigint;
} catch (error) {
throw error;
}
}

/**
* Executes a function with the given parameters.
*
Expand Down Expand Up @@ -194,7 +206,7 @@ export class RPCProvider extends Provider {
try {
const { result } = await this.provider.callContract({
contractAddress: this.getWorldAddress(),
entrypoint: "uuid",
entrypoint: WorldEntryPoints.uuid,
calldata: [],
});
if (result && result.length === 1) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./RPCProvider";
export * from "./DojoProvider";
20 changes: 12 additions & 8 deletions packages/core/src/provider/provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ICommands, Query } from "../types";
import { IWorld } from "../types";

/**
* Provider class: An abstract base class for all providers.
* It implements the ICommands interface, ensuring that any class deriving from Provider
* will have implementations for the entity and entities methods.
*/
export abstract class Provider implements ICommands {
export abstract class Provider implements IWorld {
// Store the address of the world.
private readonly worldAddress: string;

Expand All @@ -29,10 +29,11 @@ export abstract class Provider implements ICommands {
* @returns {Promise<Array<bigint>>} - A promise that resolves to an array of bigints representing the entity's details.
*/
public abstract entity(
component: string,
query: Query,
model: string,
keys: Array<string>,
offset: number,
length: number
length: number,
layout: Array<number>
): Promise<Array<bigint>>;

/**
Expand All @@ -44,9 +45,12 @@ export abstract class Provider implements ICommands {
* @returns {Promise<Array<bigint>>} - A promise that resolves to an array of bigints representing the entities' details.
*/
public abstract entities(
component: string,
length: number
): Promise<Array<bigint>>;
model: string,
index: string | null,
values: Array<string>,
valuesLength: number,
valuesLayout: Array<number>
): Promise<Array<Array<bigint>>>;

/**
* Retrieves the stored world address.
Expand Down
33 changes: 0 additions & 33 deletions packages/core/src/provider/tests/RPCProvider.test.ts

This file was deleted.

Loading

0 comments on commit 7d13b3c

Please sign in to comment.