Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions client/Build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as path from "node:path";
import process from "node:process";
import { URL, fileURLToPath, pathToFileURL } from "node:url";
import solc from "solc";
import pkg from 'esbuild-plugins-node-modules-polyfill'
const { nodeModulesPolyfillPlugin } = pkg

const options = {
plugins: [typecheckPlugin()],
Expand All @@ -13,8 +15,7 @@ const options = {

entryPoints: ["src/index.ts", "src/worker_chain.ts", "src/index.html"],

inject: ["src/shim-process.js"],

inject: ["src/shim-process.js", "src/shim-buffer.js"],
loader: { ".html": "copy" },

bundle: true,
Expand All @@ -23,8 +24,10 @@ const options = {
target: "es2020",
format: "esm",
platform: "browser",
minify: false,
minify: true,
sourcemap: true,
plugins: [nodeModulesPolyfillPlugin()],
keepNames: true
};

async function buildSolidity() {
Expand Down
1 change: 1 addition & 0 deletions client/src/shim-buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Buffer } from "buffer";
33 changes: 22 additions & 11 deletions client/src/worker_chain.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
import Ganache, { EthereumProvider } from "ganache";
import { Provider } from "@remix-project/remix-simulator";

function onConfigure(evt: MessageEvent): void {
removeEventListener("message", onConfigure);

// Without doing runtime type checking, it's impossible to ensure the
// message data conforms to the options type from ganache.
// message data conforms to the options type from provider.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const ganache = Ganache.provider(evt.data);
addEventListener("message", (evt) => onMessage(ganache, evt));
const provider = new Provider(evt.data);
provider.init()
addEventListener("message", (evt) => onMessage(provider, evt));
}

function onMessage(ganache: EthereumProvider, evt: MessageEvent): void {
function onMessage(provider: Provider, evt: MessageEvent): void {
const reply = evt.ports[0];
ganache
// Without doing runtime type checking, it's impossible to ensure the
// message data conforms to the JSON RPC spec.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
.request(evt.data)
let promise
if (provider.initializing) {
promise = new Promise<void>((res) => setTimeout(() => { res() }, 5000));
} else {
promise = new Promise<void>((res) => res());
}
promise
.then(() =>
provider
// Without doing runtime type checking, it's impossible to ensure the
// message data conforms to the JSON RPC spec.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
.request(evt.data),
)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
.then((result) => reply.postMessage({ result }))
.catch((error) => {
console.error("Uncaught (in ganache worker thread)", error);
console.error("Uncaught (in provider worker thread)", error);
reply.postMessage({
error: {
message: String(error),
Expand Down
Loading