Skip to content

Commit

Permalink
add solc/download and do not include the soljson file in source
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Sep 26, 2021
1 parent edacc52 commit 3e4eaae
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.solc-cache
soljson.js
1 change: 1 addition & 0 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { createRequire } from 'https://deno.land/[email protected]/node/module.ts'
export { existsSync } from 'https://deno.land/[email protected]/node/fs.ts'
export { default as semver } from 'https://esm.sh/semver?no-check'
export { keccak256 } from 'https://esm.sh/js-sha3'
export { readerFromStreamReader, copy } from 'https://deno.land/[email protected]/io/mod.ts'
23 changes: 23 additions & 0 deletions download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { readerFromStreamReader, copy } from './deps.ts'

export const download = async (version?: string) => {
console.log(`Fetching releases...`)
const { releases, latestRelease } = await fetch('https://solc-bin.ethereum.org/bin/list.json').then((res) =>
res.json()
)

const jsFile = releases[version || latestRelease]

console.log(`Downloading soljson from https://solc-bin.ethereum.org/bin/${jsFile}...`)

const res = await fetch(`https://solc-bin.ethereum.org/bin/${jsFile}`)

const rdr = res.body?.getReader()

if (rdr) {
const r = readerFromStreamReader(rdr)
const f = await Deno.open('./soljson.js', { create: true, write: true })
await copy(r, f)
f.close()
}
}
6 changes: 5 additions & 1 deletion egg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"releaseType": null,
"unstable": false,
"unlisted": false,
"files": ["README.md", "*.ts", "LICENSE"],
"files": [
"README.md",
"*.ts",
"LICENSE"
],
"ignore": [],
"checkFormat": false,
"checkTests": false,
Expand Down
24 changes: 22 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import { setupMethods } from './wrapper.ts'
import { soljson } from './module.ts'
import { createRequire } from './deps.ts'
import { download } from './download.ts'
import process from 'https://esm.sh/process/browser.js'
import { exists } from './utils.ts'

export const solc = setupMethods(soljson)
const require = createRequire(import.meta.url)

const __filename = new URL('', import.meta.url).pathname
const __dirname = new URL('.', import.meta.url).pathname

// @ts-ignore Node.js
globalThis.__dirname = __dirname
// @ts-ignore Node.js
globalThis.__filename = __filename

process.versions = { node: '12.4.0' }

// @ts-ignore Node.js
globalThis.process = process

if (!(await exists('./soljson.js'))) await download()

export const solc = setupMethods(require('./soljson.js'))
19 changes: 0 additions & 19 deletions module.ts

This file was deleted.

1 change: 0 additions & 1 deletion soljson-v0.8.7+commit.e28d00a7.min.js

This file was deleted.

8 changes: 2 additions & 6 deletions translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ function translateErrors(
}

function translateGasEstimates(gasEstimates: null | number | Record<string, any>) {
if (gasEstimates === null) {
return 'infinite'
}
if (gasEstimates === null) return 'infinite'

if (typeof gasEstimates === 'number') {
return gasEstimates.toString()
}
if (typeof gasEstimates === 'number') return gasEstimates.toString()

const gasEstimatesTranslated: Record<string, any> = {}
for (const func in gasEstimates) {
Expand Down
18 changes: 16 additions & 2 deletions utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import * as _assert from 'https://deno.land/x/[email protected]/node/assert.ts'

export const assert = (actual: unknown, message: string) => {
return _assert.strict(actual, message)
export const assert = (actual: unknown, message: string) => _assert.strict(actual, message)

export const exists = async (filename: string): Promise<boolean> => {
try {
await Deno.stat(filename)
// successful, file or directory must exist
return true
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
// file or directory does not exist
return false
} else {
// unexpected error, maybe permissions, pass it along
throw error
}
}
}

0 comments on commit 3e4eaae

Please sign in to comment.