Skip to content

Commit

Permalink
feat!: rm mappingPath in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
murongg committed Feb 22, 2024
1 parent b6ac220 commit e308673
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
5 changes: 1 addition & 4 deletions packages/cle-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ export async function run() {
.command('compile', 'Compile for Full Image (Link Compiled with Compiler Server)')
// .option('--local', 'Compile for Local Image')
.option('--yaml-path <path>', 'Path to yaml file')
.option('--mapping-path <path>', 'Path to mapping file')
.example('cle compile')
.action((options) => {
const { yamlPath = '', mappingPath = '' } = options
const { yamlPath = '' } = options
const wasmPath = config.WasmBinPath

compile({
Expand All @@ -37,7 +36,6 @@ export async function run() {
compilerServerEndpoint: config.CompilerServerEndpoint,
wasmPath,
watPath: wasmPath.replace(/\.wasm/, '.wat'),
mappingPath: mappingPath || config.MappingPath,
})
})

Expand Down Expand Up @@ -134,7 +132,6 @@ Usage cases:
yamlPath: config.YamlPath,
pinataEndpoint: config.PinataEndpoint,
pinataJWT: config.PinataJWT,
mappingPath: config.MappingPath,
userPrivateKey: config.UserPrivateKey,
})
})
Expand Down
17 changes: 13 additions & 4 deletions packages/cle-cli/src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import path from 'node:path'
import * as zkgapi from '@ora-io/cle-api'
import webjson from '@ora-io/cle-lib/test/weblib/weblib.json'
import to from 'await-to-js'
import { createOnNonexist, isTsFile } from '../utils'
import { CLEYaml } from '@ora-io/cle-api'
import { createOnNonexist, isTsFile, loadMappingPathFromYaml } from '../utils'
import { logger } from '../logger'

