当前位置: 首页 > news >正文

网站网站模版网站备案后怎么做

网站网站模版,网站备案后怎么做,开发一个超市app需要多少钱,佛山市门户网站建设公司本文档从区块哈希基本概念出发#xff0c;详细介绍了中移链的区块哈希交易接口和应用方向。适用于EOS区块链智能合约高级开发人员#xff0c;熟悉如何获取当前发生交易所在的区块号和区块哈希前缀#xff0c;并通过Tapos机制验证交易的有效性。 01 概述 #xff08;一详细介绍了中移链的区块哈希交易接口和应用方向。适用于EOS区块链智能合约高级开发人员熟悉如何获取当前发生交易所在的区块号和区块哈希前缀并通过Tapos机制验证交易的有效性。 01 概述 一哈希算法 哈希算法是可以将任意长度的二进制数据映射为固定长度二进制数据哈希值的一种算法。在这个过程中哈希函数将输入数据通过一系列的复杂运算变换成固定长度的输出这个值等同于存放数据的地址这个地址里面再将输入的数据进行存储所以哈希函数可以将互联网上的数据以固定长度字符串的形式来保存。同时哈希函数可以用于密码学、数据完整性验证、信息指纹等领域常见的哈希算法有MD5、SHA-1、SHA-256等。 二区块哈希 区块哈希是通过哈希算法对区块中的所有数据进行计算得出的固定长度的字符串。具体来说区块哈希是指在区块链技术中对于每一个新生产的区块会给这个区块计算一个固定长度的哈希值这个哈希值包含了这个区块中所有的数据包括交易记录、上一个区块的哈希值、时间戳等并且只要这些数据有任何一点改变那么这个区块的哈希值就会发生变化所以它在保证网络安全性、防止篡改和验证数据完整性方面起着非常重要的作用。 三区块哈希的特点 区块哈希的存在保证了区块链的数据安全性任何篡改数据的行为都会被立即发现同时它也具备以下特点 唯一性每个区块哈希值都是唯一的即使是区块链上有极其微小的一点数据改变也会导致哈希值的变化。这保证了数据的不可变性和唯一标识性。 不可逆性区块哈希函数是一个单向函数可以将任意长度的数据转换为固定长度的哈希值。对于哈希值无法进行反向计算推导恢复原始数据这保证了数据的安全性。 不可篡改性如果输入数据发生了任何改变计算得到的哈希值都会发生变化。 02 环境依赖 eosio_2.1.0-1 eosio.cdt v1.8.x 03 区块哈希接口 与区块哈希相关的交易接口分别有tapos_block_num()和tapos_block_prefix()它们用于生成区块哈希及验证交易执行的前提条件这有助于确保交易的有效性和安全性并提供区块链的相关信息以支持智能合约的开发。 一tapos_block_num() 它是一个用于获取当前交易所引用的区块号的函数它返回一个无符号整数值代表当前执行交易的区块高度。块高度表示当前执行的块在整个区块链上的位置可以用于构建块摘要和验证交易。在交易处理过程中每个块都有一个唯一的块高度。 源码描述 /*** Gets the block number used for TAPOS on the currently executing transaction.** ingroup transaction* return block number used for TAPOS on the currently executing transaction* Example:* code* int tbn tapos_block_num();* endcode*/inline int tapos_block_num() {return internal_use_do_not_use::tapos_block_num();} 调用方式 #include eosio/transaction.hpp #include eosio/eosio.hpp uint16_t current_block_num tapos_block_num(); // 获取用于当前执行交易所在的区块号 二tapos_block_prefix() 它是一个用于获取当前交易所在区块哈希前缀的函数它返回一个无符号整数值代表当前执行交易的区块哈希前缀。区块哈希前缀是区块哈希的一部分用于构建block summary。它通常作为一个随机数用于增加区块哈希的难度以保持加密的安全性。 源码描述 /*** Gets the block prefix used for TAPOS on the currently executing transaction.** ingroup transaction* return block prefix used for TAPOS on the currently executing transaction* Example:* code* int tbp tapos_block_prefix();* endcode*/inline int tapos_block_prefix() {return internal_use_do_not_use::tapos_block_prefix();} 调用方式 #include eosio/transaction.hpp #include eosio/eosio.hpp uint32_t current_block_prefix tapos_block_prefix(); // 获取用于当前执行交易所在的区块哈希前缀 三什么是TaPos机制 TaPos是“交易作为权益证明”Transaction-as-Proof-of-Stake的缩写。TaPos是在EOS的交易处理过程中引入的一个概念它是一种用于实现去中心化共识的机制目的是确保交易执行的前提条件和验证交易的有效性。在去中心化的区块链网络中由于网络可能存在延迟和分叉交易的确认和执行顺序可能会有所不同所以引入TaPos机制来防止在不包含引用区块的分叉上重放交易从而增加了安全性和可靠性。下面我们来看一下EOS白皮书是如何对TaPos进行描述的。 Transaction as Proof of Stake (TaPoS) The EOS.IO software requires every transaction to include part of the hash of a recent block header. This hash serves two purposes: 1. prevents a replay of a transaction on forks that do not include the referenced block. //防止在不包含引用区块的分叉上重放交易。 2. signals the network that a particular user and their stake are on a specific fork. //向网络发出信号表明特定用户及其权益位于哪条特定分叉上。 Over time all users end up directly confirming the blockchain which makes it difficult to forge counterfeit chains as the counterfeit would not be able to migrate transactions from the legitimate chain. 四如何通过TaPos验证交易 通过TaPoS机制EOS网络可以确保交易的顺序性并防止在不同块之间重放交易所以每个交易都必须包含正确的TaPoS字段即交易作为股权证明的一部分在交易签名过程中这些字段会与其他的交易信息一起打包进入交易以便验证它们的有效性。为了让链更稳固也让用户交易更安全当链中每发生一笔交易时都会验证两个字段分别是ref_block_num和ref_block_prefix以下是eosio.cdt中对它们的声明。 // eosio.cdt/1.8.1/include/eosiolib/contracts/eosio/transaction.hpp class transaction_header {public:/*** Construct a new transaction_header with an expiration of now 60 seconds.** brief Construct a new transaction_header object initialising the transaction header expiration to now 60 seconds*/transaction_header( time_point_sec exp time_point_sec(current_time_point()) 60):expiration(exp){}time_point_sec expiration;/// the time at which a transaction expiresuint16_t ref_block_num; /// specifies a block num in the last 2^16 blocksuint32_t ref_block_prefix; /// specifies the lower 32 bits of the block id at get_ref_blocknumunsigned_int max_net_usage_words 0UL; /// number of 8 byte words this transaction can serialize into after compressionsuint8_t max_cpu_usage_ms 0UL; /// number of CPU usage units to bill transaction forunsigned_int delay_sec 0UL; /// number of seconds to delay transaction, default: 0EOSLIB_SERIALIZE( transaction_header, (expiration)(ref_block_num)(ref_block_prefix)(max_net_usage_words)(max_cpu_usage_ms)(delay_sec) )}; 以下代码是在交易初始化时候验证ref_block_num和ref_block_prefix两个字段。 // eos/libraries/chain/transaction.cpp void transaction_header::set_reference_block( const block_id_type reference_block ) {ref_block_num fc::endian_reverse_u32(reference_block._hash[0]);ref_block_prefix reference_block._hash[1]; }bool transaction_header::verify_reference_block( const block_id_type reference_block )const {return ref_block_num (decltype(ref_block_num))fc::endian_reverse_u32(reference_block._hash[0]) ref_block_prefix (decltype(ref_block_prefix))reference_block._hash[1]; } // eos/libraries/chain/transaction_context.cpp void transaction_context::init_for_input_trx_common( uint64_t initial_net_usage, bool skip_recording ){published control.pending_block_time();is_input true;const transaction trx packed_trx.get_transaction();if (!control.skip_trx_checks()) {control.validate_expiration(trx);control.validate_tapos(trx);validate_referenced_accounts( trx, enforce_whiteblacklist control.is_producing_block() );}init( initial_net_usage );if (!skip_recording)record_transaction( packed_trx.id(), trx.expiration ); /// checks for dupes} // eos/libraries/chain/controller.cpp void controller::validate_tapos( const transaction trx )const { try {const auto tapos_block_summary db().getblock_summary_object((uint16_t)trx.ref_block_num);//Verify TaPoS block summary has correct ID prefix, and that this blocks time is not past the expirationEOS_ASSERT(trx.verify_reference_block(tapos_block_summary.block_id), invalid_ref_block_exception,Transactions reference block did not match. Is this transaction from a different fork?,(tapos_summary, tapos_block_summary)); } FC_CAPTURE_AND_RETHROW() } 五测试用例 编写智能合约测试用例通过调用上文中介绍的tapos_block_num()和tapos_block_prefix()两个函数来获取验证交易有效性的两个字段ref_block_num和ref_block_prefix。 #include eosio/transaction.hpp #include eosio/eosio.hppusing namespace eosio;class [[eosio::contract(test)]] test: public contract { public:using contract::contract;[[eosio::action]]void checktapos() {uint32_t current_block_num tapos_block_num(); // 获取当前交易执行所在的区块号uint32_t current_block_prefix tapos_block_prefix(); // 获取当前交易执行所在的区块哈希前缀print(ref_block_num: , current_block_num,\t\t\t);print(ref_block_prefix: , current_block_prefix);} }; 返回结果如下 executed transaction: b35a59a178af7dedbbad641952146470adbe5e4d48316382afec5941fcdf2372 96 bytes 146 us # test test::checktapos ref_block_num: 43983 ref_block_prefix: 448306994 以下是对应区块结构transaction中的ref_block_num和ref_block_prefix。 rootVM-24-16-ubuntu:/home/ubuntu/biosboot/genesis# cleos get transaction b35a59a178af7dedbbad641952146470adbe5e4d48316382afec5941fcdf2372 {id: b35a59a178af7dedbbad641952146470adbe5e4d48316382afec5941fcdf2372,trx: {receipt: {status: executed,cpu_usage_us: 146,net_usage_words: 12,trx: [1,{compression: none,prunable_data: {prunable_data: [0,{signatures: [SIG_K1_Jzmoz3cfi8H7tA3V8zidyihS7XYv29h1bnxdoFSM7ddvRXRo7q4GTJrgPKDsvbbXMFsaFxzCZeAqwwhG2GNVdjHXiL41y1],packed_context_free_data: }]},packed_trx: 6b6eae64cfab329fb81a0000000001000000000090b1ca0000a6d56488544301000000000090b1ca00000000a8ed32320000}]},trx: {expiration: 2023-07-12T09:12:11,ref_block_num: 43983,ref_block_prefix: 448306994,max_net_usage_words: 0,max_cpu_usage_ms: 0,delay_sec: 0,context_free_actions: [],actions: [{account: test,name: checktapos,authorization: [{actor: test,permission: active}],data: }],signatures: [SIG_K1_Jzmoz3cfi8H7tA3V8zidyihS7XYv29h1bnxdoFSM7ddvRXRo7q4GTJrgPKDsvbbXMFsaFxzCZeAqwwhG2GNVdjHXiL41y1],context_free_data: []}},block_time: 2023-07-12T09:11:41.500,block_num: 43985,last_irreversible_block: 44144,traces: [{action_ordinal: 1,creator_action_ordinal: 0,closest_unnotified_ancestor_action_ordinal: 0,receipt: {receiver: test,act_digest: f0d16f853ef72e7be5d8c84219cdcaa75d9b13d89b59c9385aebaecc20bc34f7,global_sequence: 43996,recv_sequence: 8,auth_sequence: [[test,11]],code_sequence: 2,abi_sequence: 1},receiver: test,act: {account: test,name: checktapos,authorization: [{actor: test,permission: active}],data: },context_free: false,elapsed: 39,console: ref_block_num: 43983 ref_block_prefix: 448306994,trx_id: b35a59a178af7dedbbad641952146470adbe5e4d48316382afec5941fcdf2372,block_num: 43985,block_time: 2023-07-12T09:11:41.500,producer_block_id: null,account_ram_deltas: [],account_disk_deltas: [],except: null,error_code: null,return_value_hex_data: }] } 需要注意ref_block_num表示的是交易所引用的区块的区块号码而ref_block_prefix是这个区块的哈希前缀。在交易签名过程中这些字段会与其他的交易信息一起打包进入交易中以便验证这个交易是否合法。而在cleos get transaction命令所显示的交易信息中另一个名为block_num的字段则表示最终执行该交易的区块的区块号码此字段与交易提交时所引用的区块号码ref_block_num是不同的。因为在提交交易时可能会发生交易被延迟所以最终执行该交易的区块可能与该交易所引用的区块不同。 END
http://www.pierceye.com/news/780400/

