Skip to content

Commit

Permalink
Adding forger_reward_address param (#22)
Browse files Browse the repository at this point in the history
* Adding forger_reward_address param
  • Loading branch information
ysibirski authored Apr 10, 2024
1 parent b015456 commit 7c0d262
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

**1.3.0+2**
* SCNODE_FORGER_REWARD_ADDRESS implemented in EON version **1.3.0** added to the compose project as well as to the setup forger process.

**1.3.0+1**
* EON version: 1.3.0
* SDK version: 0.11.0
Expand Down
1 change: 1 addition & 0 deletions compose_files/docker-compose-forger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ services:
- SCNODE_ALLOWED_FORGERS
- SCNODE_FORGER_ENABLED
- SCNODE_FORGER_RESTRICT
- SCNODE_FORGER_REWARD_ADDRESS
- SCNODE_GENESIS_BLOCKHEX
- SCNODE_GENESIS_SCID
- SCNODE_GENESIS_POWDATA
Expand Down
1 change: 1 addition & 0 deletions env/.env.forger.eon.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SCNODE_FORGER_ENABLED=true
SCNODE_FORGER_MAXCONNECTIONS=100
SCNODE_ALLOWED_FORGERS='{blockSignProposition: "10e9b5236a56cddb9f0332e9dd6d69151494f24172b26ab24a27473bbc92a181"\n vrfPublicKey: "6a376f8a88b386f69296baa0792641d393c85a19b28dfd4a11d8f0a74618873280"}\n{blockSignProposition: "99f8b31ad1af7d8362700f520af4cbeccd12d9b409aaf9b5574c8c483b636efd"\n vrfPublicKey: "8cbd4dd8826964a8dbc85f65b3dc9b115647cd8cacb1817214be66da1ccc9b2780"}\n{blockSignProposition: "c0f8ff4e8d486a87974bd5c4661f1757057737e14b89a8fee67f8e2b667ef109"\n vrfPublicKey: "b6ef38b729ce5501425730ec0466e24bbf9ce7a664200e8f73576abd38a6293f00"}\n{blockSignProposition: "105a0fd2d546c17a0dc5554313707cf58edc5f541ba667e1c3e8e3de485e9d25"\n vrfPublicKey: "74051ee6b9cb3acf2fd75829756270425f2611499be5586bd32e079b319d541180"}\n{blockSignProposition: "33b8c640541f69e36440336c326f32127f11f71c9aa26b9d0cfa8c3c18ae5754"\n vrfPublicKey: "a43ecdd5a67de91c4516e09e3eac121c073eecd78edc2fa87678d7ca97d9b81b80"}\n{blockSignProposition: "39b9d852f845de8dc44bd6c517e907b0960f12c4aa7b8010240182a33c325df5"\n vrfPublicKey: "38f7486245fd71a3f947973d64e2e70b40c21096fc5bb0323fb83b4084a1af1000"}\n{blockSignProposition: "cdb371270f257660ad0620b607c859814e193eba9ef7cd4c674b8df87d9cc725"\n vrfPublicKey: "a4c6a4901085ccf688ae969ab2ed888439e206239fb6f575ea0b9aa73393b72d00"}\n{blockSignProposition: "e88cc8058b05c73cbb57406159b93c26c12c9bbda19de113a1499d29be979408"\n vrfPublicKey: "6e5093705f6518fd11e82a5abe5c8a5a98a5e5ca6f92356d11d932e8a74dc43d00"}\n{blockSignProposition: "a16ff09a894cc3b4bd51bf717705d492ed53ced84a7c2a32548f3deed6293a79"\n vrfPublicKey: "9741645fafa564b26ca59a1a219980434c399d6ab3344ab7f75a535a55fac23600"}\n{blockSignProposition: "3e87a684830a641e2d29af0043ed5957138bb51b065838b2bb55a41cce0f0603"\n vrfPublicKey: "cfa46bdcb8b653761c0a16320f90ca131a19e97a1695e5bcf941454d4749d81500"}\n{blockSignProposition: "097a9f319c814f9423fec61bcb13aabc005e279a27e11b87f4b58d5b7d31a38b"\n vrfPublicKey: "bba35d39ab84937dc796b32428fff2324b1404aad48812057304d36f5cccae0700"}'
SCNODE_FORGER_RESTRICT=true
SCNODE_FORGER_REWARD_ADDRESS=

SCNODE_REMOTE_KEY_MANAGER_ENABLED=false
SCNODE_CERT_SIGNING_ENABLED=false
Expand Down
1 change: 1 addition & 0 deletions env/.env.forger.gobi.template
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SCNODE_FORGER_ENABLED=true
SCNODE_FORGER_MAXCONNECTIONS=100
SCNODE_ALLOWED_FORGERS='{blockSignProposition: "c38345f2c8d4da48258fc162166295a3664315c0751f104b8ddd25e45e0f83aa"\n vrfPublicKey: "2b316de8bf6fe0b1ee36108c231d309d344e288466e45f4c28e8dcec81ec362500"}\n{blockSignProposition: "f9cfc615c1f281465f3f7c43721df60392a00a05cba44aac1a72b78fd33e734e"\n vrfPublicKey: "c705de8ccc8f4270b09aea71b99f9900f3729218fd128646efde223251572b0880"}\n{blockSignProposition: "cbc18a20533e8a37d10babc07d9bd5632f1b85a329dabfc8c4063e0943718ea2"\n vrfPublicKey: "874a40f515b466e8948e8825e2f6e02ba1fb81c13a3afc4ff1c37e0ae1a0d93400"}\n{blockSignProposition: "4b551a46d1552c674cd8deb266bcc986384018ca5e6d73bb5a2dc2387484b63c"\n vrfPublicKey: "87b366e8c7d3d59756910bc62fb9a8de5d39c3021200fa7af1712daa9bcf092f80"}\n{blockSignProposition: "274cd77deb70a4faa110d5adab22598bc3adacf287718cb3ef8daf14027c6348"\n vrfPublicKey: "49f0f6b18b28fbbc32adf0d424fbfd78998e29fa1af373515c2b9a9f5d89cb1600"}\n{blockSignProposition: "51ec4bc21f97d1aba6ed5f339c9ee400e7678533d4638939307b028207868fae"\n vrfPublicKey: "c9cea912d9e19397e412e91cc43123c313e9b08b3f950e8e121cfbd14e9d923200"}\n{blockSignProposition: "852e1546199bb4d5ebb57c4a92bcd8b8e2fadec0d3164d422be4974c90245035"\n vrfPublicKey: "fc217f66e66dc2f0d3fbf3935d45b5a8d150d20a1284ff1a5b455c454a07963980"}\n{blockSignProposition: "298c34c57f8735959d29834de85dbec7cb617f12f9654e5120ca32bb7a8154d1"\n vrfPublicKey: "342ca0c1f8b346e9be770129dfcfd67ac3fe1bd3335b39c26ea801fe741dfe3600"}\n{blockSignProposition: "dc0696cb03c9880fd779a15dd44d679c5ae4d72a23baedacd09e25be383b42d3"\n vrfPublicKey: "22d215c1380a1940fff71cd70b8bb46662215880c818b14113d61b03e847511c00"}\n{blockSignProposition: "f0b5757d19a62e0a25f78e10c1917b0adcc3513eeea4a384085afca1e85375c2"\n vrfPublicKey: "16bcafed0f1d5d3dfe164bcab8e5d85e8cdc7c09e1c9241fbc741c0b1a28b63b00"}\n{blockSignProposition: "56fe8b23dfcbdf38a119fb0a6697caf8b923b4bb83ecc6314a02d5160c01dbce"\n vrfPublicKey: "fe1956769a909b2718694ccce4dbd9385ae622f3638bb421b8326acc6756993e00"}\n{blockSignProposition: "f4792b61c59932ab6f1b5a89ce18a775effb65f9f1214a9841bd72a202336080"\n vrfPublicKey: "d1ed813faa5ff48d91b1fe1155b566d5406da0947f6d00ed40f2a6d46e38351100"}\n{blockSignProposition: "7af7758fa990ad3537bdc116d4cbccb5679a0cd8223046128251f0ec1a6c058a"\n vrfPublicKey: "0c5f0a102dfa705c68d21aa69ee2b9b958d058763caa919f3eea00786b747f3800"}\n{blockSignProposition: "09c0aabcaf13f1f3e7159864bfd693c291627ae4b2b165198cf8a648a9d22528"\n vrfPublicKey: "2ae8760a52ee5b0e1020b75ad9b029dedc64c40f7cf247d42ed584cc9c6eb01780"}\n{blockSignProposition: "3c89826fe9e5380284af0bd2a3e8868e6ea936023d417bc06fa48644cbe32bbb"\n vrfPublicKey: "cea34f5e96abdf26e0e11330f7c6c1672316ab183755e3d035f0d38dd462ce3f00"}\n{blockSignProposition: "b2fa9c3f7c7694cf24ad96cb10462e1c155ca67a2e7c8ba49e4cc61b7a03ddd8"\n vrfPublicKey: "5cbc1d42b440f0534d2d31528cae885880a35ecc349e5b959aa55b8e79706c2d00"}\n{blockSignProposition: "7964c4d3db102c5494629a99adc0a0524c7f3db05c440c5de6472e46f1371951"\n vrfPublicKey: "2591135d07ae98f34a307d3df407a24c2d49b4e308a8707bb3e7d3ecd2fab91000"}\n{blockSignProposition: "08db0e281136472a286311dfb3d912c8ae2578edb0de50cb3dfac9a350a846f5"\n vrfPublicKey: "1813d54d5765eb3b23d4261c2df576ab674413728f9553d99dd995c86f8ea31480"}\n{blockSignProposition: "df597cee3740ff61e8199cdc4934e0bbf098ff5f9e32ace590bb633c19752dd1"\n vrfPublicKey: "756a59efba6b7bfd3a13549863b032bd1c0a7f1fe8bf1d93dba02bdb39e0941780"}\n{blockSignProposition: "62f9a65f6e99628ffe2825a05a9f67ec9dfe19089b5410ced54ba3fcef66e250"\n vrfPublicKey: "3d5953d43a277519ac1131a318ca64047e3c5883db2ffe702bb09ca4bedb381600"}\n{blockSignProposition: "4ddf8d9a16d77f4cc9a003e15c170ac35cb124b9ad20151815ef1eecea653c23"\n vrfPublicKey: "e2d94187fdee91b31b9a2d9a80aead62677b3b7d87f82e20275170e2574acf0f00"}\n{blockSignProposition: "672bd3ac9b3549e809d666b0710ef96565c0e81f7c9c0993037ace4be7bfaaf5"\n vrfPublicKey: "cd4c7fee2381e7d40ae5394ce31245eec61797c6caaa75912213f7df6f36e72880"}\n{blockSignProposition: "ed062caec2addb43c4b96ba601f91da8f79a6984388a1cb4bf9db501fc0390bd"\n vrfPublicKey: "cced539ce0f0159a6adaf62ac4e299ebeeb11d67987f760e46f724129c44612900"}\n{blockSignProposition: "d16f98f03c8eb6bfb1d6878e01a8bd7c4c2997362cec56d9d7afe8f9ce777619"\n vrfPublicKey: "ca8d752a7722b45e597db02a700ed04833e4d1153b51a875c54bc2b5a412b21500"}\n{blockSignProposition: "2a69fbda42fa43b416aeead852c38a82d220848439702e1a18cbfeecce3d685d"\n vrfPublicKey: "5a8769852432dce15327fc2d21740234703e9a69bb01751cffe46c428692e22c00"}\n{blockSignProposition: "d8cdc38ced37bf3ef930cb70131d85ceabc115eeeac0903267c92c7c527b8c30"\n vrfPublicKey: "b96f13093b361cdda617f04270cb3f2c060c7786828fe8dd4c6b4783977ef90b00"}\n{blockSignProposition: "067811552d8bab00615941b867a27ba2c06282256e2e1b6565f3f13a4b749102"\n vrfPublicKey: "0d8dc5a8fa6a4509830f9a77bbab2ff80c1b00b0e7953ea8f15fc4fb60aca23a00"}\n{blockSignProposition: "c51308486a720430146f7bb0df9006493e77eae11c656be6d76b4526c6c26542"\n vrfPublicKey: "1e2dfc130de0862e44e5e89854aa4bf6464d7a196eff714d90a4983fdcf2ff2000"}\n{blockSignProposition: "4611dc27690593e85ec37a98d1eb643c6c2d1f0eea6f3f12ad56d43f08af8de8"\n vrfPublicKey: "e9a8b0740aca9b34d6c7f4638479a887687bcf243a6f7ce90ad3c0308f72e81d80"}\n{blockSignProposition: "e1db788e904929acfdb0526a7ba1ff32777802a01d3cec16cba0938c3bdbc72d"\n vrfPublicKey: "82a6601011b8683f73d8f500986f0e60cdf33b6f1ed04095a75eda04f7609a0380"}\n{blockSignProposition: "e15b9a600aff7476ba8d061928155cd4b45f314f7772e3addf28dbbeda1d904c"\n vrfPublicKey: "3d3142ee497223fda4bb9cf8a8afde610a80993a15b8877719442d37a5b1401580"}\n{blockSignProposition: "88fad783519da0d34bcfad3fd69a3bc85482ba07d3c939e9007ec6ffa7a02150"\n vrfPublicKey: "c5b7f29a754fa8e3a01dfda0278eda6ffc938bc16b99b92d0c3b81c20a07852b80"}\n{blockSignProposition: "98c2a463c16a1a1ead9970ddf01c3b1ef159924ee88d380908677b119bbbbf95"\n vrfPublicKey: "3d84e4619f9ea2525154c86cf602222eb6e1da535d6e9cd13db47ef63595c43000"}\n{blockSignProposition: "04c93bad6afaf7d222c909653b8d54e9b675acab5e9357e5b0f18d97b96f9145"\n vrfPublicKey: "49571641af00b0ee7f9a082da34ec298164209ef74f1aa79aafae6d2a9b61a2c00"}\n{blockSignProposition: "48d889d752fdc9edf9db6b77501d494f5af26ae4d88ec2f9fe8f6e10a588b3dc"\n vrfPublicKey: "49a76e029c18fb540275d89a7783095ed5d6afc7bf93ce6b5e739bcf0e12c90d80"}\n{blockSignProposition: "8862530d1d6b9137ffc72ddd0bd2591afb9b16b517c198d48bfc0037671cb6cb"\n vrfPublicKey: "1323ffea5a853ec3141c09848256114ffcd5de754ad2b50eb4b72c8bec76262480"}\n{blockSignProposition: "b3ebd7c30cd187e320aea040ccaf2ec42542f5063326db9c2cafda492c7e63d6"\n vrfPublicKey: "2fac6c770714f47d831d1f75d5aac96ac3442df4ff5e64ced02798cd9beb040e00"}\n{blockSignProposition: "6b017bf4c4443bfc93419fbbc989e123817b2d8300d28c7f8c70fdab4cd8e8d5"\n vrfPublicKey: "dea76115ca455d398161fd9b8d519c0100d8d9f567bd8ac3100b99dd56e6803700"}\n{blockSignProposition: "4fba2bfc5e5dc20a6e4a49caa3bf3283329f56a19dc72b057f6567b60920d026"\n vrfPublicKey: "66798e7925c212322113f255bab9b1ffc88c9a93b34299bd756c87a180f02c0080"}\n{blockSignProposition: "837efdc5ee30256ced92caa664c9c3fb68a6d12f6b1fa6f92bf4386832b76aa6"\n vrfPublicKey: "bf472e40751a04a87da3fccb7aceb8ace67df861baff31dc72143d258f2e800400"}\n{blockSignProposition: "0fb445714130a826ec3061c1b777958b796dc7a9a6bd3f49cd0012c3ece0b268"\n vrfPublicKey: "41d30b23fb62ca6c9e42001905f5665d2c8f1edf1eaec28e9105121f530d0c2400"}\n{blockSignProposition: "b5328fa8453d594f0e75c18e0348a8a71abac68f3c461465cbbd74a4ef70d191"\n vrfPublicKey: "03fa4390a59cc63c8b8d9da60fcc712ff837d0adff9b3634f8e16b72d614a32f80"}\n{blockSignProposition: "dd15bc666e5ccc3f9526dda91ed2b74fcae71b53b10bf9025ddc671f06f05629"\n vrfPublicKey: "cdb5e033109773d3903ea0d8351ed9ee2201190cd25a8f2bb5f83e1f1bb7fe3480"}\n{blockSignProposition: "6f0b4047fec4d5cbdf39f63471aba5239c3e3d85b9e2127e3e815c5c8454ca9c"\n vrfPublicKey: "2fded5be5c8eee3efb8ae24e5b2543f8edd4cdb439a398cbd03863ee4496602b00"}\n{blockSignProposition: "d7d7dbc7c13c0524f2f9afb74725f25043448e08574fd2ab38bdd9873deea037"\n vrfPublicKey: "1964da97d221bad538c0d85b2ef54d4a859218acabcb14c3705bae72d21a043600"}\n{blockSignProposition: "181eb6a2c9a16e3a38cea75bf2c089422830243395d36ea377c26596e54be8b5"\n vrfPublicKey: "7f99def73483d5d2269c8fec7f1de160fe9f95116fa908546a639978c5af653000"}\n{blockSignProposition: "8eab0d83332e63f12eebac2e11efda519b183873a67a7ea68bc56f72bca6aacd"\n vrfPublicKey: "cd44336225addc49b253859307edf095e40fdcb28c15744721204b78f020020b80"}\n{blockSignProposition: "7cb091138203261d5cb02d5962b0f1b063968c0f4f1be81a299272c4ed040eee"\n vrfPublicKey: "69e34f4d90e80b03974916f17d53db0c9704b343f2ad3061cdca4fd6048c4b2180"}\n{blockSignProposition: "39d4909bfad1bebf34f1c068ea8ebd924f13b26871e74a9e4d361ec9cf05b25b"\n vrfPublicKey: "1da73770f1f615242b1a563583d941e3b722bd8ffe31a2dac78032b6208f591180"}\n{blockSignProposition: "ef90dd3207750853ad633f269962e02fb0a3af74bdf55f29c681973fc5813440"\n vrfPublicKey: "c647bfbe8de6111a9977b81b4772660e86007d60cb44320c73ea9883c64ff01200"}'
SCNODE_FORGER_RESTRICT=true
SCNODE_FORGER_REWARD_ADDRESS=

SCNODE_REMOTE_KEY_MANAGER_ENABLED=false
SCNODE_CERT_SIGNING_ENABLED=false
Expand Down
2 changes: 1 addition & 1 deletion scripts/forger/seed/download_seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -eEuo pipefail

command -v aria2c &>/dev/null || {
echo "${FUNCNAME[0]} Error: 'aria2c' is required to run this script, see installation instructions at 'https://github.com/aria2/aria2/releases/tag/release-1.37.0'."
echo "Error: 'aria2c' is required to run this script, see installation instructions at 'https://github.com/aria2/aria2/releases/tag/release-1.37.0'."
exit 1
}

Expand Down
39 changes: 36 additions & 3 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

set -eEuo pipefail

ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)"
Expand All @@ -13,8 +12,7 @@ verify_required_commands
LOCAL_USER_ID="$(id -u)"
LOCAL_GROUP_ID="$(id -g)"
if [ "${LOCAL_USER_ID}" == 0 ] || [ "${LOCAL_GROUP_ID}" == 0 ]; then
echo -e "\n\033[0;31m\033[1m=== Error: This script should not be run as root. Exiting ===\033[0m\n"
exit 1
fn_die "Error: This script should not be run as root. Exiting..."
fi

