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
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:
Or they can be passed in the
readContractfunction.Accessing plugins
In order to access the plugins inside the contract, we can do:
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 objectSecurity Flaws
A contract can override, or modify the
pluginsobject. For this reason, this object should be frozen, and all its properties should also be frozen. A deepObject.freezeif you may.@t8