Skip to content

Instantly share code, notes, and snippets.

@lukestokes
Last active June 9, 2021 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukestokes/937a38cc750c3956650258f4eadd18ac to your computer and use it in GitHub Desktop.
Save lukestokes/937a38cc750c3956650258f4eadd18ac to your computer and use it in GitHub Desktop.
#!/bin/bash
INPUT=eden_members.csv
MANAGERACCOUNT=f5axfpgffiqz
CLIO="./clio --url https://fio.greymass.com"
CLEO="/Users/lukestokes/Documents/workspace/eosDAC/chains/mainnet/cleos.sh"
DEBUG=0
MEMBERS=0
MEMBERSNEEDFIO=0
APPLICANTS=0
echo "Querying genesis.eden member table..."
echo
$CLEO get table -l 100 genesis.eden "" member | jq -r '.rows[][1] | [.account,.name,.status] | @csv' > $INPUT
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read account edenname status
do
if [ ${status} == "1" ]
then
let MEMBERS++
fioname=$(echo $edenname | iconv -t ASCII//TRANSLIT | tr '[A-Z]' '[a-z]')
fioname=${fioname//[^a-z]/}
account_no_quotes=${account//\"/}
if [ ${DEBUG} == "1" ]
then
echo "Found account $account_no_quotes named as $edenname. Obtaining EOS public key."
fi
key=$($CLEO get account $account_no_quotes -j | jq -r '.permissions[0].required_auth.keys[0].key')
fiokey="FIO${key:3}"
fioaddress="$fioname@eden"
if [ ${DEBUG} == "1" ]
then
echo "Found $key which we can use on FIO as $fiokey and assign $fioaddress."
echo "Checking if $fioaddress already exists."
fi
#HASHCMD="echo -n $fioaddress| openssl sha1 -binary | LC_ALL=C rev |xxd -p | cut -c 9-40"
HASHCMD="echo -n $fioaddress | openssl sha1 -binary | xxd -e -g 16 -l 16 | cut -d' ' -f2"
HASH="0x$(eval ${HASHCMD})"
CMD="curl -s https://fio.greymass.com/v1/chain/get_table_rows -d '{
\"code\": \"fio.address\",
\"scope\": \"fio.address\",
\"table\": \"fionames\",
\"lower_bound\": \"${HASH}\",
\"upper_bound\": \"${HASH}\",
\"key_type\": \"i128\",
\"index_position\": \"5\",
\"json\": true
}' | jq '.rows[].addresses[0].public_address'"
FIOPUBKEY=$(eval $CMD)
if [[ ${FIOPUBKEY} == "" ]]
then
let MEMBERSNEEDFIO++
if [ ${DEBUG} == "1" ]
then
echo "Use this commend to create a FIO address for $edenname:"
fi
echo "$CLIO push action fio.address regaddress '{\"fio_address\": \"$fioaddress\", \"owner_fio_public_key\": $fiokey, \"max_fee\": 100000000000, \"tpid\": \"\", \"actor\": \"$MANAGERACCOUNT\"}' -p $MANAGERACCOUNT@active"
echo
else
if [ ${DEBUG} == "1" ]
then
echo "Existing public key: |$FIOPUBKEY|"
echo
fi
fi
else
let APPLICANTS++
fi
done < $INPUT
IFS=$OLDIFS
echo
echo "Members: $MEMBERS ($MEMBERSNEEDFIO need FIO Addresses), Applicants: ${APPLICANTS}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment