mirror of
https://github.com/EvernodeXRPL/hp-devkit.git
synced 2026-04-29 15:37:58 +00:00
Resolved bug in hpdevkit clean command. (#18)
This commit is contained in:
committed by
GitHub
parent
01ff8a3c59
commit
d60bc7989e
@@ -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 <text> -- 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();
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "_projname_",
|
||||
"dependencies": {
|
||||
"hotpocket-js-client": "0.5.3"
|
||||
}
|
||||
}
|
||||
@@ -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 <node-public-key> <contract-path>')
|
||||
.description('hpdevkit bundle <node-public-key> <contract-path>')
|
||||
.action(bundle);
|
||||
const { version, codeGen, deploy, clean, logs, start, stop, update, uninstall } = require('./lib/command-handler');
|
||||
|
||||
program
|
||||
.command('version')
|
||||
|
||||
@@ -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})`);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
4
npm/package-lock.json
generated
4
npm/package-lock.json
generated
@@ -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": {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user