一、环境:ubuntu1604 python3.7
1、python3.7安装
# 使用pip3.7安装依赖包报错:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
解决这个坑:
# 先删除原来安装的python3.7,注意一定要重装
rm -rf /usr/local/python3
安装下面依赖,不安装这个会有坑:
apt install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.5 libgdm-dev libdb4o-cil-dev libpcap-dev
# 重新安装python3.7.1
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
tar -xzvf Python-3.7.1.tgz
./configure --prefix=/usr/local/python3
make && make install
# 报错:ModuleNotFoundError: No module named '_ctypes'
# 解决方法如下:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
sudo apt-get install libssl-dev openssl
sudo apt-get install libffi-dev
#重新编译
make && make install
# 添加环境变量:
export PATH=$PATH:/usr/local/python3/bin:/usr/local/python3/lib
# 建立pip3.7的软链接
rm /usr/bin/pip
rm /usr/local/bin/pip
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip
ln -s /usr/local/python3/bin/pip3.7 /usr/local/bin/pip
# 建立python3的软链接
rm /usr/bin/python3
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
2、安装 electrumx-1.14.0 的包
pip install aiohttp
pip install aiorpcX
pip install ecdsa
pip install plyvel
pip install pycodestyle
pip install pylru
pip install python-rocksdb
pip install pytest-asyncio
pip install pytest-cov
pip install Sphinx
pip install tribus-hash
pip install blake256
pip install scrypt
pip install x11_hash
pip install git+https://github.com/bitcoinplusorg/x13-hash
pip install xevan_hash
pip install quark_hash
pip install groestlcoin_hash
pip install neoscrypt
pip install x16r_hash
pip install pycryptodomex
pip install git+https://github.com/Electra-project/nist5_hash
pip install git+https://github.com/RitoProject/x21s_hash
pip install git+https://github.com/traysi/x16rv2_hash
pip install bell-yespower
pip install cpupower
二、克隆electrumx代码
git clone https://github.com/kyuupichan/electrumx.git
#checkout 1.14.0版本
cd electrumx
git checkout 1.14.0
三、修改electrumx代码,修改/electrumx/server/session.py文件的三个地方
# 通过地址获取余额
async def scripthash_get_balance(self, scripthash):
'''Return the confirmed and unconfirmed balance of a scripthash.'''
- hashX = address_to_hashX(scripthash)
+ coin = self.env.coin
+ hashX = coin.address_to_hashX(scripthash)
return await self.get_balance(hashX)
# 通过地址获取交易记录
async def scripthash_get_history(self, scripthash):
'''Return the confirmed and unconfirmed history of a scripthash.'''
- hashX = scripthash_to_hashX(scripthash)
+ coin = self.env.coin
+ hashX = coin.address_to_hashX(scripthash)
return await self.confirmed_and_unconfirmed_history(hashX)
#通过地址获取utxo
async def scripthash_listunspent(self, scripthash):
'''Return the list of UTXOs of a scripthash.'''
hashX = scripthash_to_hashX(scripthash)
+ coin = self.env.coin
+ hashX = coin.address_to_hashX(scripthash)
return await self.hashX_listunspent(hashX)
四、编译electrumx代码
cd electrumx
python setup.py build
python setup.py install #也可以不安装
五、配置electrumx的运行环境变量并启动,可以写到一个.sh文件中,不同的币种这个配置是不同的
cat run_electrumx_server_btc.sh
#!/bin/bash
export COIN=BitcoinSegwit # 币名
export DAEMON_URL=http://user:pass@127.0.0.1:8332/ #节点rpc 用户密码 ip 端口
export NET=mainnet #主网还是测试网
export CACHE_MB=1200 #同步缓存大小
export DB_DIRECTORY=/data/electrumx_data/btc #数据存储位置
export SSL_CERTFILE=/etc/electrumx/certfile.crt #SSL通信证书位置
export SSL_KEYFILE=/etc/electrumx/keyfile.key #SSL通信密钥位置
export BANNER_FILE=/etc/electrumx/banner
export DONATION_ADDRESS=your-donation-address
export ALLOW_ROOT=true #是否允许root账户
export SERVICES=tcp://0.0.0.0:50001,rpc://127.0.0.1:8000 //tcp和rpc监听端口
nohup python electrumx_server_btc & #后台启动
六、其他问题解决,安装和使用pip过程中存着一些暗坑,解决方法
# 1、问题: pip安装报错:
prompt-toolkit 1.0.15 has requirement six>=1.9.0, but you’ll have six 1.4.1 which is incompatible.
# 解决:
pip install six --user -U
pip install ipython --user -U
# 2、问题: pip升级失败
# 解决:
python -m pip install -U --upgrade pip --user
# 3、ubuntu 安装python3.7 以及安装pip3 出现Command '('lsb_release', '-a')' returned non-zero exit status 1问题解决
# 解决:
sudo rm /usr/bin/lsb_release
# 4、dash同步过程中报错:struct.error: 'H' format requires 0 <= number <= 65535
# 解决:
执行压缩历史记录脚本:electrumx_compact_history