Skip to content

Commit

Permalink
feat: added support for ephemeral state (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvalabs-gokul authored Jul 10, 2024
1 parent ba8a176 commit f5053ea
Show file tree
Hide file tree
Showing 136 changed files with 817 additions and 310 deletions.
43 changes: 34 additions & 9 deletions docs/source/logic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,16 @@ Variables
logic manifest. Developers can easily invoke and execute these routines, which
encapsulate specific functionalities and operations provided by the logic.

``ephemeralState`` - The ephemeral state, accessible via this variable,
represents the short-term or temporary state of the logic.

``persistentState`` - The persistent state is accessible via this variable. It
allows developers to retrieve state of the logic, which persists across
different invocations and interactions.
``persistentState`` - The persistent state variable provides access to enduring
state associated with the logic. This state persists across different
invocations and interactions, defining core attributes and long-term data.

It contains the following method:

* ``get``
This method retrieves the value from persistent state using the storage key.
As the storage key hash generation is complex, a builder
object is passed to callback to generate storage key. The builder object has the following methods:
This method retrieves a value from persistent state using the storage key.
A builder object is passed to a callback to generate the storage key. The
builder object offers the following methods:

* ``entity`` - This method used to select the member of the state persistent.
* ``length`` - This method used to access length/size of `Array`, `Varray` and, `Map`.
Expand Down Expand Up @@ -275,6 +272,34 @@ different invocations and interactions.
>> Chocolate
``ephemeralState`` - The ephemeral state variable provides access to transient
state associated directly with a participant. This state reflects the state of
a participant and can change frequently as interactions occur.

It contains the following method:

* ``get``
This method retrieves a value from ephemeral state using the storage key
and participant address.

**Usage**: Similar to persistent state, the get method takes a callback function.
In addition to that, it also requires a participant address. The builder
object within the callback defines how to access the state, similar to
persistent state.

.. code-block:: javascript
// Example
const address = "0x996ab2197faa069202f83d7993f174e7a3635f3278d3745d6a9fe89d75b854df"
const logic = await getLogicDriver(logicId, wallet);
const spendable = await logic.ephemeralState.get(address, (access) =>
access.entity("Spendable")
);
console.log(spendable);
>> 10000
Functions
~~~~~~~~~

Expand Down
7 changes: 7 additions & 0 deletions docs/source/utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ The ``LogicInvokeReceipt`` interface represents a receipt for logic execution. I
* ``outputs`` - ``string``: The outputs of the logic execution.
* ``error`` - ``string``: The error message associated with the execution.

**LogicEnlistReceipt**

The ``LogicEnlistReceipt`` interface represents a receipt for logic enlist. It has the following properties:

* ``outputs`` - ``string``: The outputs of the logic enlist.
* ``error`` - ``string``: The error message associated with the enlist.

**Receipt**

The ``Receipt`` interface represents an interaction receipt. It has the following properties:
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"main": "packages/js-moi/lib.cjs/index.js",
"module": "packages/js-moi/lib.esm/index.js",
"scripts": {
"clean": "find . -type d \\( -name 'lib.cjs' -o -name 'lib.esm' \\) -exec rm -rf {} +",
"clean": "find . -path ./node_modules -prune -o -type d \\( -name 'lib.cjs' -o -name 'lib.esm' \\) -exec rm -rf {} +",
"build": "tsc -b && rm -rf dist",
"build:clean": "npm run clean && npm run build",
"watch": "tsc -b -w",
"test": "jest --env=node --colors --verbose",
"test:coverage": "jest --coverage --env=node --colors --verbose",
"docs": "make -C docs html"
"docs": "make -C docs html",
"prebuild": "npm run clean"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -55,4 +55,4 @@
"websocket": "^1.0.34"
},
"sideEffects": false
}
}
2 changes: 1 addition & 1 deletion packages/js-moi-bip39/lib.cjs/bip39.d.ts.map

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

2 changes: 1 addition & 1 deletion packages/js-moi-bip39/lib.esm/bip39.d.ts.map

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

2 changes: 1 addition & 1 deletion packages/js-moi-logic/lib.cjs/element-descriptor.js

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

2 changes: 1 addition & 1 deletion packages/js-moi-logic/lib.cjs/element-descriptor.js.map

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

10 changes: 8 additions & 2 deletions packages/js-moi-logic/lib.cjs/logic-base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IxType } from "js-moi-utils";
import { LogicIxArguments, LogicIxObject, LogicIxResponse } from "../types/interaction";
import { LogicIxRequest, RoutineOption } from "../types/logic";
import ElementDescriptor from "./element-descriptor";
import { LogicId } from "./logic-id";
/**
* This abstract class extends the ElementDescriptor class and serves as a base
* class for logic-related operations.
Expand All @@ -17,14 +18,19 @@ export declare abstract class LogicBase extends ElementDescriptor {
protected manifestCoder: ManifestCoder;
constructor(manifest: LogicManifest.Manifest, arg: Signer | AbstractProvider);
protected abstract createPayload(ixObject: LogicIxObject): LogicPayload;
protected abstract getIxType(): IxType;
protected abstract processResult(response: LogicIxResponse, timeout?: number): Promise<unknown | null>;
/**
* Returns the logic ID associated with the LogicBase instance.
*
* @returns {string} The logic ID.
*/
protected getLogicId(): string;
protected getLogicId(): LogicId;
/**
* Returns the interaction type based on the routine kind.
*
* @returns {IxType} The interaction type.
*/
protected getIxType(kind: string): IxType;
/**
* Updates the signer and provider instances for the LogicBase instance.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/js-moi-logic/lib.cjs/logic-base.d.ts.map

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

Loading

0 comments on commit f5053ea

Please sign in to comment.