EOS开发

EOS开发(十三)在Centos7服务器搭建钱包服务并使用钱包A

2018-09-21  本文已影响782人  yuyangray

1. 前言

之前我们的钱包服务都是启动在本地的,如果我们要做钱包客户端,肯定是不行的。这篇文章我们将在服务器上搭建钱包服务,并且通过RPC方式调用钱包的API。

EOSIO支持Linux系统,可以选择在本地或者阿里云搭建Linux系统的服务器。这里我们在本地安装Centos7版本的Linux系统。安装的过程就不再赘述。

我们现在已经有了一台Centos7服务器,IP为10.0.1.140,下面着重讲解开放服务器端口,以及在服务器配置钱包服务。

2. 开放服务器端口

我们需要开放8899端口作为钱包服务的访问端口。由于服务器有防火墙,我们需要手动将8899端口开放。

连接服务器:

ssh root@10.0.1.140

输入密码,成功后处于root目录下。

使用https://cyberduck.io这个工具访问服务器,可以浏览文件夹

查看防火墙状态:

[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 四 2018-09-20 14:04:51 CST; 3h 42min ago
     Docs: man:firewalld(1)
 Main PID: 697 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─697 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

可以看到防火墙处于开启状态

查看下服务器端口状态

[root@localhost ~]# firewall-cmd --zone=public --list-ports

没有返回任何东西

现在添加一个端口:

[root@localhost ~]# firewall-cmd --zone=public --add-port=8899/tcp --permanent
success

移除端口的命令firewall-cmd --zone=public --remove-port=8899/tcp --permanent

然后重新载入防火墙:

[root@localhost ~]# firewall-cmd --reload
success

现在再来查看下服务器端口状态:

[root@localhost ~]# firewall-cmd --zone=public --list-ports
8899/tcp

可以看到8899端口已经开放成功

我们直接查询8899端口状态:

[root@localhost ~]# firewall-cmd --zone=public --query-port=8899/tcp
yes

再次表明端口已经开放

2. 配置钱包服务

首先需要安装EOSIO。安装过程也不再赘述,和在Mac上的安装基本一致。

安装完成后,我们进入到keosd文件夹

[root@localhost ~]# cd eos
[root@localhost eos]# ls
build           docs                externals  programs          tools
CMakeLists.txt  eos.doxygen.in      HEADER     README.md         tutorials
CMakeModules    eosio_build.sh      images     scripts           unittests
contracts       eosio_install.sh    libraries  testnet.md
debian          eosio_uninstall.sh  LICENSE    testnet.template
Docker          eosio.version.in    plugins    tests
[root@localhost eos]# cd programs/
[root@localhost programs]# ls
cleos  CMakeLists.txt  eosio-abigen  eosio-launcher  keosd  nodeos
[root@localhost programs]# cd keosd
[root@localhost keosd]# ls
CMakeLists.txt  main.cpp
[root@localhost keosd]# 

启动钱包服务并指定IP和端口号:

[root@localhost keosd]# keosd --http-server-address=10.0.1.140:8899
2018-09-20T10:00:56.324 thread-0   wallet_plugin.cpp:42          plugin_initialize    ] initializing wallet plugin
2018-09-20T10:00:56.325 thread-0   http_plugin.cpp:344           plugin_initialize    ] configured http to listen on 10.0.1.140:8899
2018-09-20T10:00:56.325 thread-0   wallet_api_plugin.cpp:123     plugin_initialize    ] 
********!!!SECURITY ERROR!!!********
*                                  *
* --       Wallet API           -- *
* - EXPOSED to the LOCAL NETWORK - *
* -  HTTP RPC is NOT encrypted   - *
* - Password and/or Private Keys - *
* - are at HIGH risk of exposure - *
*                                  *
************************************

2018-09-20T10:00:56.325 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/keosd/stop
2018-09-20T10:00:56.325 thread-0   http_plugin.cpp:401           plugin_startup       ] start listening for http requests
2018-09-20T10:00:56.326 thread-0   wallet_api_plugin.cpp:73      plugin_startup       ] starting wallet_api_plugin
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/create
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/create_key
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/get_public_keys
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/import_key
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/list_keys
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/list_wallets
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/lock
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/lock_all
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/open
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/remove_key
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/set_timeout
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/sign_digest
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/sign_transaction
2018-09-20T10:00:56.326 thread-0   http_plugin.cpp:447           add_handler          ] add api url: /v1/wallet/unlock

会有一个风险提示

还有另一种方式启动钱包服务并指定IP和端口,就是自定义钱包的配置文件config.ini。新建一个文件夹,例如config,拷贝~/eosio-wallet/config.ini到此文件夹中,并修改http-server-address = 10.0.1.140:8899,然后使用此配置启动钱包服务:

keosd --config-dir /Users/yuyang/eosio-wallet/config

3. 本地调用服务器钱包API

使用Postman调用

钱包的API可以在EOS开发(八)RPC API查看,只需要把IP换成服务器IP即可

上一篇下一篇

猜你喜欢

热点阅读