您正在查看: Surou 发布的文章

fatal error: 'eosiolib/eosio.hpp' file not found

新手第一次编译EOS后执行编译Hello World合约时经常出现如下错误

root@ubuntu:~/eos/build/tools# ./eosiocpp -o ../contracts/hello/hello.wast ../contracts/hello/hello.cpp 
../hello/hello.cpp:3:10: fatal error: 'eosiolib/eosio.hpp' file not found #include ^~~~~~~~~~~~~~~~~~~~ 1 error generated.
root@ubuntu:~/eos/build/tools#

解决此问题方案如下

  1. cd eos_source/build,执行 sudo make install
  2. cd ../contracts/hello/ 切换到hello 合约目录
  3. 去掉执行程序eosiocpp前的./,修改为 eosiocpp -o hello.wast hello.cpp

v1.1.0 之后版本 出现的问题 参考(更新v1.1.0后,在执行 sudo make install 之后,cleos 等指令还是无效

添加环境变量

打开 ~/.bashrc

vi ~/.bashrc

在文件最后添加

#set eosio path
export EOSIO_PATH=/usr/local/eosio/bin
export PATH=$EOSIO_PATH:$PATH

终端执行以下命令,添加立即生效

source ~/.bashrc

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

EOS新版 默认的genesis.json 文件位置

EOS之前的版本,如果~/.local/share/eosio/nodeos/config/genesis.json不存在的话,
会自动在此目录创建初始化的genesis.json,每次nodeos 运行也会自动读取genesis.json

之后版本默认不会再已文件的形式创建初始化的genesis.json,(可查看相关代码)。程序也不会再自动读取genesis.json
当需要时自己手动通过--genesis-json传入。这样可避免不必要的数据冲突。

相关文章:

为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    ]

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