Skip to content

[Proposal] Smartweave plugins #100

@andreespirela

Description

@andreespirela

Hey there, this is Andres from Verto.exchange.

Overview:
Plugins are a way to introduced custom Javascript functions to the execution of smart weave contracts.

Details:
Plugins should be passed in a static call to a setter, for example:

import { setPlugins } from "smartweave";

setPlugins({
   helloWorld: () => console.log("hello world");
});

Or they can be passed in the readContract function.

export declare function readContract(arweave: Arweave, contractId: string, height?: number, returnValidity?: boolean, plugins?: any): Promise<any>
import { readContract } from "smartweave";

readContract(arweaveClient,
            contractId,
            undefined,
            true,
            {
                helloWorld: () => console.log("hello world");
            }
);

Accessing plugins
In order to access the plugins inside the contract, we can do:

SmartWeave.plugins[plugin_name]();

where SmartWeave is the global that all contract has, with a new object, which is call plugins, and contains the functions we passed in our object

SmartWeave.plugins['helloWorld']();

Security Flaws
A contract can override, or modify the plugins object. For this reason, this object should be frozen, and all its properties should also be frozen. A deep Object.freeze if you may.

@t8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions