您正在查看: EOS-新手教程 分类下的文章

EOS 支持 sql_db_plugin及连接测试

更新sql_db_plugin代码

git clone https://github.com/superoneio/eos_sql_db_plugin
cp -rv eos_sql_db_plugin/sql_db_plugin/* /home/surou/Documents/github/eos/plugins/sql_db_plugin

对比了以下几个维护的sql_db_plugin版本代码

开启sql_db_plugin编译支持

  1. 打开eos/plugins/CMakeLists.txt
    取消add_subdirectory(sql_db_plugin)前面的#注释
  2. 打开 eos/programs/nodeos/CMakeLists.txt
    // 取消下面代码前的注释,如果无注释,则忽略此步骤。
    if(TARGET sql_db_plugin)
     target_link_libraries( nodeos PRIVATE -Wl,${whole_archive_flag} sql_db_plugin -Wl,${no_whole_archive_flag} )
    endif()

    重新编译EOS

    ./eosio_build.sh
    cd build
    sudo make install

    编译完成后,执行

    nodeos --help | grep "sql_db-uri"

    如果输出如下内容,证明编译成功。

    –sql_db-uri arg Sql DB URI connection string If not

Mysql 8.0 安装

  • 参考 Ubuntu 安装MySql 8.0
  • 接下来我们安装 soci。soci 是 C++ 连接 MySQL 的 Library。Ubuntu 可以快速安装,命令如下:
    sudo apt-get -y install libsoci-dev
  • 安装 mysql-client
    sudo apt-get -y install mysql-client
    sudo apt-get install libmysqlclient-dev

配置Eos数据库

  • 进入mysql
    mysql -p
  • 创建数据库以及分配账号
    CREATE DATABASE eos DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    GRANT ALL PRIVILEGES ON eos.* TO 你的账户名@'%' IDENTIFIED BY '你的密码';
    GRANT ALL PRIVILEGES ON eos.* TO 你的账户名@'127.0.0.1' IDENTIFIED BY '你的密码';
  • 查看数据库
    mysql > show databases;

  • 导入数据库(eos.db)
    mysql > use eos;  //切换到eos 数据库
    mysql > source eos_sql_db_plugin/sql_db_plugin/eos.db; //导入数据库

    执行数据同步

    nodeos --sql_db-uri="mysql://db=eos user=root host=127.0.0.1 password='数据库密码'" --sql_db-block-start=0  --delete-all-blocks

常见问题

  • ERROR 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci'
    MySql 8.0才支持的默认字符集
  • 查看Ubuntu版本
    cat /etc/issue

参考链接

安装EOS 数据获取API Server EOSTracker-API

获取源代码

git clone https://github.com/EOSEssentials/EOSTracker-API.git

开始编译

cd EOSTracker-API
composer install

开始运行

php bin/console server:run


常见问题

  • ubuntu add-apt-repository command not found解决方法
    apt-get install software-properties-common
  • Ubuntu PHP升级到最新版本
    add-apt-repository ppa:ondrej/php
    apt-get update
    apt-get upgrade php
  • The requested PHP extension ext-apcu * is missing from your system. Install or enable PHP's apcu extension
    apt-get install php7.2-apcu //修改为当前版本  php -v
  • The requested PHP extension ext-intl * is missing from your system. Install or enable PHP's intl extension
    apt-get install php7.2-intl //修改为当前版本  php -v
  • The requested PHP extension ext-mbstring * is missing from your system. Install or enable PHP's mbstring extension
    apt-get install php7.2-mbstring //修改为本地版本  php -v
  • The requested PHP extension ext-redis * is missing from your system. Install or enable PHP's redis extension
    apt-get install php7.2-redis //修改为本地版本  php -v
  • Installation request for symfony/symfony v3.4.11 -> satisfiable by symfony/symfony[v3.4.11].
    symfony/symfony v3.4.11 requires ext-xml * -> the requested PHP extension xml is missing from your system.
       apt-get install php7.2-xml //修改为本地版本 PHP -v

delegatebw 自己给自己抵押时报 Error 3050003: eosio_assert_message assertion failure

执行代码如下

root@iZj6cgy98yiuluw41gz0aoZ:~/.local/share/eosio/nodeos/config# cleos system delegatebw dappplaynode dappplaynode '10000000.0000 EOS' '10000000.0000 EOS' --transfer
2018-07-20T12:15:24.339 thread-0   main.cpp:438                  create_action        ] result: {"binargs":"a0129ddec45aab49a0129ddec45aab4900e876481700000004454f530000000000e876481700000004454f530000000001"} arg: {"code":"eosio","action":"delegatebw","args":{"from":"dappplaynode","receiver":"dappplaynode","stake_net_quantity":"10000000.0000 EOS","stake_cpu_quantity":"10000000.0000 EOS","transfer":true}} 
Error 3050003: eosio_assert_message assertion failure

查看代码
eos\contracts\eosio.system\delegate_bandwidth.cpp

void system_contract::changebw( account_name from, account_name receiver,
                                   const asset stake_net_delta, const asset stake_cpu_delta, bool transfer )
{
    ......
    // net and cpu are same sign by assertions in delegatebw and undelegatebw
         // redundant assertion also at start of changebw to protect against misuse of changebw
         bool is_undelegating = (net_balance.amount + cpu_balance.amount ) < 0;
         bool is_delegating_to_self = (!transfer && from == receiver);

         if( is_delegating_to_self || is_undelegating ) {
    .......
}

抵押时不能再添加 --transfer(此参数添加时,是说抵押同时将币的所有权转给接收者,但自己已经有所有权了,不能自己再转给自己)

为Dapp提供合适的EOS验证身份信息

简述下Extension和Dapp身份认证过程。

Dapp获取EOS帐号身份大致流程如下

开始分析流程

参考Scatter获取身份的流程(Scatter 身份获取部分代码),Dapp对于身份的验证规则如下

如果Dapp配置了所需网络的chain Id,则计算返回为("${this.blockchain}:"+"chain:${this.chainId}").toLowerCase()
如果没有配置chain Id,则计算返回 ("${this.blockchain}:"+"${this.host}:${this.port}").toLowerCase()

Dapp匹配身份有两种方式

  • chain id
  • 所需网络的地址和端口。

对于只有所需网络的地址和端口的,先根据地址和端口通过RPC获取对应的chain idgetinfo
然后Extension统一根据chain id查询对应的账户信息中选中的账号信息,以及从对应chain id网络信息中找到选中的网络信息。
然后将账户信息和网络信息创建成一个身份返回给Dapp.

补充

  • 针对于网络信息,所在的chain id,并不可靠,所在的地址有可能会切换链,所以要先有验证的逻辑(根据地址查询chain idgetinfo,判断是否相同)。
  • 针对于账户信息,所存的权限,也不可靠,因为非owner可能被owner修改或者删除掉,所以非owner权限要实现验证逻辑。(通过账户所在chain id,从网络信息中找对应的网络地址,通过getaccount,返回中查看permissions对应权限是否存在,并且公钥是否与私钥生成的公钥一致)

部署EOS Mainnet 主网络,并接入eosfans测试网络,成为BP

开始准备EOS项目

  • 获取EOS主网项目代码
    git clone https://github.com/EOS-Mainnet/eos.git
  • 进入eos代码目录,切换当前所需的分支
    git checkout --no-track -b Branch_v1.1.0 Mainnet-1.1.0 --
  • 开始编译
    ./eosio_build.sh
  • 执行安装
    sudo make install
  • 建立链接 避免出现 (更新v1.1.0后,在执行 sudo make install 之后,cleos 等指令还是无效)
    ln -s /usr/local/eosio/bin/nodeos /usr/local/bin/nodeos
    ln -s /usr/local/eosio/bin/cleos /usr/local/bin/cleos

开始配置,接入eosfans测试网络

先运行下nodeos,将会自动创建~/.local/share/eosio/nodeos/config目录和config.ini文件。
修改config.ini中如下内容

//添加
p2p-peer-address = p2p.party.eostea.io:56234
//修改 可忽略
agent-name = "EOS Test Agent"
//如果需要外部eosjs调用的话,修改
access-control-allow-origin = *
//如果需要查看get actions,取消前面注释
filter-on = *
//如果需要返回错误信息,修改
verbose-http-errors = true
//添加插件支持
plugin = eosio::chain_api_plugin
plugin = eosio::history_plugin
plugin = eosio::history_api_plugin
如果需要生产区块,成为BP

继续修改config.ini

//修改BP名
producer-name = 你的节点名字
//修改BP节点名对应的公钥,私钥 (不要用下面现成的,自己去重新生成!!!)
signature-provider = EOS66bcyj8NBeJigeCDqCeYnaJNFZfCZt328yEpHCh7VZKSxed4Cn=KEY:5KHqSSajXUi11wPEWagiWgY51G6mo4zE4FKfrD2tNH9i4PHHVxU
//添加插件支持
plugin = eosio::producer_plugin
下载测试网络对应的genesis.json

切换到~/.local/share/eosio/nodeos/config目录,
新建genesis.json,将(测试网络genesis.json)内容复制到新建的genesis.json文件中,不要用wget直接下载,github会有转向内容不对.

开始准备启动

  • 先清空data目录 (由于开始测试启动时,写入了一些不兼容的数据块)
    rm -rf ~/.local/share/eosio/nodeos/data
  • ~/.local/share/eosio/nodeos/config执行
    nodeos --genesis-json genesis.json

    此时已启动并开始同步区块

开始配置成为BP

  • cleos wallet create 创建一个默认钱包并保存好解锁密码
  • cleos wallet import {Private_Key} 导入上面config.ini中signature-provider配置的私钥
  • 在测试网络中注册config.ini中producer-name配置的账号 (可以联系eosfans创建),并转入一些系统代币
    root@iZj6cgy98yiuluw41gz0aoZ:~/.local/share/eosio/nodeos/config# cleos get currency balance eosio.token bcskillsurou EOS
    20000000.0000 EOS
  • 将系统代币抵押给自己 (常见问题
    root@iZj6cgy98yiuluw41gz0aoZ:~/.local/share/eosio/nodeos/config# cleos system delegatebw bcskillsurou bcskillsurou '10000000.0000 EOS' '10000000.0000 EOS'
    2018-07-20T12:20:56.591 thread-0   main.cpp:438                  create_action        ] result: {"binargs":"a0129ddec45aab49a0129ddec45aab4900e876481700000004454f530000000000e876481700000004454f530000000000"} arg: {"code":"eosio","action":"delegatebw","args":{"from":"bcskillsurou","receiver":"bcskillsurou","stake_net_quantity":"10000000.0000 EOS","stake_cpu_quantity":"10000000.0000 EOS","transfer":false}} 
    executed transaction: ed7bfc3787629ae9fd27c8ef2a51440a2f89717a4e442e5c5588184ce7664c4b  144 bytes  1798 us
    #         eosio <= eosio::delegatebw            {"from":"bcskillsurou","receiver":"bcskillsurou","stake_net_quantity":"10000000.0000 EOS","stake_cpu...
    #   eosio.token <= eosio.token::transfer        {"from":"bcskillsurou","to":"eosio.stake","quantity":"20000000.0000 EOS","memo":"stake bandwidth"}
    #  bcskillsurou <= eosio.token::transfer        {"from":"bcskillsurou","to":"eosio.stake","quantity":"20000000.0000 EOS","memo":"stake bandwidth"}
    #   eosio.stake <= eosio.token::transfer        {"from":"bcskillsurou","to":"eosio.stake","quantity":"20000000.0000 EOS","memo":"stake bandwidth"}
    warning: transaction executed locally, but may not be confirmed by the network yet    ] 
  • cleos system regproducer {producer-name} {public key} http://{{server}}.com //申请bp
    root@iZj6cgy98yiuluw41gz0aoZ:~/.local/share/eosio/nodeos/config# cleos system regproducer bcskillsurou EOS8H6rzgwpV2KD5AtiDMZLQWw6nDxWaV6jGc7rVY8sHfFuJZjCq4 http://bcskill.com
    2018-07-20T12:36:19.839 thread-0   main.cpp:438                  create_action        ] result: {"binargs":"a0129ddec45aab490003be6e9ef6503430e4c80a2cd52149d2b7b9330d92c2cea4a839632f94ced75daf10687474703a2f2f64617070702e636f6d0000"} arg: {"code":"eosio","action":"regproducer","args":{"producer":"bcskillsurou","producer_key":"EOS8H6rzgwpV2KD5AtiDMZLQWw6nDxWaV6jGc7rVY8sHfFuJZjCq4","url":"http://dappp.com","location":0}} 
    executed transaction: 91df9e3e6e27708ab803ee6da121c2ddd7845fef5f76145dbfd618937ecee5e5  160 bytes  1130 us
    #         eosio <= eosio::regproducer           {"producer":"bcskillsurou","producer_key":"EOS8H6rzgwpV2KD5AtiDMZLQWw6nDxWaV6jGc7rVY8sHfFuJZjCq4","u...
    warning: transaction executed locally, but may not be confirmed by the network yet    ]

需要等主网启动后,才会出块。