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

使用eosio-java计算transaction_id

开源地址:https://github.com/EOSIO/eosio-java

计算方法

Hex.toHexString(Sha256Hash.hash(Hex.decode(processor.getSerializedTransaction())));

参考:https://github.com/EOSIO/eosio-java/issues/96

EOS链的RAM资源扩增

背景

某个基于EOS开发的链,提供了免费的账户注册接口,执行调用后,空投账户免费为其抵押CPU NET和购买RAM。由于接口没有做严格有效的防刷处理,导致账户注册严重超过预期,导致链内系统资源浪费严重,以及空投部分系统代币占用过多

逻辑处理

  1. 增加注册接口的防范级别,比如增加IP注册次数,相同公钥,App机器码统计。三方有效的验证码验证,App内核心校验参数加密,增加对方破解成本。
  2. 对于已经刷入的账户做筛选,以及资源回收,比如,注册多长时间内从未使用
  3. 增加付费和邀请注册逻辑。提供与EOS目前主流钱包一样的逻辑,由三方账户进行代为抵押购买,或者直接RMB支付
  4. 由项目方提供投抵押的系统代币。提供空投服务程序给项目方,项目方账户持续为自己项目内账户补充所需的空投代币,服务程序也可以支持邀请码注册,项目方生成邀请码赠送或者出售给自己的用户

链处理

  1. 一次性扩增RAM容量。(eosio->setram)

    void system_contract::setram( uint64_t max_ram_size ) {
       require_auth( get_self() );
    
       check( _gstate.max_ram_size < max_ram_size, "ram may only be increased" ); /// decreasing ram might result market maker issues
       check( max_ram_size < 1024ll*1024*1024*1024*1024, "ram size is unrealistic" );
       check( max_ram_size > _gstate.total_ram_bytes_reserved, "attempt to set max below reserved" );
    
       auto delta = int64_t(max_ram_size) - int64_t(_gstate.max_ram_size);
       auto itr = _rammarket.find(ramcore_symbol.raw());
    
       /**
        *  Increase the amount of ram for sale based upon the change in max ram size.
        */
       _rammarket.modify( itr, same_payer, [&]( auto& m ) {
          m.base.balance.amount += delta;
       });
    
       _gstate.max_ram_size = max_ram_size;
    }
  2. 每块持续新增。(eosio->setramrate)
    设置完每块新增量后

    void system_contract::setramrate( uint16_t bytes_per_block ) {
       require_auth( get_self() );
    
       update_ram_supply();
       _gstate2.new_ram_per_block = bytes_per_block;
    }

    当下次有购买内存的操作时,执行时间差内的容量扩增

    void system_contract::buyram( const name& payer, const name& receiver, const asset& quant )
    {
       require_auth( payer );
       update_ram_supply();

参考

https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/eosio.system.cpp#L67

https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/eosio.system.cpp#L105

https://github.com/EOSIO/eosio.contracts/blob/d7bc0a5cc8c0c2edd4dc61b0126517d0cb46fd94/contracts/eosio.system/src/delegate_bandwidth.cpp#L46

https://developers.eos.io/manuals/eosio.contracts/latest/key-concepts/ram

eos 链改 2.0.x 升级2.1.x的修改点

  1. eosio::name 声明变量的N() 取消了,统一用 ""_n
  2. fc::optional替换成 std::optional
  3. t->packed_trx()->get_signed_transaction() 改成v0 获取,修改为
    t->packed_trx()->to_packed_transaction_v0()->get_signed_transaction()
  4. mongo_db_plugin 相关被删除,包括mongo异常信息类型
  5. bs->block->id(); 使用V0
    bs->block->to_signed_block_v0()->id();

持续总结

dfuse-eosio 如何添加自定义查询条件,例如transfer中的memo

为了业务的需要的,我们常常需要查询交易中的一些自定义的参数,比如transfer 中的memo
当我们按找REST API文档使用时,

http://39.106.103.152:8080/v0/search/transactions?start_block=0&block_count=327722&limit=10&sort=desc&q=receiver:eosio.token+action:transfer+data.memo:return

会报不支持

"server error: unable to initiate to search: The following fields you are trying to search are not currently indexed: 'data.memo'. Contact our support team for more."

解决方案

被索引的操作的数据字段定义为search-common-indexed-terms默认配置为"receiver, account, action, auth, scheduled, status, notif, input, event, ram.consumed, ram.released, db.key, db.table, data.account, data.active, data.active_key, data.actor, data.amount, data.auth, data.authority, data.bid, data.bidder, data.canceler, data.creator, data.executer, data.from, data.is_active, data.is_priv, data.isproxy, data.issuer, data.level, data.location, data.maximum_supply, data.name, data.newname, data.owner, data.parent, data.payer, data.permission, data.producer, data.producer_key, data.proposal_name, data.proposal_hash, data.proposer, data.proxy, data.public_key, data.producers, data.quant, data.quantity, data.ram_payer, data.receiver, data.requested, data.requirement, data.symbol, data.threshold, data.to, data.transfer, data.voter, data.voter_name, data.weight, data.abi, data.code"

所有不以data.“.”开头的字段都是“固定的”,这意味着您可以将它们包含在列表中以对其进行索引或关闭以禁用对其的索引编制,但是我们不能添加新的字段(block_timestamp例如,将被拒绝)。

所有开始data.都是动态的字段,并且可以是任何字段,如果它们与操作的字段名称匹配,则将对其进行索引,例如,如果您部署了具有操作event_id且data.event_id列表中有的智能合约,则可以按receiver:mycontract data.event_id:something。

现在,大约data.memo可以将其添加到列表中,它将起作用,但是它将是完全匹配的,在memo数据上没有标记化,也没有解释。一个手段memo形式first second third,data.memo:first将不匹配,只有data.memo:'first second third'将匹配字段。

最终修改

编译dfuse.yaml,在flags中添加

search-common-indexed-terms: "receiver, account, action, auth, scheduled, status, notif, input, event, ram.consumed, ram.released, db.key, db.table, data.account, data.active, data.active_key, data.actor, data.amount, data.auth, data.authority, data.bid, data.bidder, data.canceler, data.creator, data.executer, data.from, data.is_active, data.is_priv, data.isproxy, data.issuer, data.level, data.location, data.maximum_supply, data.name, data.newname, data.owner, data.parent, data.payer, data.permission, data.producer, data.producer_key, data.proposal_name, data.proposal_hash, data.proposer, data.proxy, data.public_key, data.producers, data.quant, data.quantity, data.ram_payer, data.receiver, data.requested, data.requirement, data.symbol, data.threshold, data.to, data.transfer, data.voter, data.voter_name, data.weight, data.abi, data.code, data.memo"

原有数据基础上增加data.memo,重新运行dfuseeos 即可

参考

https://github.com/dfuse-io/dfuse-eosio/issues/209

合约推送Action参数为time_point的序列化处理

将时间转换为微妙(uint64)推送,链上会自动转为time_point类型