├── scripts ├── .gitkeep ├── doc │ ├── .gitkeep │ └── Energi3_Provisioning_Script_-_high_level_process_flow.pdf ├── linux │ ├── .gitkeep │ ├── nodemon_icon.png │ ├── start_screen_mn.sh │ ├── start_screen_staking.sh │ ├── nodemon.conf │ ├── fix_mine.sh │ ├── ntp_fix.sh │ ├── energi3-linux-installer.sh │ ├── cleanup_logs.sh │ ├── start_mn.sh │ ├── start_staking.sh │ ├── bootnodes-testnet.txt │ ├── mn_payout_time.sh │ ├── missing_stake_rewards.sh │ ├── missing_mn_rewards.sh │ ├── nodemon-resync.sh │ ├── sync-core-node.sh │ ├── energi3-cli │ ├── nodemon-report.sh │ └── autocompounding.sh ├── macos │ ├── .gitkeep │ ├── energi3.png │ ├── set-image.py │ ├── start_staking.sh │ ├── start_mn.sh │ ├── start_node.sh │ └── energi3-macos-installer.sh ├── utils │ ├── .gitkeep │ ├── removedb-list.db │ ├── utils.js │ └── getTransactionByAccount.js ├── thirdparty │ ├── .gitkeep │ ├── 7za.exe │ ├── util.7z │ └── otp.php └── windows │ ├── .gitkeep │ ├── energi3.ico │ ├── energi3_ascii.txt │ ├── start_staking.bat │ ├── start_mn.bat │ └── energi3-windows-installer.bat ├── docker-compose ├── nodemon │ ├── .ssh │ │ ├── id_rsa │ │ ├── id_rsa.pub │ │ └── config │ ├── .gitignore │ ├── etc │ │ ├── logrotate.d │ │ │ └── nodemon │ │ ├── sudoers.d │ │ │ └── sudoers-sudo-group │ │ └── rkhunter.conf.local │ ├── scripts │ │ ├── nodemon_cron.sh │ │ └── nodemon_helper.sh │ ├── .env.template.env │ ├── Dockerfile │ └── ReadMe.md ├── .dockerignore ├── .sshd │ ├── authorized_keys │ └── sshd_config ├── .gitignore ├── configuration │ ├── .gitignore │ └── ReadMe.md ├── setup │ ├── .energi_core │ │ └── keystore │ │ │ └── .gitignore │ ├── ReadMe.md │ └── setup.sh ├── scripts │ ├── energi_command.sh │ ├── energi-masternode-enode-url.sh │ ├── energi-core-node-status.sh │ ├── bootstrap-chaindata.sh │ └── energi-core-run.sh ├── .editorconfig ├── .env ├── compose.override.template.yaml ├── compose.yaml ├── Dockerfile ├── helper └── ReadMe.md ├── sdk ├── truffle │ ├── .secret │ └── truffle-config.js ├── hardhat │ ├── .env.energiTestnet.local │ ├── .env.example │ ├── hardhat.config.js │ └── common │ │ └── constants.js └── README.md └── README.md /scripts/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/doc/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/linux/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/macos/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/utils/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/thirdparty/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/windows/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docker-compose/nodemon/.ssh/id_rsa: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docker-compose/nodemon/.ssh/id_rsa.pub: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docker-compose/.dockerignore: -------------------------------------------------------------------------------- 1 | volumes 2 | -------------------------------------------------------------------------------- /docker-compose/.sshd/authorized_keys: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docker-compose/nodemon/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /scripts/utils/removedb-list.db: -------------------------------------------------------------------------------- 1 | 3.0.0 2 | -------------------------------------------------------------------------------- /sdk/truffle/.secret: -------------------------------------------------------------------------------- 1 | # add 12 word mnemonic phrase in this file -------------------------------------------------------------------------------- /docker-compose/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *compose.override.y*ml 3 | -------------------------------------------------------------------------------- /docker-compose/configuration/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !README.md 4 | -------------------------------------------------------------------------------- /docker-compose/setup/.energi_core/keystore/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /docker-compose/scripts/energi_command.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | export energi_command="${ENERGI_BIN} --datadir ${ENERGI_CORE_DIR}" 3 | -------------------------------------------------------------------------------- /scripts/macos/energi3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/HEAD/scripts/macos/energi3.png -------------------------------------------------------------------------------- /scripts/thirdparty/7za.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/HEAD/scripts/thirdparty/7za.exe -------------------------------------------------------------------------------- /scripts/thirdparty/util.7z: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/HEAD/scripts/thirdparty/util.7z -------------------------------------------------------------------------------- /scripts/windows/energi3.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/HEAD/scripts/windows/energi3.ico -------------------------------------------------------------------------------- /scripts/linux/nodemon_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/HEAD/scripts/linux/nodemon_icon.png -------------------------------------------------------------------------------- /sdk/hardhat/.env.energiTestnet.local: -------------------------------------------------------------------------------- 1 | RPC_URL="https://nodeapi.test.energi.network" 2 | NETWORK="energiTestnet" 3 | ACCOUNT_PRIVATE_KEY="" 4 | -------------------------------------------------------------------------------- /sdk/hardhat/.env.example: -------------------------------------------------------------------------------- 1 | RPC_URL="https://nodeapi.test.energi.network" 2 | NETWORK="localhost" // localhost energiTestnet energiMainnet 3 | ACCOUNT_PRIVATE_KEY="" 4 | -------------------------------------------------------------------------------- /docker-compose/.editorconfig: -------------------------------------------------------------------------------- 1 | # https://editorconfig.org 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_size = 2 6 | indent_style = space 7 | insert_final_newline = true 8 | -------------------------------------------------------------------------------- /docker-compose/nodemon/.ssh/config: -------------------------------------------------------------------------------- 1 | Host core 2 | CheckHostIP no 3 | IdentityFile ~/.ssh/id_rsa 4 | Port 2222 5 | StrictHostKeyChecking no 6 | UserKnownHostsFile /dev/null 7 | -------------------------------------------------------------------------------- /docker-compose/nodemon/etc/logrotate.d/nodemon: -------------------------------------------------------------------------------- 1 | /home/nrgstaker/log/*.log { 2 | su nrgstaker nrgstaker 3 | rotate 4 4 | minsize 25M 5 | copytruncate 6 | compress 7 | missingok 8 | } 9 | -------------------------------------------------------------------------------- /docker-compose/scripts/energi-masternode-enode-url.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | enode='admin.nodeInfo.enode' 3 | . ./energi_command.sh 4 | printf '%s:\n' ${enode} && ${energi_command} attach --exec ${enode} 5 | 6 | exit ${?} 7 | -------------------------------------------------------------------------------- /scripts/doc/Energi3_Provisioning_Script_-_high_level_process_flow.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/HEAD/scripts/doc/Energi3_Provisioning_Script_-_high_level_process_flow.pdf -------------------------------------------------------------------------------- /docker-compose/.sshd/sshd_config: -------------------------------------------------------------------------------- 1 | AuthorizedKeysFile ~/.sshd/authorized_keys 2 | ChallengeResponseAuthentication no 3 | HostKey ~/.sshd/host_dsa_key 4 | HostKey ~/.sshd/host_rsa_key 5 | PasswordAuthentication no 6 | PidFile ~/.sshd/sshd.pid 7 | Port 2222 8 | UsePAM yes 9 | -------------------------------------------------------------------------------- /docker-compose/nodemon/etc/sudoers.d/sudoers-sudo-group: -------------------------------------------------------------------------------- 1 | %sudo ALL = (ALL:ALL) NOPASSWD:SETENV: /usr/bin/apt-get, /usr/bin/cat,\ 2 | /usr/bin/debsums, /usr/bin/mkdir, /usr/bin/rkhunter, /usr/bin/rm,\ 3 | /usr/bin/sqlite3, /usr/bin/sudo command, /usr/bin/tee, /usr/sbin/logrotate 4 | -------------------------------------------------------------------------------- /scripts/macos/set-image.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import Cocoa 3 | import sys 4 | 5 | Cocoa.NSWorkspace.sharedWorkspace().setIcon_forFile_options_(Cocoa.NSImage.alloc().initWithContentsOfFile_(sys.argv[1].decode('utf-8')), sys.argv[2].decode('utf-8'), 0) or sys.exit("Unable to set file icon") -------------------------------------------------------------------------------- /docker-compose/scripts/energi-core-node-status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . ./energi_command.sh 3 | exec="${energi_command} attach --exec" 4 | status='miner.stakingStatus()' 5 | syncing='nrg.syncing' 6 | 7 | printf '%b:\n' ${syncing} && ${exec} ${syncing} \ 8 | && printf '%b:\n' ${status} && ${exec} ${status} 9 | 10 | exit $? 11 | -------------------------------------------------------------------------------- /docker-compose/.env: -------------------------------------------------------------------------------- 1 | # https://docs.docker.com/compose/env-file/#compose-file-and-cli-variables 2 | # https://docs.docker.com/compose/reference/envvars/#compose_project_name 3 | COMPOSE_PROJECT_NAME=energi 4 | ENERGI_VERSION=v1.1.6 5 | STAKER_HOME=/home/nrgstaker 6 | ENERGI_BIN=/usr/local/bin/energi 7 | ENERGI_CORE_DIR=${STAKER_HOME}/.energi_core 8 | -------------------------------------------------------------------------------- /docker-compose/scripts/bootstrap-chaindata.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # A script to bootstrap chaindata for Energi Core Node container 3 | . ./energi_command.sh 4 | cd "${ENERGI_CORE_DIR}" || exit 5 | yes | ${energi_command} removedb 6 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/sync-core-node.sh)" ; source ~/.bashrc 7 | -------------------------------------------------------------------------------- /docker-compose/nodemon/scripts/nodemon_cron.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while : 3 | do 4 | if /bin/bash nodemon.sh cron 5 | then 6 | sleep "${ECNM_INTERVAL:-'10m'}" 7 | else 8 | printf '%s\n%s\n\n' \ 9 | "Exiting Energi Core Node Monitor container cron because of an error." \ 10 | "Please see the output above for details!" 11 | break 12 | fi 13 | done 14 | -------------------------------------------------------------------------------- /scripts/windows/energi3_ascii.txt: -------------------------------------------------------------------------------- 1 | ___ 2 | /\ \ 3 | /::\ \ 4 | /:/\:\__\ 5 | /:/ /:/ _/_ 6 | /:/ /:/ /\__\ ______ _ _ ______ _____ _____ _____ ____ 7 | \:\ \/ /:/ / | ____| \ | | ____| __ \ / ____|_ _|___ \ 8 | \:\ /:/ / | |__ | \| | |__ | |__) | | __ | | __) | 9 | \:\/:/ / | __| | . ` | __| | _ /| | |_ | | | |__ < 10 | \::/ / | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 11 | \/__/ |______|_| \_|______|_| \_\\_____|_____|____/ 12 | -------------------------------------------------------------------------------- /docker-compose/setup/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | This directory is bind-mounted into container when the script `setup.sh` from 4 | the root directory is executed and is used to set up the core container for 5 | staking. 6 | 7 | Before running `setup.sh` the keystore file must be placed in the directory 8 | `.energi_core/keystore`. 9 | 10 | > It is advisable to keep a copy of the keystore file somewhere else as it will 11 | > be moved from the directory `.energi_core/keystore` to the Energi Core Node 12 | > data directory volume. 13 | -------------------------------------------------------------------------------- /docker-compose/scripts/energi-core-run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # A script to be used as a Docker container entrypoint to run 3 | # Energi Core node and unlock account for staking. 4 | 5 | /usr/sbin/sshd.pam -f "${SSHD_DIR}/sshd_config" 6 | . ./energi_command.sh 7 | exec ${energi_command} \ 8 | --gcmode archive \ 9 | --masternode \ 10 | --maxpeers 32 \ 11 | --mine=1 \ 12 | --nat extip:"$( wget -qO- https://api.ipify.org )" \ 13 | --nousb \ 14 | --password /run/secrets/account_password \ 15 | --unlock "$( cat /run/secrets/account_address )" \ 16 | --unlock.staking \ 17 | --verbosity 0 18 | -------------------------------------------------------------------------------- /docker-compose/configuration/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Configuration files for `docker-compose` 2 | 3 | The following files containing Energi Gen 3 account access data must be added to 4 | this directory before executing the command `docker-compose up --detach`: 5 | 6 | - `energi3_account_address` - contains address(es); multiple addresses must be 7 | separated with comma; 8 | - `energi3_account_password` - contains password(s); in case of multiple 9 | passwords they must be each on its own line in the same order as addresses. 10 | 11 | These files will be added to container and used to automatically unlock account 12 | for staking. 13 | -------------------------------------------------------------------------------- /scripts/linux/start_screen_mn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##################################################################### 3 | # Description: This script is to start energi core node masternode server within screen 4 | # 5 | # Download this script 6 | # wget https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/start_screen_mn.sh 7 | ##################################################################### 8 | # 9 | 10 | export PATH=$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:$HOME/energi3/bin 11 | 12 | # Start masternode in screen 13 | screen -S energi3 start_mn.sh -------------------------------------------------------------------------------- /scripts/linux/start_screen_staking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##################################################################### 3 | # Description: This script is to start energi core node masternode server within screen 4 | # 5 | # Download this script 6 | # wget https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/start_screen_staking.sh 7 | ##################################################################### 8 | # 9 | 10 | export PATH=$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:$HOME/energi3/bin 11 | 12 | # Start masternode in screen 13 | screen -S energi3 start_staking.sh -------------------------------------------------------------------------------- /docker-compose/nodemon/.env.template.env: -------------------------------------------------------------------------------- 1 | # ECNM: Energi Core Node Monitor 2 | 3 | # All environment variables are described in `ReadMe.md` (section "Environment 4 | # variables"). 5 | 6 | #DISCORD_WEBHOOK_CHANGE=yes 7 | DISCORD_WEBHOOK_ERROR= 8 | DISCORD_WEBHOOK_INFORMATION= 9 | DISCORD_WEBHOOK_SUCCESS= 10 | DISCORD_WEBHOOK_WARNING= 11 | ECNM_CURRENCY=EUR 12 | ECNM_INTERVAL=15m 13 | ECNM_SERVER_ALIAS=energi-core-node-monitor-container 14 | ECNM_SHOW_IP=no 15 | ECNM_SHOW_IP_EXTERNAL=yes 16 | MARKET_PRICE_IN_INFORMATION=no 17 | NRG_AMOUNT_IN_CURRENCY=no 18 | MESSAGE_TIME_ZONE= 19 | INTERACTIVE_SETUP=no 20 | TELEGRAM_BOT_TOKEN= 21 | #TELEGRAM_BOT_TOKEN_CHANGE=yes 22 | -------------------------------------------------------------------------------- /docker-compose/compose.override.template.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | monitor: 3 | build: 4 | args: 5 | ENERGI_BIN: "${ENERGI_BIN}" 6 | ENERGI_CORE_DIR: "${ENERGI_CORE_DIR}" 7 | ENERGI_VERSION: ${ENERGI_VERSION} 8 | STAKER_HOME: ${STAKER_HOME} 9 | context: nodemon 10 | depends_on: 11 | - core 12 | env_file: nodemon/.env 13 | environment: 14 | - TERM=xterm 15 | image: energi-node-monitor:${ENERGI_VERSION}-1.3.5-0.0 16 | restart: unless-stopped 17 | volumes: 18 | - target: "${ENERGI_CORE_DIR}" 19 | type: volume 20 | source: core-data 21 | - monitor-data:/var/multi-masternode-data/nodebot 22 | - monitor-logs:${STAKER_HOME}/log 23 | 24 | volumes: 25 | monitor-data: 26 | monitor-logs: 27 | -------------------------------------------------------------------------------- /docker-compose/compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | secrets: 4 | account_address: 5 | file: ./configuration/energi_account_address 6 | account_password: 7 | file: ./configuration/energi_account_password 8 | 9 | services: 10 | core: 11 | build: 12 | args: 13 | ENERGI_BIN: "${ENERGI_BIN}" 14 | ENERGI_CORE_DIR: "${ENERGI_CORE_DIR:?}" 15 | ENERGI_VERSION: ${ENERGI_VERSION:?"} 16 | STAKER_HOME: ${STAKER_HOME:?} 17 | context: . 18 | image: energi-core-node:${ENERGI_VERSION}-0.0 19 | ports: 20 | - 39797:39797/tcp 21 | - 39797:39797/udp 22 | restart: unless-stopped 23 | secrets: 24 | - account_address 25 | - account_password 26 | volumes: 27 | - target: "${ENERGI_CORE_DIR}" 28 | type: volume 29 | source: core-data 30 | 31 | volumes: 32 | core-data: 33 | -------------------------------------------------------------------------------- /scripts/linux/nodemon.conf: -------------------------------------------------------------------------------- 1 | # Set following to override accounts to poll; separate by space 2 | LISTACCOUNTS='' 3 | 4 | # Set currency 5 | # https://justforex.com/education/currencies 6 | # USD - US Dollar (default) 7 | # CAD - Canadian Dollar 8 | # EUR - Euro 9 | # GBP - Great Britain Pound 10 | CURRENCY='USD' 11 | 12 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | # ADVANCED SETTING - REQUIRED SETTING UP SSMTP 14 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | # Set Email, Mobile and Email-to-SMS Gateway information 16 | SENDEMAIL=N 17 | SENDSMS=N 18 | 19 | # Set EMAIL if SENDEMAIL is Y 20 | SENDTOEMAIL='' 21 | 22 | # Set SMS information if SENDSMS is Y 23 | SENDTOMOBILE='' 24 | 25 | # Email to SMS gateways in the US; set to mobile carrier 26 | # https://www.lifewire.com/sms-gateway-from-email-to-sms-text-message-2495456 27 | SENDTOGATEWAY=tmomail.net -------------------------------------------------------------------------------- /docker-compose/setup/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # A helper script to do a one time setup to use `energi-docker-compose` 3 | data_directory="$(basename "${ENERGI_CORE_DIR}")" 4 | keystore_path="${data_directory}"/keystore 5 | setup_keystore_path=setup/"${keystore_path}" 6 | staker_keystore_path="${STAKER_HOME}/${keystore_path}" 7 | user="$(basename "${STAKER_HOME}")" 8 | 9 | mkdir --parent "${staker_keystore_path}" && 10 | mv /"${setup_keystore_path}"/* "${staker_keystore_path}" || 11 | ( 12 | printf "Most probably the directory \`%s\` " "${setup_keystore_path}" && 13 | printf "does not contain keystore file(s)\n" && 14 | printf "Keystore file(s) must be copied to \`%s\` " \ 15 | "${setup_keystore_path}" && 16 | printf "before using \`./helper setup\`\n" && 17 | exit 1 18 | ) || exit 1 19 | chown -R "${user}:${user}" "${ENERGI_CORE_DIR}" 20 | 21 | # Set up ssh key for nodemon to access instance 22 | ssh-keygen -q -t rsa -N '' -f ../nodemon/.ssh/id_rsa <</dev/null 2>&1 23 | cat ../nodemon/.ssh/id_rsa.pub >> ../.ssh/authorized_keys 24 | -------------------------------------------------------------------------------- /scripts/linux/fix_mine.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ####################################################################### 4 | # Copyright (c) 2021 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Script to update --mine flag on systemd 9 | # 10 | # Version: 11 | # 1.0.0 20210406 ZAlam Initial Script 12 | 13 | : ' 14 | # Run this file 15 | 16 | ``` 17 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/fix_mine.sh)" ; source ~/.bashrc 18 | ``` 19 | ' 20 | 21 | # Systemd service file 22 | SYSTEMD_CONF="/lib/systemd/system/energi3.service" 23 | 24 | # Main script 25 | if [[ -f ${SYSTEMD_CONF} ]] 26 | then 27 | UPDATE=$( grep "\-\-mine " ${SYSTEMD_CONF} ) 28 | if [[ ! -z ${UPDATE} ]] 29 | then 30 | echo "Updated ${SYSTEMD_CONF}" 31 | sudo sed -i 's/--mine /--mine=1 /g' ${SYSTEMD_CONF} 32 | 33 | echo "run: sudo systemctl daemon-reload" 34 | 35 | else 36 | echo "No update required" 37 | 38 | fi 39 | fi 40 | -------------------------------------------------------------------------------- /scripts/utils/utils.js: -------------------------------------------------------------------------------- 1 | function checkAllBalances() { 2 | var totalBal = 0; 3 | for (var acctNum in eth.accounts) { 4 | var acct = eth.accounts[acctNum]; 5 | var acctBal = web3.fromWei(eth.getBalance(acct), "ether"); 6 | totalBal += parseFloat(acctBal); 7 | console.log(" eth.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " NRG"); 8 | } 9 | console.log(" Total balance: " + totalBal + " NRG"); 10 | return true; 11 | }; 12 | 13 | function checkBalance(acct) { 14 | var acctBal = web3.fromWei(eth.getBalance(acct), "ether"); 15 | console.log(" account:\t" + acct + " \tbalance: " + acctBal + " NRG"); 16 | return true; 17 | }; 18 | 19 | function mnBalances() { 20 | var totalBal = 0; 21 | for (var acctNum in eth.accounts) { 22 | var acct = eth.accounts[acctNum]; 23 | var acctBal = web3.fromWei(masternode.masternodeInfo(acct).collateral, "ether"); 24 | totalBal += parseFloat(acctBal); 25 | console.log(" mn.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " NRG"); 26 | } 27 | console.log(" Total balance: " + totalBal + " NRG"); 28 | return true; 29 | }; 30 | -------------------------------------------------------------------------------- /scripts/linux/ntp_fix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # Copyright (c) 2020 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Fix NTP (Network Time Protocol) on Ubuntu Linux 9 | # 10 | # Version: 11 | # 1.0.0 20200328 ZA Initial Script 12 | # 13 | : ' 14 | # Run the script to get started: 15 | ``` 16 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/ntp_fix.sh)" ; source ~/.bashrc 17 | ``` 18 | ' 19 | ###################################################################### 20 | 21 | if [ -x "$( command -v timedatectl )" ] 22 | then 23 | echo "Stopping timedatectl..." 24 | sudo timedatectl set-ntp no 25 | fi 26 | 27 | if [ ! -x "$( command -v ntp )" ] 28 | then 29 | sudo apt install ntp -y 30 | fi 31 | 32 | if [ ! -x "$( command -v ntpdate )" ] 33 | then 34 | sudo apt install ntpdate -y 35 | fi 36 | 37 | sleep 0.3 38 | clear 39 | echo 40 | echo 41 | echo "Starting ntp service..." 42 | sudo systemctl start ntp 43 | 44 | sleep 0.3 45 | echo 46 | echo 47 | echo -n "NTP status: " 48 | systemctl status ntp | grep Active | awk '{print $2}' 49 | 50 | echo 51 | 52 | -------------------------------------------------------------------------------- /scripts/linux/energi3-linux-installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # Copyright (c) 2020 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Batch script to download and setup Energi3 on Linux. The 9 | # script will upgrade an existing installation. If v2 is 10 | # installed on the VPS, the script can be used to auto migrate 11 | # from v2 to v3. 12 | # 13 | # Version: 14 | # 1.2.9 20200309 ZA Initial Script 15 | # 1.2.12 20200311 ZA added removedb to upgrade 16 | # 1.2.14 20200312 ZA added create keystore if not downloading 17 | # 1.2.15 20200423 ZA bug in _add_nrgstaker 18 | # 19 | : ' 20 | # Run the script to get started: 21 | ``` 22 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/energi3-linux-installer.sh)" ; source ~/.bashrc 23 | ``` 24 | ' 25 | ###################################################################### 26 | 27 | clear 28 | echo "Please run the following script instead:" 29 | echo " bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/energi-linux-installer.sh)"; source ~/.bashrc" 30 | echo 31 | -------------------------------------------------------------------------------- /docker-compose/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG ENERGI_VERSION 2 | 3 | FROM energicryptocurrency/energi:${ENERGI_VERSION} 4 | 5 | ARG ENERGI_BIN 6 | ARG ENERGI_CORE_DIR 7 | ARG USER_AND_GROUP_ID=1000 8 | ARG USERNAME=nrgstaker 9 | ARG STAKER_HOME 10 | 11 | ENV ENERGI_BIN="${ENERGI_BIN:?}" 12 | ENV ENERGI_CORE_DIR="${ENERGI_CORE_DIR:?}" 13 | ENV STAKER_HOME="${STAKER_HOME:?}" 14 | ENV SSHD_DIR="${STAKER_HOME}/.sshd" 15 | 16 | WORKDIR "${STAKER_HOME}/energi" 17 | 18 | RUN addgroup --gid ${USER_AND_GROUP_ID} ${USERNAME} \ 19 | && adduser \ 20 | --uid ${USER_AND_GROUP_ID} ${USERNAME} \ 21 | --ingroup ${USERNAME} \ 22 | --disabled-password; \ 23 | apk --no-cache add curl openssh-server-pam procps; \ 24 | cd "$( dirname "${ENERGI_BIN}" )" \ 25 | && ln -s energi3 "$( basename "${ENERGI_BIN}" )"; \ 26 | mkdir -p ${SSHD_DIR} \ 27 | && ssh-keygen -f ${SSHD_DIR}/host_rsa_key -N '' -t rsa \ 28 | && ssh-keygen -f ${SSHD_DIR}/host_dsa_key -N '' -t dsa; \ 29 | mkdir ${ENERGI_CORE_DIR}; \ 30 | chown -R ${USERNAME}:${USERNAME} ${STAKER_HOME} 31 | 32 | COPY --chown=${USERNAME}:${USERNAME} [ ".sshd", "${SSHD_DIR}/" ] 33 | RUN chmod 755 ${SSHD_DIR} && chmod 600 "${SSHD_DIR}/authorized_keys" 34 | 35 | COPY --chown=${USERNAME}:${USERNAME} [ "scripts", "./" ] 36 | 37 | USER ${USERNAME} 38 | 39 | ENTRYPOINT ["/bin/sh", "energi-core-run.sh"] 40 | -------------------------------------------------------------------------------- /docker-compose/nodemon/etc/rkhunter.conf.local: -------------------------------------------------------------------------------- 1 | # 2 | # These two options determine which tests are to be performed. The ENABLE_TESTS 3 | # option can use the word 'ALL' to refer to all of the available tests. The 4 | # DISABLE_TESTS option can use the word 'NONE' to mean that no tests are 5 | # disabled. The list of disabled tests is applied to the list of enabled tests. 6 | # 7 | # Both options are space-separated lists of test names, and both options may 8 | # be specified more than once. The currently available test names can be seen 9 | # by using the command 'rkhunter --list tests'. 10 | # 11 | # The supplied configuration file has some tests already disabled, and these 12 | # are tests that will be used only occasionally, can be considered 'advanced' 13 | # or that are prone to produce more than the average number of false-positives. 14 | # 15 | # Please read the README file for more details about enabling and disabling 16 | # tests, the test names, and how rkhunter behaves when these options are used. 17 | # 18 | # The default values are to enable all tests and to disable none. However, if 19 | # either of the options below are specified, then they will override the 20 | # program defaults. 21 | # 22 | #+ `os_specific` and `system_configs_syslog` were added to the default list 23 | DISABLE_TESTS=apps deleted_files hidden_ports hidden_procs os_specific packet_cap_apps suspscan system_configs_syslog 24 | -------------------------------------------------------------------------------- /scripts/linux/cleanup_logs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # Copyright (c) 2020 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Batch script to remove uncessary logs and adjust log rotate. 9 | # 10 | # Version: 11 | # 0.0.1 20200929 DT Initial Script 12 | # 1.0.0 20201012 ZA Added echo to provide information of what is being cleaned 13 | # 1.0.1 20220101 ZA Rotate log files before clean-up 14 | : ' 15 | # Run the script to get started: 16 | ``` 17 | curl -s https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/cleanup_logs.sh | bash 18 | ``` 19 | ' 20 | ###################################################################### 21 | 22 | # Rotate all log files 23 | echo "Rotating log files..." 24 | if [[ -f /home/nrgstaker/log/nodemon.log ]] 25 | then 26 | sudo chmod 644 /home/nrgstaker/log/nodemon.log 27 | fi 28 | sudo logrotate -f /etc/logrotate.conf 29 | 30 | # Removes logs ending in .gz and .1 in /var/log 31 | echo "Cleaning /var/log directory..." 32 | sudo find /var/log -name "*.gz" -exec sudo rm {} \; 33 | sudo find /var/log -name "*.1" -exec sudo rm {} \; 34 | 35 | #Request immediate rotation of the journal files and Remove journal files older than specified time 36 | echo "Cleaning up journalctl logs..." 37 | sudo journalctl --rotate 38 | sudo journalctl --vacuum-time=1s 39 | 40 | -------------------------------------------------------------------------------- /scripts/linux/start_mn.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##################################################################### 3 | # Description: This script is to start energi core node masternode server 4 | # 5 | # Download this script 6 | # wget https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/start_mn.sh 7 | ##################################################################### 8 | # 9 | 10 | export PATH=$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:$HOME/energi3/bin 11 | 12 | 13 | if [ ! -d $HOME/.energicore3/log ] 14 | then 15 | mkdir -p $HOME/.energicore3/log 16 | fi 17 | 18 | # Set variables 19 | LOGFILE=$HOME/.energicore3/log/energicore3.log 20 | JSHOME=$HOME/energi3/js 21 | #IP=`dig +short myip.opendns.com @resolver1.opendns.com` 22 | IP=`curl -s https://ifconfig.me/` 23 | 24 | if [ "x$IP" != "x" ] 25 | then 26 | energi3 \ 27 | --masternode \ 28 | --nat extip:${IP} \ 29 | --preload $JSHOME/utils.js \ 30 | --mine \ 31 | --rpc \ 32 | --rpcport 39796 \ 33 | --rpcaddr "127.0.0.1" \ 34 | --rpcapi admin,eth,web3,rpc,personal,energi \ 35 | --ws \ 36 | --wsaddr "127.0.0.1" \ 37 | --wsport 39795 \ 38 | --wsapi admin,eth,net,web3,personal,energi \ 39 | --verbosity 3 \ 40 | console 2>> $LOGFILE 41 | else 42 | echo "Lookup external IP address by going to https://ifconfig.me/" 43 | energi3 \ 44 | --masternode \ 45 | --mine \ 46 | --rpc \ 47 | --rpcport 39796 \ 48 | --rpcaddr "127.0.0.1" \ 49 | --rpcapi admin,eth,web3,rpc,personal,energi \ 50 | --ws \ 51 | --wsaddr "127.0.0.1" \ 52 | --wsport 39795 \ 53 | --wsapi admin,eth,net,web3,personal,energi \ 54 | --verbosity 3 \ 55 | console 2>> $LOGFILE 56 | fi 57 | -------------------------------------------------------------------------------- /scripts/linux/start_staking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##################################################################### 3 | # Description: This script is to start energi gen 3 node 4 | # staking server 5 | # 6 | # Download this script 7 | # wget https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/start_staking.sh 8 | ##################################################################### 9 | # 10 | 11 | export PATH=$HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:$HOME/energi3/bin 12 | 13 | # Create directory for logfile 14 | if [ ! -d $HOME/.energicore3/log ] 15 | then 16 | mkdir -p $HOME/.energicore3/log 17 | fi 18 | 19 | # Make executable 20 | if [ ! -x $HOME/energi3/bin/energi3 ] 21 | then 22 | chmod +x $$HOME/energi3/bin/energi3 23 | fi 24 | 25 | # Set variables 26 | LOGFILE=$HOME/.energicore3/log/energicore3.log 27 | JSHOME="$HOME/energi3/js" 28 | IP=`curl -s https://ifconfig.me/` 29 | 30 | if [ -f ${HOME}/.energicore3/keystore/UTC* ] 31 | then 32 | energi3 \ 33 | --preload ${JSHOME}/utils.js \ 34 | --mine \ 35 | --rpc \ 36 | --rpcport 39796 \ 37 | --rpcaddr "127.0.0.1" \ 38 | --rpcapi admin,eth,web3,rpc,personal,energi \ 39 | --ws \ 40 | --wsaddr "127.0.0.1" \ 41 | --wsport 39795 \ 42 | --wsapi admin,eth,net,web3,personal,energi \ 43 | --verbosity 3 \ 44 | console 2>> ${LOGFILE} 45 | else 46 | energi3 \ 47 | --preload ${JSHOME}/utils.js \ 48 | --rpc \ 49 | --rpcport 39796 \ 50 | --rpcaddr "127.0.0.1" \ 51 | --rpcapi admin,eth,web3,rpc,personal,energi \ 52 | --ws \ 53 | --wsaddr "127.0.0.1" \ 54 | --wsport 39795 \ 55 | --wsapi admin,eth,net,web3,personal,energi \ 56 | --verbosity 3 \ 57 | console 2>> ${LOGFILE} 58 | fi 59 | -------------------------------------------------------------------------------- /scripts/utils/getTransactionByAccount.js: -------------------------------------------------------------------------------- 1 | function getTransactionsByAccount(myaccount, startBlockNumber, endBlockNumber) { 2 | if (endBlockNumber == null) { 3 | endBlockNumber = eth.blockNumber; 4 | console.log("Using endBlockNumber: " + endBlockNumber); 5 | } 6 | if (startBlockNumber == null) { 7 | startBlockNumber = endBlockNumber - 100; 8 | console.log("Using startBlockNumber: " + startBlockNumber); 9 | } 10 | console.log("Searching for transactions to/from account \"" + myaccount + "\" within blocks " + startBlockNumber + " and " + endBlockNumber); 11 | for (var i = startBlockNumber; i <= endBlockNumber; i++) { 12 | if (i % 1000 == 0) { 13 | console.log("Searching block " + i); 14 | } 15 | var block = eth.getBlock(i, true); 16 | if (block != null && block.transactions != null) { 17 | block.transactions.forEach( function(e) { 18 | if (myaccount == "*" || myaccount == e.from || myaccount == e.to) { 19 | console.log(" tx hash : " + e.hash + "\n" 20 | + " nonce : " + e.nonce + "\n" 21 | + " blockHash : " + e.blockHash + "\n" 22 | + " blockNumber : " + e.blockNumber + "\n" 23 | + " transactionIndex: " + e.transactionIndex + "\n" 24 | + " from : " + e.from + "\n" 25 | + " to : " + e.to + "\n" 26 | + " value : " + web3.fromWei(e.value, "energi") + " NRG\n" 27 | + " time : " + block.timestamp + " " + new Date(block.timestamp * 1000).toGMTString() + "\n" 28 | + " gasPrice : " + e.gasPrice + "\n" 29 | + " gas : " + e.gas + "\n" 30 | + " input : " + e.input); 31 | } 32 | }) 33 | } 34 | } 35 | } 36 | 37 | //getTransactionsByAccount('Gen3address', startBlockNumber, endBlockNumber) 38 | 39 | 40 | -------------------------------------------------------------------------------- /scripts/windows/start_staking.bat: -------------------------------------------------------------------------------- 1 | @echo OFF 2 | 3 | ::#################################################################### 4 | :: Description: Script to start Energi Core Node 3.x on Windows 5 | :: 6 | :: Run this script 7 | :: start_staking.bat 8 | ::#################################################################### 9 | 10 | set "ENERGI3_HOME=%ProgramFiles%\Energi Gen 3" 11 | set "BIN_DIR=%ENERGI3_HOME%\bin" 12 | set "JSHOME=%ENERGI3_HOME%\js" 13 | 14 | :: Determine Version of energi3 istalled 15 | set "VERSION=" 16 | FOR /f "tokens=1*delims=: " %%a IN ('"%BIN_DIR%\energi3.exe" version' ) DO ( 17 | IF "%%a"=="Version" SET "VERSION=%%b" 18 | ) 19 | 20 | :: Check to see if running on testnet or mainnet 21 | if "%1" == "-t" ( 22 | set "ARG=-testnet" 23 | set "RPCPORT=49796" 24 | set "WSPORT=49795 25 | set "DATA_DIR=EnergiCore3\testnet\energi3" 26 | set "LOG_DIR=%APPDATA%\EnergiCore3\testnet\log" 27 | @echo Starting Energi Core Node %VERSION% for Staking in testnet 28 | ) else ( 29 | set "ARG=" 30 | set "RPCPORT=39796" 31 | set "WSPORT=39795 32 | set "DATA_DIR=EnergiCore3\energi3" 33 | set "LOG_DIR=%APPDATA%\EnergiCore3\log" 34 | @echo Starting Energi Core Node %VERSION% for Staking 35 | ) 36 | 37 | :: Create LOG_DIR 38 | if not exist %LOG_DIR% ( 39 | md %LOG_DIR% 40 | ) 41 | 42 | :: Find Internet facing IP address 43 | curl -s https://ifconfig.me/ > ipaddr.tmp 44 | set /p IP= < ipaddr.tmp 45 | del ipaddr.tmp 46 | 47 | :: 48 | :: Main start script 49 | :: 50 | @echo Changing to install directory 51 | cd "%BIN_DIR%" 52 | 53 | %DEFAULT_EXE_LOCATION%^ 54 | %ARG%^ 55 | --mine^ 56 | --preload %JSHOME%\utils.js^ 57 | --rpc^ 58 | --rpcport %RPCPORT%^ 59 | --rpcaddr "127.0.0.1"^ 60 | --rpcapi admin,eth,web3,rpc,personal,energi^ 61 | --ws^ 62 | --wsaddr "127.0.0.1"^ 63 | --wsport %WSPORT%^ 64 | --wsapi admin,eth,net,web3,personal,energi^ 65 | --verbosity 3 console 2>> %%LOG_DIR%\energicore3.log% 66 | 67 | pause 68 | -------------------------------------------------------------------------------- /scripts/macos/start_staking.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ##################################################################### 3 | # Description: This script is to start energi gen 3 node staking server 4 | # 5 | # Download this script 6 | # wget https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/start_staking.sh 7 | ##################################################################### 8 | # 9 | 10 | export PATH=$PATH:$HOME/energi3/bin 11 | 12 | # Create directory for logfile 13 | if [ ! -d "${HOME}/Library/EnergiCore3/testnet/log" ] 14 | then 15 | mkdir -p "${HOME}/Library/EnergiCore3/testnet/log" 16 | fi 17 | 18 | # Install dig which is part of bind 19 | #brew install bind 20 | 21 | # Make executable 22 | if [ ! -x $HOME/energi3/bin/energi3 ] 23 | then 24 | chmod +x $HOME/energi3/bin/energi3 25 | fi 26 | 27 | # Set variables 28 | LOGFILE="${HOME}/Library/EnergiCore3/testnet/log/energicore3.log" 29 | JSHOME="$HOME/energi3/js" 30 | IP=`curl -s https://ifconfig.me/` 31 | 32 | # Start staking server 33 | if [ -f ${HOME}/Library/EnergiCore3/testnet/keystore/UTC* ] 34 | then 35 | energi3 \ 36 | --preload ${JSHOME}/utils.js \ 37 | --mine \ 38 | --rpc \ 39 | --rpcport 39796 \ 40 | --rpcaddr "127.0.0.1" \ 41 | --rpcapi admin,eth,web3,rpc,personal,energi \ 42 | --ws \ 43 | --wsaddr "127.0.0.1" \ 44 | --wsport 39795 \ 45 | --wsapi admin,eth,net,web3,personal,energi \ 46 | --verbosity 3 \ 47 | console 2>> ${LOGFILE} 48 | else 49 | energi3 \ 50 | --preload ${JSHOME}/utils.js \ 51 | --rpc \ 52 | --rpcport 39796 \ 53 | --rpcaddr "127.0.0.1" \ 54 | --rpcapi admin,eth,web3,rpc,personal,energi \ 55 | --ws \ 56 | --wsaddr "127.0.0.1" \ 57 | --wsport 39795 \ 58 | --wsapi admin,eth,net,web3,personal,energi \ 59 | --verbosity 3 \ 60 | console 2>> ${LOGFILE} 61 | fi 62 | 63 | -------------------------------------------------------------------------------- /scripts/windows/start_mn.bat: -------------------------------------------------------------------------------- 1 | @echo OFF 2 | 3 | ::#################################################################### 4 | :: Description: Script to start Energi Core Node 3.x on Windows 5 | :: 6 | :: Run script: start_mn.bat 7 | ::#################################################################### 8 | 9 | set "ENERGI3_HOME=%ProgramFiles%\Energi Gen 3" 10 | set "BIN_DIR=%ENERGI3_HOME%\bin" 11 | set "JSHOME=%ENERGI3_HOME%\js" 12 | 13 | :: Determine Version of energi3 istalled 14 | set "VERSION=" 15 | FOR /f "tokens=1*delims=: " %%a IN ('"%BIN_DIR%\energi3.exe" version' ) DO ( 16 | IF "%%a"=="Version" SET "VERSION=%%b" 17 | ) 18 | 19 | :: Check to see if running on testnet or mainnet 20 | if "%1" == "-t" ( 21 | set "ARG=-testnet" 22 | set "RPCPORT=49796" 23 | set "WSPORT=49795 24 | set "DATA_DIR=EnergiCore3\testnet\energi3" 25 | set "LOG_DIR=%APPDATA%\EnergiCore3\testnet\log" 26 | @echo Starting Energi Core Node %VERSION% for Masternode in testnet 27 | ) else ( 28 | set "ARG=" 29 | set "RPCPORT=39796" 30 | set "WSPORT=39795 31 | set "DATA_DIR=EnergiCore3\energi3" 32 | set "LOG_DIR=%APPDATA%\EnergiCore3\log" 33 | @echo Starting Energi Core Node %VERSION% for Masternode 34 | ) 35 | 36 | :: Create LOG_DIR 37 | if not exist %LOG_DIR% ( 38 | md %LOG_DIR% 39 | ) 40 | 41 | :: Find Internet facing IP address 42 | curl -s https://ifconfig.me/ > %TEMP%\ipaddr.tmp 43 | set /p IP= < %TEMP%\ipaddr.tmp 44 | del %TEMP%\ipaddr.tmp 45 | 46 | :: 47 | :: Main start script 48 | :: 49 | @echo Changing to install directory 50 | cd "%BIN_DIR%" 51 | 52 | "%BIN_DIR%\energi3.exe"^ 53 | %ARG%^ 54 | --masternode^ 55 | --nat extip:%IP%^ 56 | --mine^ 57 | --preload "%JSHOME%\utils.js"^ 58 | --rpc^ 59 | --rpcport %RPCPORT%^ 60 | --rpcaddr "127.0.0.1"^ 61 | --rpcapi admin,eth,web3,rpc,personal,energi^ 62 | --ws^ 63 | --wsaddr "127.0.0.1"^ 64 | --wsport %WSPORT%^ 65 | --wsapi admin,eth,net,web3,personal,energi^ 66 | --verbosity 3 console 2>> "%LOG_DIR%\energicore3.log" 67 | -------------------------------------------------------------------------------- /scripts/macos/start_mn.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ##################################################################### 3 | # Description: This script is to start energi core node masternode server 4 | # 5 | # Download this script 6 | # curl -sL https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/macos/start_mn.sh 7 | ##################################################################### 8 | # 9 | 10 | export PATH=$PATH:$HOME/energi3/bin 11 | 12 | # Create directory for logfile 13 | if [ ! -d "${HOME}/Library/EnergiCore3/log" ] 14 | then 15 | mkdir -p "${HOME}/Library/EnergiCore3/log" 16 | fi 17 | 18 | # Install dig which is part of bind 19 | #brew install bind 20 | 21 | # Make executable 22 | if [ ! -x $HOME/energi3/bin/energi3 ] 23 | then 24 | chmod +x $HOME/energi3/bin/energi3 25 | fi 26 | 27 | # Set variables 28 | LOGFILE="${HOME}/Library/EnergiCore3/log/energicore3.log" 29 | JSHOME="${HOME}/energi3/js" 30 | #IP=`dig +short myip.opendns.com @resolver1.opendns.com` 31 | IP=`curl -s https://ifconfig.me/` 32 | 33 | if [ "x$IP" != "x" ] 34 | then 35 | energi3 \ 36 | --masternode \ 37 | --nat extip:${IP} \ 38 | --preload $JSHOME/utils.js \ 39 | --mine \ 40 | --rpc \ 41 | --rpcport 39796 \ 42 | --rpcaddr "127.0.0.1" \ 43 | --rpcapi admin,eth,web3,rpc,personal,energi \ 44 | --ws \ 45 | --wsaddr "127.0.0.1" \ 46 | --wsport 39795 \ 47 | --wsapi admin,eth,net,web3,personal,energi \ 48 | --verbosity 3 \ 49 | console 2>> $LOGFILE 50 | 51 | else 52 | echo "Lookup external IP address by going to https://ifconfig.me/" 53 | energi3 \ 54 | --masternode \ 55 | --mine \ 56 | --rpc \ 57 | --rpcport 39796 \ 58 | --rpcaddr "127.0.0.1" \ 59 | --rpcapi admin,eth,web3,rpc,personal,energi \ 60 | --ws \ 61 | --wsaddr "127.0.0.1" \ 62 | --wsport 39795 \ 63 | --wsapi admin,eth,net,web3,personal,energi \ 64 | --verbosity 3 \ 65 | console 2>> $LOGFILE 66 | fi 67 | -------------------------------------------------------------------------------- /scripts/linux/bootnodes-testnet.txt: -------------------------------------------------------------------------------- 1 | admin.addPeer("enode://a98599cc6e712c97dfd1542ab6e90a47853fabe5a8623b2d752449cd683464d6730d5e58999a6cf874c29c34d531d9e5607b20f3ea286ad37ef7d1fdd1bf34dd@154.26.139.253:49797") 2 | admin.addPeer("enode://c1e36d7e879d7c151bc6916086de5b5ab5040db8c537aad796d19a20b515db9e5c4b9325de40c68daa62e5776c254488e7f0e5a0c00f19b60b84b8cbb59d2ab3@5.104.82.113:49797") 3 | admin.addPeer("enode://845162ce24c4d7ac6002126e90cdfa8193f8ea37e599771207e9bcdd8ff916691963fe90e8f452038f96aa0b9efc5a2c98c863258725040e3f1f52576e25452c@154.53.36.179:49797") 4 | admin.addPeer("enode://e07d2adb87530bf59159286a9f58a61737bb8994cfaa404aa4bab227dbf4d186f36d90c17af6fca3ab4bbdd37e6caa9e342a86c3857b11c1fb045415ea78b043@154.12.246.160:49797") 5 | admin.addPeer("enode://350fa8da6df442d6c8a579777e9d67929cc29227b0d09195c2a2ebeb3f8e19569a7a2118dd8d1f75f365d6f40590806cad00a93792211aa07ded38fcd22dbc1c@154.26.155.62:49797") 6 | admin.addPeer("enode://2e24cf5f5f6af4f7d2f407276f31bdbc620710c028e1e859e82d83cc3e7e254e5af2f4a1d4f2b67429890d06b7b228060f9a5cdca4e549d3deb785b6a849a235@95.179.193.170:49797") 7 | admin.addTrustedPeer("enode://a98599cc6e712c97dfd1542ab6e90a47853fabe5a8623b2d752449cd683464d6730d5e58999a6cf874c29c34d531d9e5607b20f3ea286ad37ef7d1fdd1bf34dd@154.26.139.253:49797") 8 | admin.addTrustedPeer("enode://c1e36d7e879d7c151bc6916086de5b5ab5040db8c537aad796d19a20b515db9e5c4b9325de40c68daa62e5776c254488e7f0e5a0c00f19b60b84b8cbb59d2ab3@5.104.82.113:49797") 9 | admin.addTrustedPeer("enode://845162ce24c4d7ac6002126e90cdfa8193f8ea37e599771207e9bcdd8ff916691963fe90e8f452038f96aa0b9efc5a2c98c863258725040e3f1f52576e25452c@154.53.36.179:49797") 10 | admin.addTrustedPeer("enode://e07d2adb87530bf59159286a9f58a61737bb8994cfaa404aa4bab227dbf4d186f36d90c17af6fca3ab4bbdd37e6caa9e342a86c3857b11c1fb045415ea78b043@154.12.246.160:49797") 11 | admin.addTrustedPeer("enode://350fa8da6df442d6c8a579777e9d67929cc29227b0d09195c2a2ebeb3f8e19569a7a2118dd8d1f75f365d6f40590806cad00a93792211aa07ded38fcd22dbc1c@154.26.155.62:49797") 12 | admin.addTrustedPeer("enode://2e24cf5f5f6af4f7d2f407276f31bdbc620710c028e1e859e82d83cc3e7e254e5af2f4a1d4f2b67429890d06b7b228060f9a5cdca4e549d3deb785b6a849a235@95.179.193.170:49797") 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # energi3-provisioning 2 | 3 | ## Scripts 4 | 5 | This repository has provisioning scripts as well as startup scrits for Energi Core Node 6 | 7 | - Linux / VPS
8 | -- energi3-linux-installer.sh : Provisioning Script for amd64 or x86_64 Linux 9 | -- energi3-aarch64-installer.sh : Provisioning Script for RPi and i386 (32-bit Linux) 10 | -- start_staking.sh : Start Staking
11 | -- start_screen_staking.sh : Start Staking within `screen`
12 | -- start_mn.sh : Start Masternode
13 | -- start_screen_mn.sh : Start Masternode within `screen`
14 | -- energi3-cli : Wrapper command-line script
15 | 16 | - Windows
17 | -- energi3-windows-installer.bat : Provisioning Script
18 | -- start_mn.bat : Start Masternode
19 | -- start_staking.bat : Start Staking
20 | -- energi3.ico : Energi Icon Logo
21 | 22 | - MacOS
23 | -- energi3-macos-installer.sh : Provisioning Script
24 | -- start_node.sh : Script to start staking/mastrnode in mainnet or testnet
25 | -- start_staking.sh : Start Staking
26 | -- start_mn.sh : Start Masternode
27 | 28 | ## Add Peers 29 | If you are having issues with low peer nodes, do the following. 30 | 31 | - 1. If you are running your core on a Linux VPS, [login to the VPS](https://wiki.energi.world/docs/guides/scripted-linux-installation#2---login-to-your-vps) 32 | - 2. Attach to core node 33 | - Linux / Mac: Run `energi3 attach` 34 | - Windows: Start [Attach](https://wiki.energi.world/docs/guides/core-node-windows#2---start-core-node--attach) 35 | 36 | - 3. Goto [list of bootnode](./scripts/linux/bootnodes-mainnet.txt) and copy the content. 37 | 38 | - 4. Paste the content to core node console. 39 | 40 | ## SDK Configuration Files 41 | 42 | - hardhat : Hardhad config files 43 | - truffle : Truffle config files 44 | 45 | ## Energi Docker Compose 46 | 47 | Files in `docker-compose` are meant to be used to spin up a Docker environment to run Energi Core node. It is monitored via `nodemon` which can send alerts to Discord and/or Telegram. 48 | -------------------------------------------------------------------------------- /docker-compose/nodemon/Dockerfile: -------------------------------------------------------------------------------- 1 | # Build the binary `energi3` in a stock Go builder container 2 | FROM golang:1.15-buster as energi-builder 3 | 4 | ARG ENERGI_VERSION 5 | 6 | RUN apt-get update \ 7 | && apt-get install --assume-yes --no-install-recommends --quiet musl-dev; \ 8 | git clone --branch ${ENERGI_VERSION} --depth 1 \ 9 | https://github.com/energicryptocurrency/energi.git energi \ 10 | && cd energi \ 11 | && make geth 12 | 13 | 14 | # `ubuntu:latest` means "The latest Ubuntu LTS release" 15 | # https://hub.docker.com/_/ubuntu 16 | FROM ubuntu:latest 17 | 18 | ARG DEBIAN_FRONTEND=noninteractive 19 | ARG ECNM_DATA_DIR=/var/multi-masternode-data/nodebot 20 | ARG ENERGI_BIN 21 | ARG ENERGI_CORE_DIR 22 | ARG LOG_DIR=/var/log 23 | ARG USER_AND_GROUP_ID=1000 24 | ARG USERNAME=nrgstaker 25 | ARG STAKER_HOME 26 | ARG NODEMON_LOG_DIR=${STAKER_HOME}/log 27 | ARG SSH_DIR=${STAKER_HOME}/.ssh 28 | 29 | ENV ENERGI_BIN="${ENERGI_BIN:?}" 30 | ENV ENERGI_CORE_DIR="${ENERGI_CORE_DIR:?}" 31 | ENV STAKER_HOME=${STAKER_HOME:?} 32 | 33 | RUN apt-get update --quiet \ 34 | && apt-get upgrade --assume-yes --quiet \ 35 | && apt-get install --assume-yes --no-install-recommends --quiet \ 36 | bc \ 37 | ca-certificates \ 38 | curl \ 39 | debsums \ 40 | init \ 41 | jq \ 42 | logrotate \ 43 | ntpdate \ 44 | openssh-client \ 45 | rkhunter \ 46 | sqlite3 \ 47 | sudo \ 48 | tzdata \ 49 | wget; \ 50 | apt-get clean all \ 51 | && rm --recursive --force /var/lib/apt/lists/*; \ 52 | addgroup --gid ${USER_AND_GROUP_ID} ${USERNAME} \ 53 | && adduser \ 54 | --uid ${USER_AND_GROUP_ID} ${USERNAME} \ 55 | --ingroup ${USERNAME} \ 56 | --disabled-password \ 57 | --quiet; \ 58 | usermod --append --groups sudo ${USERNAME}; \ 59 | mkdir --parents ${ECNM_DATA_DIR} \ 60 | && chown --recursive ${USERNAME} ${ECNM_DATA_DIR}; \ 61 | mkdir --parents "${ENERGI_CORE_DIR}" \ 62 | && mkdir --parents ${SSH_DIR}; \ 63 | mkdir --parents ${NODEMON_LOG_DIR} \ 64 | && touch ${NODEMON_LOG_DIR}/nodemon.log; \ 65 | chown --recursive ${USERNAME}:${USERNAME} ${STAKER_HOME}; \ 66 | touch ${LOG_DIR}/auth.log \ 67 | && touch ${LOG_DIR}/kern.log 68 | 69 | COPY --from=energi-builder [ "/go/energi/build/bin/energi3", "${ENERGI_BIN}" ] 70 | COPY --chown=${USERNAME}:${USERNAME} [ ".ssh", "${SSH_DIR}/" ] 71 | COPY [ "etc", "/etc" ] 72 | 73 | RUN chmod +x ${ENERGI_BIN} && chmod -R 600 ${SSH_DIR}/id_rsa 74 | 75 | WORKDIR ${STAKER_HOME} 76 | 77 | COPY --chown=${USERNAME}:${USERNAME} [ "scripts", "./" ] 78 | 79 | USER ${USERNAME} 80 | 81 | ENTRYPOINT [ "bash", "nodemon_cron.sh" ] 82 | -------------------------------------------------------------------------------- /docker-compose/nodemon/scripts/nodemon_helper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | value_to_bool() { 4 | value="${1,,}" 5 | 6 | if 7 | [[ "${value}" == 'y' ]] || 8 | [[ "${value}" == 'yes' ]] || 9 | [[ "${value}" == 'true' ]] || 10 | [[ "${value}" -eq 1 ]] 11 | then 12 | return 0 13 | fi 14 | 15 | return 1 16 | } 17 | 18 | ip_address() { 19 | if value_to_bool "${ECNM_SHOW_IP_EXTERNAL:-no}"; then 20 | IP_ADDRESS="$(wget -qO- https://api.ipify.org)" 21 | else 22 | IP_ADDRESS="$(hostname -i)" 23 | fi 24 | 25 | printf '%s' "${IP_ADDRESS}" 26 | } 27 | 28 | market_price() { 29 | if [[ -z "${NRGMKTPRICE}" ]]; then 30 | timestamp="${1}" 31 | endpoint="https://min-api.cryptocompare.com/data/price?fsym=NRG&tsyms=${CURRENCY}" 32 | 33 | if [[ -n "${timestamp}" ]]; then 34 | endpoint="${endpoint}&ts=${timestamp}" 35 | fi 36 | 37 | NRGMKTPRICE="$(curl \ 38 | --connect-timeout 30 \ 39 | --header "Accept: application/json" \ 40 | --silent \ 41 | "${endpoint}" | 42 | jq ".${CURRENCY}")" 43 | fi 44 | } 45 | 46 | message_date() { 47 | TZ="${MESSAGE_TIME_ZONE}" date -R 48 | } 49 | 50 | nrg_amount_info() { 51 | label="${1:?}" 52 | nrg_balance="${2:?}" 53 | balance_text="${label}: " 54 | balance_indentation="${#balance_text}" 55 | balance_text="$(printf '%s%s NRG\n' "${balance_text}" "${nrg_balance}")" 56 | market_price '' 57 | 58 | if value_to_bool "${NRG_AMOUNT_IN_CURRENCY}"; then 59 | balance_text="$(printf '%s\n%*s%s %s' \ 60 | "${balance_text}" \ 61 | "${balance_indentation}" \ 62 | " " \ 63 | "$(printf '%.2f' \ 64 | "$(printf '%s * %s\n' "${nrg_balance}" "${NRGMKTPRICE}" | bc)")" \ 65 | "${CURRENCY}")" 66 | fi 67 | 68 | printf '%s' "${balance_text}" 69 | } 70 | 71 | nrg_difference_info() { 72 | nrg_amount_info 'Difference' "${1:?}" 73 | } 74 | 75 | masternode_reward_info() { 76 | nrg_amount_info 'Masternode Reward' "${1:?}" 77 | } 78 | 79 | new_balance_info() { 80 | nrg_amount_info 'New Balance' "${1:?}" 81 | } 82 | 83 | override_read() { 84 | if value_to_bool "${INTERACTIVE}"; then 85 | printf '%s\n' "${1}" 86 | REPLY="${1}" 87 | else 88 | read -e -i "${1}" -r 89 | fi 90 | } 91 | 92 | stake_reward_info() { 93 | nrg_amount_info 'Stake Reward' "${1:?}" 94 | } 95 | 96 | total_node_balance() { 97 | masternode_collateral=${1} 98 | staking_balance=${2} 99 | printf '%s' "$(printf '%s\n' "${masternode_collateral} + ${staking_balance}" | 100 | bc -l | 101 | sed '/\./ s/\.\{0,1\}0\{1,\}$//')" 102 | } 103 | -------------------------------------------------------------------------------- /sdk/hardhat/hardhat.config.js: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Energi Core Authors 2 | // This file is part of the Energi Core library. 3 | // 4 | // The Energi Core library is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Lesser General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // The Energi Core library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Lesser General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public License 15 | // along with the Energi Core library. If not, see . 16 | // 17 | 18 | require("@nomicfoundation/hardhat-toolbox"); 19 | require('dotenv').config(); 20 | 21 | // set variables from .env file 22 | const { RPC_URL, ACCOUNT_PRIVATE_KEY } = process.env; 23 | 24 | // Configure network accounts 25 | const { DEV_ACCOUNTS } = require('./common/constants'); 26 | const devAccounts = DEV_ACCOUNTS; 27 | 28 | /** @type import('hardhat/config').HardhatUserConfig */ 29 | module.exports = { 30 | solidity: { 31 | version: '0.8.17', 32 | settings: { 33 | evmVersion: 'istanbul', 34 | optimizer: { 35 | enabled: true, 36 | runs: 200, 37 | }, 38 | }, 39 | }, 40 | defaultNetwork: "hardhat", 41 | networks: { 42 | hardhat: { 43 | accounts: devAccounts, 44 | blockGasLimit: 10000000, 45 | }, 46 | energiMainnet: { 47 | chainId: 39797, 48 | url: String(RPC_URL || "https://nodeapi.energi.network"), 49 | gas: 1000000, 50 | gasPrice: 20000000000, // 20 GWei 51 | accounts: [`0x${ACCOUNT_PRIVATE_KEY}`], 52 | }, 53 | energiTestnet: { 54 | chainId: 49797, 55 | url: String(RPC_URL || "https://nodeapi.test.energi.network"), 56 | gas: 1000000, 57 | gasPrice: 20000000000, // 20 GWei 58 | accounts: [`0x${ACCOUNT_PRIVATE_KEY}`], 59 | }, 60 | }, 61 | etherscan: { 62 | apiKey: { 63 | energiTestnet: 'xxxxx-no-api-key-needed-xxxxx', 64 | energiMainnet: 'xxxxx-no-api-key-needed-xxxxx' 65 | }, 66 | customChains: [ 67 | { 68 | network: "energiMainnet", 69 | chainId: 39797, 70 | urls: { 71 | apiURL: "https://explorer.energi.network/api", 72 | browserURL: "https://explorer.energi.network" 73 | }, 74 | }, 75 | { 76 | network: "energiTestnet", 77 | chainId: 49797, 78 | urls: { 79 | apiURL: "https://explorer.test.energi.network/api", 80 | browserURL: "https://explorer.test.energi.network" 81 | }, 82 | }, 83 | ] 84 | }, 85 | }; 86 | -------------------------------------------------------------------------------- /scripts/macos/start_node.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ##################################################################### 3 | # Description: This script is to start energi core node masternode server 4 | # 5 | # Download this script 6 | # curl -sL https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/macos/start_node.sh 7 | ##################################################################### 8 | # 9 | 10 | export PATH="$PATH:$HOME/energi3/bin" 11 | ARG='' 12 | LOGFILE='' 13 | NETWORK=mainnet 14 | RPCPORT=39796 15 | WSPORT=39795 16 | 17 | # Make executable 18 | if [ ! -x "$HOME/energi3/bin/energi3" ] 19 | then 20 | chmod +x "$HOME/energi3/bin/energi3" 21 | fi 22 | 23 | while [[ $# -gt 0 ]] 24 | do 25 | key="$1"; shift 26 | 27 | case $key in 28 | -t|-testnet|--testnet) 29 | NETWORK=testnet 30 | ARG="${ARG} -testnet" 31 | RPCPORT=49796 32 | WSPORT=49795 33 | ;; 34 | -m|-masternode|--masternode) 35 | ARG="$ARG --masternode" 36 | ;; 37 | -d|-debug) 38 | set -x 39 | ;; 40 | -h|-help) 41 | cat << EOL 42 | 43 | start_node.sh arguments: 44 | -t -testnet : Run in testnet 45 | -m -masternode : Run masternode mode 46 | -h --help : Display this help text 47 | -d --debug : Debug mode 48 | 49 | EOL 50 | exit 51 | ;; 52 | esac 53 | done 54 | 55 | 56 | # Set variables 57 | if [ "${NETWORK}" = "mainnet" ] 58 | then 59 | LOGFILE="${HOME}/Library/EnergiCore3/log/energicore3.log" 60 | # Create directory for logfile 61 | if [ ! -d "${HOME}/Library/EnergiCore3/log" ] 62 | then 63 | mkdir -p "${HOME}/Library/EnergiCore3/log" 64 | fi 65 | else 66 | LOGFILE="${HOME}/Library/EnergiCore3/testnet/log/energicore3.log" 67 | # Create directory for logfile 68 | if [ ! -d "${HOME}/Library/EnergiCore3/testnet/log" ] 69 | then 70 | mkdir -p "${HOME}/Library/EnergiCore3/testnet/log" 71 | fi 72 | 73 | fi 74 | 75 | JSHOME="${HOME}/energi3/js" 76 | IP=`curl -s https://ifconfig.me/` 77 | 78 | # Start Eenrgi Core Node 79 | if [ "x$IP" != "x" ] 80 | then 81 | energi3 \ 82 | ${ARG} \ 83 | --nat extip:${IP} \ 84 | --preload $JSHOME/utils.js \ 85 | --mine \ 86 | --rpc \ 87 | --rpcport ${RPCPORT} \ 88 | --rpcaddr "127.0.0.1" \ 89 | --rpcapi admin,eth,web3,rpc,personal,energi \ 90 | --ws \ 91 | --wsaddr "127.0.0.1" \ 92 | --wsport ${WSPORT} \ 93 | --wsapi admin,eth,net,web3,personal,energi \ 94 | --verbosity 3 \ 95 | console 2>> $LOGFILE 96 | 97 | else 98 | echo "Lookup external IP address by going to https://ifconfig.me/" 99 | energi3 \ 100 | ${ARG} \ 101 | --mine \ 102 | --rpc \ 103 | --rpcport ${RPCPORT} \ 104 | --rpcaddr "127.0.0.1" \ 105 | --rpcapi admin,eth,web3,rpc,personal,energi \ 106 | --ws \ 107 | --wsaddr "127.0.0.1" \ 108 | --wsport ${WSPORT} \ 109 | --wsapi admin,eth,net,web3,personal,energi \ 110 | --verbosity 3 \ 111 | console 2>> $LOGFILE 112 | 113 | fi 114 | -------------------------------------------------------------------------------- /scripts/linux/mn_payout_time.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Description: mn_payout_time.sh 4 | # 5 | # Script to get the rank and time to receive masternode reward 6 | # 7 | # Written: ZAlam 11-Nov-2020 Initial Script 8 | # 9 | # bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/mn_payout_time.sh)" ; source ~/.bashrc 10 | # 11 | 12 | #set -x 13 | 14 | # Convert seconds to days, hours, minutes, seconds. 15 | DISPLAYTIME () { 16 | # Round up the time. 17 | local T=0 18 | T=$( printf '%.*f\n' 0 "${1}" ) 19 | local D=$(( T/60/60/24 )) 20 | local H=$(( T/60/60%24 )) 21 | local M=$(( T/60%60 )) 22 | local S=$(( T%60 )) 23 | (( D > 0 )) && printf '%d days ' "${D}" 24 | (( H > 0 )) && printf '%d hr ' "${H}" 25 | (( M > 0 )) && printf '%d min ' "${M}" 26 | (( S > 0 )) && printf '%d sec ' "${S}" 27 | } 28 | 29 | COMMAND="energi3 attach --exec " 30 | 31 | #clear screen 32 | clear 33 | 34 | # Set an address if you want 35 | #MNADDR= 36 | 37 | # Get list of accounts from core node 38 | if [[ -z ${MNADDR} ]] 39 | then 40 | echo "Getting list of accounts..." 41 | MNADDR=$( ${COMMAND} "personal.listAccounts" 2>/dev/null | jq -r '.[]' ) 42 | fi 43 | 44 | # Main program 45 | for ADDR in `echo ${MNADDR}` 46 | do 47 | ISMN=$( ${COMMAND} "masternode.masternodeInfo('$ADDR').announcedBlock" 2>/dev/null ) 48 | 49 | if [[ ${ISMN} -eq 0 ]] 50 | then 51 | echo "${ADDR} is not a masternode." 52 | 53 | else 54 | 55 | # Get masternode list 56 | echo -e "Scanning List of Masternodes for Address: ${MNADDR}\nThis will take a moment." 57 | ${COMMAND} "masternode.listMasternodes()" 2>/dev/null > mnList.json 58 | 59 | # convert to lower case 60 | ADDR=${ADDR,,} # tolower 61 | 62 | sed -i 's/announcedBlock/"announcedBlock"/g' mnList.json 63 | sed -i 's/collateral/"collateral"/g' mnList.json 64 | sed -i 's/enode: /"enode": /g' mnList.json 65 | sed -i 's/isActive/"isActive"/g' mnList.json 66 | sed -i 's/isAlive/"isAlive"/g' mnList.json 67 | sed -i 's/masternode/"masternode"/g' mnList.json 68 | sed -i 's/owner/"owner"/g' mnList.json 69 | sed -i 's/swFeatures/"swFeatures"/g' mnList.json 70 | sed -i 's/swVersion/"swVersion"/g' mnList.json 71 | 72 | COUNTER=0 73 | TOTCOL=0 74 | 75 | for MNLIST in `cat mnList.json | jq -r '.[] | select (.isActive == true) | select (.swFeatures != "0x0")' | grep owner | awk -F\" '{print $4}'` 76 | do 77 | 78 | COL=$( cat mnList.json | jq --arg COUNTER ${COUNTER} '.[$COUNTER | tonumber] .collateral | tonumber' ) 79 | COL=$( printf "%.0f" $COL ) 80 | COL=$( echo " ${COL} / 1000000000000000000 " | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//' ) 81 | 82 | TOTCOL=$( echo "$TOTCOL + $COL" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//' ) 83 | 84 | COUNTER=$(( COUNTER + 1 )) 85 | 86 | if [[ "${MNLIST}" == "${ADDR}" ]] 87 | then 88 | TIME_TO_REWARD=$( echo "$TOTCOL / 10000 * 60" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//' ) 89 | TIME_TO_REWARD=$( DISPLAYTIME "${TIME_TO_REWARD}" ) 90 | 91 | echo "Address: ${MNLIST} 92 | Rank: ${COUNTER} 93 | ETA: ${TIME_TO_REWARD}" 94 | exit 95 | fi 96 | done 97 | 98 | rm mnList.json 99 | fi 100 | done 101 | -------------------------------------------------------------------------------- /scripts/linux/missing_stake_rewards.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -x 4 | 5 | # Load parameters from external conf file 6 | if [[ -f /var/multi-masternode-data/nodebot/nodemon.conf ]] 7 | then 8 | . /var/multi-masternode-data/nodebot/nodemon.conf 9 | fi 10 | 11 | # get username; exclude testnet 12 | USRNAME=$( find /home -name nodekey 2>&1 | grep -v "Permission denied" | grep -v testnet | awk -F\/ '{print $3}' ) 13 | 14 | # check for energi 15 | BINLOC=$( find /home/${USRNAME} -type f -name energi -executable 2>&1 | grep -v "Permission denied" ) 16 | COMMAND="energi attach --exec " 17 | 18 | # check for energi3 if energi not installed 19 | if [ ! -z ${BINLOC} ] 20 | then 21 | echo "Using binary name: energi" 22 | else 23 | BINLOC=$( find /home/${USRNAME} -type f -name energi3 -executable 2>&1 | grep -v "Permission denied" ) 24 | COMMAND="energi3 attach --exec " 25 | echo "Using binary name: energi3" 26 | fi 27 | 28 | # Extract path to binary 29 | EXECPATH=$( dirname ${BINLOC} ) 30 | 31 | # set PATH 32 | export PATH=$PATH:${EXECPATH} 33 | 34 | # Get list of accounts from core node 35 | if [[ -z ${LISTACCOUNTS} ]] 36 | then 37 | LISTACCOUNTS=$( ${COMMAND} "personal.listAccounts" 2>/dev/null | jq -r '.[]' ) 38 | fi 39 | 40 | # Check if CURRENCY is set 41 | if [ ! -z $CURRENCY} ] 42 | then 43 | CURRENCY=USD 44 | fi 45 | 46 | # SQL Data Store 47 | SQL_QUERY () { 48 | if [[ ! -d /var/multi-masternode-data/nodebot ]] 49 | then 50 | sudo mkdir -p /var/multi-masternode-data/nodebot 51 | fi 52 | sudo sqlite3 -batch /var/multi-masternode-data/nodebot/nodemon.db "${1}" 53 | } 54 | 55 | # No way to determine at the time. Assume default 56 | REWARDAMT=2.28 57 | 58 | for ADDR in ${LISTACCOUNTS} 59 | do 60 | 61 | # to lower case 62 | ADDR=$( echo ${ADDR} | tr '[:upper:]' '[:lower:]' ) 63 | 64 | echo "Downloading blocks mined by ${ADDR}..." 65 | curl -H "accept: application/json" -s "https://explorer.energi.network/api?module=account&action=getminedblocks&address=${ADDR}" -H "accept: application/json" > list_blk_mined.txt 66 | 67 | cat list_blk_mined.txt | jq -r '.result[] .blockNumber' | sort -u -n > blk_mined.txt 68 | 69 | # ACCTBALANCE=$( $COMMAND "web3.fromWei(nrg.getBalance('$ADDR'), 'energi')" 2>/dev/null ) 70 | ACCTBALANCE='' 71 | NRGMKTPRICE='' 72 | 73 | for i in `cat blk_mined.txt` 74 | do 75 | 76 | CHKBLOCK=$i 77 | 78 | CHKDB=$( SQL_QUERY "select * from stake_rewards where blockNum = '${CHKBLOCK}';" ) 79 | 80 | if [ -z ${CHKDB} ] 81 | then 82 | 83 | REWARDTIME=$( ${COMMAND} "nrg.getBlock($CHKBLOCK).timestamp" 2>/dev/null ) 84 | BLKMINER=$( ${COMMAND} "nrg.getBlock($CHKBLOCK).miner" 2>/dev/null | jq -r '.' | tr '[:upper:]' '[:lower:]' ) 85 | 86 | if [ "${ADDR}" = "${BLKMINER}" ] 87 | then 88 | echo "Processing block ${CHKBLOCK}" 89 | NRGMKTPRICE=$( curl -H "Accept: application/json" --connect-timeout 30 -s "https://min-api.cryptocompare.com/data/price?fsym=NRG&tsyms=${CURRENCY}&ts=${REWARDTIME}" | jq .${CURRENCY} ) 90 | 91 | if [[ ! $NRGMKTPRICE =~ ^[+-]?[0-9]+\.?[0-9]*$ ]] 92 | then 93 | NRGMKTPRICE='' 94 | fi 95 | 96 | SQL_QUERY "INSERT INTO stake_rewards (stakeAddress, rewardTime, blockNum, Reward, balance, nrgPrice) 97 | VALUES ('${ADDR}','${REWARDTIME}','${CHKBLOCK}','${REWARDAMT}', '${ACCTBALANCE}', '${NRGMKTPRICE}');" 98 | else 99 | echo "Block winner: ${BLKMINER}" 100 | fi 101 | 102 | else 103 | echo "Already in DB: ${CHKBLOCK}" 104 | fi 105 | done 106 | 107 | rm blk_mined.txt 108 | rm list_blk_mined.txt 109 | done 110 | -------------------------------------------------------------------------------- /sdk/README.md: -------------------------------------------------------------------------------- 1 | # Software Development Kit (SDK) 2 | 3 | The `sdk` folder has configuration files for Hardhat and Truffle. They will help set up your development environment so you can deploy and verify your smart contracts on the Energi blockchain. 4 | 5 | **Networks to connect to (providers):** 6 | 7 | - Testnet: https://nodeapi.test.energi.network 8 | - Mainnet: https://nodeapi.energi.network 9 | 10 | Here are guides on how you can launch your own core node and connect on either port 39797 (mainnet) or 49797 (testnet). 11 | 12 | - [Set up Linux VPS](https://wiki.energi.world/docs/guides/linux-vps) 13 | - [Install Core Node on Linux VPS](https://wiki.energi.world/docs/guides/scripted-linux-installation) 14 | 15 | 16 | ## 1. Install Extenstion 17 | 18 | Check out the [NPM Package site](https://www.npmjs.com/search?q=%40energi) for details of the extensions noted below. 19 | 20 | ### 1.1. Energi Core Node 21 | 22 | #### 1.1.1. Energi Web3js extension 23 | 24 | This module comes with three features: 25 | 26 | - web3.js extensions: `web3.nrg`, `web3.energi` and `web3.masternode` 27 | - `EnergiTxCommon`, to be used along with `require('ethereumjs-tx').Transaction`, enabling signed transaction to the Energi testnet and mainnet 28 | - Energi unit maps, so you can use `web3.utils.toWei('1', 'nrg')` 29 | 30 | Note that Energi Unit Maps, like `web3.utils.toWei('1', 'nrg')`, can only be used on a `web3` instance, not directly with `Web3`. 31 | 32 | Run the following to install the extension: 33 | 34 | | NPM | Yarn | 35 | | ---------------------------- | ------------------------- | 36 | | npm install @energi/web3-ext | yarn add @energi/web3-ext | 37 | 38 | 39 | #### 1.1.2. Energi SDK 40 | 41 | Add the library to the project by the following commands: 42 | 43 | | NPM | Yarn | 44 | | ------------------------------ | --------------------------- | 45 | | npm install @energi/energi-sdk | yarn add @energi/energi-sdk | 46 | 47 | 48 | ### 1.2. Energiswap 49 | 50 | #### 1.2.1. SDK for building applications on top of Energiswap 51 | 52 | The Energiswap SDK is provided to help developers build on top of Energiswap. It runs in any environment that can execute JavaScript (example: websites, node scripts, etc.). 53 | 54 | Run the following to install the extension: 55 | 56 | | NPM | Yarn | 57 | | ---------------------------------- | ------------------------------- | 58 | | npm install @energi/energiswap-sdk | yarn add @energi/energiswap-sdk | 59 | 60 | 61 | #### 1.2.2. Smart contracts for Energiswap 62 | 63 | Energiswap is a decentralized protocol for automated token exchange. 64 | 65 | | NPM | Yarn | 66 | | ---------------------------------------- | ------------------------------------- | 67 | | npm install @energi/energiswap-contracts | yarn add @energi/energiswap-contracts | 68 | 69 | 70 | #### 1.2.3. The Token Lists Specification 71 | 72 | Energiswap Token Lists is a specification for lists of token metadata (e.g. address, decimals, ...) that can be used by any dApp interfaces that needs one or more lists of tokens. 73 | 74 | Anyone can create and maintain a token list, as long as they follow the specification. 75 | 76 | Specifically an instance of a token list is a JSON blob that contains a list of ERC20 token metadata for use in dApp user interfaces. Token list JSON must validate against the JSON schema in order to be used in the Energiswap Interface. Tokens on token lists, and token lists themselves, are tagged so that users can easily find tokens. 77 | 78 | | NPM | Yarn | 79 | | ------------------------------------------ | --------------------------------------- | 80 | | npm install @energi/energiswap-token-lists | yarn add @energi/energiswap-token-lists | 81 | 82 | 83 | #### 1.2.4. Energiswap Default Token List 84 | 85 | This NPM module contains the default token list for all dApss used in the Energi ecosystem. It also contains all SVG logo files. 86 | 87 | | NPM | Yarn | 88 | | ------------------------------------------------- | ---------------------------------------------- | 89 | | npm install @energi/energiswap-default-token-list | yarn add @energi/energiswap-default-token-list | 90 | -------------------------------------------------------------------------------- /scripts/linux/missing_mn_rewards.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # Copyright (c) 2021 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Load missing masternode rewards to the database 9 | # 10 | # Version: 11 | # 1.0.0 20210515 ZA Initial Script 12 | # 13 | : ' 14 | # Run the script to get started: 15 | ``` 16 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/missing_mn_rewards.sh0)" '' START_BLOCK END_BLOCK MN_ADDR ; source ~/.bashrc 17 | 18 | Script arguments: 19 | START_BLOCK : Block number to start from 20 | END_BLOCK : Block number to stop at 21 | MN_ADDR : Masternode address 22 | ``` 23 | ' 24 | ###################################################################### 25 | 26 | #set -x 27 | 28 | STARTBLK=$1 29 | ENDBLK=$2 30 | ADDR=$3 31 | 32 | if [[ -z $STARTBLK || -z $ENDBLK || -z $ADDR ]] 33 | then 34 | echo "Syntax:" 35 | echo " missing_mn_rewards.sh START_BLOCK END_BLOCK MN_ADDR" 36 | echo " Script arguments:" 37 | echo " START_BLOCK : Block number to start from" 38 | echo " END_BLOCK : Block number to stop at" 39 | echo " MN_ADDR : Masternode address" 40 | exit 10 41 | fi 42 | 43 | MNTOTALNRG=0 44 | USRNAME=$( find /home -name nodekey 2>&1 | grep -v "Permission denied" | awk -F\/ '{print $3}' ) 45 | export PATH=$PATH:/home/${USRNAME}/energi3/bin 46 | 47 | if [[ ! -z $3 ]] 48 | then 49 | export ADDR=$3 50 | fi 51 | 52 | # Set API server 53 | export NRGAPI="https://explorer.energi.network/api" 54 | #export NRGAPI="http://mainnet.energi.cloudns.cl:4000/api" 55 | 56 | echo "Downloading internal transactions..." 57 | curl -H "accept: application/json" -s "${NRGAPI}?module=account&action=txlistinternal&address=${ADDR}&startblock=${STARTBLK}&endblock=${ENDBLK}" -H "accept: application/json" > list_int_tran.txt 58 | 59 | cat list_int_tran.txt | jq -r '.result[] .blockNumber' | sort -u -n > list_int_tran_blks.txt 60 | 61 | for CHKBLOCK in `cat list_int_tran_blks.txt` 62 | do 63 | # CHKBLOCK=$1 64 | 65 | if [[ -z $CHKBLOCK ]] 66 | then 67 | echo "enter a block number" 68 | exit 69 | fi 70 | 71 | if [[ -z $ADDR || -z $NRGAPI ]] 72 | then 73 | echo "No ADDR or NRGAPI set" 74 | exit 10 75 | fi 76 | 77 | COMMAND="energi3 attach --exec " 78 | if [[ ! -z $MNCOLLATERAL ]] 79 | then 80 | MNCOLLATERAL=$( $COMMAND "web3.fromWei(masternode.masternodeInfo('$ADDR').collateral, 'energi')" 2>/dev/null | jq -r '.' ) 81 | fi 82 | 83 | #if [[ ${MNCOLLATERAL} -gt 0 ]] 84 | #then 85 | 86 | # Check if CURRENCY is set 87 | if [ ! -z $CURRENCY} ] 88 | then 89 | CURRENCY=USD 90 | fi 91 | 92 | # 93 | SQL_QUERY () { 94 | if [[ ! -d /var/multi-masternode-data/nodebot ]] 95 | then 96 | sudo mkdir -p /var/multi-masternode-data/nodebot 97 | fi 98 | sudo sqlite3 -batch /var/multi-masternode-data/nodebot/nodemon.db "${1}" 99 | } 100 | 101 | # to lower case 102 | ADDR=$( echo ${ADDR} | tr '[:upper:]' '[:lower:]' ) 103 | 104 | CHKDB=$( SQL_QUERY "select * from mn_rewards where blockNum = '${CHKBLOCK}';" ) 105 | 106 | if [ -z ${CHKDB} ] 107 | then 108 | echo "Processing block ${CHKBLOCK}" 109 | 110 | TXLSTINT=$( curl -H "accept: application/json" -s "${NRGAPI}?module=account&action=txlistinternal&address=${ADDR}&startblock=${CHKBLOCK}&endblock=${CHKBLOCK}" ) 111 | 112 | BLOCKSUMWEI=$( echo $TXLSTINT | jq -r '.result | map(.value | tonumber) | add ' ) 113 | BLOCKSUMWEI=$( printf "%.0f" $BLOCKSUMWEI ) 114 | BLOCKSUMNRG=$( echo " ${BLOCKSUMWEI} / 1000000000000000000 " | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//' ) 115 | 116 | REWARDTIME=$( ${COMMAND} "nrg.getBlock($CHKBLOCK).timestamp" 2>/dev/null ) 117 | # Get price once 118 | if [[ -z "${NRGMKTPRICE}" ]] 119 | then 120 | NRGMKTPRICE=$( curl -H "Accept: application/json" --connect-timeout 30 -s "https://min-api.cryptocompare.com/data/price?fsym=NRG&tsyms=${CURRENCY}" | jq .${CURRENCY} ) 121 | fi 122 | 123 | if [[ ! -z $BLOCKSUMNRG ]] 124 | then 125 | SQL_QUERY "INSERT INTO mn_rewards (mnAddress, rewardTime, blockNum, Reward, balance, nrgPrice) 126 | VALUES ('${ADDR}','${REWARDTIME}','${CHKBLOCK}','${BLOCKSUMNRG}', '${MNCOLLATERAL}', '${NRGMKTPRICE}');" 127 | fi 128 | 129 | else 130 | echo "Already in DB: ${CHKBLOCK}" 131 | fi 132 | done 133 | 134 | # Clean-up 135 | rm list_int_tran.txt 136 | rm list_int_tran_blks.txt 137 | -------------------------------------------------------------------------------- /sdk/truffle/truffle-config.js: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Energi Core Authors 2 | // This file is part of the Energi Core library. 3 | // 4 | // The Energi Core library is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU Lesser General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // The Energi Core library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU Lesser General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public License 15 | // along with the Energi Core library. If not, see . 16 | // 17 | // See also 18 | 19 | const HDWalletProvider = require('@truffle/hdwallet-provider'); 20 | const fs = require('fs'); 21 | const mnemonic = fs.existsSync('.secret') ? fs.readFileSync('.secret').toString().trim() : null; 22 | 23 | module.exports = { 24 | plugins: ['truffle-plugin-verify'], 25 | 26 | /** 27 | * Networks define how you connect to your client and let you set the 28 | * defaults web3 uses to send transactions. If you don't specify one truffle 29 | * will spin up a development blockchain for you on port 9545 when you 30 | * run `develop` or `test`. You can ask a truffle command to use a specific 31 | * network from the command line, e.g 32 | * 33 | * $ truffle test --network 34 | */ 35 | 36 | networks: { 37 | test: { 38 | // we recommend Ganache CLI 39 | host: '127.0.0.1', // Localhost 40 | port: 7545, // Standard port for Ganache CLI 41 | network_id: '*', // Any ID will be accepted 42 | gas: 10000000 // can be configured as needed; 6721975 is the default block limit on Ganache CLI 43 | }, 44 | development: { 45 | // we recommend Ganache CLI 46 | host: '127.0.0.1', // Localhost 47 | port: 8545, // Standard port for Ganache CLI 48 | network_id: '*', // Any ID will be accepted 49 | gas: 40000000, // can be configured as needed; 6721975 is the default block limit on Ganache CLI 50 | disableConfirmationListener: true 51 | }, 52 | migration: { 53 | // for testing migrations locally 54 | host: '127.0.0.1', 55 | port: 7545, 56 | network_id: '*', 57 | gas: 10000000 58 | }, 59 | testnet: { 60 | provider: () => 61 | new HDWalletProvider({ 62 | mnemonic: { 63 | phrase: mnemonic // as defined in a local .secret_energi_testnet file before deployment. 64 | }, 65 | providerOrUrl: 'https://nodeapi.test.energi.network', // if this fails, try: 'http://172.31.77.180:49796' 66 | derivationPath: "m/44'/49797'/0'/0/" 67 | }), 68 | network_id: '49797', 69 | gas: 40000000, // gas limit used for deploy. 40000000 is the block gas limit. 70 | websockets: true, // used for the confirmations listener or to hear events using .on or .once. 71 | verify: { 72 | apiUrl: 'https://explorer.test.energi.network/api', 73 | apiKey: 'xxxxx-no-api-key-needed-xxxxx', 74 | explorerUrl: 'https://explorer.test.energi.network/address', 75 | }, 76 | }, 77 | mainnet: { 78 | provider: () => 79 | new HDWalletProvider({ 80 | mnemonic: { 81 | phrase: mnemonic // change to desired mnemonic in a local .secret_energi file before deployment. 82 | }, 83 | providerOrUrl: 'https://nodeapi.energi.network', 84 | derivationPath: "m/44'/39797'/0'/0/" 85 | }), 86 | network_id: '39797', 87 | from: '0x123...890', // = change token minter 88 | gas: 40000000, // gas limit used for deploy. 40000000 is the block gas limit. 89 | websockets: true, //Used for the confirmations listener or to hear events using .on or .once. 90 | verify: { 91 | apiUrl: 'https://explorer.energi.network/api', 92 | apiKey: 'xxxxx-no-api-key-needed-xxxxx', 93 | explorerUrl: 'https://explorer.energi.network/address', 94 | }, 95 | } 96 | }, 97 | mocha: { 98 | useColors: true 99 | }, 100 | compilers: { 101 | solc: { 102 | version: '0.8.17', 103 | evmVersion: 'istanbul', 104 | optimizer: { 105 | enabled: true, 106 | runs: 200 107 | } 108 | } 109 | } 110 | }; 111 | -------------------------------------------------------------------------------- /scripts/linux/nodemon-resync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ####################################################################### 4 | # Copyright (c) 2020 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Script to purge reward block data when in side chain 9 | # 10 | # Version: 11 | # 1.0.0 20200523 ZAlam Initial Script 12 | # 13 | : ' 14 | # Run the script to get started: 15 | ``` 16 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/nodemon-resync.sh)" ; source ~/.bashrc 17 | ``` 18 | ' 19 | ####################################################################### 20 | 21 | # Set script version 22 | BLKSYNCVER=1.0.0 23 | 24 | #set -x 25 | 26 | # Load parameters from external conf file 27 | if [[ -f /var/multi-masternode-data/nodebot/nodemon.conf ]] 28 | then 29 | . /var/multi-masternode-data/nodebot/nodemon.conf 30 | fi 31 | 32 | # get username; exclude testnet 33 | USRNAME=$( find /home -name nodekey 2>&1 | grep -v "Permission denied" | grep -v testnet | awk -F\/ '{print $3}' ) 34 | 35 | # check for energi 36 | BINLOC=$( find /home/${USRNAME} -type f -name energi -executable 2>&1 | grep -v "Permission denied" ) 37 | COMMAND="energi attach --exec " 38 | 39 | 40 | # check for energi3 if energi not installed 41 | if [ ! -z ${BINLOC} ] 42 | then 43 | echo "Using binary name: energi" 44 | else 45 | BINLOC=$( find /home/${USRNAME} -type f -name energi3 -executable 2>&1 | grep -v "Permission denied" ) 46 | COMMAND="energi3 attach --exec " 47 | echo "Using binary name: energi3" 48 | fi 49 | 50 | # Extract path to binary 51 | EXECPATH=$( dirname ${BINLOC} ) 52 | 53 | # set PATH 54 | export PATH=$PATH:${EXECPATH} 55 | 56 | # Get list of accounts from core node 57 | if [[ -z ${LISTACCOUNTS} ]] 58 | then 59 | LISTACCOUNTS=$( ${COMMAND} "personal.listAccounts" 2>/dev/null | jq -r '.[]' ) 60 | fi 61 | 62 | # Report function 63 | SQL_REPORT () { 64 | sqlite3 -noheader -csv /var/multi-masternode-data/nodebot/nodemon.db "${1}" 65 | } 66 | 67 | for ADDR in ${LISTACCOUNTS} 68 | do 69 | # change to lower case 70 | ADDR=$( echo $ADDR | tr '[:upper:]' '[:lower:]' ) 71 | 72 | # Get block data from databse 73 | SQL_REPORT "SELECT blockNum FROM mn_rewards WHERE mnAddress == '${ADDR}';" > dbmnblks.tmp 74 | SQL_REPORT "SELECT blockNum FROM stake_rewards WHERE stakeAddress == '${ADDR}';" > dbstblks.tmp 75 | 76 | # get block mined data 77 | echo "Downloading blocks mined by ${ADDR}..." 78 | curl -H "accept: application/json" -s "https://explorer.energi.network/api?module=account&action=getminedblocks&address=${ADDR}" -H "accept: application/json" > dump_minedstblks.tmp 79 | 80 | cat dump_minedstblks.tmp | jq -r '.result[] .blockNumber' | sort -u > minedstblks.tmp 81 | 82 | # get block number for mn rewards 83 | echo "Downloading internal transactions..." 84 | curl -H "accept: application/json" -s "https://explorer.energi.network/api?module=account&action=txlistinternal&address=${ADDR}" -H "accept: application/json" > dump_minedmnblks.tmp 85 | 86 | cat dump_minedmnblks.tmp | jq -r '.result[] .blockNumber' | sort -u > minedmnblks.tmp 87 | 88 | # Staking 89 | awk ' 90 | /^$/{next} 91 | FNR == NR {db_blks[$1] = 1} 92 | FNR != NR { 93 | if(!db_blks[$1]) 94 | print $1 > "staking-mainnetblks.txt" 95 | delete db_blks[$1]; 96 | } 97 | END { 98 | for(i in db_blks) 99 | print i > "staking-sidechainblks.txt" 100 | }' dbstblks.tmp minedstblks.tmp 101 | 102 | # remove sidechain staking blocks 103 | if [[ -s "staking-sidechainblks.txt" ]] 104 | then 105 | for B in `cat staking-sidechainblks.txt` 106 | do 107 | echo "Removing side chain staking block: ${B}" 108 | sudo sqlite3 -batch /var/multi-masternode-data/nodebot/nodemon.db "delete from stake_rewards where blockNum == '${B}';" 109 | done 110 | else 111 | echo "No sidechain staking blocks..." 112 | fi 113 | 114 | # Masternode 115 | awk ' 116 | /^$/{next} 117 | FNR == NR {db_blks[$1] = 1} 118 | FNR != NR { 119 | if(!db_blks[$1]) 120 | print $1 > "mn-mainnetblks.txt" 121 | delete db_blks[$1]; 122 | } 123 | END { 124 | for(i in db_blks) 125 | print i > "mn-sidechainblks.txt" 126 | }' dbmnblks.tmp minedmnblks.tmp 127 | 128 | # remove sidechain mn blocks 129 | if [[ -s "mn-sidechainblks.txt" ]] 130 | then 131 | for B in `cat mn-sidechainblks.txt` 132 | do 133 | echo "Removing side chain mn block: ${B}" 134 | sudo sqlite3 -batch /var/multi-masternode-data/nodebot/nodemon.db "delete from mn_rewards where blockNum == '${B}';" 135 | done 136 | else 137 | echo "No sidechain masternode blocks..." 138 | fi 139 | 140 | # clean-up 141 | rm dbstblks.tmp minedstblks.tmp dump_minedstblks.tmp staking-sidechainblks.txt staking-mainnetblks.txt 2>/dev/null 142 | rm dbmnblks.tmp minedmnblks.tmp dump_minedmnblks.tmp mn-sidechainblks.txt mn-mainnetblks.txt 2>/dev/null 143 | 144 | done 145 | 146 | 147 | -------------------------------------------------------------------------------- /scripts/linux/sync-core-node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # Copyright (c) 2023 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Script to download chaindata to enable faster sync 9 | # 10 | # Version: 11 | # 1.0.0 20230718 ZA Initial Script 12 | # 13 | 14 | : ' 15 | # Run this file 16 | 17 | ``` 18 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/sync-core-node.sh)" ; source ~/.bashrc 19 | ``` 20 | ' 21 | 22 | # Set colors 23 | BLUE=`tput setaf 4` 24 | RED=`tput setaf 1` 25 | GREEN=`tput setaf 2` 26 | YELLOW=`tput setaf 2` 27 | NC=`tput sgr0` 28 | 29 | # Who is running the script 30 | # If root no ${SUDO} required 31 | # If user has ${SUDO} privilidges, run ${SUDO} when necessary 32 | 33 | RUNAS=`whoami` 34 | 35 | if [[ $EUID = 0 ]] 36 | then 37 | SUDO="" 38 | else 39 | ISSUDOER=`getent group ${SUDO} | grep ${RUNAS}` 40 | if [ ! -z "${ISSUDOER}" ] 41 | then 42 | SUDO='sudo' 43 | else 44 | echo "User ${RUNAS} does not have ${SUDO} permissions." 45 | echo "Run ${BLUE}${SUDO} ls -l${NC} to set permissions if you know the user ${RUNAS} has ${SUDO} previlidges" 46 | echo "and then rerun the script" 47 | echo "Exiting script..." 48 | sleep 3 49 | exit 0 50 | fi 51 | fi 52 | 53 | # Stop nodemon if running. 54 | NODEMONSTATUS=$(systemctl status nodemon.timer | grep "Active:" | awk '{print $2}') 55 | if [[ "${NODEMONSTATUS}" = "active" ]] 56 | then 57 | echo "Stopping nodemon service for Energi" 58 | ${SUDO} systemctl stop nodemon.timer 59 | sleep 5 60 | fi 61 | 62 | # Stop energi core if running. 63 | SYSTEMCTLSTATUS=$(systemctl status energi3.service | grep "Active:" | awk '{print $2}') 64 | if [[ "${SYSTEMCTLSTATUS}" = "active" ]] 65 | then 66 | echo "Stopping Energi3 Core Node..." 67 | ${SUDO} systemctl stop energi3.service 68 | ${SUDO} systemctl disable energi3.service 69 | sleep 5 70 | else 71 | echo "energi3 service is not running..." 72 | fi 73 | 74 | # Remove old chaindata 75 | if [ -d /home/nrgstaker/.energicore3/energi3/chaindata ] 76 | then 77 | read -r -p $'Do you want to remove existing chaindata \e[7m(y/n)\e[0m? ' -e 2>&1 78 | REPLY=${REPLY,,} # tolower 79 | if [[ "${REPLY}" == 'y' ]] 80 | then 81 | /home/nrgstaker/energi3/bin/energi3 --datadir=/home/nrgstaker/energi3/.energicore3 removedb 82 | fi 83 | fi 84 | 85 | # Get list of files to download and their checksum 86 | cd /home/nrgstaker 87 | if [ ! -f chaindata-files.txt ] 88 | then 89 | wget -4qo- https://usc1.contabostorage.com/ab655ed609364bd6805208d309a046f8:mainnet/chaindata-files.txt --show-progress --progress=bar:force:noscroll 2>&1 90 | fi 91 | if [ ! -f sha256sums.txt ] 92 | then 93 | wget -4qo- https://usc1.contabostorage.com/ab655ed609364bd6805208d309a046f8:mainnet/sha256sums.txt --show-progress --progress=bar:force:noscroll 2>&1 94 | fi 95 | 96 | # Check list of files to download exists 97 | if [ ! -f chaindata-files.txt ] 98 | then 99 | echo "chaindata-files.txt was not download." 100 | echo "existing..." 101 | exit 10 102 | fi 103 | 104 | # Download and extract chaindata files 105 | for FILE in `cat chaindata-files.txt` 106 | do 107 | echo "Downloading ${FILE}..." 108 | sleep 5 109 | wget -c https://usc1.contabostorage.com/ab655ed609364bd6805208d309a046f8:mainnet/$FILE --show-progress --progress=bar:force:noscroll 2>&1 110 | 111 | # Verify sha256sum 112 | echo "Checking validity of ${FILE}. The validation may take some time." 113 | grep $FILE sha256sums.txt > SHA256SUMS 114 | CHECKFILE=$(sha256sum -c SHA256SUMS | grep OK) 115 | if [ ! -z "${CHECKFILE}" ] 116 | then 117 | echo -e "sha256sum matches ${GREEN}☑${NC}. Extracting file ${FILE}. It will some time to extract." 118 | tar xfz $FILE 119 | rm $FILE 120 | echo "Removing $FILE from list of files to download" 121 | sed -i '/'"${FILE}"'/d' chaindata-files.txt 122 | else 123 | echo "Error with file $FILE." 124 | echo "${BLUE}Run the sync script again.${NC} It will start from where it left off." 125 | echo 126 | echo "${RED}DO NOT remove the chaindata${NC} already downloaded when prompted this time." 127 | echo 128 | exit 20 129 | fi 130 | done 131 | 132 | # create log dir if it does not exist 133 | if [ ! -d /home/nrgstaker/.energicore3/energi3/log ] 134 | then 135 | mkdir -p /home/nrgstaker/.energicore3/energi3/log 136 | touch /home/nrgstaker/.energicore3/energi3/log/energi_stdout.log 137 | fi 138 | 139 | # Set ownership to .energicore3 directory 140 | echo "Changing ownership of files to nrgstaker" 141 | ${SUDO} chown -R nrgstaker:nrgstaker .energicore3 142 | 143 | # Start Energi Core Node 144 | echo "Starting Energi Core Node" 145 | ${SUDO} systemctl enable energi3.service 146 | ${SUDO} systemctl start energi3.service 147 | sleep 5 148 | 149 | # If nodemon is installed, start it 150 | if [ -f /etc/systemd/system/nodemon.timer ] 151 | then 152 | echo "Starting nodemon service for Energi" 153 | ${SUDO} systemctl daemon-reload 154 | ${SUDO} systemctl start nodemon.timer 155 | else 156 | echo "nodemon is not installed." 157 | fi 158 | 159 | # remove temporary files 160 | echo "Removing temporary files" 161 | ${SUDO} rm chaindata-files.txt sha256sums.txt SHA256SUMS 162 | -------------------------------------------------------------------------------- /scripts/linux/energi3-cli: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | if [[ $# -eq 0 ]] 5 | then 6 | $0 -h 7 | fi 8 | 9 | ARG='' 10 | OPTION='' 11 | TMPCLI=`mktemp` 12 | 13 | while [[ $# -gt 0 ]] 14 | do 15 | key="$1"; shift 16 | 17 | case $key in 18 | -t|-testnet|--testnet) 19 | ARG="$ARG -testnet" 20 | ;; 21 | -l|-listaccounts) 22 | OPTION=listaccounts 23 | break 24 | ;; 25 | -newaccount) 26 | OPTION=newaccount 27 | NEWADDRPW="$1" 28 | shift 29 | ;; 30 | -mninfo|-masternodeinfo|--masternodeinfo) 31 | OPTION=mninfo 32 | ADDR=$1 33 | break 34 | ;; 35 | -enode|enode) 36 | OPTION=enode 37 | break 38 | ;; 39 | -unlock|--unlock) 40 | OPTION=unlock 41 | ADDR=$1 42 | ADDRPW=$2 43 | if [[ "${ADDR}" = "" ]] 44 | then 45 | read -p "Enter Address to unlock: " -r ADDR 46 | fi 47 | if [[ "${ADDRPW}" = "" ]] 48 | then 49 | read -s -p "Enter Password for ${ADDR}: " -r ADDRPW 50 | fi 51 | $COMMAND "personal.unlockAccount('$ADDR', '$ADDRPW', 0)" 2>/dev/null 52 | break 53 | ;; 54 | -depositcollateral) 55 | OPTION=collateral 56 | ADDR=$1 57 | AMOUNT=$2 58 | ADDRPW=$3 59 | break 60 | ;; 61 | -collateralbalance) 62 | OPTION=collateralbalance 63 | ADDR=$1 64 | break 65 | ;; 66 | -checkAllBalances) 67 | OPTION=checkAllBalances 68 | break 69 | ;; 70 | -mnBalances) 71 | OPTION=mnBalances 72 | break 73 | ;; 74 | -announce) 75 | OPTION=announce 76 | ADDR=$1 77 | ADDRPW=$2 78 | break 79 | ;; 80 | -stakestatus) 81 | OPTION=stakestatus 82 | break 83 | ;; 84 | -mnstatus) 85 | OPTION=mnstatus 86 | break 87 | ;; 88 | -blocknumber) 89 | OPTION=blocknumber 90 | break 91 | ;; 92 | -stop|stop) 93 | OPTION=halt 94 | break 95 | ;; 96 | -start|start) 97 | OPTION=start 98 | break 99 | ;; 100 | -d|--debug) 101 | set -x 102 | ;; 103 | -h|--help) 104 | cat << EOL 105 | 106 | energi3-cli arguments: 107 | -t -testnet : Run in testnet 108 | -l -listaccounts : List accounts 109 | -newaccount : Create a new account 110 | -mninfo [address] : Masternode details 111 | -enode : Masternode enode information 112 | -unlock
: Unlock address for staking 113 | -depositcollateral
114 | : depositCollateral to Masternode 115 | -announce
116 | : announce 117 | -withdrawcollateral
118 | : Withdraw Masternode Collateral 119 | -collateralbalance : Check Masternode Collateral Balance 120 | -checkAllBalances : Check balance of all Accounts 121 | -mnBalances : Check Masternode Balance 122 | -mnstatus : Check Masternode Status 123 | -stakestatus : Check Staking Status 124 | -blocknumber : Check blockNumber 125 | --bindip
: Internal bind IP to use 126 | -k --privatekey : Private key to use 127 | -start start : Strt energi3 128 | -stop stop : Stop Energi3 129 | -h --help : Display this help text 130 | -d --debug : Debug mode 131 | 132 | EOL 133 | exit 134 | ;; 135 | *) 136 | $0 -h 137 | ;; 138 | esac 139 | done 140 | 141 | COMMAND="energi3 ${ARG} attach --exec" 142 | 143 | case ${OPTION} in 144 | halt) 145 | EPID=`ps -ef | grep energi3 | grep -v "grep energi3" | awk '{print $2}'` 146 | kill ${EPID} 147 | ;; 148 | start) 149 | echo "start script: run_screen_linux.sh" 150 | ;; 151 | listaccounts) 152 | $COMMAND 'personal.listAccounts' 2>/dev/null | jq -r '.[]' 153 | ;; 154 | newaccount) 155 | $COMMAND "personal.newAccount('$NEWADDRPW')" 2>/dev/null 156 | ;; 157 | mninfo) 158 | if [[ -z "$ADDR" ]] 159 | then 160 | $COMMAND "masternode.masternodeInfo(eth.coinbase)" 2>/dev/null 161 | else 162 | $COMMAND "masternode.masternodeInfo('$ADDR')" 2>/dev/null 163 | fi 164 | ;; 165 | enode) 166 | $COMMAND "admin.nodeInfo.enode" 2>/dev/null | jq -r '.[]' 167 | ;; 168 | unlock) 169 | #$COMMAND "personal.unlockAccount('$ADDR', '$ADDRPW', 0)" 2>/dev/null 170 | ;; 171 | depositcollateral) 172 | $COMMAND "masternode.depositCollateral('$ADDR', web3.toWei('$AMOUNT', 'ether'), '$ADDRPW)" 2>/dev/null 173 | ;; 174 | withdrawcollateral) 175 | $COMMAND "masternode.withdrawCollateral ('$ADDR', web3.toWei('$AMOUNT', 'ether'), '$ADDRPW')" 2>/dev/null 176 | ;; 177 | collateralbalance) 178 | $COMMAND "masternode.collateralBalance('$ADDR')" 2>/dev/null 179 | ;; 180 | checkAllBalances) 181 | for i in `$COMMAND 'personal.listAccounts' 2>/dev/null | jq -r '.[]'` 182 | do 183 | echo -n "${i}: " 184 | $COMMAND "web3.fromWei(eth.getBalance('${i}'), 'ether')" 2>/dev/null 185 | done 186 | ;; 187 | mnBalances) 188 | ADDR=`$COMMAND 'personal.listAccounts' 2>/dev/null | jq -r '.[]' | head -1` 189 | $COMMAND "web3.fromWei(masternode.masternodeInfo('$ADDR').collateral, 'ether')" 2>/dev/null | jq -r 190 | #$COMMAND "mnBalances" 2>/dev/null 191 | ;; 192 | announce) 193 | $COMMAND "masternode.announce('$ADDR', admin.nodeInfo.enode, '$ADDRPW')" 2>/dev/null 194 | ;; 195 | blocknumber) 196 | $COMMAND 'eth.blockNumber' 2>/dev/null 197 | ;; 198 | stakestatus) 199 | $COMMAND 'personal.listWallets[0].status' 2>/dev/null 200 | ;; 201 | mnstatus) 202 | $COMMAND 'masternode.masternodeInfo(eth.coinbase).isActive' 2>/dev/null 203 | ;; 204 | 205 | esac 206 | 207 | # done 208 | exit 0 209 | 210 | -------------------------------------------------------------------------------- /scripts/linux/nodemon-report.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ####################################################################### 4 | # Copyright (c) 2022 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: NRG Monitor Toolset: Set of tools to monitor and manage NRG 9 | # Core Node, the reward received and notify the user via email 10 | # SMS and Social Media channels. Currently, Discord and Telegram 11 | # are the social media channels supported. 12 | # 13 | # This script is meant to generate a CSV report 14 | # 15 | # Version: 16 | # 1.0.0 20200421 ZAlam Initial Script 17 | # 1.1.0 20210114 ZAlam Updated to support all version 18 | # 1.1.1 20220121 ZAlam Bug fix with current month 19 | # 20 | # Set script version 21 | NODERPTVER=1.1.0 22 | 23 | #set -x 24 | 25 | # get username; exclude testnet 26 | USRNAME=$( find /home -name nodekey 2>&1 | grep -v "Permission denied" | grep -v testnet | awk -F\/ '{print $3}' ) 27 | 28 | # check for energi 29 | BINLOC=$( find /home/${USRNAME} -type f -name energi -executable 2>&1 | grep -v "Permission denied" ) 30 | COMMAND="energi attach --exec " 31 | 32 | # check for energi3 if energi not installed 33 | if [ ! -z ${BINLOC} ] 34 | then 35 | echo "Using binary name: energi" 36 | else 37 | BINLOC=$( find /home/${USRNAME} -type f -name energi3 -executable 2>&1 | grep -v "Permission denied" ) 38 | COMMAND="energi3 attach --exec " 39 | echo "Using binary name: energi3" 40 | fi 41 | 42 | # Extract path to binary 43 | EXECPATH=$( dirname ${BINLOC} ) 44 | 45 | # set PATH 46 | export PATH=$PATH:${EXECPATH} 47 | 48 | # Report file 49 | RPTTMPFILE="/home/${USRNAME}/etc/reward_data.tmp" 50 | RPTFILE="/home/${USRNAME}/etc/reward_data.csv" 51 | 52 | # Report function 53 | SQL_REPORT () { 54 | sqlite3 -noheader -csv /var/multi-masternode-data/nodebot/nodemon.db "${1}" 55 | } 56 | 57 | # Set colors 58 | BLUE=`tput setaf 4` 59 | RED=`tput setaf 1` 60 | GREEN=`tput setaf 2` 61 | YELLOW=`tput setaf 2` 62 | NC=`tput sgr0` 63 | 64 | _instructions () { 65 | echo "${GREEN}" 66 | clear 2> /dev/null 67 | cat << "ENERGI3" 68 | ___ _ _ _ __ __ 69 | /\ \ | \| |___ __| |___| \/ |___ _ _ 70 | /::\ \ | .` / _ \/ _` / -_) |\/| / _ \ ' \ 71 | /:/\:\__\ |_|\_\___/\__,_\___|_| |_\___/_||_| 72 | /:/ /:/ _/_ | _ \___ _ __ ___ _ _| |_ 73 | /:/ /:/ /\__\ | / -_) '_ \/ _ \ '_| _| 74 | \:\ \/ /:/ / |_|_\___| .__/\___/_| \__| 75 | \:\ /:/ / |_| 76 | ENERGI3 77 | echo "${GREEN} \:\/:/ / ${NC}Options:" 78 | echo "${GREEN} \::/ / ${NC}a - Extract all data" 79 | echo "${GREEN} \/__/ ${NC}b - Generate last month data" 80 | echo " ${NC}c - Generate current month data" 81 | echo " ${NC}d - Custom dates" 82 | echo ${NC} 83 | } 84 | 85 | _instructions 86 | 87 | REPLY='a' 88 | read -p "Please select an option([a], b, c or d): " -r 89 | REPLY=${REPLY,,} # tolower 90 | if [ "${REPLY}" = "" ] 91 | then 92 | REPLY='a' 93 | fi 94 | 95 | if [[ ! -d ${HOME}/etc ]] 96 | then 97 | mkdir ${HOME}/etc 98 | fi 99 | 100 | # Generate CSV 101 | case ${REPLY} in 102 | 103 | a) 104 | 105 | # Export all data 106 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'M',mnAddress,balance,Reward,nrgPrice FROM mn_rewards;" > ${RPTTMPFILE} 107 | 108 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'S',stakeAddress,balance,Reward,nrgPrice FROM stake_rewards;" >> ${RPTTMPFILE} 109 | 110 | ;; 111 | 112 | b) 113 | 114 | # Export previous month 115 | CURRMON=$( date +%Y-%m ) 116 | PREVMON=$( date -d "$CURRMON-15 last month" '+%Y-%m' ) 117 | PREVMON2=$( date -d "$CURRMON-15 last month" '+%m %Y' ) 118 | LASTDAY=$( cal ${PREVMON2} | awk 'NF {DAYS = $NF}; END {print DAYS}' ) 119 | 120 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'M',mnAddress,balance,Reward,nrgPrice FROM mn_rewards WHERE rewardTime >= strftime('%s','${PREVMON}-01 00:00:00') and rewardTime <= strftime('%s','${PREVMON}-${LASTDAY} 23:59:59');" > ${RPTTMPFILE} 121 | 122 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'S',stakeAddress,balance,Reward,nrgPrice FROM stake_rewards WHERE rewardTime >= strftime('%s','${PREVMON}-01 00:00:00') and rewardTime <= strftime('%s','${PREVMON}-${LASTDAY} 23:59:59');" >> ${RPTTMPFILE} 123 | 124 | ;; 125 | 126 | c) 127 | 128 | # Export current month 129 | CURRMON=$( date +%Y-%m ) 130 | CURRMON2=$( date '+%m %Y' ) 131 | LASTDAY=$( cal ${CURRMON2} | awk 'NF {DAYS = $NF}; END {print DAYS}' ) 132 | 133 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'M',mnAddress,balance,Reward,nrgPrice FROM mn_rewards WHERE rewardTime >= strftime('%s','${CURRMON}-01 00:00:00') and rewardTime <= strftime('%s','${CURRMON}-${LASTDAY} 23:59:59');" > ${RPTTMPFILE} 134 | 135 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'S',stakeAddress,balance,Reward,nrgPrice FROM stake_rewards WHERE rewardTime >= strftime('%s','${CURRMON}-01 00:00:00') and rewardTime <= strftime('%s','${CURRMON}-${LASTDAY} 23:59:59');" >> ${RPTTMPFILE} 136 | 137 | ;; 138 | 139 | d) 140 | 141 | # Custom date range 142 | echo "Enter date range of report..." 143 | read -p "Start date [YYYY-MM-DD]: " STARTDATE 144 | read -p "End date [YYYY-MM-DD] : " ENDDATE 145 | 146 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'M',mnAddress,balance,Reward,nrgPrice FROM mn_rewards WHERE rewardTime >= strftime('%s','${STARTDATE} 00:00:00') and rewardTime <= strftime('%s','${ENDDATE} 23:59:59');" > ${RPTTMPFILE} 147 | 148 | SQL_REPORT "SELECT DATETIME(rewardTime,'unixepoch'),blockNum,'S',stakeAddress,balance,Reward,nrgPrice FROM stake_rewards WHERE rewardTime >= strftime('%s','${STARTDATE} 00:00:00') and rewardTime <= strftime('%s','${ENDDATE} 23:59:59');" >> ${RPTTMPFILE} 149 | 150 | ;; 151 | 152 | *) 153 | 154 | echo 155 | echo "Enter Options:" 156 | echo " a - Extract all data" 157 | echo " b - Generate last month data" 158 | echo " c - Generate current month data" 159 | echo " d - Custom dates" 160 | echo 161 | exit 0 162 | ;; 163 | 164 | esac 165 | 166 | # Sort data 167 | sort ${RPTTMPFILE} > ${RPTFILE} 168 | 169 | # Remove temp file 170 | rm ${RPTTMPFILE} 171 | 172 | # Add title 173 | sed -i '1irewardTime,blockNum,type,mnAddress,balance,reward,nrgPrice' ${RPTFILE} 174 | 175 | # Print location of file 176 | echo 177 | echo "The report has been saved to:" 178 | echo " ${RPTFILE}" 179 | echo 180 | -------------------------------------------------------------------------------- /sdk/hardhat/common/constants.js: -------------------------------------------------------------------------------- 1 | const DEV_ACCOUNTS = [ 2 | { 3 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef', 4 | balance: '10000000000000000000000000', // 10 000 000 NRG 5 | }, 6 | { 7 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdff', 8 | balance: '200000000000000000000000', // 200 000 NRG 9 | }, 10 | { 11 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcfff', 12 | balance: '100000000000000000000000', // 100 000 NRG 13 | }, 14 | { 15 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abffff', 16 | balance: '11000000000000000000000', // 11 000 NRG 17 | }, 18 | { 19 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890afffff', 20 | balance: '1000000000000000000000', // 1 000 NRG 21 | }, 22 | { 23 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890ffffff', 24 | balance: '1000000000', // 0.000 000 001 NRG 25 | }, 26 | { 27 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef123456789fffffff', 28 | balance: '0', // 0 NRG 29 | }, 30 | { 31 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef12345678ffffffff', 32 | balance: '100000000000000000000000', // 100 000 NRG 33 | }, 34 | { 35 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567fffffffff', 36 | balance: '100000000000000000000000', // 100 000 NRG 37 | }, 38 | { 39 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef123456ffffffffff', 40 | balance: '100000000000000000000000', // 100 000 NRG 41 | }, 42 | { 43 | privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef12345fffffffffff', 44 | balance: '10000000000000000000000000', // 10 000 000 NRG 45 | }, 46 | ]; 47 | 48 | const TESTNET_DERIVATION_PATH = "m/44'/49797'/0'/0/"; 49 | 50 | const MAINNET_DERIVATION_PATH = "m/44'/39797'/0'/0/"; 51 | 52 | const PROXIES = { 53 | block_reward: '0x0000000000000000000000000000000000000300', 54 | treasury: '0x0000000000000000000000000000000000000301', 55 | mn_registry: '0x0000000000000000000000000000000000000302', 56 | staker_reward: '0x0000000000000000000000000000000000000303', 57 | backbone_reward: '0x0000000000000000000000000000000000000304', 58 | spork_registry: '0x0000000000000000000000000000000000000305', 59 | checkpoint_registry: '0x0000000000000000000000000000000000000306', 60 | blacklist_registry: '0x0000000000000000000000000000000000000307', 61 | compensation_fund: '0x0000000000000000000000000000000000000000', 62 | mn_token: '0x0000000000000000000000000000000000000309', 63 | hf_registry: '0x0000000000000000000000000000000000000000', 64 | proxy_registry: '0x0000000000000000000000000000000000000000', 65 | global_constants: '0x0000000000000000000000000000000000000000', 66 | }; 67 | 68 | const IMPLEMENTATIONS = { 69 | gen2_migration: '0x0000000000000000000000000000000000000308', 70 | block_reward: '0x0000000000000000000000000000000000000310', 71 | treasury: '0x0000000000000000000000000000000000000311', 72 | mn_registry: '0x0000000000000000000000000000000000000312', 73 | staker_reward: '0x0000000000000000000000000000000000000313', 74 | backbone_reward: '0x0000000000000000000000000000000000000314', 75 | spork_registry: '0x0000000000000000000000000000000000000315', 76 | checkpoint_registry: '0x0000000000000000000000000000000000000316', 77 | blacklist_registry: '0x0000000000000000000000000000000000000317', 78 | compensation_fund: '0x0000000000000000000000000000000000000318', 79 | mn_token: '0x0000000000000000000000000000000000000319', 80 | hf_registry: '0x0000000000000000000000000000000000000321', 81 | proxy_registry: '0x0000000000000000000000000000000000000000', 82 | global_constants: '0x0000000000000000000000000000000000000000', 83 | }; 84 | 85 | const MIGRATION_CONTRACT = IMPLEMENTATIONS.gen2_migration; 86 | const SYSTEM_FAUCET = '0x0000000000000000000000000000000000000320'; 87 | const REWARD_BACKBONE = '2280000000000000000'; // 2.28 NRG 88 | const REWARD_MASTERNODE = '9140000000000000000'; // 9.14 NRG 89 | const REWARD_STAKER = '2280000000000000000'; // 2.28 NRG 90 | const REWARD_TREASURY = '184000000000000000000000'; // 184,000 NRG; 91 | const FEE_BLACKLIST = '1000000000000000000000'; // 1,000 NRG 92 | const FEE_BLACKLIST_REVOKE = '100000000000000000000'; // 100 NRG 93 | const FEE_BLACKLIST_DRAIN = '100000000000000000000'; // 100 NRG 94 | const FEE_UPGRADE = '10000000000000000000000'; // 10,000 NRG 95 | const FEE_BUDGET = '300000000000000000000'; // 300 NRG 96 | const CHECKPOINT_MAX = 10; // checkpoints 97 | const CHECKPOINT_SIGNING_PERIOD = 1440; // blocks 98 | const QUORUM_MIN = 1; // 1% 99 | const QUORUM_MAJORITY = 51; // 51% 100 | const QUORUM_MAX = 100; // 100% 101 | const PERIOD_UPGRADE_MIN = 60 * 60 * 24 * 7 * 2; // 2 weeks 102 | const PERIOD_UPGRADE_MAX = 60 * 60 * 24 * 365; // 365 days 103 | const MN_HEARTBEAT_PAST_BLOCKS = 10; // blocks 104 | const MN_HEARTBEAT_INTERVAL_MIN = 60 * 30; // 30 minutes 105 | const MN_HEARTBEAT_INTERVAL_MAX = 60 * 60 * 2; // 2 hours 106 | const MN_COLLATERAL_MIN = '1000000000000000000000'; // 1,000 NRG 107 | const CALL_GAS = '15000000'; // SporkRegistry consensusGasLimits callGas(wei) 108 | const TRANSFER_GAS = '30000000'; // SporkRegistry consensusGasLimits xferGas(wei) 109 | const BUDGET_PROPOSAL_MAX = 100; // proposals 110 | const PERIOD_BUDGET_MIN = 14 * 24 * 60 * 60; // 2 weeks 111 | const PERIOD_BUDGET_MAX = 30 * 24 * 60 * 60; // 30 days 112 | const FEE_PROXY = '1000000000000000000000'; // 1,000 NRG 113 | const PERIOD_PROXY_MIN = 60 * 60 * 24 * 7 * 2; // 2 weeks 114 | const PERIOD_PROXY_MAX = 60 * 60 * 24 * 30; // 30 days 115 | 116 | module.exports = { 117 | DEV_ACCOUNTS, 118 | TESTNET_DERIVATION_PATH, 119 | MAINNET_DERIVATION_PATH, 120 | PROXIES, 121 | IMPLEMENTATIONS, 122 | MIGRATION_CONTRACT, 123 | SYSTEM_FAUCET, 124 | REWARD_BACKBONE, 125 | REWARD_MASTERNODE, 126 | REWARD_STAKER, 127 | REWARD_TREASURY, 128 | FEE_BLACKLIST, 129 | FEE_BLACKLIST_REVOKE, 130 | FEE_BLACKLIST_DRAIN, 131 | FEE_UPGRADE, 132 | FEE_BUDGET, 133 | CHECKPOINT_MAX, 134 | CHECKPOINT_SIGNING_PERIOD, 135 | QUORUM_MIN, 136 | QUORUM_MAJORITY, 137 | QUORUM_MAX, 138 | PERIOD_UPGRADE_MIN, 139 | PERIOD_UPGRADE_MAX, 140 | MN_HEARTBEAT_PAST_BLOCKS, 141 | MN_HEARTBEAT_INTERVAL_MIN, 142 | MN_HEARTBEAT_INTERVAL_MAX, 143 | MN_COLLATERAL_MIN, 144 | CALL_GAS, 145 | TRANSFER_GAS, 146 | BUDGET_PROPOSAL_MAX, 147 | PERIOD_BUDGET_MIN, 148 | PERIOD_BUDGET_MAX, 149 | FEE_PROXY, 150 | PERIOD_PROXY_MIN, 151 | PERIOD_PROXY_MAX, 152 | }; 153 | -------------------------------------------------------------------------------- /scripts/thirdparty/otp.php: -------------------------------------------------------------------------------- 1 | . 15 | * 16 | * PHP Google two-factor authentication module. 17 | * 18 | * See https://www.idontplaydarts.com/2011/07/google-totp-two-factor-authentication-for-php/ 19 | * for more details 20 | * 21 | * @author Phil 22 | **/ 23 | error_reporting(-1); 24 | 25 | class Google2FA { 26 | const keyRegeneration = 30; // Interval between key regeneration 27 | const otpLength = 6; // Length of the Token generated 28 | 29 | private static $lut = array( // Lookup needed for Base32 encoding 30 | "A" => 0, "B" => 1, 31 | "C" => 2, "D" => 3, 32 | "E" => 4, "F" => 5, 33 | "G" => 6, "H" => 7, 34 | "I" => 8, "J" => 9, 35 | "K" => 10, "L" => 11, 36 | "M" => 12, "N" => 13, 37 | "O" => 14, "P" => 15, 38 | "Q" => 16, "R" => 17, 39 | "S" => 18, "T" => 19, 40 | "U" => 20, "V" => 21, 41 | "W" => 22, "X" => 23, 42 | "Y" => 24, "Z" => 25, 43 | "2" => 26, "3" => 27, 44 | "4" => 28, "5" => 29, 45 | "6" => 30, "7" => 31 46 | ); 47 | 48 | /** 49 | * Generates a 16 digit secret key in base32 format 50 | * @return string 51 | **/ 52 | public static function generate_secret_key($length = 16) { 53 | $b32 = "234567QWERTYUIOPASDFGHJKLZXCVBNM"; 54 | $s = ""; 55 | 56 | for ($i = 0; $i < $length; $i++) 57 | $s .= $b32[rand(0,31)]; 58 | 59 | return $s; 60 | } 61 | 62 | /** 63 | * Returns the current Unix Timestamp devided by the keyRegeneration 64 | * period. 65 | * @return integer 66 | **/ 67 | public static function get_timestamp() { 68 | return floor(microtime(true)/self::keyRegeneration); 69 | } 70 | 71 | /** 72 | * Decodes a base32 string into a binary string. 73 | **/ 74 | public static function base32_decode($b32) { 75 | 76 | $b32 = strtoupper($b32); 77 | 78 | if (!preg_match('/^[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]+$/', $b32, $match)) 79 | throw new Exception('Invalid characters in the base32 string.'); 80 | 81 | $l = strlen($b32); 82 | $n = 0; 83 | $j = 0; 84 | $binary = ""; 85 | 86 | for ($i = 0; $i < $l; $i++) { 87 | 88 | $n = $n << 5; // Move buffer left by 5 to make room 89 | $n = $n + self::$lut[$b32[$i]]; // Add value into buffer 90 | $j = $j + 5; // Keep track of number of bits in buffer 91 | 92 | if ($j >= 8) { 93 | $j = $j - 8; 94 | $binary .= chr(($n & (0xFF << $j)) >> $j); 95 | } 96 | } 97 | 98 | return $binary; 99 | } 100 | 101 | /** 102 | * Takes the secret key and the timestamp and returns the one time 103 | * password. 104 | * 105 | * @param binary $key - Secret key in binary form. 106 | * @param integer $counter - Timestamp as returned by get_timestamp. 107 | * @return string 108 | **/ 109 | public static function oath_hotp($key, $counter) 110 | { 111 | if (strlen($key) < 8) 112 | throw new Exception('Secret key is too short. Must be at least 16 base 32 characters'); 113 | 114 | $bin_counter = pack('N*', 0) . pack('N*', $counter); // Counter must be 64-bit int 115 | $hash = hash_hmac ('sha1', $bin_counter, $key, true); 116 | 117 | return str_pad(self::oath_truncate($hash), self::otpLength, '0', STR_PAD_LEFT); 118 | } 119 | 120 | /** 121 | * Verifys a user inputted key against the current timestamp. Checks $window 122 | * keys either side of the timestamp. 123 | * 124 | * @param string $b32seed 125 | * @param string $key - User specified key 126 | * @param integer $window 127 | * @param boolean $useTimeStamp 128 | * @return boolean 129 | **/ 130 | public static function verify_key($b32seed, $key, $window = 4, $useTimeStamp = true) { 131 | 132 | $timeStamp = self::get_timestamp(); 133 | 134 | if ($useTimeStamp !== true) $timeStamp = (int)$useTimeStamp; 135 | 136 | $binarySeed = self::base32_decode($b32seed); 137 | 138 | for ($ts = $timeStamp - $window; $ts <= $timeStamp + $window; $ts++) 139 | if (self::oath_hotp($binarySeed, $ts) == $key) 140 | return true; 141 | 142 | return false; 143 | 144 | } 145 | 146 | /** 147 | * Extracts the OTP from the SHA1 hash. 148 | * @param binary $hash 149 | * @return integer 150 | **/ 151 | public static function oath_truncate($hash) 152 | { 153 | $offset = ord($hash[19]) & 0xf; 154 | 155 | return ( 156 | ((ord($hash[$offset+0]) & 0x7f) << 24 ) | 157 | ((ord($hash[$offset+1]) & 0xff) << 16 ) | 158 | ((ord($hash[$offset+2]) & 0xff) << 8 ) | 159 | (ord($hash[$offset+3]) & 0xff) 160 | ) % pow(10, self::otpLength); 161 | } 162 | } 163 | 164 | if (isset($argv[2]) && file_exists($argv[2])) { 165 | $f = fopen($argv[2], 'r'); 166 | } 167 | else if (file_exists($_SERVER['HOME'] . '/.google_authenticator')) { 168 | $f = fopen($_SERVER['HOME'] . '/.google_authenticator', 'r'); 169 | } 170 | else if (file_exists($_SERVER['HOME'] . '/.google_authenticator.temp')) { 171 | $f = fopen($_SERVER['HOME'] . '/.google_authenticator.temp', 'r'); 172 | } 173 | if (empty($f)) { 174 | echo "Could not open the .google_authenticator file for reading."; 175 | fclose($f); 176 | exit; 177 | } 178 | if (!empty($argv[3])) { 179 | $InitalizationKey = $argv[3]; 180 | } 181 | else { 182 | $InitalizationKey = trim(fgets($f)); 183 | } 184 | if (strlen($InitalizationKey) > 100) { 185 | echo "Key is too long."; 186 | fclose($f); 187 | exit; 188 | } 189 | 190 | $TimeStamp = Google2FA::get_timestamp(); 191 | $secretkey = Google2FA::base32_decode($InitalizationKey); // Decode it into binary 192 | // $otp = Google2FA::oath_hotp($secretkey, $TimeStamp); // Get current token 193 | 194 | // Use this to verify a key as it allows for some time drift. 195 | if (isset($argv[1])) { 196 | $verify_key = $argv[1]; 197 | } 198 | else { 199 | echo "Key was not passed in."; 200 | fclose($f); 201 | exit; 202 | } 203 | 204 | $result = Google2FA::verify_key($InitalizationKey, $verify_key); 205 | 206 | if ($result == TRUE) { 207 | echo "Key Verified\n"; 208 | } 209 | else { 210 | echo 'Current PHP version: ' . phpversion(); 211 | echo "\n"; 212 | echo "Failure\n $argv[0]\n $argv[1]\n $argv[2]\n"; 213 | echo "Key: >$InitalizationKey<\n"; 214 | $line = trim(fgets($f)); 215 | echo "Line: >${line}<\n"; 216 | $line = trim(fgets($f)); 217 | echo "Line: >${line}<\n"; 218 | $line = trim(fgets($f)); 219 | echo "Line: >${line}<\n"; 220 | } 221 | 222 | fclose($f); 223 | // End Of File. -------------------------------------------------------------------------------- /scripts/linux/autocompounding.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # Copyright (c) 2021 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Batch script to change AutoCompounding parameter on VPS 9 | # 10 | # Version: 11 | # 1.0.0 20200321 ZA Initial Script 12 | # 1.1.0 20210112 ZA Update to support v3.1 13 | # 1.1.1 20210817 ZA Update to support support v3.1.0; no change in binary name 14 | # 1.1.2 20211228 ZA Fix `--miner.setAutoCompounding` - Core Node v3.1.1 15 | # 16 | : ' 17 | # Run the script to get started: 18 | ``` 19 | bash -ic "$(wget -4qO- -o- raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/linux/autocompounding.sh)" ; source ~/.bashrc 20 | ``` 21 | ' 22 | ###################################################################### 23 | 24 | # Service File location - adjusted to keep same name 25 | SERVICEFILE=/lib/systemd/system/energi3.service 26 | OLDSERVICEFILE=/lib/systemd/system/energi3.service-tmp 27 | 28 | # Set colors 29 | BLUE=`tput setaf 4` 30 | RED=`tput setaf 1` 31 | GREEN=`tput setaf 2` 32 | YELLOW=`tput setaf 2` 33 | NC=`tput sgr0` 34 | 35 | # Command functions 36 | _cmd-collChk () { 37 | # Check status of autocollateralize 38 | 39 | # SETTO=`energi ${ARG} attach --exec "miner.setAutoCompounding()" 2>/dev/null | head -1` 40 | # if [[ ${SETTO} == 0 ]] 41 | # then 42 | # echo "AutoCompounding is set to ${RED}OFF${NC}" 43 | 44 | # elif [[ ${SETTO} == 1 ]] 45 | # then 46 | # echo "AutoCompounding is set to ${GREEN}ON${NC}" 47 | 48 | # fi 49 | CHKIFTHERE1=`grep miner.autocollateralize ${SERVICEFILE}` 50 | CHKIFTHERE2=`grep miner.autocompounding ${SERVICEFILE}` 51 | if [[ ! -z ${CHKIFTHERE1} ]] || [[ ! -z ${CHKIFTHERE2} ]] 52 | then 53 | ISDISABLED1=`grep "miner.autocollateralize 0" ${SERVICEFILE}` 54 | ISDISABLED2=`grep "miner.autocompounding 0" ${SERVICEFILE}` 55 | ISENABLED1=`grep "miner.autocollateralize 1" ${SERVICEFILE}` 56 | ISENABLED2=`grep "miner.autocompounding 1" ${SERVICEFILE}` 57 | if [[ ! -z ${ISDISABLED1} ]] || [[ ! -z ${ISDISABLED2} ]] 58 | then 59 | echo "AutoCompounding is set to ${RED}OFF${NC}" 60 | SETTO=0 61 | elif [[ ! -z ${ISENABLED1} ]] || [[ ! -z ${ISENABLED2} ]] 62 | then 63 | echo "AutoCompounding is set to ${GREEN}ON${NC}" 64 | SETTO=1 65 | fi 66 | else 67 | # Default is set to ON 68 | echo "AutoCompounding is set to ${GREEN}ON${NC}" 69 | SETTO=1 70 | fi 71 | } 72 | 73 | _cmd-collOff () { 74 | # Turn autocollateralize off 75 | energi ${ARG} attach --exec "miner.setAutoCompounding(0)" 2>/dev/null 1>/dev/null 76 | _cmd-collChk 77 | 78 | } 79 | 80 | _cmd-collOn () { 81 | # Turn autocollateralize on 82 | energi ${ARG} attach --exec "miner.setAutoCompounding(1)" 2>/dev/null 1>/dev/null 83 | _cmd-collChk 84 | } 85 | 86 | _post_message () { 87 | 88 | echo 89 | echo "Turn on staking on by attaching to Core Node:" 90 | echo " energi3 attach" 91 | echo 92 | echo "and then run:" 93 | echo " personal.unlockAccount('put_your_address', null, 0, true)" 94 | echo 95 | 96 | } 97 | 98 | # 99 | if [[ -f ${SERVICEFILE} ]] 100 | then 101 | _cmd-collChk 102 | 103 | else 104 | clear 105 | echo 106 | echo "Cannot find energi3.service file to update" 107 | echo " Filename: ${SERVICEFILE}" 108 | echo 109 | echo "Exiting script..." 110 | echo 111 | #echo "To manually change setting attach to Core Node:" 112 | #echo " energi3 attach" 113 | #echo 114 | #echo "and then run:" 115 | #echo " miner.setAutoCompounding(0) - to disable" 116 | #echo " miner.setAutoCompounding(1) - to enable" 117 | #echo " miner.setAutoCompounding() - to check current setting" 118 | #echo 119 | exit 1 120 | fi 121 | 122 | # 123 | echo "${GREEN}" 124 | clear 2> /dev/null 125 | cat << "ENERGI3" 126 | ___ ______ _ _ ______ _____ _____ _____ 127 | /\ \ | ____| \ | | ____| __ \ / ____|_ _| 128 | /::\ \ | |__ | \| | |__ | |__) | | __ | | 129 | /:/\:\__\ | __| | . ` | __| | _ /| | |_ | | | 130 | /:/ /:/ _/_ | |____| |\ | |____| | \ \| |__| |_| |_ 131 | /:/ /:/ /\__\ |______|_| \_|______|_| \_\\_____|_____| 132 | \:\ \/ /:/ / 133 | ENERGI3 134 | echo "${GREEN} \:\ /:/ / ${NC}This script determines if autocollateralize is enabled" 135 | echo "${GREEN} \:\/:/ / ${NC}and changes the setting for you. You do not need to" 136 | echo "${GREEN} \::/ / ${NC}re-announce masternode or unlock staking after you" 137 | echo "${GREEN} \/__/ ${NC}run the script." 138 | echo ${NC} 139 | echo 140 | 141 | if [[ ${SETTO} == 0 ]] 142 | then 143 | echo "AutoCompounding is ${RED}DISABLED${NC} on the Core Node" 144 | #_cmd-collChk 145 | echo 146 | echo "To enable AutoCompounding, type: e" 147 | echo "Exit without making change, type : x" 148 | echo 149 | read -n 1 -p " Select option (e/[x]): " OPTION 150 | echo 151 | OPTION=${OPTION,,} # tolower 152 | echo 153 | 154 | elif [[ ${SETTO} == 1 ]] 155 | then 156 | echo "AutoCompounding is ${GREEN}ENABLED${NC} on the Core Node" 157 | #_cmd-collChk 158 | echo 159 | echo "To disable AutoCompounding, type: d" 160 | echo "Exit without making change, type : x" 161 | echo 162 | read -n 1 -p " Select option (d/[x]): " OPTION 163 | echo 164 | OPTION=${OPTION,,} # tolower 165 | echo 166 | 167 | elif [[ ! -z ${CHKIFTHERE1} ]] || [[ ! -z ${CHKIFTHERE2} ]] 168 | then 169 | # Blank if parameter is not there 170 | echo "AutoCompounding ${BLUE}PARAMETER NOT ENTERED${NC} on the Core Node" 171 | #_cmd-collChk 172 | echo 173 | echo "To enable AutoCompounding, type: e" 174 | echo "To disable AutoCompounding, type: d" 175 | echo "Exit without making change, type : x" 176 | echo 177 | read -n 1 -p " Select option (e/d/[x]): " OPTION 178 | echo 179 | OPTION=${OPTION,,} # tolower 180 | echo 181 | 182 | fi 183 | 184 | # Main program 185 | case ${OPTION} in 186 | e) 187 | if [[ ! -z ${ISDISABLED1} ]] || [[ ! -z ${ISDISABLED2} ]] 188 | then 189 | echo "Updating energi3.service file" 190 | if [[ -f ${OLDSERVICEFILE} ]] 191 | then 192 | sudo mv ${OLDSERVICEFILE} ${SERVICEFILE} 193 | fi 194 | sudo sed -i 's/--miner.autocollateralize 0/--miner.autocompounding 1/' ${SERVICEFILE} 195 | sudo sed -i 's/--miner.autocompounding 0/--miner.autocompounding 1/' ${SERVICEFILE} 196 | sudo systemctl daemon-reload 197 | sudo systemctl restart energi3.service 198 | echo 199 | #_cmd-collOn 200 | _post_message 201 | echo 202 | 203 | elif [[ -z ${CHKIFTHERE1} ]] || [[ -z ${CHKIFTHERE2} ]] 204 | then 205 | # Parameter not there, add to enable 206 | echo 207 | echo "Updating energi3.service file" 208 | if [[ -f ${OLDSERVICEFILE} ]] 209 | then 210 | sudo mv ${OLDSERVICEFILE} ${SERVICEFILE} 211 | fi 212 | sudo sed -i 's/node/node --miner.autocompounding 1/' ${SERVICEFILE} 213 | sudo systemctl daemon-reload 214 | sudo systemctl restart energi3.service 215 | echo 216 | #_cmd-collOn 217 | _post_message 218 | echo 219 | 220 | else 221 | echo "AutoCompounding is already set to roll up" 222 | echo "No changes made" 223 | echo 224 | 225 | fi 226 | 227 | ;; 228 | 229 | d) 230 | if [[ ! -z ${ISENABLED1} ]] || [[ ! -z ${ISENABLED2} ]] 231 | then 232 | echo "Updating energi3.service file" 233 | if [[ -f ${OLDSERVICEFILE} ]] 234 | then 235 | sudo mv ${OLDSERVICEFILE} ${SERVICEFILE} 236 | fi 237 | sudo sed -i 's/--miner.autocollateralize 1/--miner.autocompounding 0/' ${SERVICEFILE} 238 | sudo sed -i 's/--miner.autocompounding 1/--miner.autocompounding 0/' ${SERVICEFILE} 239 | sudo systemctl daemon-reload 240 | sudo systemctl restart energi3.service 241 | echo 242 | #_cmd-collOff 243 | _post_message 244 | echo 245 | 246 | elif [[ -z ${CHKIFTHERE1} ]] || [[ -z ${CHKIFTHERE2} ]] 247 | then 248 | echo "Updating energi3.service file" 249 | if [[ -f ${OLDSERVICEFILE} ]] 250 | then 251 | sudo mv ${OLDSERVICEFILE} ${SERVICEFILE} 252 | fi 253 | sudo sed -i 's/node/node --miner.autocompounding 0/' ${SERVICEFILE} 254 | sudo systemctl daemon-reload 255 | sudo systemctl restart energi3.service 256 | echo 257 | #_cmd-collOff 258 | _post_message 259 | echo 260 | 261 | fi 262 | 263 | ;; 264 | 265 | *) 266 | echo 267 | echo "Exiting without doing anything." 268 | echo 269 | exit 0 270 | 271 | ;; 272 | 273 | esac 274 | -------------------------------------------------------------------------------- /docker-compose/nodemon/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Energi Core Node Monitor for `energi-docker-compose` 2 | 3 | Dockerised Energi Core Node Monitor for the dockerised Energi Core Node. 4 | 5 | --- 6 | 7 | - [Enable the Energi Core Node Monitor service](#enable-the-energi-core-node-monitor-service) 8 | - [Environment variables](#environment-variables) 9 | - [Boolean-like values](#boolean-like-values) 10 | - [Environment variables explained](#environment-variables-explained) 11 | - [`DISCORD_WEBHOOK_CHANGE`](#discord_webhook_change) 12 | - [Discord webhook addresses](#discord-webhook-addresses) 13 | - [`DISCORD_WEBHOOK_ERROR`](#discord_webhook_error) 14 | - [`DISCORD_WEBHOOK_INFORMATION`](#discord_webhook_information) 15 | - [`DISCORD_WEBHOOK_SUCCESS`](#discord_webhook_success) 16 | - [`DISCORD_WEBHOOK_WARNING`](#discord_webhook_warning) 17 | - [`ECNM_CURRENCY`](#ecnm_currency) 18 | - [`ECNM_INTERVAL`](#ecnm_interval) 19 | - [`ECNM_SERVER_ALIAS`](#ecnm_server_alias) 20 | - [`ECNM_SHOW_IP`](#ecnm_show_ip) 21 | - [`ECNM_SHOW_IP_EXTERNAL`](#ecnm_show_ip_external) 22 | - [`INTERACTIVE_SETUP`](#interactive_setup) 23 | - [`MARKET_PRICE_IN_INFORMATION`](#market_price_in_information) 24 | - [`MESSAGE_TIME_ZONE`](#message_time_zone) 25 | - [`NRG_AMOUNT_IN_CURRENCY`](#nrg_amount_in_currency) 26 | - [`TELEGRAM_BOT_TOKEN`](#telegram_bot_token) 27 | - [`TELEGRAM_BOT_TOKEN_CHANGE`](#telegram_bot_token_change) 28 | 29 | --- 30 | 31 | ## Enable the Energi Core Node Monitor service 32 | 33 | To enable Energi Core Node Monitor, 34 | [`compose.override.template.yaml`](../compose.override.template.yaml) 35 | has to be copied in the root directory and renamed to `compose.override.yaml`. 36 | Then [`nodemon/.env.template.env`](.env.template.env) must be copied and renamed 37 | to `.env` and values should be provided for environment variables when a 38 | non-interactive setup is used (value for 39 | [`INTERACTIVE_SETUP`](#interactive_setup) is a negative 40 | [boolean-like value](#boolean-like-values)). All the environment variables are 41 | described in [the subsection below](#environment-variables). 42 | 43 | To setup Energi Core Node Monitor container, command `./helper setup monitor` 44 | (or `./helper setup` if Energi Core Node and Energi Core Node Monitor are set up 45 | together) must be executed from the root directory (where 46 | [`compose.yaml`](../compose.yaml) is located). Energi Core Node 47 | Monitor container will be automatically started afterwards. 48 | 49 | > `docker compose` is used in `./helper setup` so `sudo` might be necessary. 50 | > 51 | > After the Energi Core Node Monitor container is launched for the first time or 52 | > it is recreated, a message about user and group changes will be sent. 53 | > 54 | > A note on uptime value in informational messages. As originally 55 | > [`nodemon.sh`](scripts/nodemon.sh) is intended to run on the same server as 56 | > Energi Core Node, then uptime value is meant to be the uptime of Core. In 57 | > `energi-docker-compose` this value is the uptime of the cron process in the 58 | > Energi Core Node Monitor container as Core and Monitor run in separate Docker 59 | > containers. 60 | 61 | ### Environment variables 62 | 63 | `.env` contains environment variables that are used to set up Energi Core Node 64 | Monitor in a non-interactive mode ([`INTERACTIVE_SETUP`](#interactive_setup) has 65 | a positive [boolean-like](#boolean-like-values) value). All of them are optional 66 | and most of them are used only in the configuration run. 67 | 68 | #### Boolean-like values 69 | 70 | The following values are considered as positive boolean values (`true`, case 71 | insensitive): 72 | 73 | - `y`; 74 | - `yes`; 75 | - `true`; 76 | - `1`. 77 | 78 | Anything else (including empty value or omitted variable) is considered as 79 | `false`. 80 | 81 | #### Environment variables explained 82 | 83 | This section contains a short description for each of environment variables that 84 | are used to configure the dockerised Energi Core Node Monitor. 85 | 86 | ##### `DISCORD_WEBHOOK_CHANGE` 87 | 88 | For non-interactive setup a positive [boolean-like](#boolean-like-values) value 89 | indicates that the existing Discord webhooks should be replaced with the value 90 | of the following environment variables if the Energi Core Node Monitor has 91 | already been set up: 92 | 93 | - [`DISCORD_WEBHOOK_ERROR`](#discord_webhook_error); 94 | - [`DISCORD_WEBHOOK_INFORMATION`](#discord_webhook_information); 95 | - [`DISCORD_WEBHOOK_SUCCESS`](#discord_webhook_success); 96 | - [`DISCORD_WEBHOOK_WARNING`](#discord_webhook_warning). 97 | 98 | ##### Discord webhook addresses 99 | 100 | One webhook address can be used for all message types. 101 | 102 | More detailed instructions on how to set up Discord to receive messages from the 103 | Energi Core Node Monitor are located in 104 | [the official Energi Core Node Monitoring Tool guide (the section "Setup Discord")](https://wiki.energi.world/en/advanced/nodemon#discord). 105 | 106 | ###### `DISCORD_WEBHOOK_ERROR` 107 | 108 | Discord webhook address for error messages. 109 | 110 | ###### `DISCORD_WEBHOOK_INFORMATION` 111 | 112 | Discord webhook address for information messages. 113 | 114 | ###### `DISCORD_WEBHOOK_SUCCESS` 115 | 116 | Discord webhook address for success messages. 117 | 118 | ###### `DISCORD_WEBHOOK_WARNING` 119 | 120 | Discord webhook address for warning messages. 121 | 122 | ##### `ECNM_CURRENCY` 123 | 124 | The currency to be used in messages about wallet balance. 125 | 126 | If not set, `USD` will be used. 127 | 128 | ##### `ECNM_INTERVAL` 129 | 130 | An interval between two subsequent Energi Core Node Monitor runs. \ 131 | The following suffixes can be used to specify the desired time units: 132 | 133 | - `s` or no suffix for seconds; 134 | - `m` for minutes; 135 | - `h` for hours; 136 | - `d` for days. 137 | 138 | When this environment variable is not defined or it's value is not specified, 139 | the default interval will be used: 10 minutes. 140 | 141 | ##### `ECNM_SERVER_ALIAS` 142 | 143 | A server name to be used in messages. 144 | 145 | The default value: container's hostname (something like `35199a65247e`). 146 | 147 | ##### `ECNM_SHOW_IP` 148 | 149 | A positive [boolean-like](#boolean-like-values) value indicates that the Energi 150 | Core Node Monitor's IP address should be displayed in messages. 151 | 152 | This value alone is quite pointless as it will display the Energi Core Node 153 | Monitor Docker container's internal IP address. 154 | 155 | To display server's external IP address, the environment variable 156 | [`ECNM_SHOW_IP_EXTERNAL`](#ecnm_show_ip_external) must be set to a positive 157 | [boolean-like](#boolean-like-values) value. 158 | 159 | ##### `ECNM_SHOW_IP_EXTERNAL` 160 | 161 | When [`ECNM_SHOW_IP`](#ecnm_show_ip), a positive 162 | [boolean-like](#boolean-like-values) value indicates that the server's external 163 | IP address should be displayed in messages instead of container's internal IP. 164 | 165 | ##### `INTERACTIVE_SETUP` 166 | 167 | A positive [boolean-like](#boolean-like-values) value indicates that the Energi 168 | Core Node Monitor setup process will be interactive. This means that all the 169 | neccessary values in setup process will have to be entered manually. 170 | 171 | For interactive setup all environment variables can be left without values. 172 | 173 | The default value is `yes`. 174 | 175 | ##### `MARKET_PRICE_IN_INFORMATION` 176 | 177 | When set to a positive [boolean-like](#boolean-like-values) value, the current 178 | market price will be added to informational message. 179 | 180 | The default value is `no`. 181 | 182 | ##### `MESSAGE_TIME_ZONE` 183 | 184 | To display date in time in messages in the specified time zone. 185 | 186 | If `MESSAGE_TIME_ZONE` is omitted or its value is empty, or if time zone name 187 | is misspelled, container's default time zone (UTC) will be used. 188 | 189 | Available time zones are listed on: 190 | 191 | - ; 192 | - . 193 | 194 | ##### `NRG_AMOUNT_IN_CURRENCY` 195 | 196 | When set to a positive [boolean-like](#boolean-like-values) value, NRG balance 197 | in success messages is displayed in the configured currency. 198 | 199 | The default value is `no`. 200 | 201 | ##### `TELEGRAM_BOT_TOKEN` 202 | 203 | Token for Telegram bot to send Energi Core Node Monitor messages to. 204 | 205 | > When a Telegram bot is used, at least one message has to be sent to it 206 | > recently so the `result` array in the response of 207 | > `https://api.telegram.org/bot{Telegram bot token}/getUpdates` (where 208 | > `{Telegram bot token}` is the actual token) is not empty, otherwise the script 209 | > will not be able to set up Telegram integration. 210 | 211 | Detailed instructions on how to set up Telegram are in 212 | [the official Energi Core Node Monitoring Tool guide (the section "Setup Telegram")](https://wiki.energi.world/en/advanced/nodemon#telegram). 213 | 214 | ##### `TELEGRAM_BOT_TOKEN_CHANGE` 215 | 216 | For interactive setup a positive [boolean-like](#boolean-like-values) value 217 | indicates that the existing Telegram token must be replaced with the one that is 218 | assigned to [`TELEGRAM_BOT_TOKEN`](#telegram_bot_token) if the Energi Core Node 219 | Monitor has been already set up. 220 | -------------------------------------------------------------------------------- /docker-compose/helper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | command_pattern_attach='attach' 4 | command_pattern_chaindata='bootstrap-chaindata | chaindata' 5 | service_choices='core | monitor' 6 | command_pattern_console="console | shell | terminal ${service_choices}" 7 | command_pattern_masternode="\ 8 | masternode-enode-url | masternode-enode | mn-enode-url | mn-enode" 9 | command_pattern_preimages='apply-preimages | preimages' 10 | service_pattern="all | ${service_choices}" 11 | command_pattern_update="update [${service_pattern}] []" 12 | command_pattern_setup="setup [${service_pattern}]" 13 | command_pattern_start="start [${service_pattern}]" 14 | command_pattern_status='staking-status | status' 15 | env='.env' 16 | help_description='Print this help message' 17 | help_message="\ 18 | helper - a helper command for \`energi-docker-compose\`, a dockerised 19 | Energi Core Node. 20 | 21 | Available commands: 22 | ${command_pattern_preimages} 23 | Apply Energi Core Node preimages 24 | ${command_pattern_attach} 25 | Attach to the Energi Core Node console 26 | ${command_pattern_chaindata} 27 | Bootstrap Energi Core Node chaindata 28 | ${command_pattern_console} 29 | Attach to Energi Core Node or Monitor container 30 | help 31 | ${help_description} 32 | ${command_pattern_masternode} 33 | Get Masternode enode URL to be used to announce Masternode 34 | ${command_pattern_setup} 35 | Setup Energi Core Node container(s) 36 | ${command_pattern_start} 37 | Start Energi Core Node container(s); this is a shortcut for 38 | \`docker compose up --detach [${service_choices}]\` 39 | ${command_pattern_status} 40 | Energi Core Node synchronisation and staking status 41 | ${command_pattern_update} 42 | Update image(s) and recreate container(s). 43 | Version argument (i.e. v1.1.4) can be used to build images and create 44 | containers with Energi version other than the one that is specified in 45 | \`${env}\` 46 | 47 | Available options: 48 | -?, -h, --help 49 | ${help_description} 50 | " 51 | service_arguments_message="Valid arguments are: 52 | - no value or \`all\`; 53 | - \`core\`; 54 | - \`monitor\`." 55 | exec='docker compose exec' 56 | exec_core="${exec} core" 57 | exec_monitor="${exec} monitor" 58 | run='docker compose run --rm' 59 | stop='docker compose stop' 60 | up='docker compose up --detach' 61 | 62 | bootstrap_chaindata() { 63 | ${run} --entrypoint '/bin/sh bootstrap-chaindata.sh' core 64 | } 65 | 66 | check_max_arguments_count() { 67 | count=${1} 68 | max=${2} 69 | pattern=${3} 70 | 71 | if [ "${count}" -gt "${max}" ]; then 72 | printf '%s\n' 'Too much arguments!' 73 | 74 | if [ -n "${pattern}" ] && [ "${pattern}" != '' ]; then 75 | printf "Subcommand's pattern is: %s\n" "${pattern}" 76 | fi 77 | 78 | exit 1 79 | fi 80 | } 81 | 82 | print_help_message() { 83 | printf '%b' "\n${help_message}\n" 84 | } 85 | 86 | case "${1}" in 87 | '') 88 | printf 'No command or option was provided!\n' 89 | print_help_message 90 | 91 | exit 1 92 | ;; 93 | -\? | -h | --help | help) 94 | check_max_arguments_count ${#} 1 '-? | -h | --help | help' 95 | print_help_message 96 | 97 | exit 0 98 | ;; 99 | apply-preimages | preimages) 100 | check_max_arguments_count ${#} 1 "${command_pattern_preimages}" 101 | ${stop} 102 | exit_code="${?}" 103 | ${run} --entrypoint '/bin/sh apply-preimages.sh' core 104 | exit_code=$((exit_code + ${?})) 105 | ${up} 106 | exit_code=$((exit_code + ${?})) 107 | 108 | exit ${exit_code} 109 | ;; 110 | attach) 111 | check_max_arguments_count ${#} 1 "${command_pattern_attach}" 112 | . ./.env 113 | ${exec_core} "${ENERGI_BIN}" --datadir "${ENERGI_CORE_DIR}" attach 114 | 115 | exit ${?} 116 | ;; 117 | bootstrap-chaindata | chaindata) 118 | check_max_arguments_count ${#} 1 "${command_pattern_chaindata}" 119 | ${stop} 120 | exit_code="${?}" 121 | bootstrap_chaindata && ${up} 122 | exit_code=$((exit_code + ${?})) 123 | 124 | exit "${exit_code}" 125 | ;; 126 | console | shell | terminal) 127 | check_max_arguments_count ${#} 2 "${command_pattern_console}" 128 | 129 | if [ -z "${2}" ] || [ "${2}" = '' ]; then 130 | printf 'Service name (%s) is not provided!\n' "${service_choices}" 131 | 132 | exit 1 133 | fi 134 | 135 | case "${2}" in 136 | core) 137 | ${exec_core} /bin/sh 138 | 139 | exit ${?} 140 | ;; 141 | monitor) 142 | ${exec_monitor} /bin/bash 143 | 144 | exit ${?} 145 | ;; 146 | *) 147 | printf "\`%s\` is not a valid service name!\n" "${2}" 148 | printf 'Valid options are: %s.\n' "${service_choices}" 149 | 150 | exit 1 151 | ;; 152 | esac 153 | ;; 154 | masternode-enode-url | masternode-enode | mn-enode-url | mn-enode) 155 | check_max_arguments_count ${#} 1 "${command_pattern_masternode}" 156 | ${exec_core} sh energi-masternode-enode-url.sh 157 | 158 | exit ${?} 159 | ;; 160 | setup) 161 | setup_monitor() { 162 | ${run} --entrypoint='/bin/bash nodemon.sh' --user=root monitor 163 | } 164 | 165 | setup_core() { 166 | ${run} \ 167 | --entrypoint '/bin/sh /setup/setup.sh' \ 168 | --user=root --volume="${PWD}/setup:/setup" \ 169 | core && bootstrap_chaindata 170 | } 171 | 172 | check_max_arguments_count ${#} 2 "${command_pattern_setup}" 173 | 174 | case "${2}" in 175 | '' | all) 176 | setup_core && ${up} core && setup_monitor && ${up} monitor 177 | 178 | exit ${?} 179 | ;; 180 | core) 181 | setup_core && ${up} core 182 | 183 | exit ${?} 184 | ;; 185 | monitor) 186 | setup_monitor && ${up} monitor 187 | 188 | exit ${?} 189 | ;; 190 | *) 191 | printf "\`%s\` is not a valid argument for the subcommand \`setup\`.\n" \ 192 | "${2}" 193 | printf '%s\n' "${service_arguments_message}" 194 | 195 | exit 1 196 | ;; 197 | esac 198 | ;; 199 | start) 200 | check_max_arguments_count ${#} 2 "${command_pattern_start}" 201 | 202 | case "${2}" in 203 | '' | all) 204 | ${up} 205 | 206 | exit ${?} 207 | ;; 208 | core) 209 | ${up} core 210 | 211 | exit ${?} 212 | ;; 213 | monitor) 214 | ${up} monitor 215 | 216 | exit ${?} 217 | ;; 218 | *) 219 | printf "\`%b\` is not a valid argument for the subcommand \`start\`.\n" \ 220 | "${2}" 221 | printf '%b\n' "${service_arguments_message}" 222 | 223 | exit 1 224 | ;; 225 | esac 226 | ;; 227 | staking-status | status) 228 | check_max_arguments_count ${#} 1 "${command_pattern_status}" 229 | ${exec_core} sh energi-core-node-status.sh 230 | 231 | exit ${?} 232 | ;; 233 | update) 234 | update_value_in_file() { 235 | pattern_prefix="${1}" 236 | pattern_value="${2}" 237 | new_value="${3}" 238 | target="${4}" 239 | current_value="$(value_from_file \ 240 | "${pattern_prefix}" \ 241 | "${pattern_value}" \ 242 | "${target}")" 243 | 244 | if [ "${new_value}" != "${current_value}" ] && [ -f "${target}" ]; then 245 | printf "Current value \`%s\` differs from the provided one: \`%s\`.\n" \ 246 | "${current_value}" \ 247 | "${new_value}" 248 | printf "Updating it in \`%s\`.\n" "${target}" 249 | sed -i \ 250 | "s/^\(${pattern_prefix}\)${pattern_value}$/\1${new_value}/" \ 251 | "${target}" 252 | fi 253 | } 254 | 255 | value_from_file() { 256 | pattern_prefix="${1}" 257 | pattern_value="${2}" 258 | file="${3}" 259 | sed -n "s/${pattern_prefix}\(${pattern_value}\)$/\1/p" "${file}" 260 | } 261 | 262 | case "${2}" in 263 | all | core | monitor) 264 | check_max_arguments_count ${#} 3 "${command_pattern_update}" 265 | ;; 266 | *) check_max_arguments_count ${#} 2 "${command_pattern_update}" ;; 267 | esac 268 | 269 | update="${up} --build" 270 | command="${update}" 271 | git pull 272 | 273 | case "${2}" in 274 | core) command="${update} core" ;; 275 | monitor) command="${update} --no-deps monitor" ;; 276 | esac 277 | 278 | for last_argument in "${@}"; do :; done 279 | 280 | if [ "${last_argument}" = 'update' ]; then 281 | last_argument='' 282 | fi 283 | 284 | pattern_version_value='v[0-9]\+\.[0-9]\+\.[0-9]\+' 285 | env_version="$(value_from_file \ 286 | '^ENERGI_VERSION=' \ 287 | "${pattern_version_value}" \ 288 | "${env}")" 289 | 290 | case "${last_argument}" in 291 | '' | all | core | monitor) version="${env_version}" ;; 292 | *) 293 | version=$(printf '%s' \ 294 | "${last_argument}" | grep "${pattern_version_value}") 295 | 296 | if [ -z "${version}" ] || [ "${version}" = '' ]; then 297 | printf 'Invalid version format!\n' 298 | printf 'Version must be formatted like vX.Y.Z (for example: v1.1.4).\n' 299 | printf 'Version provided: %s\n' "${last_argument}" 300 | 301 | exit 1 302 | elif [ "${version}" != "${env_version}" ]; then 303 | export ENERGI_VERSION="${version}" 304 | fi 305 | ;; 306 | esac 307 | 308 | case "${last_argument}" in 309 | '' | all | monitor) 310 | pattern_monitor_image_prefix='^[[:space:]]*image: ' 311 | pattern_monitor_tag_value='.*' 312 | update_value_in_file \ 313 | "${pattern_monitor_image_prefix}" \ 314 | "${pattern_monitor_tag_value}" \ 315 | "$(value_from_file \ 316 | "${pattern_monitor_image_prefix}" \ 317 | "${pattern_monitor_tag_value}" \ 318 | 'compose.override.template.yaml')" \ 319 | 'compose.override.yaml' 320 | ;; 321 | esac 322 | 323 | ${command} 324 | 325 | exit ${?} 326 | ;; 327 | *) 328 | printf "\`%s\` is not a valid subcommand!\n" "${1}" 329 | print_help_message 330 | 331 | exit 1 332 | ;; 333 | esac 334 | -------------------------------------------------------------------------------- /docker-compose/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Energi Core Node in a Docker container using Docker Compose 2 | 3 | The original files were cloned from [Github Repo](https://github.com/eandersons/energi-docker-compose) by [Edgars](https://github.com/eandersons). The private keys embedded in the repo was removed to ensure there is no back door to the environment. 4 | 5 | This repository is meant to ease running Energi Core Node in a Docker container 6 | using [Docker Compose](https://docs.docker.com/compose/) and the official 7 | [Energi image](https://hub.docker.com/r/energicryptocurrency/energi). 8 | 9 | As Energi Core node officially can be run on macOS, Ubuntu and Windows (menu 10 | subsections "Staking Guides" and "VPS Guides" in 11 | [Energi Support Wiki](https://wiki.energi.world/en/home)), this repository is 12 | intended for use on non-Ubuntu Linux machines, though `energi-docker-compose` 13 | can be used on Ubuntu as well and it should work on macOS too. 14 | Theoretically this repository should also work on Windows by using WSL and maybe 15 | Git Bash or any other Linux shell emulator that supports commands used in the 16 | helper shell script [`helper`](helper). 17 | 18 | --- 19 | 20 | - [Prerequisites](#prerequisites) 21 | - [Run Energi Core Node](#run-energi-core-node) 22 | - [Masternode](#masternode) 23 | - [Troubleshooting](#troubleshooting) 24 | - [Apply preimages](#apply-preimages) 25 | - [Bootstrap chaindata](#bootstrap-chaindata) 26 | - [Energi Core Node Monitor](#energi-core-node-monitor) 27 | - [Update](#update) 28 | - [Helper script](#helper-script) 29 | - [Credits](#credits) 30 | 31 | --- 32 | 33 | ## Prerequisites 34 | 35 | Requirements to run a Energi Core Node in a Docker container: 36 | 37 | - [Docker](https://docs.docker.com/engine/install/); 38 | - [Docker Compose](https://docs.docker.com/compose/install/); 39 | - enough free space to store blockchain data (at the beginning of January 2022 40 | size of the Energi Core Node data volume is roughly 50 GB). 41 | 42 | ## Run Energi Core Node 43 | 44 | To run Energi Core Node in a Docker container: 45 | 46 | - clone this git repository: 47 | `git clone https://github.com/eandersons/energi-docker-compose.git`; 48 | - create the following files: 49 | 50 | - `configuration/energi_account_address` that contains the Energi account 51 | address; 52 | 53 | to add multiple accounts for staking, they must be specified as a comma 54 | separated list of addresses; 55 | 56 | - `configuration/energi_account_password` that contains the Energi account 57 | password; 58 | 59 | to use multiple accounts for staking each password must be entered in a 60 | separate line in the same order addresses are specified in 61 | `configuration/energi_account_address`; these files are used to get 62 | account's address and password to automatically unlock account for staking 63 | when launching Energi Core Node; 64 | 65 | - copy keystore file(s) to 66 | [`setup/.energi_core/keystore`](setup/.energi_core/keystore); 67 | 68 | > Note: original keystore file(s) should be stored in a safe place as the 69 | > keystore file(s) that will be placed in the directory 70 | > [`setup/.energi_core/keystore`](setup/.energi_core/keystore) will be moved 71 | > to a Docker volume. 72 | 73 | - open the necessary ports for external inbound access in router and/or 74 | firewall: 75 | 76 | - `39797` TCP; 77 | - `39797` UDP; 78 | 79 | `39797` TCP and UDP ports are required for staking and Masternode as it is 80 | mentioned 81 | [here (section "1.7. Firewall Rules")](https://wiki.energi.world/en/advanced/core-node-vps#h-17-firewall-rules); 82 | 83 | - optionally, the Energi Core Node Monitor container can be enabled; 84 | instructions on how to do it can be found in 85 | [`nodemon/ReadMe.md`](nodemon/ReadMe.md); 86 | - to move keystore file to the Energi data directory volume, bootstrap chaindata 87 | and start the Energi Core Node container the following command should be 88 | executed: `./helper setup core` (or `./helper setup` if Energi Core Node 89 | Monitor container should be set up and started as well and all the neccessary 90 | preparation for it has been done); 91 | 92 | > `docker compose` is used in `./helper setup` so `sudo` might be necessary. 93 | 94 | The aforementioned actions must be executed only once - when running Energi Core 95 | Node container for the first time. Later on container can be started with the 96 | command `docker compose up --detach` or with the helper command 97 | `./helper start`. 98 | 99 | To check if Energi Core Node is running and account is unlocked for staking, the 100 | command `./helper status` should be executed. When Energi Core Node is fully 101 | synchronised, value under `nrg.syncing:` is `false` and value for `miner` and 102 | `staking` in the output under `miner.stakingStatus():` is `true`. If not, a 103 | block synchronisation might be in progress and `./helper status` should be 104 | executed after a while again to check if Energi Core Node is syncrhonised. 105 | 106 | ## Masternode 107 | 108 | `energi-docker-compose` is masternode ready. Masternode can be enabled by 109 | following the official 110 | [Masternode Guide](https://wiki.energi.world/en/masternode-guide). 111 | 112 | A helper command is available to get masternode enode URL: 113 | `./helper masternode-enode-url` (shorter aliases are available as well: 114 | `masternode-enode`, `mn-enode-url`, `mn-enode`). It covers steps 3.1 and 3.2 115 | from the section 116 | [Announcing the Masternode](https://wiki.energi.world/en/masternode-guide#h-3-announcing-the-masternode).\ 117 | Alternatively step 3.1 can be executed with `./helper attach`, then 3.2 as 118 | described in the guide. 119 | 120 | ## Troubleshooting 121 | 122 | General troubleshooting is described in the official 123 | [Energi troubleshooting guide](https://wiki.energi.world/en/core-node-troubleshoot). 124 | 125 | The following actions executed one by one might help if something goes sideways 126 | with chain synchronisation in Energi Core Node container: 127 | 128 | 1. [apply preimages](#apply-preimages); 129 | 130 | if the problem is not solved, the next step should be executed; 131 | 132 | 2. [bootstrap chaindata](#bootstrap-chaindata). 133 | 134 | If applying preimages and bootstraping chaindata did not help, it might help if 135 | those actions are executed again. 136 | [Energi support](https://wiki.energi.world/en/support/help-me) should be 137 | contacted if the problem is still persistent after multiple tries. 138 | 139 | ### Apply preimages 140 | 141 | Official Energi documentation: 142 | [Apply Preimages](https://wiki.energi.world/en/core-node-troubleshoot#preimages). 143 | 144 | To apply preimages for Energi Core Node container the following command 145 | can be used: `./helper apply-preimages`. 146 | 147 | > `docker compose` is used in `./helper apply-preimages` so `sudo` might be 148 | > necessary. 149 | 150 | ### Bootstrap chaindata 151 | 152 | Official Energi documentation: 153 | [Bootstrap Chaindata](https://wiki.energi.world/en/core-node-troubleshoot#bootstrap). 154 | 155 | To bootstrap chaindata for Energi Core Node container the following command can 156 | be used: `./helper bootstrap-chaindata`. 157 | 158 | > `docker compose` is used in `./helper bootstrap-chaindata` so `sudo` might be 159 | > necessary. 160 | 161 | ## Energi Core Node Monitor 162 | 163 | It is possible to enable Energi Core Node Monitor. Instructions on how to set it 164 | up are located in [`nodemon/ReadMe.md`](nodemon/ReadMe.md). 165 | 166 | Energi Core Node Monitor container provides some additional features that can be 167 | enabled optionally: 168 | 169 | - configurable interval between Monitor runs 170 | ([`ECNM_INTERVAL`](nodemon/ReadMe.md#ecnm_interval)); 171 | - configurable timezone for time display in messages 172 | ([`MESSAGE_TIME_ZONE`](nodemon/ReadMe.md#message_time_zone)); 173 | - display the current Enrgi market price in the configured currency in 174 | information messages 175 | ([`MARKET_PRICE_IN_INFORMATION`](nodemon/ReadMe.md#market_price_in_information)); 176 | - display reward amount, balance and its changes also in the configured currency 177 | ([`NRG_AMOUNT_IN_CURRENCY`](nodemon/ReadMe.md#nrg_amount_in_currency)). 178 | 179 | ## Update 180 | 181 | To get changes from the repository and update Energi Core Node images and 182 | containers the command `./helper update` should be executed. Or 183 | `./helper update core` or `./helper update monitor` to update image and 184 | container only for the specified service. 185 | 186 | It is possible to build images and create containers for Energi Core Node 187 | versions other than the one specified in `.env`: `./helper update vX.Y.Z` or 188 | `./helper update core|monitor vX.Y.Z`. This may be especially useful for cases 189 | when a new version has been released but it has not been reflected in `.env` yet 190 | to update Energi Core Node (and Monitor) to the lateset version. 191 | Note that there is a chance that this command will fail (most probably because 192 | of an error while building Monitor image when the newest Energi version cannot 193 | be compiled using the Go version specified in `nodemon/Dockerfile`), and in such 194 | case the following commands should be executed: 195 | 196 | 1. `./helper start core` to start Core container as the image for the newest 197 | Energi Core Node version should be already built; 198 | 2. `./helper update monitor` if Energi Core Node Monitor is used; this will use 199 | the version that is specified in `.env` 200 | 201 | or `./helper update` to use Core and Monitor version specified in `.env` till 202 | isues are resolved in the repopsitory. 203 | 204 | ## Helper script 205 | 206 | A little helper script [`helper`](helper) is available. To see what it provides, 207 | `./helper help` should be executed. 208 | 209 | ## Credits 210 | 211 | A list of tools and sources used in this repository: 212 | 213 | - [Docker Engine](https://docs.docker.com/engine/); 214 | - [Docker Compose](https://docs.docker.com/compose/); 215 | - [Energi Docker image](https://hub.docker.com/r/energicryptocurrency/energi) 216 | (source: 217 | [Energi Core GitHub repository](https://github.com/energicryptocurrency/energi) 218 | ([`containers/docker/master-alpine/Dockerfile`](https://github.com/energicryptocurrency/energi/blob/master/containers/docker/master-alpine/Dockerfile))); 219 | - [Energi Core Node Monitor script `nodemon.sh`](https://github.com/energicryptocurrency/energi3-provisioning/blob/master/scripts/linux/nodemon.sh). 220 | -------------------------------------------------------------------------------- /scripts/windows/energi3-windows-installer.bat: -------------------------------------------------------------------------------- 1 | @echo OFF 2 | 3 | ::#################################################################### 4 | :: Copyright (c) 2019 5 | :: All rights reserved. 6 | :: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | :: 8 | :: Desc: Batch script to download and setup Energi 3.x on Windows PC. 9 | :: The script will upgrade an existing installation. 10 | :: 11 | :: Version: 12 | :: 1.0.0 ZA Initial Script 13 | :: 1.2.4 ZA Bug Fixes and Enhancements 14 | :: 1.2.10 20200310 ZA added removedb to upgrade 15 | :: 16 | :: Download and run the batch script to: 17 | :: explorer.exe https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/windows/energi3-windows-installer.bat 18 | ::#################################################################### 19 | 20 | cls 21 | @echo. 22 | @echo. 23 | setlocal ENABLEEXTENSIONS 24 | 25 | :: Check OS Architecture (32-bit or 64-bit) 26 | wmic os get osarchitecture | findstr bit > "%userprofile%\osarchitecture.txt" 27 | set /p osarch= < "%userprofile%\osarchitecture.txt" 28 | del "%userprofile%\osarchitecture.txt" 29 | :: remove whitespace 30 | set osarch=%osarch: =% 31 | if "%osarch%" == "64-bit" ( 32 | @echo "Windows x86 %osarch% is supported" 33 | set "ARCH=amd64" 34 | goto :doneSysCheck 35 | ) 36 | if "%osarch%" == "32-bit" ( 37 | @echo "Windows x86 %osarch% is supported" 38 | set "ARCH=i686" 39 | goto :doneSysCheck 40 | ) 41 | 42 | @echo "Windows x86 %osarch% is not supported" 43 | exit /b 44 | 45 | :doneSysCheck 46 | 47 | :: Set Default Install Directory 48 | set "ENERGI3_HOME=%ProgramFiles%\Energi Gen 3" 49 | 50 | ::@echo Enter Full Path where you want to install Energi3 Node. 51 | :: :checkhome 52 | :: set "CHK_HOME=Y" 53 | :: set /p ENERGI3_HOME="Enter Install Path (Default: %ENERGI3_HOME%): " 54 | :: set /p CHK_HOME="Is Install path correct: %ENERGI3_HOME% (Y/n): " 55 | :: if /I not "%CHK_HOME%" == "Y" goto :checkhome 56 | 57 | @echo Energi Core Node will be installed in %ENERGI3_HOME% 58 | 59 | :: Confirm Mainnet or Testnet 60 | :setNetwork 61 | set "isMainnet=Y" 62 | :: set /p isMainnet="Are you setting up Mainnet [Y]/n: " 63 | 64 | if /I "%isMainnet%" == "Y" ( 65 | set "DATA_DIR=EnergiCore3" 66 | echo The application will be setup for Mainnet 67 | goto :setdir 68 | ) 69 | 70 | if /I "%isMainnet%" == "N" ( 71 | set "DATA_DIR=EnergiCore3\testnet" 72 | echo The application will be setup for Testnet 73 | goto :setdir 74 | ) 75 | 76 | :: Set Directories 77 | :setdir 78 | set "BIN_DIR=%ENERGI3_HOME%\bin" 79 | set "JS_DIR=%ENERGI3_HOME%\js" 80 | set "PW_DIR=%ENERGI3_HOME%\secure" 81 | set "TMP_DIR=c:\tmp" 82 | set "CONF_DIR=%userprofile%\AppData\Roaming\%DATA_DIR%" 83 | 84 | :: Set Executables & Configuration 85 | set "EXE_NAME=energi3.exe" 86 | set "DATA_CONF=energi3.toml" 87 | 88 | :: Save location of current working directory 89 | @echo Get Current Working Directory. 90 | cd > dir.tmp 91 | set /p mycwd= < dir.tmp 92 | del dir.tmp 93 | 94 | :: Create directories if it does not exist 95 | if Not exist "%TMP_DIR%\" ( 96 | @echo Creating directory: %TMP_DIR% 97 | md "%TMP_DIR%" 98 | ) 99 | 100 | :: Add Application specific PATH 101 | setx PATH "%windir%\System32\OpenSSH\;%userprofile%\AppData\Local\Microsoft\WindowsApps;%PATH%" 102 | setx PATH "%windir%\system32;%windir%;%windir%\System32\Wbem;%windir%\System32\WindowsPowerShell\v1.0\;%PATH%" 103 | setx PATH "%PATH%;%BIN_DIR%;%TMP_DIR%" 104 | 105 | ::stop energi3 console if running 106 | :stopEnergi3 107 | FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE_NAME%"') DO IF %%x == %EXE_NAME% goto Energi3Running 108 | echo %EXE_NAME% is not running 109 | goto endStopEnergi3 110 | :Energi3Running 111 | echo Stopping "%EXE_NAME%" 112 | TIMEOUT /T 5 113 | Taskkill /F /IM "%EXE_NAME%" 114 | :endStopEnergi3 115 | 116 | :: Download utilities 117 | :downloadutils 118 | @echo Changing to the %TMP_DIR% folder. 119 | cd "%TMP_DIR%" 120 | 121 | @echo Downloading utility files. 122 | if exist "%TMP_DIR%\7za.exe" ( 123 | del "%TMP_DIR%\7za.exe" 124 | ) 125 | if exist "%TMP_DIR%\util.7z" ( 126 | del "%TMP_DIR%\util.7z" 127 | ) 128 | 129 | :: runas with administrator TrustLevel 130 | runas /TrustLevel:0x20000 "bitsadmin /RESET /ALLUSERS" 131 | bitsadmin /TRANSFER DL7zipAndUtil /DOWNLOAD /PRIORITY FOREGROUND "https://github.com/energicryptocurrency/energi3-provisioning/raw/master/scripts/thirdparty/7za.exe?dl=1" "%TMP_DIR%\7za.exe" "https://github.com/energicryptocurrency/energi3-provisioning/raw/master/scripts/thirdparty/util.7z?dl=1" "%TMP_DIR%\util.7z" 132 | "%TMP_DIR%\7za.exe" x -y "%TMP_DIR%\util.7z" -o "%TMP_DIR%\" 133 | bitsadmin /TRANSFER DLwget /DOWNLOAD /PRIORITY FOREGROUND "https://eternallybored.org/misc/wget/1.20.3/64/wget.exe" "%TMP_DIR%\wget.exe" 134 | 135 | @echo Downloading jq 136 | "%TMP_DIR%\wget.exe" --no-check-certificate --progress=bar:force:noscroll "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-win64.exe?dl=1" -O "%TMP_DIR%\jq.exe" 137 | 138 | :: Check if Energi3 is installed and version installed 139 | if exist "%BIN_DIR%\%EXE_NAME%" ( 140 | cd "%BIN_DIR%" 141 | set "RUN_VERSION=" 142 | FOR /f "tokens=1* delims=: " %%a IN ('"%BIN_DIR%\%EXE_NAME%" version ') DO ( 143 | SET "RUN_VERSION=%%b 144 | IF "%%a" == "Version" goto SetRunVersion 145 | ) 146 | ) 147 | 148 | @echo Cannot determine version of installed energi3.exe 149 | exit /b 150 | 151 | :SetRunVersion 152 | 153 | set RUN_VERSION=%RUN_VERSION:-=&rem.% 154 | @echo Current version of Energi3 installed: %RUN_VERSION% 155 | TIMEOUT /T 5 156 | ) else ( 157 | @echo Energi3 is not installed in %BIN_DIR% of this computer. 158 | set "NEWINSTALL=Y" 159 | goto :CHECKGITVER 160 | ) 161 | 162 | 163 | :: Set for script testing 164 | ::set "RUN_VERSION=0.5.5" 165 | 166 | :CHECKGITVER 167 | cd "%TMP_DIR%" 168 | curl -o "%TMP_DIR%\gitversion.txt" "https://api.github.com/repos/energicryptocurrency/energi3/releases/latest" 169 | 170 | type "%TMP_DIR%\gitversion.txt" | "%TMP_DIR%\jq.exe" -r .tag_name > "%TMP_DIR%\gitversion.tmp" 171 | set /p GIT_VERSION= < "%TMP_DIR%\gitversion.tmp" 172 | set GIT_VERSION=%GIT_VERSION:v=% 173 | set GIT_VERSION=%GIT_VERSION:"=% 174 | set GIT_VERSION=%GIT_VERSION:,=% 175 | del "%TMP_DIR%\gitversion.tmp" 176 | 177 | type "%TMP_DIR%\gitversion.txt" | "%TMP_DIR%\jq.exe" -r ".assets | .[] | select(.name==\"energi3-windows-4.0-%ARCH%.exe\") .browser_download_url" > "%TMP_DIR%\appurl.tmp" 178 | set /p APPURL= < "%TMP_DIR%\appurl.tmp" 179 | del "%TMP_DIR%\appurl.tmp" 180 | del "%TMP_DIR%\gitversion.txt" 181 | 182 | echo GIT_VERSION: %GIT_VERSION% 183 | TIMEOUT /T 3 184 | if /I "%NEWINSTALL%" == "Y" goto :NEWVERSION 185 | 186 | :: Compare Versions 187 | call :testVersions %GIT_VERSION% %RUN_VERSION% 188 | exit /b 189 | 190 | :testVersions version1 version2 191 | call :compareVersions %1 %2 192 | if %errorlevel% == 1 goto :NEWVERSION 193 | if %errorlevel% == -1 goto :OLDVERSION 194 | if %errorlevel% == 0 goto :SAMEVERSION 195 | echo %~1 is %result% %~2 196 | exit /b 197 | 198 | 199 | :: 200 | :: Compares two version numbers and returns the result in the ERRORLEVEL 201 | :: 202 | :: Returns 1 if version1 > version2 203 | :: 0 if version1 = version2 204 | :: -1 if version1 < version2 205 | :: 206 | :: The nodes must be delimited by . or , or - 207 | :: 208 | :: Nodes are normally strictly numeric, without a 0 prefix. A letter suffix 209 | :: is treated as a separate node 210 | :: 211 | :compareVersions version1 version2 212 | setlocal enableDelayedExpansion 213 | set "v1=%~1" 214 | set "v2=%~2" 215 | call :divideLetters v1 216 | call :divideLetters v2 217 | :loop 218 | call :parseNode "%v1%" n1 v1 219 | call :parseNode "%v2%" n2 v2 220 | if %n1% gtr %n2% exit /b 1 221 | if %n1% lss %n2% exit /b -1 222 | if not defined v1 if not defined v2 exit /b 0 223 | if not defined v1 exit /b -1 224 | if not defined v2 exit /b 1 225 | goto :loop 226 | 227 | :parseNode version nodeVar remainderVar 228 | for /f "tokens=1* delims=.,-" %%A in ("%~1") do ( 229 | set "%~2=%%A" 230 | set "%~3=%%B" 231 | ) 232 | exit /b 233 | 234 | :divideLetters versionVar 235 | for %%C in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do set "%~1=!%~1:%%C=.%%C!" 236 | exit /b 237 | 238 | :: 239 | :: Main program to download and setup Energi Gen 3 240 | :: 241 | :NEWVERSION 242 | @echo Download Energi Core Node %GIT_VERSION% 243 | TIMEOUT /T 3 244 | 245 | @echo Downloading Energi3 Core Node %GIT_VERSION% from repository 246 | set "S3URL=https://s3-us-west-2.amazonaws.com/download.energi.software/releases/energi3" 247 | set "GITURL=https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts" 248 | set "ICONURL=https://github.com/energicryptocurrency/energi3-provisioning/raw/master/scripts/windows/energi3.ico" 249 | 250 | if exist "%BIN_DIR%\%EXE_NAME%" ( 251 | cd "%BIN_DIR%" 252 | "%EXE_NAME%" removedb 253 | ren "%EXE_NAME%" "%EXE_NAME%.old" 254 | ) 255 | 256 | cd %TMP_DIR% 257 | @echo Downloading Energi3 Core Node Version: %GIT_VERSION% 258 | "%TMP_DIR%\wget.exe" --no-check-certificate --progress=bar:force:noscroll "%S3URL%/%GIT_VERSION%/energi3-%GIT_VERSION%-windows-%ARCH%.zip" -O "%TMP_DIR%\energi3-%GIT_VERSION%-windows-%ARCH%.zip" 259 | 260 | "%TMP_DIR%\7za.exe" x energi3-%GIT_VERSION%-windows-%ARCH%.zip -y 261 | cd energi3-%GIT_VERSION%-windows-%ARCH%\bin 262 | 263 | 264 | if exist "%BIN_DIR%\" ( 265 | copy "%EXE_NAME%" "%BIN_DIR%" 266 | ) else ( 267 | md "%BIN_DIR%" 268 | copy "%EXE_NAME%" "%BIN_DIR%" 269 | 270 | ) 271 | 272 | if not exist "%BIN_DIR%\energi3.ico" ( 273 | @echo Downloading Energi3 icon 274 | "%TMP_DIR%\wget.exe" --no-check-certificate --progress=bar:force:noscroll "%ICONURL%?dl=1" -O "%BIN_DIR%\energi3.ico" 275 | ) 276 | 277 | if not exist "%BIN_DIR%\start_staking.bat" ( 278 | @echo Downloading staking batch script 279 | "%TMP_DIR%\wget.exe" --no-check-certificate --progress=bar:force:noscroll "%GITURL%/windows/start_staking.bat?dl=1" -O "%BIN_DIR%\start_staking.bat" 280 | ) 281 | 282 | if not exist "%BIN_DIR%\start_mn.bat" ( 283 | @echo Downloading masternode batch script 284 | "%TMP_DIR%\wget.exe" --no-check-certificate --progress=bar:force:noscroll "%GITURL%/windows/start_mn.bat?dl=1" -O "%BIN_DIR%\start_mn.bat" 285 | ) 286 | 287 | if not exist "%BIN_DIR%\energi3_ascii.txt" ( 288 | @echo Downloading Energi3 logo 289 | "%TMP_DIR%\wget.exe" --no-check-certificate --progress=bar:force:noscroll "%GITURL%/windows/energi3_ascii.txt?dl=1" -O "%BIN_DIR%\energi3_ascii.txt" 290 | ) 291 | 292 | if Not exist "%JS_DIR%\" ( 293 | @echo Creating directory: %JS_DIR% 294 | md "%JS_DIR%" 295 | ) 296 | 297 | if not exist "%JS_DIR%\utils.js" ( 298 | @echo Downloading utils.js JavaScript file 299 | "%TMP_DIR%\wget.exe" --no-check-certificate --progress=bar:force:noscroll "%GITURL%/utils/utils.js?dl=1" -O "%JS_DIR%\utils.js" 300 | ) 301 | 302 | if not exist "%CONF_DIR%\keystore\" ( 303 | @echo Creating %CONF_DIR%\keystore directory 304 | md "%CONF_DIR%\keystore" 305 | ) 306 | 307 | cd "%BIN_DIR%" 308 | goto :bootstrap 309 | 310 | 311 | :OLDVERSION 312 | @echo Current version %RUN_VERSION% is newer. Nothing to install. 313 | goto :bootstrap 314 | 315 | 316 | :SAMEVERSION 317 | @echo Versions are the same. Nothing to install. 318 | goto :bootstrap 319 | 320 | 321 | :bootstrap 322 | :: Bootstrap Settings 323 | :: set "BLK_HASH=gsaqiry3h1ho3nh" 324 | :: set BOOTSTRAP_URL="https://www.dropbox.com/s/%BLK_HASH%/blocks_n_chains.tar.gz" 325 | 326 | ::@echo Please wait for the snapshot to download. 327 | :: --no-check-certificate 328 | ::"%TMP_DIR%\wget.exe" -4q -o- "%BOOTSTRAP_URL%?dl=1" -O "%CONF_DIR%\blocks_n_chains.tar.gz" 329 | 330 | ::if Not exist "%CONF_DIR%\blocks_n_chains.tar.gz" ( 331 | :: bitsadmin /RESET /ALLUSERS 332 | :: bitsadmin /TRANSFER blocks_n_chains.tar.gz /DOWNLOAD /PRIORITY FOREGROUND "%BOOTSTRAP_URL%?dl=1" "%CONF_DIR%\blocks_n_chains.tar.gz" 333 | ::) 334 | 335 | ::"%TMP_DIR%\7za.exe" e -y "%CONF_DIR%\blocks_n_chains.tar.gz" -o"%CONF_DIR%\" 336 | ::if Not exist "%CONF_DIR%\blocks_n_chains.tar" ( 337 | :: echo Download of the snapshot failed. 338 | :: pause 339 | :: EXIT 340 | ::) 341 | 342 | :createshortcut 343 | @echo Set WshShell = WScript.CreateObject("WScript.Shell") > "%TMP_DIR%\CreateShortcut.vbs" 344 | @echo sLinkFile = "%userprofile%\Desktop\Energi Core Node.lnk" >> "%TMP_DIR%\CreateShortcut.vbs" 345 | @echo Set oMyShortCut = WshShell.CreateShortcut(sLinkFile) >> "%TMP_DIR%\CreateShortcut.vbs" 346 | @echo oMyShortcut.IconLocation = "%BIN_DIR%\energi3.ico" >> "%TMP_DIR%\CreateShortcut.vbs" 347 | if /I "%isMainnet%"=="Y" ( 348 | @echo oMyShortCut.TargetPath = "%BIN_DIR%\start_mn.bat" >> "%TMP_DIR%\CreateShortcut.vbs" 349 | ) else ( 350 | @echo oMyShortCut.TargetPath = "%BIN_DIR%\staking_mn.bat" -t >> "%TMP_DIR%\CreateShortcut.vbs" 351 | ) 352 | @echo oMyShortCut.WorkingDirectory = "%BIN_DIR%" >> "%TMP_DIR%\CreateShortcut.vbs" 353 | @echo oMyShortCut.Save >> "%TMP_DIR%\CreateShortcut.vbs" 354 | 355 | if not exist "%userprofile%\Desktop\Energi Core Node.lnk" ( 356 | cscript "%TMP_DIR%\CreateShortcut.vbs" 357 | @echo Energi3 shortcut created on Desktop 358 | ) else ( 359 | @echo Shortcut already exists 360 | ) 361 | del "%TMP_DIR%\CreateShortcut.vbs" 362 | 363 | 364 | :utilCleanup 365 | @echo Cleanup utilities files downloaded for setup from %TMP_DIR% 366 | :: TIMEOUT /T 3 367 | del %BIN_DIR%\%EXE_NAME%.old 368 | rmdir /s /q "%TMP_DIR%" 369 | 370 | :: Set keystore password 371 | ::if not exist "%PW_DIR%\securefile.txt" ( 372 | :: set "SETPWD=N" 373 | :: @echo You can set password of your keystore account for automated start of staking/mining. 374 | :: @echo It will create a secure/hidden file with the password. 375 | :: set /p SETPWD="Do you want to save your password? (y/N): " 376 | :: if /I "%SETPWD%" == "Y" ( 377 | :: if Not exist "%PW_DIR%\" ( 378 | :: @echo Creating hidden directory: %PW_DIR% 379 | :: md "%PW_DIR%" 380 | :: attrib +r +h +s "%PW_DIR%" 381 | :: ) 382 | :: cd "%PW_DIR%" 383 | :: :setpassword 384 | :: set /p ACCTPASSWD1="Enter your keystore account password: " 385 | :: set /p ACCTPASSWD2="Re-enter your keystore account password: " 386 | :: if "%ACCTPASSWD1%" NEQ "%ACCTPASSWD2%" ( 387 | :: @echo Passwords do not match. Try again. 388 | :: goto :setpassword 389 | :: ) 390 | :: echo Password is %ACCTPASSWD1% 391 | :: echo %ACCTPASSWD1% 1> securefile.txt 392 | :: attrib +r "%PW_DIR%\securefile.txt" 393 | :: ) 394 | ::) 395 | 396 | @echo Move back to Initial Working Directory. 397 | cd "%mycwd%" 398 | 399 | :: Color 400 | :: Background Text 401 | :: 0 = Black 8 = Gray 402 | :: 1 = Blue 9 = Light Blue 403 | :: 2 = Green A = Light Green 404 | :: 3 = Aqua B = Light Aqua 405 | :: 4 = Red C = Light Red 406 | :: 5 = Purple D = Light Purple 407 | :: 6 = Yellow E = Light Yellow 408 | :: 7 = White F = Bright White 409 | 410 | color 0A 411 | cls 412 | @echo. 413 | @echo. 414 | type "%BIN_DIR%\energi3_ascii.txt" 415 | @echo. 416 | color 0F 417 | @echo Congratulations! Energi Node Version %GIT_VERSION% is installed on this computer 418 | @echo. 419 | @echo Install directory is: %ENERGI3_HOME% 420 | @echo. 421 | @echo To start Energi Core Node, double-clicking on the "Energi Core Node" shortcut on the Desktop. 422 | @echo. 423 | 424 | 425 | :: End batch script 426 | cmd.exe /k cmd /c 427 | -------------------------------------------------------------------------------- /scripts/macos/energi3-macos-installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ###################################################################### 4 | # Copyright (c) 2020 5 | # All rights reserved. 6 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 7 | # 8 | # Desc: Batch script to download and setup Energi3 on MacOS. The 9 | # script will upgrade an existing installation. 10 | # 11 | # Version: 12 | # 1.2.3 20200302 ZA Initial Script 13 | # 1.2.10 20200310 ZA added removedb to upgrade 14 | # 15 | : ' 16 | # Run the script to get started: 17 | ``` 18 | bash -i <( curl -sL https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts/macos/energi3-macos-installer.sh ) 19 | ``` 20 | ' 21 | ###################################################################### 22 | 23 | 24 | ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### 25 | # Global Variables 26 | ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### 27 | 28 | # Check if we have enough memory 29 | FREE_BLOCKS=$(vm_stat | grep free | awk '{ print $3 }' | sed 's/\.//') 30 | INACTIVE_BLOCKS=$(vm_stat | grep inactive | awk '{ print $3 }' | sed 's/\.//') 31 | SPECULATIVE_BLOCKS=$(vm_stat | grep speculative | awk '{ print $3 }' | sed 's/\.//') 32 | 33 | FREE=$((($FREE_BLOCKS+SPECULATIVE_BLOCKS)*4096/1048576)) 34 | INACTIVE=$(($INACTIVE_BLOCKS*4096/1048576)) 35 | TOTAL=$((($FREE+$INACTIVE))) 36 | 37 | if [[ ${TOTAL} -lt 850 ]]; then 38 | echo "This installation requires at least 1GB of RAM."; 39 | exit 1 40 | fi 41 | 42 | # OS Settings 43 | export DEBIAN_FRONTEND=noninteractive 44 | 45 | # Locations of Repositories and Guide 46 | API_URL="https://api.github.com/repos/energicryptocurrency/energi3/releases/latest" 47 | # Production 48 | if [[ -z ${BASE_URL} ]] 49 | then 50 | BASE_URL="https://raw.githubusercontent.com/energicryptocurrency/energi3-provisioning/master/scripts" 51 | fi 52 | #==> For testing set environment variable 53 | #BASE_URL="https://raw.githubusercontent.com/zalam003/EnergiCore3/master/production/scripts" 54 | SCRIPT_URL="${BASE_URL}/macos" 55 | TP_URL="${BASE_URL}/thirdparty" 56 | DOC_URL="https://docs.energi.software" 57 | S3URL="https://s3-us-west-2.amazonaws.com/download.energi.software/releases/energi3" 58 | 59 | # Energi3 Bootstrap Settings 60 | #export BLK_HASH=gsaqiry3h1ho3nh 61 | #export BOOTSTRAP_URL="https://www.dropbox.com/s/%BLK_HASH%/energi3bootstrap.tar.gz" 62 | 63 | # Snapshot Block (need to update) 64 | MAINNETSSBLOCK=1500000 65 | TESTNETSSBLOCK=1500000 66 | 67 | # Set Executables & Configuration 68 | export ENERGI3_EXE=energi3 69 | export ENERGI3_CONF=energi3.toml 70 | export ENERGI3_IPC=energi3.ipc 71 | 72 | # Set colors 73 | BLUE=`tput setaf 4` 74 | RED=`tput setaf 1` 75 | GREEN=`tput setaf 2` 76 | YELLOW=`tput setaf 2` 77 | NC=`tput sgr0` 78 | 79 | ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### 80 | # Functions 81 | ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### 82 | 83 | _os_arch () { 84 | # Check Architecture 85 | OSNAME=`system_profiler SPSoftwareDataType | grep Kernel | awk '{print $3}'` 86 | OSVERSIONLONG=`sw_vers -productVersion` 87 | KERNELVERSION=`echo ${OSVERSIONLONG} | awk -F\. '{ print $1 }'` 88 | MAJORVERSION=`echo ${OSVERSIONLONG} | awk -F\. '{ print $2 }'` 89 | 90 | # 10.15 - Catalina 91 | # 10.14 - Mojave 92 | # 10.13 - High Sierra 93 | # 10.12 - Sierra 94 | # 10.11 - El Capitan 95 | 96 | echo -n "${OSNAME} ${OSVERSIONLONG} is " 97 | if [ "${OSNAME}" = "Darwin" ] && [ ${KERNELVERSION} -ge 10 ] && [ ${MAJORVERSION} -ge 12 ] 98 | then 99 | echo "${GREEN}supported${NC}" 100 | else 101 | echo "${RED}not supported${NC}" 102 | exit 0 103 | fi 104 | 105 | echo -n "OS architecture " 106 | OSARCH=`uname -m` 107 | if [ "${OSARCH}" != "x86_64" ] 108 | then 109 | echo "${RED}${OSARCH} is not supported${NC}" 110 | echo "Please goto our website to check which platforms are supported." 111 | exit 0 112 | else 113 | echo "${GREEN}${OSARCH} is supported${NC}" 114 | sleep 0.3 115 | fi 116 | 117 | } 118 | 119 | _check_runas () { 120 | 121 | # Who is running the script 122 | # If root no sudo required 123 | # If user has sudo privilidges, run sudo when necessary 124 | 125 | RUNAS=`whoami` 126 | 127 | if [[ $EUID = 0 ]] 128 | then 129 | SUDO="" 130 | else 131 | ISSUDOER=`getent group sudo | grep ${RUNAS}` 132 | if [ ! -z "${ISSUDOER}" ] 133 | then 134 | SUDO='sudo' 135 | else 136 | echo "User ${RUNAS} does not have sudo permissions." 137 | echo "Run ${BLUE}sudo ls -l${NC} to set permissions if you know the user ${RUNAS} has sudo previlidges" 138 | echo "and then rerun the script" 139 | echo "Exiting script..." 140 | sleep 3 141 | exit 0 142 | fi 143 | fi 144 | } 145 | 146 | _check_install () { 147 | 148 | CHKV3USRTMP=/tmp/chk_v3_usr.tmp 149 | if [[ -d ${HOME}/Library/EnergiCore3 ]] 150 | then 151 | find ${HOME}/Library/EnergiCore3 -name nodekey | awk -F\/ '{print $3}' > ${CHKV3USRTMP} 152 | else 153 | touch ${CHKV3USRTMP} 154 | fi 155 | V3USRCOUNT=`wc -l ${CHKV3USRTMP} | awk '{ print $1 }'` 156 | # Clean-up temporary file 157 | rm -rf ${CHKV3USRTMP} 158 | 159 | USRNAME=`whoami` 160 | cd 161 | export USRHOME=`pwd` 162 | export ENERGI3_HOME="${USRHOME}/energi3" 163 | 164 | case ${V3USRCOUNT} in 165 | 166 | 0) 167 | 168 | # New Installation: 169 | # * No energi3.ipc file on the computer 170 | # * No energi.conf or energid on the computer 171 | # 172 | # Migration Installation: 173 | # * energi.conf and energid exists 174 | # * No energi3.ipc file on the computer 175 | # * energi3.ipc file exists on the computer 176 | # * Keystore file does not exists 177 | # * No $ENERGI3_HOME/etc/migrated_to_v3.log exists 178 | 179 | INSTALLTYPE=new 180 | 181 | ;; 182 | 183 | 1) 184 | 185 | # Upgrade existing version of Energi 3: 186 | # * One instance of Energi3 is already installed 187 | # * energi3.ipc file exists 188 | # * Version on computer is older than version in Github 189 | 190 | INSTALLTYPE=upgrade 191 | echo "The script will upgrade to the latest version of energi3 from Github" 192 | echo "if available as user: ${GREEN}${USRNAME}${NC}" 193 | 194 | ;; 195 | 196 | *) 197 | 198 | # Upgrade existing version of Energi3: 199 | # * More than one instance of Energi3 is already installed 200 | # * energi3.ipc file exists 201 | # * Version on computer is older than version in Github 202 | # * User selects which instance to upgrade 203 | 204 | INSTALLTYPE=upgrade 205 | 206 | ;; 207 | 208 | esac 209 | 210 | } 211 | 212 | _setup_appdir () { 213 | 214 | # Setup application directories if does not exist 215 | 216 | echo "Energi3 will be installed in ${ENERGI3_HOME}" 217 | sleep 0.5 218 | # Set application directories 219 | export BIN_DIR=${ENERGI3_HOME}/bin 220 | export ETC_DIR=${ENERGI3_HOME}/etc 221 | export JS_DIR=${ENERGI3_HOME}/js 222 | export PW_DIR=${ENERGI3_HOME}/.secure 223 | export TMP_DIR=${ENERGI3_HOME}/tmp 224 | 225 | # Create directories if it does not exist 226 | if [ ! -d ${BIN_DIR} ] 227 | then 228 | echo " Creating directory: ${BIN_DIR}" 229 | mkdir -p ${BIN_DIR} 230 | fi 231 | if [ ! -d ${ETC_DIR} ] 232 | then 233 | echo " Creating directory: ${ETC_DIR}" 234 | mkdir -p ${ETC_DIR} 235 | fi 236 | if [ ! -d ${JS_DIR} ] 237 | then 238 | echo " Creating directory: ${JS_DIR}" 239 | mkdir -p ${JS_DIR} 240 | fi 241 | if [ ! -d ${TMP_DIR} ] 242 | then 243 | echo " Creating directory: ${TMP_DIR}" 244 | mkdir -p ${TMP_DIR} 245 | fi 246 | 247 | echo 248 | echo "Changing ownership of ${ENERGI3_HOME} to ${USRNAME}" 249 | if [[ ${EUID} = 0 ]] 250 | then 251 | chown -R ${USRNAME}:${USRNAME} ${ENERGI3_HOME} 252 | fi 253 | 254 | } 255 | 256 | _check_ismainnet () { 257 | 258 | # Confirm Mainnet or Testnet 259 | # Default: Mainnet 260 | 261 | isMainnet=y 262 | export CONF_DIR=${USRHOME}/.energicore3 263 | export FWPORT=39797 264 | export APPARG='' 265 | export isMainnet=y 266 | echo "The application will be setup for Mainnet" 267 | 268 | } 269 | 270 | _install_energi3 () { 271 | 272 | # Download and install node software and supporting scripts 273 | 274 | # Name of scripts 275 | NODE_SCRIPT=start_node.sh 276 | MN_SCRIPT=start_mn.sh 277 | JS_SCRIPT=utils.js 278 | #NODE_SCRIPT=run_macos.sh 279 | #MN_SCRIPT=run_mn_macos.sh 280 | 281 | # Check Github for URL of latest version 282 | if [ -z "${GIT_LATEST}" ] 283 | then 284 | curl -fsSL https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 --output "${HOME}/jq" 285 | chmod 755 jq 286 | GITHUB_LATEST=$( curl -s ${API_URL} ) 287 | GIT_VERSION=$( echo "${GITHUB_LATEST}" | ${HOME}/jq -r '.tag_name' ) 288 | 289 | # Extract latest version number without the 'v' 290 | GIT_LATEST=$( echo ${GIT_VERSION} | sed 's/v//g' ) 291 | rm "${HOME}/jq" 292 | fi 293 | 294 | # Download from repositogy 295 | echo "Downloading Energi Core Node and scripts" 296 | 297 | cd ${USRHOME} 298 | # Pull energi3 from Amazon S3 299 | curl -fsSL "${S3URL}/${GIT_LATEST}/energi3-${GIT_LATEST}-macos-amd64.tgz" --output energi3-${GIT_LATEST}-macos-amd64.tgz 300 | 301 | #wget -4qo- "${S3URL}/${GIT_LATEST}/energi3-${GIT_LATEST}-macos-amd64-alltools.tgz" --show-progress --progress=bar:force:noscroll 2>&1 302 | #wget -4qo- "${BIN_URL}" -O "${ENERGI3_EXE}" --show-progress --progress=bar:force:noscroll 2>&1 303 | sleep 0.3 304 | 305 | tar xvfz energi3-${GIT_LATEST}-macos-amd64.tgz 306 | sleep 0.3 307 | 308 | # Copy latest energi3 and cleanup 309 | if [[ -x "${ENERGI3_EXE}" ]] 310 | then 311 | mv energi3-${GIT_LATEST}-macos-amd64/bin/energi3 ${BIN_DIR}/. 312 | rm -rf energi3-${GIT_LATEST}-macos-amd64 313 | else 314 | mv energi3-${GIT_LATEST}-macos-amd64 ${ENERGI3_HOME} 315 | fi 316 | rm energi3-${GIT_LATEST}-macos-amd64.tgz 317 | 318 | # Check if software downloaded 319 | if [ ! -d ${BIN_DIR} ] 320 | then 321 | echo "${RED}ERROR: energi3-${GIT_LATEST}-linux-amd64.tgz did not download${NC}" 322 | sleep 5 323 | fi 324 | 325 | # Create missing app directories 326 | _setup_appdir 327 | 328 | cd ${BIN_DIR} 329 | 330 | chmod 755 ${ENERGI3_EXE} 331 | if [[ ${EUID} = 0 ]] 332 | then 333 | chown ${USRNAME}:${USRNAME} ${ENERGI3_EXE} 334 | fi 335 | 336 | if [ ! -f "${BIN_DIR}/${NODE_SCRIPT}" ] 337 | then 338 | curl -sL "${SCRIPT_URL}/${NODE_SCRIPT}" --output ${NODE_SCRIPT} 339 | #wget -4qo- "${SCRIPT_URL}/${NODE_SCRIPT}?dl=1" -O "${NODE_SCRIPT}" --show-progress --progress=bar:force:noscroll 2>&1 340 | sleep 0.3 341 | chmod 755 ${NODE_SCRIPT} 342 | if [[ ${EUID} = 0 ]] 343 | then 344 | chown ${USRNAME}:${USRNAME} ${NODE_SCRIPT} 345 | fi 346 | fi 347 | 348 | if [ ! -f "${BIN_DIR}/${MN_SCRIPT}" ] 349 | then 350 | curl -sL "${SCRIPT_URL}/${MN_SCRIPT}" --output ${MN_SCRIPT} 351 | #wget -4qo- "${SCRIPT_URL}/${MN_SCRIPT}?dl=1" -O "${MN_SCRIPT}" --show-progress --progress=bar:force:noscroll 2>&1 352 | sleep 0.3 353 | chmod 755 ${MN_SCRIPT} 354 | if [[ ${EUID} = 0 ]] 355 | then 356 | chown ${USRNAME}:${USRNAME} ${MN_SCRIPT} 357 | fi 358 | fi 359 | 360 | if [ ! -d ${JS_DIR} ] 361 | then 362 | echo " Creating directory: ${JS_DIR}" 363 | mkdir -p ${JS_DIR} 364 | fi 365 | cd ${JS_DIR} 366 | if [ ! -f "${JS_DIR}/${JS_SCRIPT}" ] 367 | then 368 | curl -sL "${BASE_URL}/utils/${JS_SCRIPT}" --output ${JS_SCRIPT} 369 | #wget -4qo- "${BASE_URL}/utils/${JS_SCRIPT}?dl=1" -O "${JS_SCRIPT}" --show-progress --progress=bar:force:noscroll 2>&1 370 | sleep 0.3 371 | chmod 644 ${JS_SCRIPT} 372 | if [[ ${EUID} = 0 ]] 373 | then 374 | chown ${USRNAME}:${USRNAME} ${JS_SCRIPT} 375 | fi 376 | fi 377 | 378 | # Change to install directory 379 | cd 380 | 381 | } 382 | 383 | _version_gt() { 384 | 385 | # Check if FIRST version is greater than SECOND version 386 | 387 | test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; 388 | 389 | } 390 | 391 | _upgrade_energi3 () { 392 | 393 | # Set PATH to energi3 394 | export BIN_DIR=${ENERGI3_HOME}/bin 395 | 396 | if [[ -z ${GIT_LATEST} ]] 397 | then 398 | curl -fsSL https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 --output "${HOME}/jq" 399 | chmod 755 jq 400 | fi 401 | 402 | # Check the latest version in Github 403 | 404 | GITHUB_LATEST=$( curl -s ${API_URL} ) 405 | GIT_VERSION=$( echo "${GITHUB_LATEST}" | jq -r '.tag_name' ) 406 | 407 | # Extract latest version number without the 'v' 408 | GIT_LATEST=$( echo ${GIT_VERSION} | sed 's/v//g' ) 409 | 410 | # Installed Version 411 | INSTALL_VERSION=$( ${BIN_DIR}/${ENERGI3_EXE} version | grep "^Version" | awk '{ print $2 }' | awk -F\- '{ print $1 }' 2>/dev/null ) 412 | 413 | if _version_gt ${GIT_LATEST} ${INSTALL_VERSION}; then 414 | echo "Installing newer version ${GIT_VERSION} from Github" 415 | ${BIN_DIR}/${ENERGI3_EXE} removedb 416 | _install_energi3 417 | else 418 | echo "Latest version of Energi3 is installed: ${INSTALL_VERSION}" 419 | echo "Nothing to install" 420 | sleep 0.3 421 | fi 422 | 423 | if [[ -x "${HOME}/jq" ]] 424 | then 425 | rm "${HOME}/jq" 426 | fi 427 | 428 | } 429 | 430 | _copy_keystore() { 431 | 432 | # Copy Energi3 keystore file to computer 433 | if [[ ! -d "${HOME}/Library/EnergiCore3/keystore" ]] 434 | then 435 | mkdir -p "${HOME}/Library/EnergiCore3/keystore" 436 | fi 437 | 438 | if [[ ! -f "${HOME}/Library/EnergiCore3/keystore/UTC*" ]] 439 | then 440 | clear 441 | echo 442 | echo "Copy the Gen 3 address file into the keystore directory by doing the following:" 443 | echo 444 | echo "Finder -> Menubar (top of screen) -> Go -> Utilities, open Terminal" 445 | echo "Type or paste in " 446 | echo 447 | echo "open \"${HOME}/Library/EnergiCore3/keystore\" " 448 | echo 449 | read -t 10 -p "Wait 10 sec or Press [ENTER] key to continue..." 450 | 451 | fi 452 | 453 | } 454 | 455 | _start_energi3 () { 456 | 457 | # Start energi3 458 | EXTERNALIP=`curl -s https://ifconfig.me/` 459 | 460 | 461 | } 462 | 463 | _stop_energi3 () { 464 | 465 | # Check if energi3 process is running and stop it 466 | 467 | ENERGI3PID=`ps -ef | grep energi3 | grep console | grep -v "grep energi3" | grep -v "color=auto" | awk '{print $2}' ` 468 | 469 | 470 | } 471 | 472 | _add_shortcut () { 473 | 474 | # Add shorcut to Desktop 475 | SHORTCUTNAME="Energi Core Node".command 476 | 477 | if [[ ! -f "${HOME}/Desktop/${SHORTCUTNAME}" ]] 478 | then 479 | echo 480 | echo "Adding shortcut to the Destop" 481 | cd "${HOME}/Desktop" 482 | cp "${BIN_DIR}/start_node.sh" "${HOME}/Desktop/${SHORTCUTNAME}" 483 | 484 | curl -fsSL https://github.com/energicryptocurrency/energi3-provisioning/raw/master/scripts/macos/energi3.png --output energi3.png 485 | if [ ! -x "${ETC_DIR}/set-image.py" ] 486 | then 487 | curl -sL "${SCRIPT_URL}/set-image.py" --output "${ETC_DIR}/set-image.py" 488 | chmod 755 "${ETC_DIR}/set-image.py" 489 | fi 490 | "${ETC_DIR}/set-image.py" energi3.png "${HOME}/Desktop/${SHORTCUTNAME}" 491 | chmod 755 "${HOME}/Desktop/${SHORTCUTNAME}" 492 | rm energi3.png 493 | cd - 494 | fi 495 | 496 | } 497 | 498 | 499 | _ascii_logo () { 500 | echo "${GREEN}" 501 | clear 2> /dev/null 502 | cat << "ENERGI3" 503 | ___ 504 | /\ \ 505 | /::\ \ 506 | /:/\:\__\ 507 | /:/ /:/ _/_ 508 | /:/ /:/ /\__\ ______ _ _ ______ _____ _____ _____ ____ 509 | \:\ \/ /:/ / | ____| \ | | ____| __ \ / ____|_ _|___ \ 510 | \:\ /:/ / | |__ | \| | |__ | |__) | | __ | | __) | 511 | \:\/:/ / | __| | . ` | __| | _ /| | |_ | | | |__ < 512 | \::/ / | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 513 | \/__/ |______|_| \_|______|_| \_\\_____|_____|____/ 514 | ENERGI3 515 | echo -n ${NC} 516 | } 517 | 518 | _ascii_logo_bottom () { 519 | echo "${GREEN}" 520 | clear 2> /dev/null 521 | cat << "ENERGI3" 522 | ___ 523 | /\ \ 524 | /::\ \ 525 | /:/\:\__\ 526 | /:/ /:/ _/_ 527 | /:/ /:/ /\__\ ______ _ _ ______ _____ _____ _____ ____ 528 | \:\ \/ /:/ / | ____| \ | | ____| __ \ / ____|_ _|___ \ 529 | \:\ /:/ / | |__ | \| | |__ | |__) | | __ | | __) | 530 | \:\/:/ / | __| | . ` | __| | _ /| | |_ | | | |__ < 531 | \::/ / | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 532 | \/__/ |______|_| \_|______|_| \_\\_____|_____|____/ 533 | ENERGI3 534 | echo -n ${NC} 535 | } 536 | 537 | _ascii_logo_2 () { 538 | echo "${GREEN}" 539 | clear 2> /dev/null 540 | cat << "ENERGI3" 541 | ___ 542 | /\ \ 543 | /::\ \ 544 | /:/\:\__\ 545 | /:/ /:/ _/_ ______ _ _ ______ _____ _____ _____ ____ 546 | /:/ /:/ /\__\ | ____| \ | | ____| __ \ / ____|_ _|___ \ 547 | \:\ \/ /:/ / | |__ | \| | |__ | |__) | | __ | | __) | 548 | \:\ /:/ / | __| | . ` | __| | _ /| | |_ | | | |__ < 549 | \:\/:/ / | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 550 | \::/ / |______|_| \_|______|_| \_\\_____|_____|____/ 551 | \/__/ 552 | ENERGI3 553 | echo -n ${NC} 554 | } 555 | 556 | _ascii_logo_3 () { 557 | echo "${GREEN}" 558 | clear 2> /dev/null 559 | cat << "ENERGI3" 560 | ___ 561 | /\ \ 562 | /::\ \ 563 | /:/\:\__\ ______ _ _ ______ _____ _____ _____ ____ 564 | /:/ /:/ _/_ | ____| \ | | ____| __ \ / ____|_ _|___ \ 565 | /:/ /:/ /\__\ | |__ | \| | |__ | |__) | | __ | | __) | 566 | \:\ \/ /:/ / | __| | . ` | __| | _ /| | |_ | | | |__ < 567 | \:\ /:/ / | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 568 | \:\/:/ / |______|_| \_|______|_| \_\\_____|_____|____/ 569 | \::/ / 570 | \/__/ 571 | ENERGI3 572 | echo -n ${NC} 573 | } 574 | 575 | _ascii_logo_4 () { 576 | echo "${GREEN}" 577 | clear 2> /dev/null 578 | cat << "ENERGI3" 579 | ___ 580 | /\ \ 581 | /::\ \ ______ _ _ ______ _____ _____ _____ ____ 582 | /:/\:\__\ | ____| \ | | ____| __ \ / ____|_ _|___ \ 583 | /:/ /:/ _/_ | |__ | \| | |__ | |__) | | __ | | __) | 584 | /:/ /:/ /\__\ | __| | . ` | __| | _ /| | |_ | | | |__ < 585 | \:\ \/ /:/ / | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 586 | \:\ /:/ / |______|_| \_|______|_| \_\\_____|_____|____/ 587 | \:\/:/ / 588 | \::/ / 589 | \/__/ 590 | ENERGI3 591 | echo -n ${NC} 592 | } 593 | 594 | _ascii_logo_5 () { 595 | echo "${GREEN}" 596 | clear 2> /dev/null 597 | cat << "ENERGI3" 598 | ___ 599 | /\ \ ______ _ _ ______ _____ _____ _____ ____ 600 | /::\ \ | ____| \ | | ____| __ \ / ____|_ _|___ \ 601 | /:/\:\__\ | |__ | \| | |__ | |__) | | __ | | __) | 602 | /:/ /:/ _/_ | __| | . ` | __| | _ /| | |_ | | | |__ < 603 | /:/ /:/ /\__\ | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 604 | \:\ \/ /:/ / |______|_| \_|______|_| \_\\_____|_____|____/ 605 | \:\ /:/ / 606 | \:\/:/ / 607 | \::/ / 608 | \/__/ 609 | ENERGI3 610 | echo -n ${NC} 611 | } 612 | 613 | _ascii_logo_top () { 614 | echo "${GREEN}" 615 | clear 2> /dev/null 616 | cat << "ENERGI3" 617 | ___ ______ _ _ ______ _____ _____ _____ ____ 618 | /\ \ | ____| \ | | ____| __ \ / ____|_ _|___ \ 619 | /::\ \ | |__ | \| | |__ | |__) | | __ | | __) | 620 | /:/\:\__\ | __| | . ` | __| | _ /| | |_ | | | |__ < 621 | /:/ /:/ _/_ | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 622 | /:/ /:/ /\__\ |______|_| \_|______|_| \_\\_____|_____|____/ 623 | \:\ \/ /:/ / 624 | \:\ /:/ / 625 | \:\/:/ / 626 | \::/ / 627 | \/__/ 628 | ENERGI3 629 | echo -n ${NC} 630 | } 631 | 632 | _menu_option_new () { 633 | echo "${GREEN}" 634 | clear 2> /dev/null 635 | cat << "ENERGI3" 636 | ___ ______ _ _ ______ _____ _____ _____ ____ 637 | /\ \ | ____| \ | | ____| __ \ / ____|_ _|___ \ 638 | /::\ \ | |__ | \| | |__ | |__) | | __ | | __) | 639 | /:/\:\__\ | __| | . ` | __| | _ /| | |_ | | | |__ < 640 | /:/ /:/ _/_ | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 641 | /:/ /:/ /\__\ |______|_| \_|______|_| \_\\_____|_____|____/ 642 | \:\ \/ /:/ / 643 | ENERGI3 644 | echo "${GREEN} \:\ /:/ / ${NC}Options:" 645 | echo "${GREEN} \:\/:/ / ${NC} a) New server installation of Energi3" 646 | echo "${GREEN} \::/ / ${NC}" 647 | echo "${GREEN} \/__/ ${NC} x) Exit without doing anything" 648 | echo ${NC} 649 | } 650 | 651 | _menu_option_mig () { 652 | echo "${GREEN}" 653 | clear 2> /dev/null 654 | cat << "ENERGI3" 655 | ___ ______ _ _ ______ _____ _____ _____ ____ 656 | /\ \ | ____| \ | | ____| __ \ / ____|_ _|___ \ 657 | /::\ \ | |__ | \| | |__ | |__) | | __ | | __) | 658 | /:/\:\__\ | __| | . ` | __| | _ /| | |_ | | | |__ < 659 | /:/ /:/ _/_ | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 660 | /:/ /:/ /\__\ |______|_| \_|______|_| \_\\_____|_____|____/ 661 | \:\ \/ /:/ / 662 | ENERGI3 663 | echo "${GREEN} \:\ /:/ / ${NC}Options:" 664 | echo "${GREEN} \:\/:/ / ${NC} a) Upgrade Energi v2 to v3; automatic wallet migration" 665 | echo "${GREEN} \::/ / ${NC} b) Upgrade Energi v2 to v3; manual wallet migration" 666 | echo "${GREEN} \/__/ ${NC} x) Exit without doing anything" 667 | echo ${NC} 668 | } 669 | 670 | _menu_option_upgrade () { 671 | echo "${GREEN}" 672 | clear 2> /dev/null 673 | cat << "ENERGI3" 674 | ___ ______ _ _ ______ _____ _____ _____ ____ 675 | /\ \ | ____| \ | | ____| __ \ / ____|_ _|___ \ 676 | /::\ \ | |__ | \| | |__ | |__) | | __ | | __) | 677 | /:/\:\__\ | __| | . ` | __| | _ /| | |_ | | | |__ < 678 | /:/ /:/ _/_ | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 679 | /:/ /:/ /\__\ |______|_| \_|______|_| \_\\_____|_____|____/ 680 | \:\ \/ /:/ / 681 | ENERGI3 682 | echo "${GREEN} \:\ /:/ / ${NC}Options:" 683 | echo "${GREEN} \:\/:/ / ${NC} a) Upgrade version of Energi3" 684 | echo "${GREEN} \::/ / ${NC}" 685 | echo "${GREEN} \/__/ ${NC} x) Exit without doing anything" 686 | echo ${NC} 687 | } 688 | 689 | _welcome_instructions () { 690 | echo "${GREEN}" 691 | clear 2> /dev/null 692 | cat << "ENERGI3" 693 | ___ ______ _ _ ______ _____ _____ _____ ____ 694 | /\ \ | ____| \ | | ____| __ \ / ____|_ _|___ \ 695 | /::\ \ | |__ | \| | |__ | |__) | | __ | | __) | 696 | /:/\:\__\ | __| | . ` | __| | _ /| | |_ | | | |__ < 697 | /:/ /:/ _/_ | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 698 | /:/ /:/ /\__\ |______|_| \_|______|_| \_\\_____|_____|____/ 699 | \:\ \/ /:/ / 700 | ENERGI3 701 | echo "${GREEN} \:\ /:/ / ${NC}Welcome to the Energi3 Installer." 702 | echo "${GREEN} \:\/:/ / ${NC}- New Install : No previous installs" 703 | echo "${GREEN} \::/ / ${NC}- Upgrade : Upgrade previous version" 704 | echo "${GREEN} \/__/ " 705 | echo ${NC} 706 | read -t 10 -p "Wait 10 sec or Press [ENTER] key to continue..." 707 | } 708 | 709 | _end_instructions () { 710 | echo "${GREEN}" 711 | clear 2> /dev/null 712 | cat << "ENERGI3" 713 | ___ ______ _ _ ______ _____ _____ _____ ____ 714 | /\ \ | ____| \ | | ____| __ \ / ____|_ _|___ \ 715 | /::\ \ | |__ | \| | |__ | |__) | | __ | | __) | 716 | /:/\:\__\ | __| | . ` | __| | _ /| | |_ | | | |__ < 717 | /:/ /:/ _/_ | |____| |\ | |____| | \ \| |__| |_| |_ ___) | 718 | /:/ /:/ /\__\ |______|_| \_|______|_| \_\\_____|_____|____/ 719 | \:\ \/ /:/ / 720 | ENERGI3 721 | echo "${GREEN} \:\ /:/ / ${NC}Thank you for supporting Energi! Good luck staking." 722 | echo "${GREEN} \:\/:/ / ${NC}" 723 | echo "${GREEN} \::/ / ${NC}To start Energi Core Node, double-clicking on the" 724 | echo "${GREEN} \/__/ ${NC}\"Energi Core Node\" shortcut on the Desktop." 725 | echo ${NC} 726 | echo "For instructions visit: ${DOC_URL}" 727 | echo 728 | } 729 | 730 | 731 | ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### 732 | # Main Program 733 | ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ### 734 | 735 | # Make installer interactive and select normal mode by default. 736 | 737 | while [[ $# -gt 0 ]] 738 | do 739 | key="$1" 740 | shift 741 | 742 | case $key in 743 | -a|--advanced) 744 | ADVANCED="y" 745 | ;; 746 | -n|--normal) 747 | ADVANCED="n" 748 | UFW="y" 749 | BOOTSTRAP="y" 750 | ;; 751 | -i|--externalip) 752 | EXTERNALIP="$2" 753 | ARGUMENTIP="y" 754 | shift 755 | ;; 756 | --bindip) 757 | BINDIP="$2" 758 | shift 759 | ;; 760 | -k|--privatekey) 761 | KEY="$2" 762 | shift 763 | ;; 764 | -b|--bootstrap) 765 | BOOTSTRAP="y" 766 | ;; 767 | --no-bootstrap) 768 | BOOTSTRAP="n" 769 | ;; 770 | --no-interaction) 771 | INTERACTIVE="n" 772 | ;; 773 | -d|--debug) 774 | set -x 775 | ;; 776 | -h|--help) 777 | cat << EOL 778 | 779 | Energi3 installer arguments: 780 | -n --normal : Run installer in normal mode 781 | -a --advanced : Run installer in advanced mode 782 | --no-interaction : Do not wait for wallet activation 783 | -i --externalip
: Public IP address of VPS 784 | --bindip
: Internal bind IP to use 785 | -k --privatekey : Private key to use 786 | -b --bootstrap : Sync node using Bootstrap 787 | --no-bootstrap : Do not use Bootstrap 788 | -h --help : Display this help text 789 | -d --debug : Debug mode 790 | 791 | EOL 792 | exit 793 | ;; 794 | *) 795 | $0 -h 796 | ;; 797 | esac 798 | done 799 | 800 | 801 | # 802 | # Clears screen and present Energi3 logo 803 | _ascii_logo_bottom 804 | sleep 0.2 805 | _ascii_logo_2 806 | sleep 0.2 807 | _ascii_logo_3 808 | sleep 0.2 809 | _ascii_logo_4 810 | sleep 0.2 811 | _ascii_logo_5 812 | sleep 0.2 813 | _welcome_instructions 814 | 815 | # Check architecture 816 | _os_arch 817 | 818 | # Check Install type and set ENERGI3_HOME 819 | echo 820 | echo "Checking system..." 821 | _check_install 822 | #read -t 10 -p "Wait 10 sec or Press [ENTER] key to continue..." 823 | 824 | # Present menu to choose an option based on Installation Type determined 825 | case ${INSTALLTYPE} in 826 | new) 827 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 828 | # Scenario: 829 | # * No energi3.ipc file on the computer 830 | # * No energi.conf file on the computer 831 | # 832 | # Menu Options 833 | # a) New server installation of Energi3 834 | # x) Exit without doing anything 835 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 836 | 837 | _menu_option_new 838 | 839 | REPLY='x' 840 | read -p "Please select an option to get started (a or x): " -r 841 | REPLY=$( echo "${REPLY}" | tr '[:upper:]' '[:lower:]' ) 842 | 843 | if [ "${REPLY}" = "" ] 844 | then 845 | REPLY='h' 846 | fi 847 | 848 | case ${REPLY} in 849 | a) 850 | # New server installation of Energi3 851 | _install_energi3 852 | _add_shortcut 853 | _copy_keystore 854 | 855 | ;; 856 | 857 | x) 858 | # Exit - Nothing to do 859 | echo 860 | echo 861 | echo "Nothing to install. Exiting from the installer." 862 | exit 0 863 | 864 | ;; 865 | 866 | h) 867 | echo 868 | echo 869 | echo "${RED}ERROR: ${NC}Need to select one of the options to continue..." 870 | echo 871 | echo "Restart the installer" 872 | exit 0 873 | ;; 874 | 875 | esac 876 | 877 | ;; 878 | 879 | upgrade) 880 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 881 | # Scenario: 882 | # * energi3.ipc file exists 883 | # * Keystore file exists 884 | # * Version on computer is older than version in Github 885 | # * $ENERGI3_HOME/etc/migrated_to_v3.log exists 886 | # 887 | # Menu Options 888 | # a) Upgrade version of Energi3 889 | # x) Exit without doing anything 890 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 891 | 892 | _menu_option_upgrade 893 | 894 | REPLY='x' 895 | read -p "Please select an option to get started (a or x): " -r 896 | REPLY=$( echo "${REPLY}" | tr '[:upper:]' '[:lower:]' ) 897 | 898 | if [ "x${REPLY}" = "x" ] 899 | then 900 | REPLY='h' 901 | fi 902 | 903 | case ${REPLY} in 904 | a) 905 | # Upgrade version of Energi3 906 | _upgrade_energi3 907 | _add_shortcut 908 | 909 | ;; 910 | 911 | b) 912 | # Install monitoring on Discord and/or Telegram 913 | echo "Monitoring functionality to be added" 914 | ;; 915 | 916 | x) 917 | # Exit - Nothing to do 918 | echo 919 | echo 920 | echo "Nothing to install. Exiting from the installer." 921 | exit 0 922 | ;; 923 | 924 | h) 925 | echo 926 | echo 927 | echo "${RED}ERROR: ${NC}Need to select one of the options to continue..." 928 | echo 929 | echo "Restart the installer" 930 | exit 0 931 | ;; 932 | 933 | esac 934 | ;; 935 | 936 | esac 937 | 938 | ## 939 | # End installer 940 | ## 941 | _end_instructions 942 | 943 | 944 | # End of Installer --------------------------------------------------------------------------------