-
-
Save ekkis/e2220ed8447196bb2fd87bd9b5a993fc to your computer and use it in GitHub Desktop.
EOS scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CMD=$1; shift | |
EOS=~/dev/eos/eosio | |
isRunning() { | |
s=$(echo $1 |sed 's/./[&]/') # this trick prevents grep from finding itself | |
ps aux |grep --silent $s | |
[ $? -eq 0 ] && echo Y || echo N | |
} | |
walletExists() { | |
# cleos can't tell me whether a wallet exists | |
# so I have to rely on a failure to open | |
# see: https://stackoverflow.com/questions/56284969/how-can-i-determine-if-i-need-to-create-a-wallet | |
cleos wallet open > /dev/null 2>&1 | |
[ $? -eq 0 ] && echo Y || echo N | |
} | |
walletUnlock() { | |
[[ $(cleos wallet list) != *"*"* ]] && { | |
echo "* Unlocking wallet..." | |
cat .Wallet |cleos wallet unlock | |
} | |
} | |
acct() { | |
PK=$(tail -1 .Keys |sed 's/Public key: //') | |
for acct in "$@"; do | |
cleos create account eosio $acct $PK $PK | |
done | |
} | |
quit() { | |
s=$(echo $1 |sed 's/./[&]/') # this trick prevents grep from finding itself | |
ps aux |grep $s | | |
awk '{print $2}' | | |
xargs -I % sh -c '[ ! -z % ] && kill %' | |
} | |
start_keosd() { | |
nohup keosd > $EOS/logs/keosd.log 2>&1 & | |
} | |
start_nodeos() { | |
nohup nodeos -e -p eosio \ | |
--plugin eosio::producer_plugin \ | |
--plugin eosio::chain_api_plugin \ | |
--plugin eosio::http_plugin \ | |
--plugin eosio::history_plugin \ | |
--plugin eosio::history_api_plugin \ | |
--data-dir $EOS/data \ | |
--config-dir $EOS/config \ | |
--access-control-allow-origin='*' \ | |
--contracts-console \ | |
--http-validate-host=false \ | |
--verbose-http-errors \ | |
--delete-all-blocks \ | |
--filter-on='*' > $EOS/logs/nodeos.log 2>&1 & | |
} | |
[ "$CMD" == "stop" ] && { | |
echo "* Stopping nodeos..." | |
quit "nodeos" | |
echo "* Stopping keosd..." | |
quit "keosd" | |
exit 0 | |
} | |
[ "$CMD" == "start" ] && { | |
start_$1 | |
exit 0 | |
} | |
# default behaviour (when no arguments are passed) | |
[ `isRunning keosd` == "N" ] && { | |
echo "* Starting keosd..." | |
start_keosd | |
} | |
[ `isRunning nodeos` == "N" ] && { | |
echo "* Starting nodeos..." | |
start_nodeos | |
sleep 1 | |
} | |
[ `walletExists` == "N" ] && { | |
echo "Creating wallet..." | |
cleos wallet create --file .Wallet | |
} | |
walletUnlock | |
[ "$(cleos wallet keys)" == "[]" ] && { | |
echo "* Importing development key..." | |
PK=5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 | |
cleos wallet import --private-key=$PK | |
echo "* Creating keys..." | |
cleos create key --file .Keys | |
echo "* Importing private key..." | |
PK=$(head -1 .Keys |sed 's/Private key: //') | |
cleos wallet import --private-key=$PK | |
} | |
PK=$(tail -1 .Keys |sed 's/Public key: //') | |
cleos get accounts $PK |grep -q $ACCT | |
[ $? -eq 1 ] && { | |
echo "* Creating system accounts..." | |
acct $ACCT | |
} | |
echo "* Deferred transaction support..." | |
cleos set account permission --add-code $ACCT active | |
echo "* Done" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- t.hpp -- | |
struct [[eosio::table]] _settings { | |
bool debug = false; | |
}; | |
eosio::singleton<name("settings"), _settings> settings; | |
typedef eosio::multi_index<name("settings"), _settings> M1; // see note #1 | |
// [1] dummy definitions are used by the ABI generator and required by a bug: | |
// cf. https://github.com/EOSIO/eosio.cdt/issues/280#issuecomment-439666574 | |
-- t.cpp -- | |
auto r = settings.get(); | |
r.debug = true; | |
settings.set(r, _self); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment