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

去中心化化终结账户权限

http://eosio-lock.net/
https://github.com/bloxchanger/ACCOUNT-LOCK

代码比较简单,就是将账户的权限移交给合约账户,并在指定的到期时间会恢复公钥。

发散思维

  1. 可以作为账户的二级账户密码,一个账户2套权限私钥,要是第一套丢了,用第二套找回。
  2. 固定期限分配代币,有些项目会指定到某个时间,给项目投资方分对应的币,投资方可以先创建好账号,设定好权限赎回时间,并把权限锁定到锁定合约,然后项目方可以把对应的币打倒对应的账户即可。到期后投资方自己赎回账户权限。

EOS contract uint128 convert to std::string

static const char* charmap = "0123456789";

std::string uint128ToString(const uint128_t& value)
{
    std::string result;
    result.reserve( 40 ); // max. 40 digits possible ( uint64_t has 20) 
    uint128_t helper = value;

    do {
        result += charmap[ helper % 10 ];
        helper /= 10;
    } while ( helper );
    std::reverse( result.begin(), result.end() );
    return result;
}

https://eosio.stackexchange.com/questions/2927/how-can-i-convert-a-uint128-t-to-a-string

一笔交易的资源开销,可以由智能合约创建者来支付

最近项目上线,数据一致性等问题已处理完,准备做使用资源上的一些优化,
考虑到普通账户CPU和net的资源有限,需要考虑下由合约方出这部分资源,减少用户反复抵押相应资源,以及了解资源相关的学习成本。
按照思路,应该是执行合约相关的动作,用户和合约账户一同多签,并指定资源消耗方为合约账户。

记得之前已经看过相关的EOSIO技术规划,有提到相关,那根下代码把
https://github.com/EOSIO/eos/blob/1418543149b7caf8fc69a23621e3db7f3c6d18ad/libraries/chain/transaction_context.cpp#L230

// Record accounts to be billed for network and CPU usage
      if( control.is_builtin_activated(builtin_protocol_feature_t::only_bill_first_authorizer) ) {
         bill_to_accounts.insert( trx.first_authorizer() );
      } else {
         for( const auto& act : trx.actions ) {
            for( const auto& auth : act.authorization ) {
               bill_to_accounts.insert( auth.actor );
            }
         }
      }

此时“侧链”代码为 V1.6.6, 预计等1.8.x稳定后,会升级到新共识协议,所以为了最小的差异,先做最小的修改支持吧。

为了简单的先实现,所以改下代码(本想放到config.ini,但是代码嵌套层较深,并且这种协议上的不会在做更新,直接放到代码里吧)
libraries\chain\include\eosio\chain\config.hpp
中增加一字段

const static bool       support_only_bill_first_authorizer           = true; // support only bill first authorizer

修改源代码为

// Record accounts to be billed for network and CPU usage
      if( config::support_only_bill_first_authorizer ) {
         bill_to_accounts.insert( trx.first_authorizer() );
      } else {
         for( const auto& act : trx.actions ) {
            for( const auto& auth : act.authorization ) {
               bill_to_accounts.insert( auth.actor );
            }
         }
      }

方案的实现建立在,客户端签名后,将数据发给后端,重新签名,并将项目方的验证授权放到第一个,这样执行的资源消耗就都算在项目方的账号上了。

更新各个节点,先支持,等待1.8.x稳定,在做共识性质的更新。

参考

https://github.com/EOSIO/spec-repo/blob/master/esr_contract_trx_auth.md
https://github.com/EOSIO/eos/issues/6332
https://github.com/EOSIO/eos/pull/7089
https://bihu.com/article/1522267629

test_cypher_suites ubuntu 18.04 build failure due to lack of pthread linkage {pthread_atfork}

一个老问题,编译时出现以下错误

[ 91%] �[32mBuilding CXX object libraries/chain/CMakeFiles/eosio_chain.dir/chain_id_type.cpp.o�[0m

/usr/lib/x86_64-linux-gnu/libcrypto.a(threads_pthread.o): In function `fork_once_func':

(.text+0x16): undefined reference to `pthread_atfork'

clang: [0;1;31merror: [0mlinker command failed with exit code 1 (use -v to see invocation) [0m

libraries/fc/test/crypto/CMakeFiles/test_cypher_suites.dir/build.make:113: recipe for target 'libraries/fc/test/crypto/test_cypher_suites' failed

make[2]: *** [libraries/fc/test/crypto/test_cypher_suites] Error 1

CMakeFiles/Makefile2:783: recipe for target 'libraries/fc/test/crypto/CMakeFiles/test_cypher_suites.dir/all' failed

make[1]: *** [libraries/fc/test/crypto/CMakeFiles/test_cypher_suites.dir/all] Error 2

解决方案

~/eos1.6/eos/libraries/fc$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8056cf0..efb09db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -157,7 +157,7 @@ IF(APPLE)
   find_library(security_framework Security)
   find_library(corefoundation_framework CoreFoundation)
 ENDIF()
-target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} ${security_framework} ${corefoundation_framework} )
+target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} ${security_framework} ${corefoundation_framework} pthread )


 SET(OPENSSL_CONF_TARGET )

参考

https://github.com/EOSIO/eos/issues/7490