Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Smartweave plugins #100

Open
andreespirela opened this issue Nov 1, 2021 · 0 comments
Open

[Proposal] Smartweave plugins #100

andreespirela opened this issue Nov 1, 2021 · 0 comments

Comments

@andreespirela
Copy link

andreespirela commented Nov 1, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant