Skip to content

Commit

Permalink
chore: various cleanups and docs adaptations
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Jan 14, 2025
1 parent 5310f26 commit 599cf86
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 136 deletions.
113 changes: 1 addition & 112 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ This creates a CSV file with the EVM network params in your data directory.
cargo run --bin antctl -- local run --build --clean --rewards-address <YOUR_ETHEREUM_ADDRESS>
```

The EVM Network parameters are loaded from the CSV file in your data directory automatically when the `local` option is passed to the `antctl` command.
The EVM Network parameters are loaded from the CSV file in your data directory automatically when the `local` mode is enabled.

##### 4. Verify node status

Expand Down Expand Up @@ -142,117 +142,6 @@ Now to download the files again:
cargo run --bin ant -- --local file download <addr> <dest_path>
```

### Registers

Registers are one of the network's data types. The workspace here has an example app demonstrating
their use by two users to exchange text messages in a crude chat application.

In the first terminal, using the registers example, Alice creates a register:

```
cargo run --example registers -- --local --user alice --reg-nickname myregister
```

Alice can now write a message to the register and see anything written by anyone else. For example
she might enter the text "Hello, who's there?" which is written to the register and then shown as
the "Latest value", in her terminal:

```
Register address: "50f4c9d55aa1f4fc19149a86e023cd189e509519788b4ad8625a1ce62932d1938cf4242e029cada768e7af0123a98c25973804d84ad397ca65cb89d6580d04ff07e5b196ea86f882b925be6ade06fc8d"
Register owned by: PublicKey(0cf4..08a5)
Register permissions: Permissions { anyone_can_write: true, writers: {PublicKey(0cf4..08a5)} }
Current total number of items in Register: 0
Latest value (more than one if concurrent writes were made):
--------------
--------------
Enter a blank line to receive updates, or some text to be written.
Hello, who's there?
Writing msg (offline) to Register: 'Hello, who's there?'
Syncing with SAFE in 2s...
synced!
Current total number of items in Register: 1
Latest value (more than one if concurrent writes were made):
--------------
[Alice]: Hello, who's there?
--------------
Enter a blank line to receive updates, or some text to be written.
```

For anyone else to write to the same register they need to know its xor address, so to communicate
with her friend Bob, Alice needs to find a way to send it to Bob. In her terminal, this is the
value starting "50f4..." in the output above. This value will be different each time you run the
example to create a register.

Having received the xor address, in another terminal Bob can access the same register to see the
message Alice has written, and he can write back by running this command with the address received
from Alice. (Note that the command should all be on one line):

```
cargo run --example registers -- --local --user bob --reg-address 50f4c9d55aa1f4fc19149a86e023cd189e509519788b4ad8625a1ce62932d1938cf4242e029cada768e7af0123a98c25973804d84ad397ca65cb89d6580d04ff07e5b196ea86f882b925be6ade06fc8d
```

After retrieving the register and displaying the message from Alice, Bob can reply and at any time,
Alice or Bob can send another message and see any new messages which have been written, or enter a
blank line to poll for updates.

Here's Bob writing from his terminal:

```
Latest value (more than one if concurrent writes were made):
--------------
[Alice]: Hello, who's there?
--------------
Enter a blank line to receive updates, or some text to be written.
hi Alice, this is Bob!
```

Alice will see Bob's message when she either enters a blank line or writes another message herself.

### Inspect a Register

A second example, `register_inspect` allows you to view its structure and content. To use this with
the above example you again provide the address of the register. For example:

```
cargo run --example register_inspect -- --local --reg-address 50f4c9d55aa1f4fc19149a86e023cd189e509519788b4ad8625a1ce62932d1938cf4242e029cada768e7af0123a98c25973804d84ad397ca65cb89d6580d04ff07e5b196ea86f882b925be6ade06fc8d
```

After printing a summary of the register, this example will display
the structure of the register each time you press Enter, including the following:

