Add a script to simplify creating and funding a new account. #131

Merged
telackey merged 3 commits from telackey/account-script into main 2024-01-10 23:04:53 +00:00
Showing only changes of commit b8f56076ff - Show all commits

View File

@ -1,17 +1,13 @@
#!/bin/bash #!/bin/bash
Review

Add some comments saying what the script is for and how to run it please.

Add some comments saying what the script is for and how to run it please.
KEYNAME=`uuidgen | tr -d '-'` KEYNAME=`uuidgen | tr -d '-'`
KEYRING_DIR=`mktemp -d` KEYRING_DIR=`mktemp -d`
KEYRING=test KEYRING=test
LACONIC_CONFIG=${LACONIC_CONFIG:-$HOME/.laconic/config.yml} LACONIC_CONFIG=${LACONIC_CONFIG:-$HOME/.laconic/config.yml}
ACCOUNT_JSON=$(laconicd keys add $KEYNAME --keyring-backend $KEYRING --algo eth_secp256k1 --keyring-dir $KEYRING_DIR --output json) ACCOUNT_JSON=$(laconicd keys add $KEYNAME --keyring-backend $KEYRING --algo eth_secp256k1 --keyring-dir $KEYRING_DIR --output json)
PRIVATE_KEY=$(yes | laconicd keys export $KEYNAME --keyring-backend $KEYRING --keyring-dir $KEYRING_DIR --unarmored-hex --unsafe) PRIVATE_KEY=$(yes | laconicd keys export $KEYNAME --keyring-backend $KEYRING --keyring-dir $KEYRING_DIR --unarmored-hex --unsafe)
PUB_KEY=$(echo $ACCOUNT_JSON | jq -r ".pubkey | fromjson | .key") PUB_KEY=$(echo $ACCOUNT_JSON | jq -r ".pubkey | fromjson | .key")
ACCOUNT_JSON=$(echo $ACCOUNT_JSON | jq ".privkey = \"$PRIVATE_KEY\"" | jq ".pubkey = \"$PUB_KEY\"")
laconicd keys delete $KEYNAME --keyring-backend $KEYRING --keyring-dir $KEYRING_DIR -y 2> /dev/null laconicd keys delete $KEYNAME --keyring-backend $KEYRING --keyring-dir $KEYRING_DIR -y 2> /dev/null
rm -rf $KEYRING_DIR rm -rf $KEYRING_DIR
@ -24,4 +20,4 @@ BOND_AMOUNT=$((AVG_RECORD_PHOTON * NUM_RECORDS))
laconic -c $LACONIC_CONFIG cns tokens send --address $(echo $ACCOUNT_JSON | jq -r '.address') --type aphoton --quantity $((BOND_AMOUNT + BOND_OVERHEAD)) > /dev/null laconic -c $LACONIC_CONFIG cns tokens send --address $(echo $ACCOUNT_JSON | jq -r '.address') --type aphoton --quantity $((BOND_AMOUNT + BOND_OVERHEAD)) > /dev/null
BOND_ID=$(laconic -c $LACONIC_CONFIG cns bond create --user-key $PRIVATE_KEY --type aphoton --quantity $BOND_AMOUNT | jq -r '.bondId') BOND_ID=$(laconic -c $LACONIC_CONFIG cns bond create --user-key $PRIVATE_KEY --type aphoton --quantity $BOND_AMOUNT | jq -r '.bondId')
echo $ACCOUNT_JSON | jq ".bond = \"$BOND_ID\"" | jq ".balance = $BOND_AMOUNT" echo $ACCOUNT_JSON | jq ".bond = \"$BOND_ID\"" | jq ".balance = $BOND_AMOUNT" | jq ".privkey = \"$PRIVATE_KEY\"" | jq ".pubkey = \"$PUB_KEY\""