echo -e "\n\033[1mWhat kind of node type would you like to run: \033[0m"
Expand Down Expand Up @@ -69,6 +67,8 @@ if ! [ -f "${ENV_FILE}" ]; then
SCNODE_WALLET_SEED="${imported_wallet_seed}"
sed -i "s/SCNODE_WALLET_SEED=.*/SCNODE_WALLET_SEED=${imported_wallet_seed}/g" "${ENV_FILE}"
else
# Removing env_file since exit script will leave it in incomplete state
rm -f "${ENV_FILE}"
fn_die "Wallet seed phrase import aborted; please run again the init.sh script. Exiting ..."
fi
else
Expand All @@ -88,6 +88,39 @@ if ! [ -f "${ENV_FILE}" ]; then
SCNODE_NET_NODENAME="ext-${role_value}-$((RANDOM % 100000 + 1))" || fn_die "Error: could not set NODE_NAME variable for some reason. Fix it before proceeding any further. Exiting..."
sed -i "s/SCNODE_NET_NODENAME=.*/SCNODE_NET_NODENAME=${SCNODE_NET_NODENAME}/g" "${ENV_FILE}"

# Setting explicit wallet address for forger rewards to be sent to vs default local forger
if [ "${role_value}" = "forger" ]; then
echo -e "\n\033[1m=== Setting up FORGER rewards address ===\033[0m\n"
read -rp "Do you want to provide the wallet address for your FORGER rewards to be sent to (FORGER local wallet address is used by default)? ('yes' or 'no') " reward_address_set
while [[ ! "${reward_address_set}" =~ ^(yes|no)$ ]]; do
echo -e "\nWarning: The only allowed answers are 'yes' or 'no'. Please try again...\n"
read -rp "Do you want to provide the wallet address for your FORGER rewards to be sent to (FORGER local wallet address is used by default)? ('yes' or 'no') " reward_address_set
done
if [ "${reward_address_set}" = "yes" ]; then
read -rp "Please type or copy/paste here the wallet address for your FORGER rewards to be sent to: " forger_reward_address
echo -e "\nYou have provided the following wallet address: \033[1m${forger_reward_address}\033[0m\n"
read -rp "Do you confirm this is the wallet address you want to use for your FORGER rewards to be sent to: ${forger_reward_address}? ('yes' or 'no') " reward_address_set_2
while [[ ! "${reward_address_set_2}" =~ ^(yes|no)$ ]]; do
echo -e "\nWarning: The only allowed answers are 'yes' or 'no'. Please try again...\n"
read -rp "Do you confirm this is the wallet address you want to use for your FORGER rewards to be sent to: ${forger_reward_address}? ('yes' or 'no') " reward_address_set_2
done
if [ "${reward_address_set_2}" = "yes" ]; then
forger_reward_address="$(strip_0x "${forger_reward_address}")"
if [ "${forger_reward_address}" != "invalid" ]; then
sed -i "s/SCNODE_FORGER_REWARD_ADDRESS=.*/SCNODE_FORGER_REWARD_ADDRESS=${forger_reward_address}/g" "${ENV_FILE}"
else
# Removing env_file since exit script will leave it in incomplete state
rm -f "${ENV_FILE}"
fn_die "Error: Provided wallet address is in the WRONG format.\n\n=== An Ethereum address is a 42-character hexadecimal address derived from the last 20 bytes of the public key controlling the account with '0x' appended in front ===\n\nPlease re-run the init.sh script again. Exiting ..."
fi
else
# Removing env_file since exit script will leave it in incomplete state
rm -f "${ENV_FILE}"
fn_die "Error: Setting wallet address to send FORGER rewards to has failed. Please re-run the init.sh script again. Exiting ..."
fi
fi
fi

