一、環境: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:[email protected]: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