Skip to content

Commit

Permalink
Update the wrapper to utilise /resolc endpoint (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
smiasojed authored Oct 4, 2024
1 parent c5fc4c3 commit 778aa8d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:22-bookworm-slim

ENV SOLC_VERSION="0.8.26"
ENV RESOLC_VERSION="0.0.1"
ENV RESOLC_VERSION="0.1.0-dev"

# Install dependencies
RUN apt-get update && apt-get install -y \
Expand All @@ -15,7 +15,7 @@ RUN wget --progress=dot:mega https://github.com/ethereum/solidity/releases/downl
-O /usr/local/bin/solc && chmod +x /usr/local/bin/solc

# Download and install re-solc
RUN wget --progress=dot:mega https://github.com/smiasojed/revive/releases/download/${RESOLC_VERSION}/resolc \
RUN wget --progress=dot:mega https://github.com/paritytech/revive/releases/download/v${RESOLC_VERSION}/resolc \
-O /usr/local/bin/resolc && chmod +x /usr/local/bin/resolc

RUN chown node:node /usr/local/bin/resolc /usr/local/bin/solc
Expand Down
2 changes: 1 addition & 1 deletion controllers/metricsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getMetrics = async (req, res) => {
} catch (ex) {
log('error', 'Failed to get metrics', {
method: req.method,
endpoint: req.path,
endpoint: req.originalUrl,
error: ex.message,
});
res.status(500).end(ex.message);
Expand Down
2 changes: 1 addition & 1 deletion controllers/taskController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const processTask = (binName) => (req, res) => {
const end = httpRequestDuration.startTimer();
log('info', 'Received request', {
method: req.method,
endpoint: req.path,
endpoint: req.originalUrl,
command: req.body.cmd || 'unknown',
});

Expand Down
20 changes: 10 additions & 10 deletions middleware/reposnseHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ function getErrorMessage(statusCode) {
function handleError(request, response, end, status, error = null) {
httpRequestCount.inc({
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
status,
});
httpRequestErrors.inc({
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
status,
});

log('error', 'Request processing failed', {
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
command: request.body.cmd || 'unknown',
status,
error: error || getErrorMessage(status),
Expand All @@ -39,25 +39,25 @@ function handleError(request, response, end, status, error = null) {
// Log the sending failure
log('error', 'Failed to send error response', {
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
status,
error: sendError.message,
});
} finally {
end({ method: request.method, endpoint: request.path, status });
end({ method: request.method, endpoint: request.originalUrl, status });
}
}

function handleResult(request, response, end, result) {
const status = 200;
httpRequestCount.inc({
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
status,
});
log('info', 'Request processed successfully', {
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
command: request.body.cmd,
status,
});
Expand All @@ -68,17 +68,17 @@ function handleResult(request, response, end, result) {
// Log the sending failure
log('error', 'Failed to send error response', {
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
status,
error: sendError.message,
});
httpRequestErrors.inc({
method: request.method,
endpoint: request.path,
endpoint: request.originalUrl,
status,
});
} finally {
end({ method: request.method, endpoint: request.path, status });
end({ method: request.method, endpoint: request.originalUrl, status });
}
}

Expand Down
18 changes: 10 additions & 8 deletions public/soljson.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! This is the compiler worker executed byt Remix IDE
//! It proxies requests to the solc proxy server
let missingSources = [];
let compilerBackend = 'http://localhost:3000/resolc';
// Staging backend
// let compilerBackend='https://remix-backend.parity-stg.parity.io/solc'
let compilerBackend = 'http://localhost:3000';

// synchronous fetch
function proxySync(cmd, input) {
function proxySync(path, cmd, input) {
const request = new XMLHttpRequest();
request.open('POST', compilerBackend, false);
request.open('POST', compilerBackend + path, false);
request.setRequestHeader('Content-Type', 'application/json');
request.send(JSON.stringify({ cmd, input }));
if (request.status === 200) {
Expand All @@ -19,8 +21,8 @@ function proxySync(cmd, input) {
}

// asynchronous fetch
async function proxyAsync(cmd, input) {
const resp = await fetch(compilerBackend, {
async function proxyAsync(path, cmd, input) {
const resp = await fetch(compilerBackend + path, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -40,7 +42,7 @@ self.onmessage = async function (e) {
console.log('soljson.js received message', e.data);
try {
if (e.data.cmd === 'compile') {
let result = await proxyAsync('--standard-json', e.data.input);
let result = await proxyAsync('/resolc', '--standard-json', e.data.input);
let data = JSON.parse(result);
if (data.errors) {
data.errors.forEach((err) => {
Expand Down Expand Up @@ -113,12 +115,12 @@ function cwrap(methodName) {
}

function _solidity_license() {
const stdout = proxySync('--license', '');
const stdout = proxySync('/resolc', '--license');
return stdout;
}

function _solidity_version() {
const stdout = proxySync('--version', '');
const stdout = proxySync('/solc', '--version');
const versionMatch = stdout.match(/[v\s]([\d.]+)/);
return versionMatch[1];
}
Expand Down

0 comments on commit 778aa8d

Please sign in to comment.