# Setting local user and group in docker containers
echo -e "\n\033[1m=== Setting up the docker containers local user and group ids ===\033[0m\n"
echo -e "The uid:gid with which to run the processes inside of the container will default to ${LOCAL_USER_ID}:${LOCAL_GROUP_ID}"
Expand Down
27 changes: 25 additions & 2 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Functions
fn_die() {
echo -e "\n\033[1m${1}\033[0m\n" >&2
echo -e "\n\033[1;31m${1}\033[0m\n" >&2
exit "${2:-1}"
}

Expand All @@ -25,7 +25,7 @@ check_env_var() {
local usage="Check if required environmental variable is empty and produce an error - usage: ${FUNCNAME[0]} {env_var_name}"
[ "${1:-}" = "usage" ] && echo "${usage}" && return
[ "$#" -ne 1 ] && {
fn_die -e "${FUNCNAME[0]} error: function requires exactly one argument.\n\n${usage}"
fn_die "${FUNCNAME[0]} error: function requires exactly one argument.\n\n${usage}"
}

local var="${1}"
Expand Down Expand Up @@ -128,3 +128,26 @@ scnode_start_check() {
fi
done
}

# Function to strip 0x prefix
strip_0x() {
local usage="Check validity of Ethereum wallet address - usage: ${FUNCNAME[0]} {eth_wallet_address}"
[ "${1:-}" = "usage" ] && echo "${usage}" && return
[ "$#" -ne 1 ] && {
fn_die "${FUNCNAME[0]} error: function requires exactly one argument.\n\n${usage}"
}

local input="${1}"
local eth_address_regex="[0-9a-fA-F]{40}$"

# Check if the input starts with "0x"
if [[ "${input}" =~ ^0x${eth_address_regex} ]]; then
# Remove the "0x" prefix
echo "${input:2}"
elif [[ "${input}" =~ ^${eth_address_regex} ]]; then
echo "${input}"
else
# If address is in the wrong format
echo "invalid"
fi
}

0 comments on commit 7c0d262

Please sign in to comment.