您正在查看: EOS 分类下的文章

EOS合约内判断账户是否部署了合约

根据社区小伙伴需求,需要合约内查看某账户是否部署了合约,
我们根据setabi action,看下系统合约代码
https://github.com/EOSIO/eosio.contracts/blob/636406b45a4e1d4c3d7b308f6064dfe61b962814/contracts/eosio.system/src/eosio.system.cpp#L361

  void native::setabi( const name& acnt, const std::vector<char>& abi ) {
      eosio::multi_index< "abihash"_n, abi_hash >  table(get_self(), get_self().value);
      auto itr = table.find( acnt.value );
      if( itr == table.end() ) {
         table.emplace( acnt, [&]( auto& row ) {
            row.owner = acnt;
            row.hash = eosio::sha256(const_cast<char*>(abi.data()), abi.size());
         });
      } else {
         table.modify( itr, same_payer, [&]( auto& row ) {
            row.hash = eosio::sha256(const_cast<char*>(abi.data()), abi.size());
         });
      }
   }

当账户部署合约时,会将合约的hash更新到abihash表,所以我们根据这个表,来判断是否部署了合约就好了

cleos -u https://api.eoslaomao.com get table eosio eosio abihash -L eosio.token -l 1

返回数据

{
  "rows": [{
      "owner": "eosio.token",
      "hash": "85fd4e647e88e595223e69d09a3368a14a45d29320ed1515f54fdfac6ca999df"
    }
  ],
  "more": true
}

当合约账户删除部署合约时,

cleos -u https://api.eoslaomao.com set abi -c

这个hash值为

0000000000000000000000000000000000000000000000000000000000000000
结论

判断下对应账户在该abihash表有记录,且hash值不为0000000000000000000000000000000000000000000000000000000000000000,即为已部署合约。

备注

cleos get code 拿到的是 wasm 和 abi 原数据,然后本地计算的hash(查看源代码),这个一般主要是判断 合约 有没有更新变化用。如果只是判断是否部署合约,还是本文更直接

【Ubuntu】Ubuntu 18.04 LTS 更换国内源——解决终端下载速度慢的问题

最近装了ubuntu18.04 LTS,下载软件有点慢,网上搜了下解决方案,大致是两种:一、把/etc/apt/sources.list文件里的源更换一下,改成阿里云或者其它的镜像的文件;二、更换software&updates里的select best server。

一、更换/etc/apt/sources.list文件里的源

1. 备份源列表

Ubuntu配置的默认源并不是国内的服务器,下载更新软件都比较慢。首先备份源列表文件sources.list:

# 首先备份源列表
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

2. 打开sources.list文件修改

选择合适的源,替换原文件的内容,保存编辑好的文件, 以阿里云更新服务器为例(可以分别测试阿里云、清华、中科大、163源的速度,选择最快的):

# 打开sources.list文件
sudo gedit /etc/apt/sources.list

编辑/etc/apt/sources.list文件, 在文件最前面添加阿里云镜像源:

#  阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

3. 刷新列表

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential

下载速度瞬间就起飞了。

4. 其他源

中科大源:

#  中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

163源:

# 163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

清华源:

# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

转载自:https://zhuanlan.zhihu.com/p/61228593

WSL 编译EOS报 set: -i: invalid option

windows10 Linux子系统(Ubuntu 18.04)编译EOS报错如下

surou@DESKTOP-444S803:/mnt/c/github/eos$ ./scripts/eosio_build.sh
EOSIO Version: 1.8.6
Sat Jan  4 05:50:58 UTC 2020
User: surou
Current branch: develop
./scripts/eosio_build.sh: line 129: set: -i: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]

原因是子系统的系统名不是Ubuntu

( [[ ! $NAME == "Ubuntu" ]] && [[ ! $ARCH == "Darwin" ]] ) && set -i # Ubuntu doesn't support interactive mode since it uses dash + Some folks are having this issue on Darwin; colors aren't supported yet anyway

查看子系统的Name

surou@DESKTOP-444S803:/mnt/c/github/eos$ echo $NAME
DESKTOP-444S803

所以编译时设置下环境变量即可
编辑环境变量配置文件

vim ~/.bashrc

将下面参数添加到文件尾部

export NAME=Ubuntu
export VERSION_ID=18.04

备注:如果安装1.8.x的EOS,且没配置过环境变量的话,可以一起加上

export PATH=$PATH:/home/surou(当前用户名)/eosio/1.8/bin

然后刷新环境变量

source ~/.bashrc

然后再次执行

surou@DESKTOP-444S803:/mnt/c/github/eos$ ./scripts/eosio_build.sh

工作量证明(PoW)与EOSIO一起使用

https://www.eospow.org/
https://github.com/NedAmarril/eosiopowcoin

EOS 工作量证明硬币(POW)[1]将PoW(工作量证明)采矿时间表和调整比特币(BTC)[2] 的难度应用于EOSIO [3]令牌。

每10分钟铸造50个战俘,持续约4年,然后将一半铸造成一半。一直重复,直到有2100万个POW,与BTC完全一样。

EOS CPU和NET资源用于通过将EOS转移到eosiopowcoin来挖掘POW。每次您将EOS发送到eosiopowcoin合约账户时,该EOS的确切金额加上eosiopowcoin账户中总POW供应量的0.0025%将会被转回给您。

POW是一个完全分散的,不信任的开源项目,无需开发人员分配。每个单独的战俘都已经或将要被开采。没有给予战俘免费或预先开采。使用setupminer 操作后,任何人都可以挖掘POW 。战俘的铸造将持续到供应达到2100万为止。没有人可以阻止POW的铸造,开采或分销。合同是无钥匙的。

推送交易上链“假”失败的处理方案

解决问题

对于通过Rpc推送交易上链,因超时等因素导致无返回交易id或者失败,实际交易已上链。

解决方案

在推送交易时附加一个action,action可以填一个与此次推送任务对应的唯一值mark,并把当前链的块高度记下

void addmark( const name& owner, const string& mark )
{
   require_auth( owner );
}

然后mongo会把这个action数据以及对应的交易Id 洗出来

bool
mongo_db_plugin_impl::add_action_trace( mongocxx::bulk_write& bulk_action_traces, const chain::action_trace& atrace,
                                        const chain::transaction_trace_ptr& t,
                                        bool executed, const std::chrono::milliseconds& now,
                                        bool& write_ttrace )
{
   using namespace bsoncxx::types;
   using bsoncxx::builder::basic::kvp;

   const auto block_time = std::chrono::duration_cast<std::chrono::milliseconds>(
               std::chrono::microseconds{atrace.block_time.to_time_point().time_since_epoch().count()} );

   if( executed && atrace.receipt->receiver == chain::config::system_account_name ) {
      update_account( atrace, now, block_time );
   }
   .....
   else if(atrace.act.name == name("addmark")) {
      add_trx_marks( atrace, now, block_time );
   }
void mongo_db_plugin_impl::add_trx_marks( const chain::action_trace& atrace, const std::chrono::milliseconds& now, const std::chrono::milliseconds& block_time ) {
   using namespace bsoncxx::types;
   using bsoncxx::builder::basic::kvp;
   using bsoncxx::builder::basic::make_document;

   auto addma = fc::raw::unpack<mongo_db_plugin::addmark>(atrace.act.data);

   auto doc = make_document( 
                           kvp( "mark", addma.mark),
                           kvp( "trx_id", atrace.trx_id.str()),
                           kvp( "owner", addma.owner.to_string()),
                           kvp( "contract",atrace.receipt.receiver.to_string()),
                           kvp( "block_time", b_date{block_time}),
                           kvp( "block_timestamp", block_time.count()),
                           kvp( "createdAt", b_date{now} ));

   try {
      if( !_trx_marks.insert_one(doc.view())) {
         EOS_ASSERT( false, chain::mongo_db_insert_fail, "Failed to insert _trx_marks ${name} : ${mark}", ("name", addma.owner.to_string())("mark", addma.mark) );
      }
   } catch (...) {
      handle_mongo_exception( "_trx_marks", __LINE__ );
   }
}

测试查询记录

也就是如果推送没返回交易id,可以尝试查洗出的这个表,如果有的话,使用对应的交易id做数据补全。

{
    "_id" : ObjectId("5df34b721e722d468e02260f"),
    "mark" : "944c1698dc62c1817cc02c68207c47bf85dfc7e830839d2ab7267899bb04ada9",
    "trx_id" : "0e65b2b921019604b7928fdea11fe4e02e10550fe50fe767cbb84043b245e5ee",
    "owner" : "bcskillsurou",
    "contract" : "eosio.token",
    "block_time" : ISODate("2019-12-13T08:27:30.000Z"),
    "block_timestamp" : NumberLong(1576225650000),
    "createdAt" : ISODate("2019-12-13T08:27:30.028Z")
}

如果超过一段时间,且判断mongo中块高度增长正常,且超过前面记下的块高度一段距离(以防意外的话,就是超过当前最新区块与不可逆块的差)【防止mongo同步问题】,也没记录的话,就可以判定失败了。