Skip to content
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
6 changes: 3 additions & 3 deletions clijs/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command, Flags } from "@oclif/core";
import * as os from "node:os";
import * as path from "node:path";
import {
CometaService,
CometaClient,
FaucetClient,
type Hex,
HttpTransport,
Expand Down Expand Up @@ -58,7 +58,7 @@ abstract class BaseCommand extends Command {
protected cfg?: Record<string, string>;
protected rpcClient?: PublicClient;
protected faucetClient?: FaucetClient;
protected cometaClient?: CometaService;
protected cometaClient?: CometaClient;
protected quiet = false;

public async init(): Promise<void> {
Expand Down Expand Up @@ -112,7 +112,7 @@ abstract class BaseCommand extends Command {
}

if (this.cfg[ConfigKeys.CometaEndpoint]) {
this.cometaClient = new CometaService({
this.cometaClient = new CometaClient({
transport: new HttpTransport({
endpoint: this.cfg[ConfigKeys.CometaEndpoint],
}),
Expand Down
6 changes: 3 additions & 3 deletions clijs/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mkdtemp } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import {
CometaService,
CometaClient,
FaucetClient,
type Hex,
HttpTransport,
Expand Down Expand Up @@ -37,7 +37,7 @@ interface CliTestFixture {
stdout: string;
}>;

cometaClient: CometaService;
cometaClient: CometaClient;
faucetClient: FaucetClient;
rpcClient: PublicClient;

Expand Down Expand Up @@ -80,7 +80,7 @@ export const CliTest = test.extend<CliTestFixture>({
});
},

cometaClient: new CometaService({
cometaClient: new CometaClient({
transport: new HttpTransport({
endpoint: testEnv.cometaServiceEndpoint,
}),
Expand Down
4 changes: 2 additions & 2 deletions docs/nil/guides/cometa-and-debugging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ To use the Cometa service with =nil; developer tools, it is necessary to to set
cometa_endpoint: COMETA_ENDPOINT
```

* For `Nil.js`, the endpoint should be set when creating an instance of `CometaService`:
* For `Nil.js`, the endpoint should be set when creating an instance of `CometaClient`:

```ts showLineNumbers
const service = new CometaService({
const service = new CometaClient({
transport: new HttpTransport({
endpoint: COMETA_ENDPOINT,
}),
Expand Down
2 changes: 1 addition & 1 deletion docs/nil/migration-guides/november-0611-2024-release.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ nil contract top-up CONTRACT_ADDRESS AMOUNT Token_ID

* Use the new Cometa service bindings in `Nil.js` scripts

The `Nil.js` package now contains several 'helper' functions and classes for interacting with the Cometa service. To access the service, simply initialize a new `CometaService` and then call `compileContract()` and `registerContract()`.
The `Nil.js` package now contains several 'helper' functions and classes for interacting with the Cometa service. To access the service, simply initialize a new `CometaClient` and then call `compileContract()` and `registerContract()`.

More information about the `Nil.js` Cometa bindings is given in [**the references section**](../reference/client/index.mdx).

Expand Down
6 changes: 3 additions & 3 deletions docs/nil/niljs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ Here is a non-exhaustive list of 'helper' classes and functions provided by `Nil
| `SmartAccountV1.sendMessage()` | Sends a message to a smart contract via previously deployed smart account. |
| `FaucetClient` | Provides an instance of a client interacting with the faucet service. |
| `FaucetClient.topUpAndWaitUntilCompletion()` | Tops up a smart contract from the specified faucet. |
| `CometaService` | Allows for interacting with the Cometa service. |
| `CometaService.registerContractData()` | Registers a smart contract inside the Cometa service. |
| `CometaClient` | Allows for interacting with the Cometa service. |
| `CometaClient.registerContractData()` | Registers a smart contract inside the Cometa service. |

To see all members exposed by `Nil.js`, proceed to [**the 'References' section**](../reference/client/index.mdx).

:::info

The testnet RPC endpoint provides access to the cluster and all related services including the faucet service and the Cometa service.

When running the cluster, the faucet service and the Cometa service locally, their endpoints will be different. This will require providing different endpoints when creating instances of `PublicClient`, `FaucetClient` and `CometaService`.
When running the cluster, the faucet service and the Cometa service locally, their endpoints will be different. This will require providing different endpoints when creating instances of `PublicClient`, `FaucetClient` and `CometaClient`.

:::

Expand Down
4 changes: 2 additions & 2 deletions docs/tests/cometa-and-debugging.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

//startNilJSImport
import {
CometaService,
CometaClient,
HttpTransport,
PublicClient,
generateSmartAccount,
Expand Down Expand Up @@ -100,7 +100,7 @@ describe.sequential("CLI tutorial flows pass correctly for CounterBug", () => {
describe.skip.sequential("Nil.js correctly interacts with Cometa", () => {
test.sequential("Nil.js passes the Cometa tutorial flow", async () => {
//startNilJSCometaTutorialSnippet
const cometa = new CometaService({
const cometa = new CometaClient({
transport: new HttpTransport({
endpoint: COMETA_ENDPOINT,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { useStyletron } from "baseui";
import { useUnit } from "effector-react";
import { useEffect } from "react";
import { $cometaService } from "../../cometa/model";
import { $cometaClient } from "../../cometa/model";
import { addressRoute } from "../../routing";
import { Divider } from "../../shared";
import { Info } from "../../shared/components/Info";
Expand Down Expand Up @@ -43,14 +43,14 @@ export const AccountInfo = () => {
loadAccountStateFx.pending,
loadAccountCometaInfoFx.pending,
addressRoute.$params,
$cometaService,
$cometaClient,
]);
const [css] = useStyletron();
const sourceCode = accountCometaInfo?.sourceCode?.Compiled_Contracts;

useEffect(() => {
loadAccountStateFx(params.address);
loadAccountCometaInfoFx({ address: params.address, cometaService: cometa });
loadAccountCometaInfoFx({ address: params.address, cometaClient: cometa });
}, [params.address, cometa]);

if (isLoading) return <AccountLoading />;
Expand Down
8 changes: 4 additions & 4 deletions explorer_frontend/src/features/account/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sample } from "effector";
import { combine } from "effector";
import { $cometaService } from "../cometa/model";
import { $cometaClient } from "../cometa/model";
import { addressRoute } from "../routing";
import { $account, $accountCometaInfo, loadAccountCometaInfoFx, loadAccountStateFx } from "./model";

Expand All @@ -13,11 +13,11 @@ sample({

sample({
clock: addressRoute.navigated,
source: combine(addressRoute.$params, $cometaService, (params, cometaService) => ({
source: combine(addressRoute.$params, $cometaClient, (params, cometaClient) => ({
params,
cometaService,
cometaClient,
})),
filter: ({ cometaService }) => cometaService !== null,
filter: ({ cometaClient }) => cometaClient !== null,
fn: (params) => params.address,
target: loadAccountCometaInfoFx,
});
Expand Down
8 changes: 4 additions & 4 deletions explorer_frontend/src/features/account/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type CometaService, type Hex, addHexPrefix } from "@nilfoundation/niljs";
import { type CometaClient, type Hex, addHexPrefix } from "@nilfoundation/niljs";
import { createDomain } from "effector";
import { fetchAccountState } from "../../api/account";
import type { AccountCometaInfo, AccountState } from "./types";
Expand All @@ -15,7 +15,7 @@ export const loadAccountStateFx = createEffect<string, AccountState>();
export const loadAccountCometaInfoFx = createEffect<
{
address: Hex;
cometaService: CometaService;
cometaClient: CometaClient;
},
AccountCometaInfo
>();
Expand All @@ -24,7 +24,7 @@ loadAccountStateFx.use(async (address) => {
return fetchAccountState(address);
});

loadAccountCometaInfoFx.use(async ({ address, cometaService }) => {
const res = await cometaService.getContract(addHexPrefix(address));
loadAccountCometaInfoFx.use(async ({ address, cometaClient }) => {
const res = await cometaClient.getContract(addHexPrefix(address));
return res;
});
10 changes: 5 additions & 5 deletions explorer_frontend/src/features/cometa/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CometaService, HttpTransport } from "@nilfoundation/niljs";
import { CometaClient, HttpTransport } from "@nilfoundation/niljs";
import { combine, sample } from "effector";
import { $rpcUrl } from "../account-connector/model";
import { $cometaApiUrl, $cometaService, createCometaService, createCometaServiceFx } from "./model";
import { $cometaApiUrl, $cometaClient, createCometaService, createCometaServiceFx } from "./model";

const $refinedCometaApiUrl = combine(
$rpcUrl,
Expand All @@ -16,14 +16,14 @@ $refinedCometaApiUrl.watch((url) => {
});

createCometaServiceFx.use(async (endpoint) => {
const cometaService = new CometaService({
const cometaClient = new CometaClient({
transport: new HttpTransport({ endpoint }),
});

return cometaService;
return cometaClient;
});

$cometaService.on(createCometaServiceFx.doneData, (_, cometaService) => cometaService);
$cometaClient.on(createCometaServiceFx.doneData, (_, cometaClient) => cometaClient);

sample({
clock: createCometaService,
Expand Down
6 changes: 3 additions & 3 deletions explorer_frontend/src/features/cometa/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CometaService } from "@nilfoundation/niljs";
import type { CometaClient } from "@nilfoundation/niljs";
import { createDomain } from "effector";
import { getRuntimeConfigOrThrow } from "../runtime-config";

Expand All @@ -9,6 +9,6 @@ export const cometaDomain = createDomain("cometa");
export const $cometaApiUrl = cometaDomain.createStore(
COMETA_SERVICE_API_URL || RPC_API_URL || null,
);
export const $cometaService = cometaDomain.createStore<CometaService | null>(null);
export const $cometaClient = cometaDomain.createStore<CometaClient | null>(null);
export const createCometaService = cometaDomain.createEvent();
export const createCometaServiceFx = cometaDomain.createEffect<string, CometaService>();
export const createCometaServiceFx = cometaDomain.createEffect<string, CometaClient>();
14 changes: 7 additions & 7 deletions explorer_frontend/src/features/contracts/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CometaService, Hex, SmartAccountV1, Token } from "@nilfoundation/niljs";
import type { CometaClient, Hex, SmartAccountV1, Token } from "@nilfoundation/niljs";
import type { Abi, AbiFunction } from "abitype";
import { combine, merge, sample } from "effector";
import { persist } from "effector-storage/local";
Expand All @@ -11,7 +11,7 @@ import {
loadedTutorialPage,
} from "../code/model";
import type { App } from "../code/types";
import { $cometaService } from "../cometa/model";
import { $cometaClient } from "../cometa/model";
import { getTokenAddressBySymbol } from "../tokens";
import {
$activeApp,
Expand Down Expand Up @@ -678,20 +678,20 @@ sample({
target: registerContractInCometaFx,
source: combine({
app: $activeAppWithState,
cometaService: $cometaService,
cometaClient: $cometaClient,
solidityVersion: $solidityVersion,
}),
filter: combine(
$activeAppWithState,
$cometaService,
(app, cometaService) => !!app && !!cometaService,
$cometaClient,
(app, cometaClient) => !!app && !!cometaClient,
),
fn: ({ app, cometaService, solidityVersion }, { address, name }) => {
fn: ({ app, cometaClient, solidityVersion }, { address, name }) => {
return {
app: app as App,
name: name,
address: address as Hex,
cometaService: cometaService as CometaService,
cometaClient: cometaClient as CometaClient,
solidityVersion,
};
},
Expand Down
8 changes: 4 additions & 4 deletions explorer_frontend/src/features/contracts/models/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
type CometaService,
type CometaClient,
type Hex,
HttpTransport,
PublicClient,
Expand Down Expand Up @@ -131,11 +131,11 @@ export const registerContractInCometaFx = createEffect<
name: string;
app: App;
address: Hex;
cometaService: CometaService;
cometaClient: CometaClient;
solidityVersion: string;
},
void
>(async ({ name, app, address, cometaService, solidityVersion }) => {
>(async ({ name, app, address, cometaClient, solidityVersion }) => {
const result = createCompileInput(app.sourcecode);

const refinedSolidityVersion = solidityVersion.match(/\d+\.\d+\.\d+/)?.[0] || "";
Expand All @@ -146,7 +146,7 @@ export const registerContractInCometaFx = createEffect<
compilerVersion: refinedSolidityVersion,
};

await cometaService.registerContract(JSON.stringify(refinedResult), address);
await cometaClient.registerContract(JSON.stringify(refinedResult), address);
});

export const $importedSmartContractAddress = createStore<Hex>("" as Hex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MockTransport } from "../transport/MockTransport.js";
import { CometaService } from "./CometaService.js";
import { CometaClient } from "./CometaClient.js";
import type { ContractData } from "./types/CometaTypes.js";

test("getContract", async ({ expect }) => {
const fn = vi.fn();
fn.mockReturnValue({});
const cometa = new CometaService({
const cometa = new CometaClient({
transport: new MockTransport(fn),
shardId: 1,
});
Expand All @@ -22,7 +22,7 @@ test("getContract", async ({ expect }) => {
test("getLocation", async ({ expect }) => {
const fn = vi.fn();
fn.mockReturnValue({});
const cometa = new CometaService({
const cometa = new CometaClient({
transport: new MockTransport(fn),
shardId: 1,
});
Expand All @@ -39,7 +39,7 @@ test("getLocation", async ({ expect }) => {
test("compileContract", async ({ expect }) => {
const fn = vi.fn();
fn.mockReturnValue({});
const cometa = new CometaService({
const cometa = new CometaClient({
transport: new MockTransport(fn),
shardId: 1,
});
Expand All @@ -56,7 +56,7 @@ test("compileContract", async ({ expect }) => {
test("registerContractData", async ({ expect }) => {
const fn = vi.fn();
fn.mockReturnValue({});
const cometa = new CometaService({
const cometa = new CometaClient({
transport: new MockTransport(fn),
shardId: 1,
});
Expand All @@ -73,7 +73,7 @@ test("registerContractData", async ({ expect }) => {
test("registerContract", async ({ expect }) => {
const fn = vi.fn();
fn.mockReturnValue({});
const cometa = new CometaService({
const cometa = new CometaClient({
transport: new MockTransport(fn),
shardId: 1,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import type { Hex } from "../types/Hex.js";
import { BaseClient } from "./BaseClient.js";
import type { ContractData, Location } from "./types/CometaTypes.js";
import type { CometaServiceConfig } from "./types/Configs.js";
import type { CometaClientConfig } from "./types/Configs.js";

/**
* CometaService is a client that interacts with the Cometa service.
* CometaClient is a client that interacts with the Cometa service.
* Cometa service is used to store contract metadata: source code, ABI, etc.
* @class CometaService
* @class CometaClient
* @extends BaseClient
* @example
* import { CometaService } from '@nilfoundation/niljs';
* import { CometaClient } from '@nilfoundation/niljs';
*
* const service = new CometaService({
* const service = new CometaClient({
* transport: new HttpTransport({
* endpoint: COMETA_ENDPOINT,
* }),
* });
*/
class CometaService extends BaseClient {
class CometaClient extends BaseClient {
// biome-ignore lint/complexity/noUselessConstructor: may be useful in the future
constructor(config: CometaServiceConfig) {
constructor(config: CometaClientConfig) {
super(config);
}

Expand Down Expand Up @@ -85,4 +85,4 @@ class CometaService extends BaseClient {
}
}

export { CometaService };
export { CometaClient };
Loading