```
Enter a blank line to print the latest register structure (or 'Q' <Enter> to quit)
Syncing with SAFE...
synced!
======================
Root (Latest) Node(s):
[ 0] Node("4eadd9"..) Entry("[alice]: this is alice 3")
[ 3] Node("f05112"..) Entry("[bob]: this is bob 3")
======================
Register Structure:
(In general, earlier nodes are more indented)
[ 0] Node("4eadd9"..) Entry("[alice]: this is alice 3")
[ 1] Node("f5afb2"..) Entry("[alice]: this is alice 2")
[ 2] Node("7693eb"..) Entry("[alice]: hello this is alice")
[ 3] Node("f05112"..) Entry("[bob]: this is bob 3")
[ 4] Node("8c3cce"..) Entry("[bob]: this is bob 2")
[ 5] Node("c7f9fc"..) Entry("[bob]: this is bob 1")
[ 1] Node("f5afb2"..) Entry("[alice]: this is alice 2")
[ 2] Node("7693eb"..) Entry("[alice]: hello this is alice")
======================
```

Each increase in indentation shows the children of the node above.
The numbers in square brackets are just to make it easier to see
where a node occurs more than once.

### RPC

The node manager launches each node process with a remote procedure call (RPC) service. The
Expand Down
9 changes: 9 additions & 0 deletions autonomi/nodejs/dist/graphEntry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { GraphEntryOptions, PaymentOption } from './types';
export declare class GraphEntry {
private nativeList;
private constructor();
static create(address: string): Promise<GraphEntry>;
get(): Promise<any[]>;
put(options: GraphEntryOptions, payment: PaymentOption): Promise<void>;
getCost(key: string): Promise<string>;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GarphEntry = void 0;
class GarphEntry {
exports.GraphEntry = void 0;
class GraphEntry {
constructor(nativeList) {
this.nativeList = nativeList;
}
Expand All @@ -22,4 +22,4 @@ class GarphEntry {
throw new Error('Not implemented');
}
}
exports.GarphEntry = GarphEntry;
exports.GraphEntry = GraphEntry;
9 changes: 0 additions & 9 deletions autonomi/nodejs/dist/linkedList.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ dataGetPublic(address: string): Promise<Buffer>
#### Graph Operations

```typescript
GarphEntryGet(address: string): Promise<any[]>
GarphEntryPut(options: GarphEntryOptions, payment: PaymentOption): Promise<void>
GarphEntryCost(key: string): Promise<string>
GraphEntryGet(address: string): Promise<any[]>
GraphEntryPut(options: GraphEntryOptions, payment: PaymentOption): Promise<void>
GraphEntryCost(key: string): Promise<string>
```

#### Pointer Operations
Expand Down
4 changes: 2 additions & 2 deletions nodejs/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkConfig, PaymentOption, GarphEntryOptions, PointerOptions, VaultOptions, UserData } from './types';
import { NetworkConfig, PaymentOption, GraphEntryOptions, PointerOptions, VaultOptions, UserData } from './types';

export class Client {
private nativeClient: any; // Will be replaced with actual native binding type
Expand Down Expand Up @@ -29,7 +29,7 @@ export class Client {
throw new Error('Not implemented');
}

async graphEntryPut(options: GarphEntryOptions, payment: PaymentOption): Promise<void> {
async graphEntryPut(options: GraphEntryOptions, payment: PaymentOption): Promise<void> {
// TODO: Implement native binding call
throw new Error('Not implemented');
}
Expand Down
2 changes: 1 addition & 1 deletion nodejs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './client';
export * from './types';
export * from './wallet';
export * from './GarphEntry';
export * from './GraphEntry';
export * from './pointer';
export * from './vault';
2 changes: 1 addition & 1 deletion nodejs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface PaymentOption {
wallet: string;
}

export interface GarphEntryOptions {
export interface GraphEntryOptions {
owner: PublicKey;
counter: number;
target: string;
Expand Down
10 changes: 5 additions & 5 deletions nodejs/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ describe('Client', () => {
});
});

describe('GarphEntryOperations', () => {
it('should throw not implemented error for GarphEntryGet', async () => {
describe('GraphEntryOperations', () => {
it('should throw not implemented error for GraphEntryGet', async () => {
const client = await Client.connect({ peers: [] }).catch(() => null);
if (!client) return;
await expect(client.GarphEntryGet('address')).rejects.toThrow('Not implemented');
await expect(client.GraphEntryGet('address')).rejects.toThrow('Not implemented');
});

it('should throw not implemented error for GarphEntryPut', async () => {
it('should throw not implemented error for GraphEntryPut', async () => {
const client = await Client.connect({ peers: [] }).catch(() => null);
if (!client) return;
await expect(
client.GarphEntryPut(
client.GraphEntryPut(
{
owner: 'owner',
counter: 0,
Expand Down

0 comments on commit 599cf86

Please sign in to comment.