Yenten:Raspberry Piでウォレットを動かす

仮想通貨のYentenの公式ウォレットアプリケーション「Yenten Core」をRaspberry Piで動かす方法です。公式のGitHubにてUbuntu版のパッケージが公開されていますが、ラズパイでは動作しないため、自分でビルドが必要です。本記事ではサーバとして動かします。
なお取引が活発になるとウォレットのデータサイズも大きくなるため、低容量のMicroSDでの運用はオススメしません。
※ソフトウェアのインストール・実行は自己責任です。特に仮想通貨はお金の絡むことなので、十分にお気をつけください。また基本的なことは知っている、もしくは調べられる人向けに書いているため、コマンドなど細かく説明していません。
※2017/12/28 RasbianのバージョンをJessieからStretchに変更したところ、OpenSSLが適合しなくなったため、記事を修正しました。

<環境>

  • 型番:Raspberry Pi 3 Model B
  • OS:Rasbian Stretch
  • バージョン:1.2.1

https://github.com/conan-equal-newone/yenten
https://github.com/conan-equal-newone/yenten/archive/1.2.1.tar.gz

ソースコードからYenten Coreをビルドする

1-1. apt-getで揃うパッケージのインストール

~ $ sudo apt-get update
~ $ sudo apt-get install build-essential
~ $ sudo apt-get install libtool autotools-dev autoconf
~ $ sudo apt-get install libboost-all-dev
~ $ sudo apt-get install pkg-config

OpenSSLをapt-getでインストールしないのは、Rasbian Stretchの標準のOpenSSL 1.1.0でコンパイルエラーとなるためです。

ここからはapt-getでインストールしたパッケージとバッティングするのが嫌なので、/home/wallet/commonに仮想通貨用のライブラリを配置します。

1-2. Berkeley DB 4.8のインストール

~ $ wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
~ $ tar xvzf db-4.8.30.NC.tar.gz
~ $ cd db-4.8.30.NC/build_unix/
~/db-4.8.30.NC/build_unix $ ../dist/configure --prefix=/home/wallet/common --enable-cxx
~/db-4.8.30.NC/build_unix $ make
~/db-4.8.30.NC/build_unix $ make install

1-3. OpenSSL(1.0.2系最新)のインストール

~ $ wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
~ $ tar xvzf openssl-1.0.2n.tar.gz
~ $ cd openssl-1.0.2n/
~/openssl-1.0.2n $ ./config --prefix=/home/wallet/common --openssldir=/home/wallet/common/openssl -fPIC shared
~/openssl-1.0.2n $ make
~/openssl-1.0.2n $ make install

1-4. Yenten Coreのビルド

ビルドしたファイルの出力先は/home/wallet/yentenとしています。
気をつけなければならないのは、Makefile.amのコンパイルオプションに-msse4.1を指定してる箇所がありますが、ラズパイではコンパイルエラーになるため(ARMだからSSE4.1が使えないので)、消します。
※ビルド中にエラーとなる場合は「Raspberry Piでウォレットビルド中にエラーとなる場合」を参照

~ $ wget https://github.com/conan-equal-newone/yenten/archive/1.2.1.tar.gz
~ $ tar xvzf 1.2.1.tar.gz
~ $ cd yenten-1.2.1
~/yenten-1.2.1 $ vi src/Makefile.am
※src/Makefile.amから-msse4.1の記述を消します

if TARGET_DARWIN
hash/yescrypt/yescrypt.o: CFLAGS += -O3 -msse4.1 -funroll-loops -fomit-frame-pointer
else
hash/yescrypt/yescrypt.o: CFLAGS += -msse4.1 -fPIC
endif

↓

if TARGET_DARWIN
hash/yescrypt/yescrypt.o: CFLAGS += -O3 -funroll-loops -fomit-frame-pointer
else
hash/yescrypt/yescrypt.o: CFLAGS += -fPIC
endif

~/yenten-1.2.1 $ ./autogen.sh
~/yenten-1.2.1 $ LD_LIBRARY_PATH=/home/wallet/common/lib \
LIBS="-lssl -lcrypto -lrt" \
CPPFLAGS=-I/home/wallet/common/include \
LDFLAGS=-L/home/wallet/common/lib \
SSL_CFLAGS=-I/home/wallet/common/include \
SSL_LIBS=-L/home/wallet/common/lib \
CRYPTO_CFLAGS=-I/home/wallet/common/include \
CRYPTO_LIBS=-L/home/wallet/common/lib \
PKG_CONFIG_PATH=/home/wallet/common/lib/pkgconfig \
PKG_CONFIG_LIBDIR=/home/wallet/common/lib \
./configure --prefix=/home/wallet/yenten --enable-upnp-default --without-gui --disable-tests
~/yenten-1.2.1 $ make
~/yenten-1.2.1 $ make install
~/yenten-1.2.1 $ ls -l /home/wallet/yenten/bin
-rwxr-xr-x 1 wallet wallet 16326328 12月 10 06:55 yenten-cli
-rwxr-xr-x 1 wallet wallet 61286784 12月 10 06:55 yentend

補足

今回のように任意の場所にライブラリを配置し、かつ、/etc/ld.so.confにパスを通さない場合、Yenten Coreを起動する際には環境変数LD_LIBRARY_PATHにライブラリのパスを設定しなければなりません。

~ $ export LD_LIBRARY_PATH=/home/wallet/common/lib
~ $ ./yentend
~ $ ./yenten-cli stop

もしくは

~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yentend
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yenten-cli stop

Yenten Coreを起動する

2-1. yentendの初回起動(エラー)

yentendを実行するとYenten Coreが起動しますが、設定ファイルが無いため、エラーになります。ただ初回起動時にデータのディレクトリを作成するため、エラーでもよいので起動します。

~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yentend
Error: To use the "-server" option, you must set a rpcpassword in the configuration file:
/home/wallet/.yenten/yenten.conf
It is recommended you use the following random password:
rpcuser=yentenrpc
rpcpassword=HzSmt2sBN2owrhUeUYw93Yh1NLA8QiAjq6SqY93uHgX
(you do not need to remember this password)
The username and password MUST NOT be the same.
If the file does not exist, create it with owner-readable-only file permissions.
It is also recommended to set alertnotify so you are notified of problems;
for example: alertnotify=echo %s | mail -s "Yenten Alert" admin@foo.com

2-2. yenten.confの作成

/home/ユーザ名/.yenten配下にデータが作成されたため、設定ファイルのyenten.confを作成します。rpcxxxの部分は自分の環境に合わせてください。

~ $ vi /home/ユーザ名/.yenten/yenten.conf
rpcuser=user
rpcpassword=pass
rpcallowip=127.0.0.1
rpcport=9982
daemon=1
server=1
gen=0

2-3. yentendの起動

設定ファイル作成後に再度yentendを実行します。実行後は起動したことを確認するため、yenten-cli getinfoを実行します。

~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yentend
Yenten server starting
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yenten-cli getinfo
{
    "version" : 1020100,
    "protocolversion" : 70006,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 836,
    "timeoffset" : 0,
    "connections" : 5,
    "proxy" : "",
    "difficulty" : 0.00325450,
    "testnet" : false,
    "keypoololdest" : 1512925804,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00001000,
    "errors" : ""
}

Yenten Coreを停止するには、yenten-cli stopを実行します。

~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yenten-cli stop
Yenten server stopping

2-4. ウォレットの暗号化

ウォレット(wallet.dat)を暗号化するには、yenten-cli encryptwalletを実行します。実行後にはYenten Coreが停止するため、再度起動が必要です。暗号化すると送金等一部の処理にパスワードが必要となります。
Linux上ではコマンド履歴が残るため、Windowsで暗号化したwallet.datをLinuxへアップロードして使う、.bash_historyを削除するなど対策をすることをおススメします。

~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yenten-cli encryptwallet パスワード
wallet encrypted; Yenten server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup.
~ $ LD_LIBRARY_PATH=/home/wallet/common/lib ./yentend

 
参考になりましたらYentenを寄付していただけると幸いです。
Yentenアドレス:Yh5Q12DsQsF6xPaQXByPdh3HcyjfYgZEz2


※下記は過去(Jessie)の記事

ソースコードからYenten Coreをビルドする

1-1. apt-getで揃うパッケージのインストール

~ $ sudo apt-get update
~ $ sudo apt-get install build-essential
~ $ sudo apt-get install libtool autotools-dev autoconf
~ $ sudo apt-get install libssl-dev
~ $ sudo apt-get install libboost-all-dev
~ $ sudo apt-get install pkg-config

ppa:bitcoin/bitcoinの追加はエラーとなるため、ラズパイでは不要です。

※実行不要です
~ $ sudo apt install software-properties-common
~ $ sudo apt-add-repository ppa:bitcoin/bitcoin
You are about to add the following PPA to your system:
 Stable Channel of bitcoin-qt and bitcoind for Ubuntu, and their dependencies

Note that you should prefer to use the official binaries, where possible, to limit trust in Launchpad/the PPA owner.

No longer supports precise, due to its ancient gcc and Boost versions.
 More info: https://launchpad.net/~bitcoin/+archive/ubuntu/bitcoin
Press [ENTER] to continue or ctrl-c to cancel adding it

Traceback (most recent call last):
  File "/usr/bin/apt-add-repository", line 167, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 105, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 595, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)
  File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 89, in get_sources
    (self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/jessie

1-2. Berkeley DB 4.8のインストール

~ $ wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
~ $ tar xvzf db-4.8.30.NC.tar.gz
~ $ cd db-4.8.30.NC/build_unix/
~/db-4.8.30.NC/build_unix $ ../dist/configure --enable-cxx
~/db-4.8.30.NC/build_unix $ make
~/db-4.8.30.NC/build_unix $ sudo make install
~/db-4.8.30.NC/build_unix $ cd /usr/local/include
/usr/local/include $ sudo ln -s /usr/local/BerkeleyDB.4.8/include/* ./
/usr/local/include $ cd /usr/local/lib
/usr/local/lib $ sudo ln -s /usr/local/BerkeleyDB.4.8/lib/* ./

下記は/usr/local/libにライブラリパスが通っていない場合に対応します。

~ $ less /etc/ld.so.conf
include ld.so.conf.d/*.conf
~ $ sudo vi /etc/ld.so.conf.d/usrlocallib.conf
/usr/local/lib
~ $ sudo ldconfig

1-3. Yenten Coreのビルド

ビルドしたファイルの出力先は/home/pi/wallet/yentenとしています。
気をつけなければならないのは、Makefile.amのコンパイルオプションに-msse4.1を指定してる箇所がありますが、ラズパイではコンパイルエラーになるため(ARMだからSSE4.1が使えないので)、消します。
※ビルド中にエラーとなる場合は「Raspberry Piでウォレットビルド中にエラーとなる場合」を参照

~ $ wget https://github.com/conan-equal-newone/yenten/archive/1.2.1.tar.gz
~ $ tar xvzf 1.2.1.tar.gz
~ $ cd yenten-1.2.1
~/yenten-1.2.1 $ vi src/Makefile.am
※src/Makefile.amから-msse4.1の記述を消します

if TARGET_DARWIN
hash/yescrypt/yescrypt.o: CFLAGS += -O3 -msse4.1 -funroll-loops -fomit-frame-pointer
else
hash/yescrypt/yescrypt.o: CFLAGS += -msse4.1 -fPIC
endif

↓

if TARGET_DARWIN
hash/yescrypt/yescrypt.o: CFLAGS += -O3 -funroll-loops -fomit-frame-pointer
else
hash/yescrypt/yescrypt.o: CFLAGS += -fPIC
endif

~/yenten-1.2.1 $ ./autogen.sh
~/yenten-1.2.1 $ ./configure --prefix=/home/pi/wallet/yenten --enable-upnp-default --without-gui --disable-tests
~/yenten-1.2.1 $ make
~/yenten-1.2.1 $ make install
~/yenten-1.2.1 $ ls -l /home/pi/wallet/yenten/bin
-rwxr-xr-x 1 pi pi 16326328 12月 10 06:55 yenten-cli
-rwxr-xr-x 1 pi pi 61286784 12月 10 06:55 yentend

Yenten Coreを起動する

2-1. yentendの初回起動(エラー)

yentendを実行するとYenten Coreが起動しますが、設定ファイルが無いため、エラーになります。ただ初回起動時にデータのディレクトリを作成するため、エラーでもよいので起動します。

~ $ ./yentend
Error: To use the "-server" option, you must set a rpcpassword in the configuration file:
/home/pi/.yenten/yenten.conf
It is recommended you use the following random password:
rpcuser=yentenrpc
rpcpassword=HzSmt2sBN2owrhUeUYw93Yh1NLA8QiAjq6SqY93uHgX
(you do not need to remember this password)
The username and password MUST NOT be the same.
If the file does not exist, create it with owner-readable-only file permissions.
It is also recommended to set alertnotify so you are notified of problems;
for example: alertnotify=echo %s | mail -s "Yenten Alert" admin@foo.com

2-2. yenten.confの作成

/home/ユーザ名/.yenten配下にデータが作成されたため、設定ファイルのyenten.confを作成します。rpcxxxの部分は自分の環境に合わせてください。

~ $ vi /home/ユーザ名/.yenten/yenten.conf
rpcuser=user
rpcpassword=pass
rpcallowip=127.0.0.1
rpcport=9982
daemon=1
server=1
gen=0

2-3. yentendの起動

設定ファイル作成後に再度yentendを実行します。実行後は起動したことを確認するため、yenten-cli getinfoを実行します。

~ $ ./yentend
Yenten server starting
~ $ ./yenten-cli getinfo
{
    "version" : 1020100,
    "protocolversion" : 70006,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 836,
    "timeoffset" : 0,
    "connections" : 5,
    "proxy" : "",
    "difficulty" : 0.00325450,
    "testnet" : false,
    "keypoololdest" : 1512925804,
    "keypoolsize" : 101,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00001000,
    "errors" : ""
}

Yenten Coreを停止するには、yenten-cli stopを実行します。

~ $ ./yenten-cli stop
Yenten server stopping