diff --git a/docker/code-templates/nodejs/starter-client/_projname_.js b/docker/code-templates/nodejs/starter-client/_projname_.js deleted file mode 100644 index 9c7aa62..0000000 --- a/docker/code-templates/nodejs/starter-client/_projname_.js +++ /dev/null @@ -1,120 +0,0 @@ -const fs = require('fs'); -const readline = require('readline'); -const HotPocket = require('hotpocket-js-client'); - -async function clientApp() { - - const keyFile = 'user.key'; - - // Re-generate a user key pair for the client. - if (process.argv[2] == 'generatekeys' || !fs.existsSync(keyFile)) { - const newKeyPair = await HotPocket.generateKeys(); - const saveData = Buffer.from(newKeyPair.privateKey).toString('hex'); - fs.writeFileSync(keyFile, saveData); - console.log('New key pair generated.'); - - if (process.argv[2] == 'generatekeys') { - const pkhex = Buffer.from(newKeyPair.publicKey).toString('hex'); - console.log('My public key is: ' + pkhex); - return; - } - } - - // Generate the key pair using saved private key data. - const savedPrivateKeyHex = fs.readFileSync(keyFile).toString(); - const userKeyPair = await HotPocket.generateKeys(savedPrivateKeyHex); - - const pkhex = Buffer.from(userKeyPair.publicKey).toString('hex'); - console.log('My public key is: ' + pkhex); - - // Simple connection to single server without any validations. - const ip = process.argv[2] || 'localhost'; - const port = process.argv[3] || '8081'; - const client = await HotPocket.createClient( - ['wss://' + ip + ':' + port], - userKeyPair - ); - - client.on(HotPocket.events.disconnect, () => { - console.log('Disconnected'); - rl.close(); - }) - - // This will get fired as servers connects/disconnects. - client.on(HotPocket.events.connectionChange, (server, action) => { - console.log(server + " " + action); - }) - - // This will get fired when contract sends outputs. - client.on(HotPocket.events.contractOutput, (r) => { - r.outputs.forEach(o => { - if (o?.type == 'data_result') { - console.log('\x1b[32m%s\x1b[0m', `Output >> ${o.data}`); - } else if (o?.type == 'error') { - console.log('\x1b[31m%s\x1b[0m', `Error >> ${o.error}`); - } - }); - }) - - - // Establish HotPocket connection. - if (!await client.connect()) { - console.log('Connection failed.'); - return; - } - - console.log('HotPocket Connected.'); - - // start listening for stdin - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout - }); - - // On ctrl + c we should close HP connection gracefully. - rl.on('SIGINT', () => { - console.log('SIGINT received...'); - rl.close(); - client.close(); - }); - - console.log('\x1b[36m%s\x1b[0m',"Run 'help' for more information on commands."); - console.log("Ready to accept inputs."); - - const input_pump = () => { - rl.question('', (inp) => { - - - if (inp.length > 0) { - if (inp.startsWith("help")) { - console.log('\x1b[36m%s\x1b[0m', ` - Commands : - set -- To write some text to a file on the contract side. - get -- To retrieve the written content. - `); - } else { - if (inp.startsWith("set ")) { - inp = JSON.stringify({ type: "set", data: inp.substr(4) }); - } - - else if (inp.startsWith("get")) { - inp = JSON.stringify({ type: "get" }); - } - - client.submitContractInput(inp).then(input => { - input.submissionStatus.then(s => { - if (s.status != "accepted") - console.log(s.reason); - }); - }); - } - - } - - input_pump(); - }) - } - input_pump(); -} - -clientApp(); \ No newline at end of file diff --git a/docker/code-templates/nodejs/starter-client/package.json b/docker/code-templates/nodejs/starter-client/package.json deleted file mode 100644 index 2ec530f..0000000 --- a/docker/code-templates/nodejs/starter-client/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "_projname_", - "dependencies": { - "hotpocket-js-client": "0.5.3" - } -} diff --git a/npm/index.js b/npm/index.js index cc27f00..22728a3 100755 --- a/npm/index.js +++ b/npm/index.js @@ -1,12 +1,7 @@ #! /usr/bin/env node const { program } = require('commander'); -const { version, codeGen, bundle, deploy, clean, logs, start, stop, update, uninstall } = require('./lib/command-handler'); - -program - .command('bundle ') - .description('hpdevkit bundle ') - .action(bundle); +const { version, codeGen, deploy, clean, logs, start, stop, update, uninstall } = require('./lib/command-handler'); program .command('version') diff --git a/npm/lib/command-handler.js b/npm/lib/command-handler.js index 4685a7b..06cf2b9 100644 --- a/npm/lib/command-handler.js +++ b/npm/lib/command-handler.js @@ -74,82 +74,6 @@ function deploy(contractPath) { } } -function bundle(nodePublicKey, contractDirectoryPath) { - info(`command: bundle`); - - try { - - contractDirectoryPath = path.normalize(contractDirectoryPath); - let stats = fs.statSync(contractDirectoryPath); - - if (!stats.isDirectory()) - throw 'You are supposed to provide a path of the contract directory.'; - - const overrideConfigPath = path.resolve(contractDirectoryPath, CONSTANTS.confOverrideFile); - const contractConfigPath = path.resolve(contractDirectoryPath, CONSTANTS.contractCfgFile); - const prerequisiteInstaller = path.resolve(contractDirectoryPath, CONSTANTS.prerequisiteInstaller); - const overrideConfig = JSON.parse(fs.readFileSync(overrideConfigPath).toString()); - - const contractConfigs = { - "version": "2.0", - "unl": [ - `${nodePublicKey}` - ], - "bin_path": `${overrideConfig?.contract.bin_path}`, - "bin_args": `${overrideConfig?.contract.bin_args}`, - "environment": {}, - "max_input_ledger_offset": 10, - "consensus": { - "mode": "private", - "roundtime": 8000, - "stage_slice": 25, - "threshold": 50 - }, - "npl": { - "mode": "private" - }, - "appbill": { - "mode": "", - "bin_args": "" - }, - "round_limits": { - "user_input_bytes": 0, - "user_output_bytes": 0, - "npl_output_bytes": 0, - "proc_cpu_seconds": 0, - "proc_mem_bytes": 0, - "proc_ofd_count": 0 - } - } - - // Write contract.config file content. - fs.writeFileSync(contractConfigPath, JSON.stringify(contractConfigs, null, 4)); - info(`Prepared ${CONSTANTS.contractCfgFile} file.`); - - // Add prerequisite install script. - fs.writeFileSync(prerequisiteInstaller, - `#!/bin/bash\n` + - `echo "Prerequisite installer script"\n` + - `exit 0`, null); - - // Change permission pre-requisite installer. - fs.chmodSync(prerequisiteInstaller, 0o755); - info("Added prerequisite installer script."); - - const bundleTargetPath = path.normalize(`${contractDirectoryPath}/../bundle`); - - if (!fs.existsSync(bundleTargetPath)) { - fs.mkdirSync(bundleTargetPath); - } - - archiveDirectory(contractDirectoryPath, bundleTargetPath); - - } catch (e) { - error(e); - } - -} - function clean() { info(`command: clean (cluster: ${appenv.cluster})`); diff --git a/npm/lib/common.js b/npm/lib/common.js index 842ddb0..a4528c0 100644 --- a/npm/lib/common.js +++ b/npm/lib/common.js @@ -101,8 +101,10 @@ function initializeDeploymentCluster() { } function teardownDeploymentCluster() { - exec(`docker stop ${CONSTANTS.deploymentContainerName}`); - exec(`docker rm ${CONSTANTS.deploymentContainerName}`); + if (isExists(CONSTANTS.deploymentContainerName)) { + exec(`docker stop ${CONSTANTS.deploymentContainerName}`); + exec(`docker rm ${CONSTANTS.deploymentContainerName}`); + } runOnContainer(null, null, true, true, null, "cluster stop ; cluster destroy", null, false); } diff --git a/npm/package-lock.json b/npm/package-lock.json index 090acb5..9afb2a8 100644 --- a/npm/package-lock.json +++ b/npm/package-lock.json @@ -1,12 +1,12 @@ { "name": "hpdevkit", - "version": "0.5.3", + "version": "0.5.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "hpdevkit", - "version": "0.5.3", + "version": "0.5.4", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/npm/package.json b/npm/package.json index ad795a5..54621e3 100644 --- a/npm/package.json +++ b/npm/package.json @@ -1,6 +1,6 @@ { "name": "hpdevkit", - "version": "0.5.3", + "version": "0.5.4", "description": "Developer toolkit for HotPocket smart contract development", "scripts": { "install": "node scripts/install.js"