相关文章:

  • 国外的包装设计网站三明网站设计
  • 网站源码怎样弄成网站工商登记网站
  • 2016做砸了的小网站一键创建网站
  • 怎么制作网站域名六安网站制作人才招聘
  • 网站建设 启象科技上海公司排名100强
  • 户外旅游网站排名深圳seo专家
  • 娄底建设网站的公司深圳人才招聘网
  • 网站建设和制作网站名称设置
  • 温州外贸网站深圳工程建设交易服务中心网站
  • 网站导航网址大全网页设计模板代码免费
  • 卖机械设备什么网站做推广好做机械有什么兼职网站
  • 全屋定制十大公认品牌有哪些seo页面链接优化
  • 电子商务网站建设基础考试十大营销手段
  • 关于做服饰网站的首页WordPress纯代码添加
  • 网站qq交谈怎么做的公司注册50万和100万
  • 网站推广的电子邮件推广使用ftp修改网站图片
  • 建设宣传家乡的网站跨境电商怎么注册
  • 广州天河区网站建设公司wordpress调用文章描述
  • 网站开发项目策划书制作书签怎么做
  • 做网站组织结构框架例子整站seo优化哪家好
  • 网站内存不足哈尔滨网站优化页面
  • 响应式网站 图片尺寸奇数南宁网站建设业务员
  • 咸宁 网站建设wordpress聚合广告平台
  • 家具展示型网站个人可以做几个网站
  • 建设网站商城需要多少费用注册网页代码
  • 徐州企业网站制作南宁网站建设专家
  • 雨发建设集团有限公司网站wordpress related posts
  • 成品网站速成网站大连专业app开发设计
  • 十堰门户网站建设中小企业网站制作407
  • 房产网站排行部署自己做的网站吗