Hook candidate propose implementations (#227)

This commit is contained in:
Chalith Desaman
2023-02-09 11:02:39 +05:30
committed by GitHub
parent bb9882bc36
commit f828717f4c
9 changed files with 1708 additions and 28 deletions

View File

@@ -69,7 +69,8 @@ add_custom_command(TARGET sagent POST_BUILD
COMMAND cp ./evernode-bootstrap-contract/src/bootstrap_upgrade.sh ./build/contract_template/contract_fs/seed/state/
COMMAND mv ./build/bootstrap_contract ./build/contract_template/contract_fs/seed/state/
COMMAND ./installer/docker-install.sh ./build/dockerbin
COMMAND npm --prefix ./mb-xrpl install && npm run --prefix ./mb-xrpl build
COMMAND npm --prefix ./mb-xrpl install && npm run --prefix ./mb-xrpl build
COMMAND npm --prefix ./governance-helper install && npm run --prefix ./governance-helper build
)
target_precompile_headers(sagent PUBLIC src/pchheader.hpp)
@@ -81,6 +82,7 @@ add_custom_target(installer
COMMAND bash -c "cp -r ./installer/{docker-install.sh,docker-registry-install.sh,docker-registry-uninstall.sh,prereq.sh,sashimono-install.sh,sashimono-uninstall.sh} ./build/installer/"
COMMAND bash -c "cp -r ./dependencies/{user-cgcreate.sh,libblake3.so,licence.txt} ./build/installer/"
COMMAND bash -c "cp -r ./mb-xrpl/dist ./build/installer/mb-xrpl"
COMMAND bash -c "cp -r ./governance-helper/dist ./build/installer/governance-helper"
COMMAND tar cfz ./build/installer.tar.gz --directory=./build/ installer
COMMAND rm -r ./build/installer

2
governance-helper/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules
dist

View File

@@ -0,0 +1,74 @@
const evernode = require("evernode-js-client");
const process = require("process");
const fs = require("fs");
const DATA_DIR = process.env.DATA_DIR || __dirname;
const CONFIG_PATH = DATA_DIR + '/mb-xrpl.cfg';
const SECRET_CONFIG_PATH = DATA_DIR + '/secret.cfg';
const getConfig = (skipSecret = false) => {
// Only root user can access the secret config.
if (!skipSecret) {
if (process.getuid() != 0)
throw `Please run with root privileges (sudo).`;
}
if (!fs.existsSync(CONFIG_PATH))
throw `Config file does not exist at ${CONFIG_PATH}`;
else if (!fs.existsSync(SECRET_CONFIG_PATH))
throw `Config file does not exist at ${SECRET_CONFIG_PATH}`;
let config = JSON.parse(fs.readFileSync(CONFIG_PATH).toString());
const secretCfg = JSON.parse(fs.readFileSync(SECRET_CONFIG_PATH).toString());
config.xrpl = { ...config.xrpl, ...secretCfg.xrpl };
return config;
}
const propose = async (hashFilePath, shortName) => {
if (!hashFilePath)
throw `Hash file param cannot be empty.`;
else if (!fs.existsSync(hashFilePath))
throw `Hash file ${hashFilePath} does not exist.`;
else if (!shortName)
throw `Short name cannot be empty.`;
const hashes = fs.readFileSync(hashFilePath).toString();
const config = getConfig();
const xrplApi = new evernode.XrplApi(config.xrpl.rippledServer);
evernode.Defaults.set({
governorAddress: config.xrpl.governorAddress,
xrplApi: xrplApi
})
await xrplApi.connect();
const hostClient = new evernode.HostClient(config.xrpl.address, config.xrpl.secret);
try {
await hostClient.connect();
await hostClient.propose(hashes, shortName);
} finally {
await hostClient.disconnect();
await xrplApi.disconnect();
}
}
const app = async () => {
const command = process.argv[2];
const params = process.argv.slice(3);
if (command == "propose" && params.length == 2)
await propose(params[0], params[1]);
else {
console.error("Supported governance commands:\n propose <hash_file> <short_name> - Propose new hook candidate");
process.exit(2);
}
}
app().then(() => {
process.exit(0);
}).catch((e) => {
console.error(e);
process.exit(1);
});

1585
governance-helper/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,9 @@
{
"name": "governance-helper",
"scripts": {
"build": "ncc build index.js --minify -o dist"
},
"dependencies": {
"evernode-js-client": "0.5.17"
}
}

View File

@@ -6,7 +6,7 @@
"": {
"name": "evernode-setup-helper",
"dependencies": {
"evernode-js-client": "0.5.14"
"evernode-js-client": "0.5.16"
}
},
"node_modules/@types/node": {
@@ -270,9 +270,9 @@
"integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw=="
},
"node_modules/evernode-js-client": {
"version": "0.5.14",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.14.tgz",
"integrity": "sha512-VH/Pu9kELIXJ4vhtOIZGgcljsE+In4JpXsnuj89Rw7kt4vYRGOQWEJHxxmvGQQsfD9/pHPQFt6XR0gpnVoRi+A==",
"version": "0.5.16",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.16.tgz",
"integrity": "sha512-DZxbbc+RPnQXLYlipNIYcZUndOgIfEW4f+fB1cNA5ImAQL6mCeE2cpWrz6GULfOS8X99A2Fcxy7X7ny66QfT9g==",
"dependencies": {
"elliptic": "6.5.4",
"libsodium-wrappers": "0.7.10",
@@ -1109,9 +1109,9 @@
"integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw=="
},
"evernode-js-client": {
"version": "0.5.14",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.14.tgz",
"integrity": "sha512-VH/Pu9kELIXJ4vhtOIZGgcljsE+In4JpXsnuj89Rw7kt4vYRGOQWEJHxxmvGQQsfD9/pHPQFt6XR0gpnVoRi+A==",
"version": "0.5.16",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.16.tgz",
"integrity": "sha512-DZxbbc+RPnQXLYlipNIYcZUndOgIfEW4f+fB1cNA5ImAQL6mCeE2cpWrz6GULfOS8X99A2Fcxy7X7ny66QfT9g==",
"requires": {
"elliptic": "6.5.4",
"libsodium-wrappers": "0.7.10",

View File

@@ -230,7 +230,7 @@ if [ "$NO_MB" == "" ]; then
# Configure message board users and register host.
echo "Configuaring host registration on Evernode..."
cp -r "$script_dir"/mb-xrpl $SASHIMONO_BIN
cp -r "$script_dir"/{mb-xrpl,governance-helper} $SASHIMONO_BIN
# Creating message board user (if not exists).
if ! grep -q "^$MB_XRPL_USER:" /etc/passwd; then

View File

@@ -32,6 +32,7 @@ export USER_BIN=/usr/bin
export SASHIMONO_BIN=/usr/bin/sashimono
export MB_XRPL_BIN=$SASHIMONO_BIN/mb-xrpl
export DOCKER_BIN=$SASHIMONO_BIN/dockerbin
export GOVERNANCE_HELPER_BIN=$SASHIMONO_BIN/governance-helper
export SASHIMONO_DATA=/etc/sashimono
export MB_XRPL_DATA=$SASHIMONO_DATA/mb-xrpl
export SASHIMONO_SERVICE="sashimono-agent"
@@ -89,20 +90,26 @@ if [ -f /etc/systemd/system/$SASHIMONO_SERVICE.service ] && [ -d $SASHIMONO_BIN
&& echo "$evernode is already installed on your host. Use the 'evernode' command to manage your host." \
&& exit 1
[ "$1" != "uninstall" ] && [ "$1" != "status" ] && [ "$1" != "list" ] && [ "$1" != "update" ] && [ "$1" != "log" ] && [ "$1" != "applyssl" ] && [ "$1" != "transfer" ] && [ "$1" != "config" ] && [ "$1" != "delete" ] \
&& echomult "$evernode host management tool
if ([ "$1" != "uninstall" ] && [ "$1" != "status" ] && [ "$1" != "list" ] && [ "$1" != "update" ] &&
[ "$1" != "log" ] && [ "$1" != "applyssl" ] && [ "$1" != "transfer" ] && [ "$1" != "config" ] && [ "$1" != "delete" ]); then
output=$(DATA_DIR=$MB_XRPL_DATA /usr/bin/node $GOVERNANCE_HELPER_BIN "$@" 2>&1)
exit_code=$?
[ $exit_code -eq 2 ] && echomult "$evernode host management tool
\nYour host is registered on $evernode.
\nSupported commands:
\nstatus - View $evernode registration info
\nlist - View contract instances running on this system
\nlog - Generate evernode log file.
\napplyssl - Apply new SSL certificates for contracts.
\nconfig - View and update host configuration.
\nupdate - Check and install $evernode software updates
\ntransfer - Initiate an $evernode transfer for your machine
\ndelete - Remove an instance from the system and recreate the lease
\nuninstall - Uninstall and deregister from $evernode" \
&& exit 1
\n status - View $evernode registration info
\n list - View contract instances running on this system
\n log - Generate evernode log file.
\n applyssl - Apply new SSL certificates for contracts.
\n config - View and update host configuration.
\n update - Check and install $evernode software updates
\n transfer - Initiate an $evernode transfer for your machine
\n delete - Remove an instance from the system and recreate the lease
\n uninstall - Uninstall and deregister from $evernode"
echo "$output"
[ ! $exit_code -eq 0 ] && exit 1
fi
elif [ -d $SASHIMONO_BIN ] ; then
[ "$1" != "install" ] && [ "$1" != "uninstall" ] \
&& echomult "$evernode host management tool
@@ -644,6 +651,7 @@ function install_evernode() {
echo "Installing Sashimono..."
init_setup_helpers
registry_address=$(exec_jshelper access-evernode-cfg $rippled_server $EVERNODE_GOVERNOR_ADDRESS $xrpl_account_address registryAddress)
# Filter logs with STAGE prefix and ommit the prefix when echoing.

View File

@@ -6,7 +6,7 @@
"": {
"name": "mb-xrpl",
"dependencies": {
"evernode-js-client": "0.5.14",
"evernode-js-client": "0.5.16",
"sqlite3": "5.0.2"
},
"devDependencies": {
@@ -937,9 +937,9 @@
}
},
"node_modules/evernode-js-client": {
"version": "0.5.14",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.14.tgz",
"integrity": "sha512-VH/Pu9kELIXJ4vhtOIZGgcljsE+In4JpXsnuj89Rw7kt4vYRGOQWEJHxxmvGQQsfD9/pHPQFt6XR0gpnVoRi+A==",
"version": "0.5.16",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.16.tgz",
"integrity": "sha512-DZxbbc+RPnQXLYlipNIYcZUndOgIfEW4f+fB1cNA5ImAQL6mCeE2cpWrz6GULfOS8X99A2Fcxy7X7ny66QfT9g==",
"dependencies": {
"elliptic": "6.5.4",
"libsodium-wrappers": "0.7.10",
@@ -3931,9 +3931,9 @@
"dev": true
},
"evernode-js-client": {
"version": "0.5.14",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.14.tgz",
"integrity": "sha512-VH/Pu9kELIXJ4vhtOIZGgcljsE+In4JpXsnuj89Rw7kt4vYRGOQWEJHxxmvGQQsfD9/pHPQFt6XR0gpnVoRi+A==",
"version": "0.5.16",
"resolved": "https://registry.npmjs.org/evernode-js-client/-/evernode-js-client-0.5.16.tgz",
"integrity": "sha512-DZxbbc+RPnQXLYlipNIYcZUndOgIfEW4f+fB1cNA5ImAQL6mCeE2cpWrz6GULfOS8X99A2Fcxy7X7ny66QfT9g==",
"requires": {
"elliptic": "6.5.4",
"libsodium-wrappers": "0.7.10",