export interface CompileOptions {
Expand All @@ -12,7 +13,6 @@ export interface CompileOptions {
compilerServerEndpoint: string
wasmPath: string
watPath: string
mappingPath: string
}

export async function compile(options: CompileOptions) {
Expand All @@ -32,13 +32,23 @@ async function compileRun(options: CompileOptions) {
yamlPath,
wasmPath,
watPath,
mappingPath,
// local,
} = options
if (!yamlPath) {
logger.error('no yaml path provided')
return false
}
const yaml = fs.readFileSync(yamlPath, 'utf8')
const yamlMappingPath = loadMappingPathFromYaml(CLEYaml.fromYamlContent(yaml))
if (!yamlMappingPath) {
logger.error('[-] no mapping path provided in cle.yaml')
return false
}
const mappingPath = path.join(path.dirname(yamlPath), yamlMappingPath)
if (!isTsFile(mappingPath)) {
logger.error('[-] mapping path provided in cle.yaml is not a ts file')
return false
}

createOnNonexist(wasmPath)
createOnNonexist(watPath)
Expand All @@ -48,7 +58,6 @@ async function compileRun(options: CompileOptions) {
const fileMap = getFileContentsByFilePaths(relativePaths, path.dirname(mappingPath))

const relativeYamlPath = path.relative(path.dirname(mappingPath), yamlPath)
const yaml = fs.readFileSync(yamlPath, 'utf8')

const [err, res] = await to(zkgapi.compile({
...webjson,
Expand Down
17 changes: 14 additions & 3 deletions packages/cle-cli/src/commands/upload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fs from 'node:fs'
import path from 'node:path'
import { upload as uploadApi } from '@ora-io/cle-api'
import { computeAddress } from 'ethers/lib/utils'
import { logger } from '../logger'
import { checkPinataAuthentication, loadYamlFromPath } from '../utils'
import { checkPinataAuthentication, isTsFile, loadMappingPathFromYaml, loadYamlFromPath } from '../utils'

export interface UploadOptions {
// local: boolean
Expand All @@ -11,13 +12,12 @@ export interface UploadOptions {
yamlPath: string
pinataEndpoint: string
pinataJWT: string
mappingPath: string
}

export async function upload(options: UploadOptions) {
logger.info('>> UPLOAD')

const { wasmPath, yamlPath, mappingPath, pinataEndpoint, pinataJWT, userPrivateKey } = options
const { wasmPath, yamlPath, pinataEndpoint, pinataJWT, userPrivateKey } = options

if (!await checkPinataAuthentication(pinataJWT)) {
logger.error('[-] PINATA AUTHENTICATION FAILED.')
Expand All @@ -26,6 +26,17 @@ export async function upload(options: UploadOptions) {

const yaml = loadYamlFromPath(yamlPath)

const yamlMappingPath = loadMappingPathFromYaml(yaml)
if (!yamlMappingPath) {
logger.error('[-] no mapping path provided in cle.yaml')
return false
}
const mappingPath = path.join(path.dirname(yamlPath), yamlMappingPath)
if (!isTsFile(mappingPath)) {
logger.error('[-] mapping path provided in cle.yaml is not a ts file')
return false
}

const userAddress = computeAddress(userPrivateKey).toLowerCase()

const mappingFile = fs.createReadStream(mappingPath)
Expand Down
6 changes: 0 additions & 6 deletions packages/cle-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ export interface UserConfig {
*/
YamlPath?: string

/**
* @default "[root]/src/mapping.ts"
*/
MappingPath?: string

/**
* @default "[root]/build/proof_[taskId].txt"
*/
Expand Down Expand Up @@ -106,7 +101,6 @@ export async function getConfig(configFile?: string, configRoot?: string) {
userConfig.WasmBinPath = parseTemplateTag(userConfig.WasmBinPath || '', TAGS)
// userConfig.LocalWasmBinPath = parseTemplateTag(userConfig.LocalWasmBinPath || '', TAGS)
userConfig.YamlPath = parseTemplateTag(userConfig.YamlPath || '', TAGS)
userConfig.MappingPath = parseTemplateTag(userConfig.MappingPath || '', TAGS)

return userConfig as Required<UserConfig>
}
1 change: 0 additions & 1 deletion packages/cle-cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const DEFAULT_CONFIG: Required<UserConfig> = {
WasmBinPath: '[root]/build/cle.wasm',

YamlPath: '[root]/src/cle.yaml',
MappingPath: '[root]/src/mapping.ts',

OutputProofFilePath: '[root]/build/proof_[taskId].txt',

Expand Down
4 changes: 4 additions & 0 deletions packages/cle-cli/src/utils/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ export function loadYamlFromPath(path: string) {
}
return CLEYaml.fromYamlContent(fileContents)
}

export function loadMappingPathFromYaml(yaml: CLEYaml) {
return yaml.mapping.file
}
3 changes: 0 additions & 3 deletions test/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`config > load default config 1`] = `
"mainnet": "https://eth-mainnet.nodereal.io/v1/5c1f0a30d6ff4093a31afce579bca8d6",
"sepolia": "https://rpc.ankr.com/eth_sepolia",
},
"MappingPath": "[root]/src/mapping.ts",
"OutputProofFilePath": "[root]/build/proof_[taskId].txt",
"PinataEndpoint": "https://api.pinata.cloud/pinning/pinFileToIPFS",
"PinataJWT": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiJhNmQyY2VmMS03ODMzLTQ0YWEtYjdjMi1jYmJmMGUyOTA2OWYiLCJlbWFpbCI6InN5Mjk0MEBueXUuZWR1IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInBpbl9wb2xpY3kiOnsicmVnaW9ucyI6W3siaWQiOiJGUkExIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9LHsiaWQiOiJOWUMxIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9XSwidmVyc2lvbiI6MX0sIm1mYV9lbmFibGVkIjpmYWxzZSwic3RhdHVzIjoiQUNUSVZFIn0sImF1dGhlbnRpY2F0aW9uVHlwZSI6InNjb3BlZEtleSIsInNjb3BlZEtleUtleSI6ImY2NmY0ZDE2ZjhjZTQxMjEzY2YyIiwic2NvcGVkS2V5U2VjcmV0IjoiZjcyZjcwMGJjNDkzYTIzMGNmNjAxMmFkOTQzZDY2MjIzMzkyZTJiZjI5NTE5MzNjMzNhOGVhYjU0NTM1NzE3OCIsImlhdCI6MTY5MTgwOTUyNH0.OU-IY0AV1OABmtX3ySBBdzvvrIgz8IGCRbgOBPvRO0Y",
Expand All @@ -30,7 +29,6 @@ exports[`config > load function config 1`] = `
"mainnet": "https://eth-mainnet.nodereal.io/v1/5c1f0a30d6ff4093a31afce579bca8d6",
"sepolia": "https://rpc.ankr.com/eth_sepolia",
},
"MappingPath": "[root]/src/mapping.ts",
"OutputProofFilePath": "[root]/build/proof_[taskId].txt",
"PinataEndpoint": "https://api.pinata.cloud/pinning/pinFileToIPFS",
"PinataJWT": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiJhNmQyY2VmMS03ODMzLTQ0YWEtYjdjMi1jYmJmMGUyOTA2OWYiLCJlbWFpbCI6InN5Mjk0MEBueXUuZWR1IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInBpbl9wb2xpY3kiOnsicmVnaW9ucyI6W3siaWQiOiJGUkExIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9LHsiaWQiOiJOWUMxIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9XSwidmVyc2lvbiI6MX0sIm1mYV9lbmFibGVkIjpmYWxzZSwic3RhdHVzIjoiQUNUSVZFIn0sImF1dGhlbnRpY2F0aW9uVHlwZSI6InNjb3BlZEtleSIsInNjb3BlZEtleUtleSI6ImY2NmY0ZDE2ZjhjZTQxMjEzY2YyIiwic2NvcGVkS2V5U2VjcmV0IjoiZjcyZjcwMGJjNDkzYTIzMGNmNjAxMmFkOTQzZDY2MjIzMzkyZTJiZjI5NTE5MzNjMzNhOGVhYjU0NTM1NzE3OCIsImlhdCI6MTY5MTgwOTUyNH0.OU-IY0AV1OABmtX3ySBBdzvvrIgz8IGCRbgOBPvRO0Y",
Expand All @@ -52,7 +50,6 @@ exports[`config > load object config 1`] = `
"mainnet": "https://eth-mainnet.nodereal.io/v1/5c1f0a30d6ff4093a31afce579bca8d6",
"sepolia": "https://rpc.ankr.com/eth_sepolia",
},
"MappingPath": "[root]/src/mapping.ts",
"OutputProofFilePath": "[root]/build/proof_[taskId].txt",
"PinataEndpoint": "https://api.pinata.cloud/pinning/pinFileToIPFS",
"PinataJWT": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiJhNmQyY2VmMS03ODMzLTQ0YWEtYjdjMi1jYmJmMGUyOTA2OWYiLCJlbWFpbCI6InN5Mjk0MEBueXUuZWR1IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInBpbl9wb2xpY3kiOnsicmVnaW9ucyI6W3siaWQiOiJGUkExIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9LHsiaWQiOiJOWUMxIiwiZGVzaXJlZFJlcGxpY2F0aW9uQ291bnQiOjF9XSwidmVyc2lvbiI6MX0sIm1mYV9lbmFibGVkIjpmYWxzZSwic3RhdHVzIjoiQUNUSVZFIn0sImF1dGhlbnRpY2F0aW9uVHlwZSI6InNjb3BlZEtleSIsInNjb3BlZEtleUtleSI6ImY2NmY0ZDE2ZjhjZTQxMjEzY2YyIiwic2NvcGVkS2V5U2VjcmV0IjoiZjcyZjcwMGJjNDkzYTIzMGNmNjAxMmFkOTQzZDY2MjIzMzkyZTJiZjI5NTE5MzNjMzNhOGVhYjU0NTM1NzE3OCIsImlhdCI6MTY5MTgwOTUyNH0.OU-IY0AV1OABmtX3ySBBdzvvrIgz8IGCRbgOBPvRO0Y",
Expand Down
2 changes: 0 additions & 2 deletions test/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ describe('compile', () => {
const yamlPath = path.join(commandsFixturesRoot, 'cle.yaml')
const wasmPath = path.join(projectRoot, 'temp/cle.wasm')
const watPath = wasmPath.replace(/\.wasm/, '.wat')
const mappingPath = path.join(commandsFixturesRoot, 'mapping.ts')

await compile({
yamlPath,
// local: false,
compilerServerEndpoint: 'http://compiler.dev.hyperoracle.io/compile',
wasmPath,
watPath,
mappingPath,
})
const hasWasm = fs.existsSync(wasmPath)
const hasWat = fs.existsSync(watPath)
Expand Down

0 comments on commit e308673

Please sign in to comment.