shell脚本-钱包相关
AI-摘要
KunKunYu GPT
AI初始化中...
介绍自己
生成本文简介
推荐相关文章
前往主页
前往tianli博客
1.1 BTC_USDT 生成新地址
#!/bin/bash
# 2019-10-10
# BTC和USDT生成随机地址和标签
# 生成新地址个数
GETNEWADDRESS_NUMBER=5
# 生成标签长度
LABEL_LENGTH=16
# BTC获取新地址命令
BTC_GETNEWADDRESS_COMMAND="/data/coins/BTC/bitcoin-0.17.1/bin/bitcoin-cli -conf=/data/coins/BTC/btcdata/bitcoin.conf getnewaddress"
# BTC新地址文件存放位置
BTC_GETNEWADDRESS_DIR="/tmp/btc_getnewaddress.txt"
# BTC标签文件存放位置
BTC_LABEL_DIR="/tmp/btc_label.txt"
# BTC新地址和标签合并之后文件存放位置
BTC_PASTE_GETNEWADDRESS_LABEL_DIR="/tmp/btc_paste_getnewaddress_label.txt"
# USDT获取新地址命令
USDT_GETNEWADDRESS_COMMAND="/data/coins/USDT/omnicore-0.3.1/bin/omnicore-cli --datadir=/data/coins/USDT/usdtdata --conf=/data/coins/USDT/usdtdata/usdtcoin.conf getnewaddress"
# USDT新地址文件存放位置
USDT_GETNEWADDRESS_DIR="/tmp/usdt_getnewaddress.txt"
# USDT标签文件存放位置
USDT_LABEL_DIR="/tmp/usdt_label.txt"
# USDT新地址和标签合并之后文件存放位置
USDT_PASTE_GETNEWADDRESS_LABEL_DIR="/tmp/usdt_paste_getnewaddress_label.txt"
# 清空文件
function clear_dir(){
> $1
> $2
> $3
}
# 生成新地址
function generate_btc_usdt_getnewaddress(){
# 生成新地址个数
for (( i = 0; i < ${GETNEWADDRESS_NUMBER}; i++ )); do
$1 >> $2
done
}
# 生成固定标签
function generate_fixed_labels(){
for (( i = 0; i < ${GETNEWADDRESS_NUMBER}; i++ )); do
echo $1 >> $2
done
}
# 生成随机标签
function generate_random_labels(){
# 数字0-9
NUMBER=($(echo {0..9}))
# 小写字母
LOWERCASE_LETTERS=($(echo {a..z}))
# 大写字母
CAPITAL_LETTER=($(echo {A..Z}))
# 全部字符
ALL_CHARACTERS=(${NUMBER[@]} ${LOWERCASE_LETTERS[@]} ${CAPITAL_LETTER[@]})
# 全部字符长度
ALL_CHARACTERS_LENGTH=${#ALL_CHARACTERS[@]}
# 计数器
COUNT=0
while [[ true ]]; do
# 生成标签长度
# LABEL_LENGTH=16
LABEL=""
for (( j = 0; j < ${LABEL_LENGTH}; j++ )); do
# 随机下标
INDEX=$(($RANDOM%${ALL_CHARACTERS_LENGTH}))
# 标签组合
LABEL=${LABEL}${ALL_CHARACTERS[INDEX]}
done
echo ${LABEL} >> $1
# 多少个标签就停止输出
let COUNT++
if [[ ${COUNT} -ge ${GETNEWADDRESS_NUMBER} ]]; then
break
fi
done
}
# 合并新地址和标签
function paste_btc_usdt_getnewaddress_label(){
paste $1 $2 > $3
}
function main(){
if [[ $1 == "btc" ]]; then
# 清空文件
clear_dir "${BTC_GETNEWADDRESS_DIR}" "${BTC_LABEL_DIR}" "${BTC_PASTE_GETNEWADDRESS_LABEL_DIR}"
# 生成新地址
generate_btc_usdt_getnewaddress "${BTC_GETNEWADDRESS_COMMAND}" "${BTC_GETNEWADDRESS_DIR}"
if [[ $2 == "fixed" ]]; then
# 生成固定标签
BTC_LABEL="BTC$(date +"%Y%m%d%H%M")${GETNEWADDRESS_NUMBER}"
generate_fixed_labels "${BTC_LABEL}" "${BTC_LABEL_DIR}"
elif [[ $2 == "random" ]]; then
# 生成随机标签
generate_random_labels "${BTC_LABEL_DIR}"
else
echo "参数错误!"
echo "$0 btc|usdt fixed|random"
fi
# 合并新地址和标签
paste_btc_usdt_getnewaddress_label "${BTC_GETNEWADDRESS_DIR}" "${BTC_LABEL_DIR}" "${BTC_PASTE_GETNEWADDRESS_LABEL_DIR}"
elif [[ $1 == "usdt" ]]; then
# 清空文件
clear_dir "${USDT_GETNEWADDRESS_DIR}" "${USDT_LABEL_DIR}" "${USDT_PASTE_GETNEWADDRESS_LABEL_DIR}"
# 生成新地址
generate_btc_usdt_getnewaddress "${USDT_GETNEWADDRESS_COMMAND}" "${USDT_GETNEWADDRESS_DIR}"
if [[ $2 == "fixed" ]]; then
# 生成固定标签
USDT_LABEL="USDT$(date +"%Y%m%d%H%M")${GETNEWADDRESS_NUMBER}"
generate_fixed_labels "${USDT_LABEL}" "${USDT_LABEL_DIR}"
elif [[ $2 == "random" ]]; then
# 生成随机标签
generate_random_labels "${USDT_LABEL_DIR}"
else
echo "参数错误!"
echo "$0 btc|usdt fixed|random"
fi
# 合并新地址和标签
paste_btc_usdt_getnewaddress_label "${USDT_GETNEWADDRESS_DIR}" "${USDT_LABEL_DIR}" "${USDT_PASTE_GETNEWADDRESS_LABEL_DIR}"
else
echo "参数错误!"
echo "$0 btc|usdt fixed|random"
fi
}
main $1 $2
1.2 BTC_USDT导入新地址和标签
#!/bin/bash
# 2019-10-10
# BTC和USDT导入新地址和标签
# BTC导入新地址和标签命令(flase是不验证地址)
# BTC_GETNEWADDRESS_COMMAND="/data/coins/BTC-test/bitcoin-0.17.1/bin/bitcoin-cli -conf=/data/coins/BTC-test/btc-test-data/bittest.conf importaddress "地址XXX" "labelXXX" false"
BTC_GETNEWADDRESS_COMMAND="/data/coins/BTC/bitcoin-0.17.1/bin/bitcoin-cli -conf=/data/coins/BTC/btcdata/btccoin.conf"
# BTC新地址和标签合并之后文件存放位置
BTC_PASTE_GETNEWADDRESS_LABEL_DIR="/tmp/btc_paste_getnewaddress_label.txt"
# usdt导入新地址和标签命令
USDT_GETNEWADDRESS_COMMAND="/data/coins/USDT/omnicore-0.3.1/bin/omnicore-cli -conf=/data/coins/USDT/usdtdata/usdtcoin.conf"
# USDT新地址和标签合并之后文件存放位置
USDT_PASTE_GETNEWADDRESS_LABEL_DIR="/tmp/usdt_paste_getnewaddress_label.txt"
# 导入新地址和标签
function import_btc_usdt_getnewaddress_label(){
# 获取新地址和标签行数
NEWADDRESS_ROW=$(cat $1 | wc -l)
for (( i = 1; i <= ${NEWADDRESS_ROW}; i++ )); do
IMPORT_GETNEWADDRESS=""
IMPORT_LABEL=""
# 新地址
# awk -v 是接收shell变量
IMPORT_GETNEWADDRESS=$(awk -v newaddress_nr="${i}" 'NR==newaddress_nr {print $1}' $1)
# 标签
IMPORT_LABEL=$(awk -v newaddress_nr="${i}" 'NR==newaddress_nr {print $2}' $1)
# 导入新地址命令+地址+标签+false
$2 importaddress ${IMPORT_GETNEWADDRESS} ${IMPORT_LABEL} false
done
}
# 判断需要导入的参数
function main(){
# 判断传入的参数
if [[ $1 == "btc" ]]; then
# 调用函数(传值为btc)
import_btc_usdt_getnewaddress_label "${BTC_PASTE_GETNEWADDRESS_LABEL_DIR}" "${BTC_GETNEWADDRESS_COMMAND}"
echo -e "\033[31m用下面的命令测试BTC是否导入地址成功\033[0m"
echo "${BTC_GETNEWADDRESS_COMMAND} getaddressesbylabel "标签""
elif [[ $1 == "usdt" ]]; then
# 调用函数(传值为usdt)
import_btc_usdt_getnewaddress_label "${USDT_PASTE_GETNEWADDRESS_LABEL_DIR}" "${USDT_GETNEWADDRESS_COMMAND}"
echo -e "\033[31m用下面的命令测试USDT是否导入地址成功\033[0m"
echo "${USDT_GETNEWADDRESS_COMMAND} getaddressesbyaccount "标签""
else
echo "参数错误"
echo "$0 btc|usdt"
fi
}
main $1
1.3 EOS_Ubuntu部署
#!/bin/bash
# 2019-09-16
# EOS部署(Ubuntu 16.04.6 LTS)
# 参考:https://www.cnblogs.com/elvi/p/10205785.html
# https://www.cnblogs.com/sinsenliu/p/9634670.html
# 安装eos
function eosio_install(){
sudo apt update
# 安装git
sudo apt install -y git
[ ! -d /data ] && mkdir -p /data
cd /data/
# 参数 --recursive 表示下载项目需要的所有子模块
git clone https://github.com/EOS-Mainnet/eos.git --recursive
cd /data/eos/
# 切换到最新版本
git checkout $(git tag | grep mainnet | tail -n 1)
git branch
# 更新子模块
git submodule update --init --recursive
# 修改MongoDB的下载地址
sed -i 's#https://fastdl.mongodb.org#http://downloads.mongodb.org#' scripts/*.sh
echo -e "\033[31m准备运行编译,要几个小时才完成\033[0m"
echo -e "\033[31m需要输入“1”去确认下载依赖包,之后就是等待编译完成\033[0m"
sleep 5
# 运行编译,要几个小时才完成
./eosio_build.sh -s "EOS"
# 需要输入“1”去确认下载依赖包
# 出现信息,成功
# EOSIO has been successfully built. 02:04:58
# To verify your installation run the following commands:
# /root/data/mongodb/bin/mongod -f /root/data/mongodb/mongod.conf &
# source /data/rh/python33/enable
# export PATH=${HOME}/data/mongodb/bin:$PATH
# cd /data/eos/build; make test
# For more information:
# EOSIO website: https://eos.io
# EOSIO Telegram channel @ https://t.me/EOSProject
# EOSIO resources: https://eos.io/resources/
# EOSIO Stack Exchange: https://eosio.stackexchange.com
# EOSIO wiki: https://github.com/EOSIO/eos/wiki
# 编译完成后,安装
./eosio_install.sh
# 出现信息,成功
# Installing EOSIO Binary Symlinks
# _______ _______ _______ _________ _______
# ( ____ \( ___ )( ____ \\__ __/( ___ )
# | ( \/| ( ) || ( \/ ) ( | ( ) |
# | (__ | | | || (_____ | | | | | |
# | __) | | | |(_____ ) | | | | | |
# | ( | | | | ) | | | | | | |
# | (____/\| (___) |/\____) |___) (___| (___) |
# (_______/(_______)\_______)\_______/(_______)
# For more information:
# EOSIO website: https://eos.io
# EOSIO Telegram channel @ https://t.me/EOSProject
# EOSIO resources: https://eos.io/resources/
# EOSIO Stack Exchange: https://eosio.stackexchange.com
# EOSIO wiki: https://github.com/EOSIO/eos/wiki
# 创建主网节点目录
[ ! -d /data/EOSmainNet ] && mkdir -p /data/EOSmainNet
cd /data/EOSmainNet/
git clone https://github.com/CryptoLions/EOS-MainNet.git ./
chmod a+x ./*.sh
chmod a+x ./Wallet/*.sh
# 修改区块存储限制
# 备份初始文件
cp config.ini /tmp/config.ini_initial
sed -i 's/chain-state-db-size-mb = 65536/chain-state-db-size-mb = 102400/' config.ini
# 更改nodeos编译路径(cleos.sh,start.sh,Wallet/start_wallet.sh)
sed -i 's#/home/eos-sources/eos#/data/eos#' *.sh
sed -i 's#/home/eos-sources/eos#/data/eos#' Wallet/*.sh
# 修改脚本路径
sed -i 's/opt/data/g' *.sh
sed -i 's/opt/data/g' Wallet/*.sh
# 提前解决报错
sed -i "s/http-threads.*/#&/" config.ini
# 首次启动,清除现有区块并加入主网
sudo /data/EOSmainNet/start.sh --genesis-json /data/EOSmainNet/genesis.json --delete-all-blocks
# 再次启动,不需指定genesis.json
# sudo /data/EOSmainNet/start.sh
# 关闭
# sudo /data/EOSmainNet/stop.sh
# “首次启动,清除现有区块并加入主网”报错
# std::exception::what: unrecognised dataion 'http-threads'
# 解决
# 注释掉config.ini里面的http-threads = 6
# 再启动
# sudo /data/EOSmainNet/start.sh --genesis-json /data/EOSmainNet/genesis.json --delete-all-blocks
}
# 倒计时
function countdown(){
# 倒计时多少时间
TIME="120"
i=0
while [[ ${TIME} -ge ${i} ]]; do
echo -e "\033[31m倒计时\033[0m \033[34m ${TIME} \033[0m"
let TIME-=1
sleep 1
done
}
# 解决不可用节点
function p2p_peer_address(){
# 查看错误日志,报错Connection refused和Host not found和Connection timed out
# tail -f stderr.txt
# error 2019-09-17T02:19:26.665 thread-0 net_plugin.cpp:1903 operator() ] connection failed to peering.dutcheos.io:9876: Connection refused
# error 2019-09-17T02:19:26.773 thread-0 net_plugin.cpp:1903 operator() ] connection failed to peer.eosio.sg:9876: Connection refused
# error 2019-09-17T02:19:56.354 thread-0 net_plugin.cpp:1903 operator() ] connection failed to p2p.mainnet.eosgermany.online:9876: Connection refused
# error 2019-09-17T02:19:56.399 thread-0 net_plugin.cpp:1903 operator() ] connection failed to 94.130.250.22:9806: Connection refused
# error 2019-09-17T02:19:56.689 thread-0 net_plugin.cpp:1903 operator() ] connection failed to peering.dutcheos.io:9876: Connection refused
# error 2019-09-17T02:19:56.754 thread-0 net_plugin.cpp:1903 operator() ] connection failed to peer.eosio.sg:9876: Connection refused
# error 2019-09-17T02:15:34.028 thread-0 net_plugin.cpp:1903 operator() ] connection failed to 45.33.60.65:9820: Connection timed out
# error 2019-09-17T02:15:34.028 thread-0 net_plugin.cpp:1903 operator() ] connection failed to fullnode.eoslaomao.com:443: Connection timed out
# error 2019-09-17T02:15:34.029 thread-0 net_plugin.cpp:1903 operator() ] connection failed to peering.eosio.cr:1976: Connection timed out
# error 2019-09-17T02:17:26.528 thread-0 net_plugin.cpp:1875 operator() ] Unable to resolve dc1.eosemerge.io:9876: Host not found (authoritative)
# error 2019-09-17T02:17:26.568 thread-0 net_plugin.cpp:1875 operator() ] Unable to resolve new.eoshenzhen.io:10034: Host not found (authoritative)
# error 2019-09-17T02:17:26.706 thread-0 net_plugin.cpp:1875 operator() ] Unable to resolve p2p-public.hkeos.com:19875: Host not found (authoritative)
# error 2019-09-17T02:17:26.762 thread-0 net_plugin.cpp:1875 operator() ] Unable to resolve node.eosmeso.io:9876: Host not found (authoritative)
# error 2019-09-17T02:17:26.813 thread-0 net_plugin.cpp:1875 operator() ] Unable to resolve 807534da.eosnodeone.io:19872: Host not found (authoritative)
# error 2019-09-17T02:17:26.873 thread-0 net_plugin.cpp:1875 operator() ] Unable to resolve mainnet.eoseco.com:10010: Host not found (authoritative)
# 先睡眠2分钟,尽量让不能用的节点都显示出来,做好替换的准备。
countdown
EOSMAINNET_DIR="/data/EOSmainNet/"
cd ${EOSMAINNET_DIR}
EOS_STDERR_LOG="/data/EOSmainNet/stderr.txt"
EOS_CONFIG_INI="/data/EOSmainNet/config.ini"
# 获取全部不可用的节点
CONNECTION_REFUSED_ARRAY=($(awk '/Connection refused/{print $10}' ${EOS_STDERR_LOG} | awk -F':' '{print $1":"$2}' | sort -u))
HOST_NOT_FOUND_ARRAY=($(awk '/Host not found/{print $10}' ${EOS_STDERR_LOG} | awk -F':' '{print $1":"$2}' | sort -u))
CONNECTION_TIMED_OUT_ARRAY=($(awk '/Connection timed out/{print $10}' ${EOS_STDERR_LOG} | awk -F':' '{print $1":"$2}' | sort -u))
# 放到大数组里
UNAVAILABLE_NODES=(${CONNECTION_REFUSED_ARRAY[@]} ${HOST_NOT_FOUND_ARRAY[@]} ${CONNECTION_TIMED_OUT_ARRAY[@]})
# 备份原文件
cp config.ini{,_$(date +%F).bak}
for nodes in ${UNAVAILABLE_NODES[@]}; do
sed -i "s/^p2p-peer-address.*${nodes}/#&/" ${EOS_CONFIG_INI}
done
# 添加可用节点
# 输出看看可用节点
echo -e "\033[31m可用节点\033[0m"
curl https://eosnodes.privex.io/?config=1 -w "\n"
cp config.ini{,_$(date +%F).bak}
# 输出到文件
AVAILABLE_NODE_DIRECTORY="/tmp/p2p_peer_address.txt"
curl https://eosnodes.privex.io/?config=1 -w "\n" > ${AVAILABLE_NODE_DIRECTORY}
# 然后添加可用节点到/data/EOSmainNet/config.ini文件里
for i in $(awk '{print $NF}' ${AVAILABLE_NODE_DIRECTORY}); do
if [[ ! $(grep ${i} ${EOS_CONFIG_INI}) ]]; then
echo "p2p-peer-address = ${i}" >> ${EOS_CONFIG_INI}
fi
done
# 重启EOS
sudo /data/EOSmainNet/start.sh
}
function main(){
eosio_install
p2p_peer_address
}
main
# 查看chain_id是否为:aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906(主网的id)
# sudo /data/EOSmainNet/cleos.sh get info
# 查看区块同步
# curl -s http://localhost:8888/v1/chain/get_info | jq
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
作者编辑不易,如有转载请注明出处。完整转载来自https://wangairui.com 网站名称:猫扑linux
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果