Skip to content

Commit

Permalink
little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Jan 23, 2022
1 parent c5368f0 commit d783201
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
9 changes: 9 additions & 0 deletions Deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://deno.land/x/[email protected]/cli/schemas/config-file.v1.json",
"lint": {
"files": {
"include": ["./**/*.ts"],
"exclude": ["soljson.js"]
}
}
}
4 changes: 1 addition & 3 deletions example/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const input: Input = {
}
}

const compile = () => JSON.parse(solc.compile(JSON.stringify(input)))

const result = compile() as Output
const result: Output = JSON.parse(solc.compile(JSON.stringify(input)))

console.log(result.contracts['MyToken.sol'].MyToken.evm.bytecode)
53 changes: 34 additions & 19 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export type Input = {
language: 'Solidity' | 'Yul'
sources: Record<string, { content: string }>
settings: Partial<{
optimizer: {
enabled?: boolean
}
optimizer: Partial<{
enabled: boolean
runs: number
}>

outputSelection: Record<string, Record<string, string[]>>
libraries: Record<string, any>
}>
Expand All @@ -33,12 +35,12 @@ export type Contract = {
interface: string
metadata: string
assembly: string
bytecode: any
bytecode: string
opcodes: string
srcmap: any
runtimeBytecode: any
srcmapRuntime: any
functionHashes: any
runtimeBytecode: string
srcmapRuntime: string
functionHashes: Record<string, string>
}

export type CompilationError = {
Expand All @@ -52,26 +54,33 @@ export type CompilationError = {
}

export type ABI = {
inputs?: any[]
inputs: {
internalType: string
name: string
type: string
}[]

name?: string
outputs?: any[]
outputs?: { internalType: string; name: string; type: string }[]
stateMutability: string
type: string
payable?: boolean
constant?: boolean
}

type Statement = {
body: { nodeType: string; src: string; statements: Statement[] }
name: string
nodeType: string
parameters: { name: string; nodeType: string; src: string; type: string }[]
src: string
}

export type YulAST = {
nodeType: string
src: string
name?: string
statements: {
body: { nodeType: string; src: string; statements: any[] }
name: string
nodeType: string
parameters: { name: string; nodeType: string; src: string; type: string }[]
src: string
}[]
statements: Statement[]
}

export type GeneratedSources = {
Expand All @@ -92,7 +101,7 @@ export type ContractEVM = {
bytecode: {
functionDebugData: FunctionDebugData
generatedSources: GeneratedSources
linkReferences: any
linkReferences: Record<string, unknown>
object: string
opcodes: string
sourceMap: string
Expand All @@ -101,12 +110,18 @@ export type ContractEVM = {
functionDebugData: FunctionDebugData
generatedSources: GeneratedSources
immutableReferences: Record<string, { length: number; start: number }[]>
linkReferences: any
linkReferences: Record<string, unknown>
}
gasEstimates: GasEstimates
legacyAssembly: {
'.code': LegacyAssemblyCode[]
'.data': Record<string, any>
'.data': Record<
string,
{
'.auxdata': string
'.code': LegacyAssemblyCode[]
}
>
}
methodIdentifiers: Record<string, string>
}
Expand Down
17 changes: 7 additions & 10 deletions wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FunctionResult, Input } from './types.ts'

export const setupMethods = (soljson: {
cwrap: (arg0?: unknown, arg1?: unknown, arg2?: unknown[]) => (arg0?: unknown, arg1?: unknown) => any
_malloc: (arg0?: unknown, arg1?: unknown) => any
_malloc: (arg0?: unknown, arg1?: unknown) => unknown
lengthBytesUTF8: (arg0: string) => number
stringToUTF8: (arg0: string, arg1: unknown, arg2: number) => void
setValue: (arg0: unknown, arg1: unknown, arg2: string) => void
Expand Down Expand Up @@ -57,7 +57,7 @@ export const setupMethods = (soljson: {

const wrapCallbackWithKind = (callback: { (kind: 'source' | 'smt-query', data: unknown): FunctionResult }) => {
assert(typeof callback === 'function', 'Invalid callback specified.')
return (context: number, kind: unknown, data: unknown, contents: string, error: string) => {
return (context: number, kind: unknown, data: string, contents: string, error: string) => {
// Must be a null pointer.
assert(context === 0, 'Callback context must be null.')
const result = callback(copyFromCString(kind), copyFromCString(data))
Expand All @@ -68,7 +68,7 @@ export const setupMethods = (soljson: {

// This calls compile() with args || cb
const runWithCallbacks = (
callbacks: Record<string, (...args: unknown[]) => any>,
callbacks: Record<string, (arg: unknown) => any>,
compile: (...args: unknown[]) => any,
args: unknown[]
) => {
Expand Down Expand Up @@ -110,21 +110,20 @@ export const setupMethods = (soljson: {
return output
}

let compileJSON: ((arg0: unknown, arg1: unknown) => unknown) | null = null
let compileJSON: ((arg0: string, arg1: unknown) => string) | null = null
if ('_compileJSON' in soljson) {
// input (text), optimize (bool) -> output (jsontext)
compileJSON = soljson.cwrap('compileJSON', 'string', ['string', 'number'])
}

let compileJSONMulti: ((arg0: string, arg1: unknown) => unknown) | null = null
let compileJSONMulti: ((arg0: string, arg1: unknown) => string) | null = null
if ('_compileJSONMulti' in soljson) {
// input (jsontext), optimize (bool) -> output (jsontext)
compileJSONMulti = soljson.cwrap('compileJSONMulti', 'string', ['string', 'number'])
}

let compileJSONCallback: {
(arg0: string, arg1: unknown, arg2: any): any
(input: unknown, optimize: boolean, readCallback: unknown): unknown
(input: unknown, optimize: boolean, readCallback: Record<string, (...args: unknown[]) => any>): unknown
} | null = null
if ('_compileJSONCallback' in soljson) {
// input (jsontext), optimize (bool), callback (ptr) -> output (jsontext)
Expand All @@ -134,9 +133,7 @@ export const setupMethods = (soljson: {
}

let compileStandard: {
(arg0: any, arg1: any): any
(input: any, readCallback: unknown): any
(input: unknown, callbacks: unknown): unknown
(arg0: string, arg1: any): string
} | null = null
if ('_compileStandard' in soljson) {
// input (jsontext), callback (ptr) -> output (jsontext)
Expand Down

0 comments on commit d783201

Please sign in to comment.