feat: ethers plugin (#278)
* chore: arweave upgrade * fix: add Buffer for browser env * feat: ethers extension plugin * fix: remove trash * fix: normalize-source test
This commit is contained in:
16
bundle.js
16
bundle.js
@@ -1,6 +1,8 @@
|
||||
const { build } = require('esbuild');
|
||||
const rimraf = require('rimraf');
|
||||
const fs = require("fs");
|
||||
const fs = require('fs');
|
||||
const plugin = require('node-stdlib-browser/helpers/esbuild/plugin');
|
||||
const stdLibBrowser = require('node-stdlib-browser');
|
||||
|
||||
const clean = async () => {
|
||||
return new Promise((resolve) => {
|
||||
@@ -17,14 +19,22 @@ const runBuild = async () => {
|
||||
platform: 'browser',
|
||||
target: ['esnext'],
|
||||
format: 'esm',
|
||||
globalName: 'warp'
|
||||
globalName: 'warp',
|
||||
inject: [require.resolve('node-stdlib-browser/helpers/esbuild/shim')],
|
||||
define: {
|
||||
global: 'global',
|
||||
process: 'process',
|
||||
Buffer: 'Buffer',
|
||||
crypto: 'crypto'
|
||||
},
|
||||
plugins: [plugin(stdLibBrowser)]
|
||||
};
|
||||
|
||||
console.log('Building web bundle esm.');
|
||||
const result = await build({
|
||||
...buildConfig,
|
||||
minify: true,
|
||||
outfile: './bundles/web.bundle.min.js',
|
||||
outfile: './bundles/web.bundle.min.js'
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
"@assemblyscript/loader": "^0.19.23",
|
||||
"@idena/vrf-js": "^1.0.1",
|
||||
"archiver": "^5.3.0",
|
||||
"arweave": "1.11.6",
|
||||
"arweave": "1.11.7",
|
||||
"elliptic": "^6.5.4",
|
||||
"events": "3.3.0",
|
||||
"fast-copy": "^3.0.0",
|
||||
@@ -84,7 +84,6 @@
|
||||
"@typescript-eslint/parser": "^5.30.7",
|
||||
"arlocal": "1.1.42",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"cli-table": "0.3.11",
|
||||
"colors": "^1.4.0",
|
||||
"esbuild": "0.15.12",
|
||||
"eslint": "^7.32.0",
|
||||
@@ -92,16 +91,13 @@
|
||||
"eslint-plugin-prettier": "^3.4.1",
|
||||
"gen-esm-wrapper": "^1.1.3",
|
||||
"jest": "^28.1.3",
|
||||
"node-nlp": "^4.24.0",
|
||||
"node-stdlib-browser": "1.2.0",
|
||||
"prettier": "^2.3.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"simple-statistics": "^7.7.0",
|
||||
"smartweave": "0.4.48",
|
||||
"ts-jest": "^28.0.7",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.7.4",
|
||||
"warp-contracts-pubsub": "1.0.3",
|
||||
"warp-contracts-subscription-plugin": "1.0.2",
|
||||
"ws": "^8.11.0"
|
||||
},
|
||||
"browser": {
|
||||
|
||||
@@ -25,7 +25,7 @@ describe('normalizeContractSource function', () => {
|
||||
expect(normalizeContractSource(exampleSrcIIFEArrow, false)).toEqual(
|
||||
'\n' +
|
||||
' const window=void 0,document=void 0,Function=void 0,eval=void 0;\n' +
|
||||
' const [SmartWeave, BigNumber, logger] = arguments;\n' +
|
||||
' const [SmartWeave, BigNumber, logger, Buffer] = arguments;\n' +
|
||||
" class ContractError extends Error { constructor(message) { super(message); this.name = 'ContractError' } };\n" +
|
||||
' function ContractAssert(cond, message) { if (!cond) throw new ContractError(message) };\n' +
|
||||
' function handle(state, action) {\n' +
|
||||
@@ -37,7 +37,7 @@ describe('normalizeContractSource function', () => {
|
||||
expect(normalizeContractSource(exampleSrcIIFEArrowWeirdFormatting, false)).toEqual(
|
||||
'\n' +
|
||||
' const window=void 0,document=void 0,Function=void 0,eval=void 0;\n' +
|
||||
' const [SmartWeave, BigNumber, logger] = arguments;\n' +
|
||||
' const [SmartWeave, BigNumber, logger, Buffer] = arguments;\n' +
|
||||
" class ContractError extends Error { constructor(message) { super(message); this.name = 'ContractError' } };\n" +
|
||||
' function ContractAssert(cond, message) { if (!cond) throw new ContractError(message) };\n' +
|
||||
' function handle(state, action) {\n' +
|
||||
@@ -51,7 +51,7 @@ describe('normalizeContractSource function', () => {
|
||||
expect(normalizeContractSource(exampleSrcIIFE, false)).toEqual(
|
||||
'\n' +
|
||||
' const window=void 0,document=void 0,Function=void 0,eval=void 0;\n' +
|
||||
' const [SmartWeave, BigNumber, logger] = arguments;\n' +
|
||||
' const [SmartWeave, BigNumber, logger, Buffer] = arguments;\n' +
|
||||
" class ContractError extends Error { constructor(message) { super(message); this.name = 'ContractError' } };\n" +
|
||||
' function ContractAssert(cond, message) { if (!cond) throw new ContractError(message) };\n' +
|
||||
' function handle(state, action) {\n' +
|
||||
@@ -63,7 +63,7 @@ describe('normalizeContractSource function', () => {
|
||||
expect(normalizeContractSource(exampleSrcIIFEWeirdFormatting, false)).toEqual(
|
||||
'\n' +
|
||||
' const window=void 0,document=void 0,Function=void 0,eval=void 0;\n' +
|
||||
' const [SmartWeave, BigNumber, logger] = arguments;\n' +
|
||||
' const [SmartWeave, BigNumber, logger, Buffer] = arguments;\n' +
|
||||
" class ContractError extends Error { constructor(message) { super(message); this.name = 'ContractError' } };\n" +
|
||||
' function ContractAssert(cond, message) { if (!cond) throw new ContractError(message) };\n' +
|
||||
' function handle(state, action) {\n' +
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export const knownWarpPlugins = [
|
||||
'evm-signature-verification',
|
||||
'smartweave-extension',
|
||||
'smartweave-nlp-extension',
|
||||
'smartweave-ethers-extension',
|
||||
'subscription',
|
||||
'ivm-handler-api',
|
||||
'evaluation-progress'
|
||||
|
||||
@@ -205,7 +205,7 @@ export class HandlerExecutorFactory implements ExecutorFactory<HandlerApi<unknow
|
||||
});
|
||||
} else {
|
||||
const contractFunction = new Function(normalizedSource);
|
||||
const handler = contractFunction(swGlobal, BigNumber, LoggerFactory.INST.create(swGlobal.contract.id));
|
||||
const handler = contractFunction(swGlobal, BigNumber, LoggerFactory.INST.create(swGlobal.contract.id), Buffer);
|
||||
return new JsHandlerApi(swGlobal, contractDefinition, handler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,14 @@ export class JsHandlerApi<State> extends AbstractContractHandler<State> {
|
||||
this.assignRefreshState(executionContext);
|
||||
|
||||
const { warp } = executionContext;
|
||||
if (warp.hasPlugin('smartweave-extension')) {
|
||||
const extension = warp.loadPlugin<any, void>('smartweave-extension');
|
||||
extension.process(this.swGlobal.extensions);
|
||||
}
|
||||
|
||||
const extensionPlugins = ['smartweave-nlp-extension', 'smartweave-ethers-extension'] as const;
|
||||
extensionPlugins.forEach((ex) => {
|
||||
if (warp.hasPlugin(ex)) {
|
||||
const extension = warp.loadPlugin<any, void>(ex);
|
||||
extension.process(this.swGlobal.extensions);
|
||||
}
|
||||
});
|
||||
|
||||
const handlerResult = await Promise.race([timeoutPromise, this.contractFunction(stateCopy, interaction)]);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export function normalizeContractSource(contractSrc: string, useVM2: boolean): s
|
||||
} else {
|
||||
return `
|
||||
const window=void 0,document=void 0,Function=void 0,eval=void 0;
|
||||
const [SmartWeave, BigNumber, logger] = arguments;
|
||||
const [SmartWeave, BigNumber, logger, Buffer] = arguments;
|
||||
class ContractError extends Error { constructor(message) { super(message); this.name = 'ContractError' } };
|
||||
function ContractAssert(cond, message) { if (!cond) throw new ContractError(message) };
|
||||
${contractSrc};
|
||||
|
||||
@@ -3,7 +3,6 @@ import {defaultCacheOptions, LoggerFactory, Warp, WarpFactory} from '../src';
|
||||
import os from 'os';
|
||||
import {JWKInterface} from "arweave/web/lib/wallet";
|
||||
import fs from "fs";
|
||||
import {StateUpdatePlugin} from "warp-contracts-subscription-plugin";
|
||||
|
||||
const logger = LoggerFactory.INST.create('Contract');
|
||||
|
||||
|
||||
@@ -4,9 +4,6 @@ import {defaultCacheOptions, defaultWarpGwOptions, LoggerFactory, WarpFactory} f
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {JWKInterface} from 'arweave/node/lib/wallet';
|
||||
import {WarpPlugin, WarpPluginType} from "../src/core/WarpPlugin";
|
||||
|
||||
const { NlpManager } = require('node-nlp');
|
||||
|
||||
async function main() {
|
||||
let wallet: JWKInterface = readJSON('./.secrets/33F0QHcb22W7LwWR1iRC8Az1ntZG09XQ03YWuw2ABqA.json');;
|
||||
@@ -19,17 +16,6 @@ async function main() {
|
||||
protocol: 'https'
|
||||
});
|
||||
|
||||
class NlpExtension implements WarpPlugin<any, void> {
|
||||
process(input: any): void {
|
||||
input.NlpManager = NlpManager;
|
||||
}
|
||||
|
||||
type(): WarpPluginType {
|
||||
return 'smartweave-extension';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
const warp = WarpFactory
|
||||
.forMainnet({...defaultCacheOptions, inMemory: true});
|
||||
|
||||
Reference in New Issue
Block a user