Skip to content

Commit

Permalink
feat: add bytecode generation script and update deployment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey committed Oct 29, 2024
1 parent 382ae25 commit d89909c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"scripts": {
"build": "tsc",
"build:sc": "cd ../smart-contract && npm ci && npm run build && cp build/deweb-interface.wasm ../cli/src/lib/website/sc/main.wasm",
"build:sc": "cd ../smart-contract && npm ci && npm run build && cp build/deweb-interface.wasm ../cli/src/lib/website/sc/main.wasm && cd ../cli && npm run generate:deweb:bytecode",
"generate:deweb:bytecode": "ts-node ./src/lib/website/sc/generate-deweb-bytecode.ts",
"start": "node ./bin/index.js",
"dev": "ts-node ./src/index.ts",
"test": "jest",
Expand Down
6 changes: 2 additions & 4 deletions cli/src/lib/website/deploySC.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Provider, SmartContract } from '@massalabs/massa-web3'
import { readFileSync } from 'fs'
import { storageCostForEntry } from '../utils/storage'
import { DEWEB_VERSION_TAG } from './storageKeys'

const byteCode = readFileSync('src/lib/website/sc/main.wasm')
import { DEWEB_SC_BYTECODE } from './sc/deweb-sc-bytecode'
const ownerKey = 'OWNER'

export async function deploySC(provider: Provider): Promise<SmartContract> {
return SmartContract.deploy(provider, byteCode, undefined, {
return SmartContract.deploy(provider, DEWEB_SC_BYTECODE, undefined, {
coins: deployCost(provider),
})
}
Expand Down
5 changes: 5 additions & 0 deletions cli/src/lib/website/sc/deweb-sc-bytecode.ts

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions cli/src/lib/website/sc/generate-deweb-bytecode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import path from 'path'
import fs from 'fs'

console.log('Generating deweb contract bytecode...')
function generateBytecode(src?: string, dst?: string): void {
const wasmPath = src ?? path.join(__dirname, 'main.wasm')
const wasmData = fs.readFileSync(wasmPath)

const output = `
/* eslint-disable max-len */
export const DEWEB_SC_BYTECODE: Uint8Array = new Uint8Array([${[...wasmData]}]);\n
`

const outputDir = dst ?? path.join(__dirname, './deweb-sc-bytecode.ts')

fs.writeFileSync(outputDir, output)
}

generateBytecode()

0 comments on commit d89909c

Please sign in to comment.