Added new contract templates (#31)

This commit is contained in:
Chalith Desaman
2024-03-15 17:16:24 +05:30
committed by GitHub
parent 5838ea7fcc
commit 1face50d32
46 changed files with 3860 additions and 73 deletions

View File

@@ -8,6 +8,9 @@ const appenv = {
instanceImage: process.env.HP_INSTANCE_IMAGE || 'evernode/hotpocket:0.6.4-ubt.20.04-njs.20',
hpUserPortBegin: process.env.HP_USER_PORT_BEGIN || 8081,
hpPeerPortBegin: process.env.HP_PEER_PORT_BEGIN || 22861,
network: process.env.HP_EV_NETWORK || 'mainnet',
signerWeight: process.env.HP_MULTI_SIGNER_WEIGHT || 1,
signerQuorum: process.env.HP_MULTI_SIGNER_QUORUM || 0.8
}
Object.freeze(appenv);

View File

@@ -8,6 +8,11 @@ program
.description('Display the hpdevkit version.')
.action(commands.version);
program
.command('list [platform]')
.description('Lists existing templates in the specified platform. Lists all templates in the all platforms if unspecified.')
.action(commands.list);
program
.command('gen <platform> <app-type> <project-name>')
.description('Generate HotPocket application development projects.')
@@ -15,6 +20,9 @@ program
program
.command('deploy <contract-path>')
.option('-m, --multi-sig [multi-sig]', 'Multi signing enabled.')
.option('-a, --master-addr [master-addr]', 'Master address for multi signing.')
.option('-s, --master-sec [master-sec]', 'Master secret for multi signing.')
.description('Deploy the specified directory to a HotPocket cluster.')
.action(commands.deploy);

View File

@@ -1,5 +1,7 @@
const fs = require('fs');
const appenv = require('../appenv');
const kp = require('ripple-keypairs');
const evernode = require("evernode-js-client")
const { exec } = require('./child-proc');
const {
CONSTANTS,
@@ -28,6 +30,21 @@ function version() {
error(`\n${CONSTANTS.npmPackageName} is not installed.`);
}
function list(platform) {
info("List templates\n");
try {
runOnNewContainer(CONSTANTS.codegenContainerName, null, null, null, null, platform ? `list ${platform}` : 'list', 'templates');
}
catch (e) {
error(`Listing templates failed.`);
}
finally {
if (isExists(CONSTANTS.codegenContainerName))
exec(`docker rm ${CONSTANTS.codegenContainerName}`, false);
}
}
function codeGen(platform, apptype, projName) {
info("Code generator\n");
@@ -50,9 +67,14 @@ function codeGen(platform, apptype, projName) {
}
}
function deploy(contractPath) {
async function deploy(contractPath, options) {
info(`command: deploy (cluster: ${appenv.cluster})`);
if (options.multiSig && !options.masterSec) {
error('Master secret is required to setup multi signing!');
return;
}
initializeDeploymentCluster();
// If copying a directory, delete target bundle directory. If not create empty target bundle directory to copy a file.
@@ -63,6 +85,56 @@ function deploy(contractPath) {
executeOnManagementContainer(prepareBundleDir);
exec(`docker cp ${contractPath} "${CONSTANTS.managementContainerName}:${CONSTANTS.bundleMount}"`);
// Prepare signers if multisig specified
if (options.multiSig) {
if (!options.masterAddr) {
const keypair = kp.deriveKeypair(options.masterSec);
options.masterAddr = kp.deriveAddress(keypair.publicKey);
}
let signers = [];
for (let i = 0; i < appenv.clusterSize; i++) {
const nodeSecret = kp.generateSeed({ algorithm: "ecdsa-secp256k1" });
const keypair = kp.deriveKeypair(nodeSecret);
const signerInfo = {
account: kp.deriveAddress(keypair.publicKey),
secret: nodeSecret,
weight: appenv.signerWeight
};
signers.push(signerInfo);
const disparatePath = `${CONSTANTS.bundleMount}/${CONSTANTS.disparateDir}/${i + 1}`;
executeOnManagementContainer(`mkdir -p ${disparatePath} && echo '${JSON.stringify(signerInfo, null, 2).replace(/"/g, '\\"')}' > ${disparatePath}/${options.masterAddr}.key`);
}
await evernode.Defaults.useNetwork(appenv.network);
const xrplApi = new evernode.XrplApi(null);
evernode.Defaults.set({
xrplApi: xrplApi
});
await xrplApi.connect();
const xrplAcc = new evernode.XrplAccount(options.masterAddr, options.masterSec);
try {
const totalWeights = signers.reduce((sum, x) => sum + x.weight, 0);
await xrplAcc.setSignerList(signers.map(s => {
return {
account: s.account,
weight: s.weight
};
}), { signerQuorum: Math.floor(totalWeights * appenv.signerQuorum) });
await xrplApi.disconnect();
}
catch (e) {
error('Error occurred while preparing the signer list', e);
await xrplApi.disconnect();
return;
}
info(`Multi signer setup for ${options.masterAddr} completed!`);
}
// Sync contract bundle to all instance directories in the cluster.
executeOnManagementContainer('cluster stop ; cluster sync ; cluster start');
@@ -157,6 +229,7 @@ function uninstall() {
module.exports = {
version,
list,
codeGen,
deploy,
clean,

View File

@@ -11,6 +11,7 @@ const CONSTANTS = {
network: `${GLOBAL_PREFIX}_${appenv.cluster}_net`,
containerPrefix: `${GLOBAL_PREFIX}_${appenv.cluster}_node`,
bundleMount: `${GLOBAL_PREFIX}_vol/contract_bundle`,
disparateDir: `disparate`,
managementContainerName: `${GLOBAL_PREFIX}_${appenv.cluster}_deploymgr`,
confOverrideFile: "hp.cfg.override",
codegenOutputDir: "/codegen-output",
@@ -49,7 +50,7 @@ function runOnNewContainer(name, detached, autoRemove, mountSock, mountVolume, e
command += ` --restart ${restart}`;
command += ` -e CLUSTER=${appenv.cluster} -e CLUSTER_SIZE=${appenv.clusterSize} -e DEFAULT_NODE=${appenv.defaultNode} -e VOLUME=${CONSTANTS.volume} -e NETWORK=${CONSTANTS.network}`;
command += ` -e CONTAINER_PREFIX=${CONSTANTS.containerPrefix} -e VOLUME_MOUNT=${CONSTANTS.volumeMount} -e BUNDLE_MOUNT=${CONSTANTS.bundleMount} -e HOTPOCKET_IMAGE=${appenv.instanceImage}`;
command += ` -e CONTAINER_PREFIX=${CONSTANTS.containerPrefix} -e VOLUME_MOUNT=${CONSTANTS.volumeMount} -e BUNDLE_MOUNT=${CONSTANTS.bundleMount} -e DISPARATE_DIR=${CONSTANTS.disparateDir} -e HOTPOCKET_IMAGE=${appenv.instanceImage}`;
command += ` -e CONFIG_OVERRIDES_FILE=${CONSTANTS.confOverrideFile} -e CODEGEN_OUTPUT=${CONSTANTS.codegenOutputDir}`;
command += ` -e HP_USER_PORT_BEGIN=${appenv.hpUserPortBegin} -e HP_PEER_PORT_BEGIN=${appenv.hpPeerPortBegin}`;

2390
npm/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "hpdevkit",
"version": "0.6.5",
"version": "0.6.6",
"license": "SEE LICENSE IN https://raw.githubusercontent.com/EvernodeXRPL/evernode-resources/main/license/evernode-license.pdf",
"description": "Developer toolkit for HotPocket smart contract development",
"scripts": {
@@ -18,7 +18,8 @@
],
"homepage": "https://github.com/HotPocketDev/evernode-sdk",
"dependencies": {
"commander": "9.4.0"
"commander": "9.4.0",
"evernode-js-client": "0.6.43"
},
"devDependencies": {
"eslint": "8.3.0"