Created
April 3, 2019 06:09
-
-
Save hackdapp/b200b70b1e5d32fa9e7ae1fc082681cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
function getDeployableFilesFromDir(dir) { | |
const dirCont = fs.readdirSync(dir) | |
const wasmFileName = dirCont.find(filePath => filePath.match(/.*\.(wasm)$/gi)) | |
const abiFileName = dirCont.find(filePath => filePath.match(/.*\.(abi)$/gi)) | |
if (!wasmFileName) throw new Error(`Cannot find a ".wasm file" in ${dir}`) | |
if (!abiFileName) throw new Error(`Cannot find an ".abi file" in ${dir}`) | |
return { | |
wasmPath: path.join(dir, wasmFileName), | |
abiPath: path.join(dir, abiFileName), | |
} | |
} | |
function deployContract(eos, { account, contractDir }) { | |
const { wasmPath, abiPath } = getDeployableFilesFromDir(contractDir) | |
const wasm = fs.readFileSync(wasmPath) | |
const abi = fs.readFileSync(abiPath) | |
const codePromise = eos.setcode(account, 0, 0, wasm) | |
const abiPromise = eos.setabi(account, JSON.parse(abi)) | |
return Promise.all([codePromise, abiPromise]) | |
} | |
module.exports = {deployContract} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment