Invalid cast from type 'string_type' to Object

2019-08-01 17:52:29

查询交易返回

clfsc -u https://beta-api-chain.xxx.com get transaction_id 784886dbbc6cbbbfd2a223e1fc91a7b87231718aa94efdf39ec1e085331d9490
Error 3010006: Invalid transaction
Ensure that your transaction JSON follows the right transaction format!
You can refer to contracts/fsciolib/transaction.hpp for reference
Error Details:
Fail to parse transaction JSON '784886dbbc6cbbbfd2a223e1fc91a7b87231718aa94efdf39ec1e085331d9490'
Invalid cast from type 'string_type' to Object

查看数据

{
"timestamp": "2019-07-31T09:47:28.000",
"producer": "peacock15chy",
"confirmed": 0,
"previous": "006174d7444f5590416508b2cc03991549a9163ef8cf96dab4a5ce00f0f5ebf2",
"transaction_mroot": "d5cf5dc8b315844c92b625c3ff25ffb62766cdc6cb86ff69c64f4d0c927bd3cb",
"action_mroot": "3fbfdf22745803b79bd90022c9308775a1b6296beee81987efce8ef877dac543",
"schedule_version": 1,
"new_producers": null,
"header_extensions": [],
"producer_signature": "SIG_K1_KfnTYbdhByrtGbHrdNStbhYo2MQakmoweyBeQcRMmpXcgdPKB66yGnGAfT1g1rPfK3SVXFXAULU2CexRCoEqxdg6wSYUii",
"transactions": [
{
"status": "executed",
"cpu_usage_us": 419,
"net_usage_words": 0,
"trx": "784886dbbc6cbbbfd2a223e1fc91a7b87231718aa94efdf39ec1e085331d9490"
}
],
"block_extensions": [],
"id": "006174d85cf3afe91baaca598413f4395e412723ed9478eb6e797085dc6ab391",
"block_num": 6386904,
"ref_block_prefix": 1506454043
}

发现trx非object导致,查看本地代码

get_transaction_id_subcommand(CLI::App* actionRoot) {
      auto get_transaction_id = actionRoot->add_subcommand("transaction_id", localized("Get transaction id given transaction object"));
      get_transaction_id->add_option("transaction", trx_to_check, localized("The JSON string or filename defining the transaction which transaction id we want to retrieve"))->required();

      get_transaction_id->set_callback([&] {
         try {
            auto trx_var = json_from_file_or_string(trx_to_check);
            auto trx = trx_var.as<transaction>();
            std::cout << string(trx.id()) << std::endl;
         } EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Fail to parse transaction JSON '${data}'", ("data",trx_to_check))
      });
   }
};

并未做判断,怀疑版本太旧,查看github 最新代码
https://github.com/EOSIO/eos/blob/eb88d033c0abbc481b8a481485ef4218cdaa033a/programs/cleos/main.cpp#L1316

 get_transaction_id->set_callback([&] {
         try {
            fc::variant trx_var = json_from_file_or_string(trx_to_check);
            if( trx_var.is_object() ) {  // 增加了判断
               fc::variant_object& vo = trx_var.get_object();
               // if actions.data & actions.hex_data provided, use the hex_data since only currently support unexploded data
               if( vo.contains("actions") ) {
                  if( vo["actions"].is_array() ) {
                     fc::mutable_variant_object mvo = vo;
                     fc::variants& action_variants = mvo["actions"].get_array();
                     for( auto& action_v : action_variants ) {
                        if( !action_v.is_object() ) {
                           std::cerr << "Empty 'action' in transaction" << endl;
                           return;
                        }
                        fc::variant_object& action_vo = action_v.get_object();
                        if( action_vo.contains( "data" ) && action_vo.contains( "hex_data" ) ) {
                           fc::mutable_variant_object maction_vo = action_vo;
                           maction_vo["data"] = maction_vo["hex_data"];
                           action_vo = maction_vo;
                           vo = mvo;
                        } else if( action_vo.contains( "data" ) ) {
                           if( !action_vo["data"].is_string() ) {
                              std::cerr << "get transaction_id only supports un-exploded 'data' (hex form)" << std::endl;
                              return;
                           }
                        }
                     }
                  } else {
                     std::cerr << "transaction json 'actions' is not an array" << std::endl;
                     return;
                  }
               } else {
                  std::cerr << "transaction json does not include 'actions'" << std::endl;
                  return;
               }
               auto trx = trx_var.as<transaction>();
               transaction_id_type id = trx.id();
               if( id == transaction().id() ) {
                  std::cerr << "file/string does not represent a transaction" << std::endl;
               } else {
                  std::cout << string( id ) << std::endl;
               }
            } else {
               std::cerr << "file/string does not represent a transaction" << std::endl;
            }
         } EOS_RETHROW_EXCEPTIONS(transaction_type_exception, "Fail to parse transaction JSON '${data}'", ("data",trx_to_check))
      });

所以解决方案就是更新对应的代码,或者直接升级版本。

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »