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

ethereumjs/merkle-patricia-tree-2-API

SecureTrie

src/secure.js:10-15

Extends Trie 扩展前缀树

You can create a secure Trie where the keys are automatically hashed using SHA3 by using require('merkle-patricia-tree/secure'). It has the same methods and constructor as Trie.

你可以通过使用require('merkle-patricia-tree/secure')创建一个keys会自动使用SHA3进行hash的安全前缀树。它有着与Trie相同的方法和构造函数

 

 

Trie

src/baseTrie.js:27-55

Use require('merkel-patricia-tree') for the base interface. In Ethereum applications stick with the Secure Trie Overlay require('merkel-patricia-tree/secure'). The API for the raw and the secure interface are about the same

使用require('merkel-patricia-tree')获取基本接口。在Ethereum应用程序坚持使用安全的Trie,即require('merkel-patricia-tree/secure')。对于原始的和安全的Trie的接口的API是相同的。

Parameters参数

  • db Object? An instance of levelup or a compatible API. If the db is null or left undefined, then the trie will be stored in memory via memdown   levelup实例或一个兼容API。如果db为null或undefined,那么trie将通过memdown存储到内存中
  • root (Buffer | String)? A hex String or Buffer for the root of a previously stored trie  以前存储的trie的根,为一个十六进制字符串或buffer

Properties属性

  • root Buffer The current root of the trie 当前trie的根
  • isCheckpoint Boolean determines if you are saving to a checkpoint or directly to the db 决定是保存到检查点还是直接保存到数据库
  • EMPTY_TRIE_ROOT Buffer the Root for an empty trie 空trie的根

 

 

get

src/baseTrie.js:64-77

Gets a value given a key

得到给定key的value

Parameters参数

  • key (Buffer | String) the key to search for 搜索的key
  • cb Function A callback Function which is given the arguments err - for errors that may have occured and value- the found value in a Buffer or if no value was found null 有给定参数err-可能发生的错误和value-在Buffer中发现的value,如果没有则为null的回调函数

 

 

put

src/baseTrie.js:87-113

Stores a given value at the given key

在给定的key上存储给定的value

Parameters参数

  • key (Buffer | String)
  • Value (Buffer | String)
  • cb Function A callback Function which is given the argument err - for errors that may have occured  有定参数err-可能发生的错误的回调函数

 

 

del

src/baseTrie.js:122-140

deletes a value given a key

删除给定key的value

Parameters

  • key (Buffer | String)
  • callback Function the callback Function 回调函数

 

 

getRaw

src/baseTrie.js:149-165

Retrieves a raw value in the underlying db

检索底层数据库中的原始value

Parameters

  • key Buffer
  • callback Function A callback Function, which is given the arguments err - for errors that may have occured and value - the found value in a Buffer or if no value was found null.有给定参数err-可能发生的错误和value-在Buffer中发现的value,如果没有则为null的回调函数

 

 

putRaw

src/baseTrie.js:205-205

Writes a value directly to the underlining db

直接将value写入底层数据库

Parameters

  • key (Buffer | String) The key as a Buffer or String Buffer或String类型的key
  • value Buffer The value to be stored 存储的value
  • callback Function A callback Function, which is given the argument err - for errors that may have occured 定参数err-可能发生的错误的回调函数

 

delRaw

src/baseTrie.js:214-221

Removes a raw value in the underlying db

移除在底层数据库中的原始数据

Parameters

  • key (Buffer | String)
  • callback Function A callback Function, which is given the argument err - for errors that may have occured定参数err-可能发生的错误的回调函数

 

 

findPath

src/baseTrie.js:256-304

Trys to find a path to the node for the given key It returns a stack of nodes to the closet node

根据给定key尝试找到node的path。其返回到最近节点node的nodes的堆栈

Parameters参数

  • null-null (String | Buffer) key - the search key  搜索key
  • null-null Function cb - the callback function. Its is given the following arguments回调函数,给定以下参数
    • err - any errors  encontered  遇见的错误
    • node - the last node found  最后找到的节点node
    • keyRemainder - the remaining key nibbles not accounted for   剩余的没有找到半个字节的key
    • stack - an array of nodes that forms the path to node we are searching for  一个节点数组,它构成我们正在搜索的节点的路径

 

createReadStream

src/baseTrie.js:723-725

The data event is given an Object hat has two properties; the key and the value. Both should be Buffers.

data事件给了带有两个属性的对象:keyvalue,都为Buffer类型

Returns stream.Readable Returns a stream of the contents of the trie

返回类型是stream.Readable ,返回trie内容的流

 

 

batch

src/baseTrie.js:749-761

The given hash of operations (key additions or deletions) are executed on the DB

给定的要执行在数据库上的操作(key添加或删除)的hash

Parameters

  • ops Array 操作的数组
  • cb Function

Examples

var ops = [
   { type: 'del', key: 'father' }
 , { type: 'put', key: 'name', value: 'Yuri Irsenovich Kim' }
 , { type: 'put', key: 'dob', value: '16 February 1941' }
 , { type: 'put', key: 'spouse', value: 'Kim Young-sook' }
 , { type: 'put', key: 'occupation', value: 'Clown' }
]
trie.batch(ops)

 

 

checkRoot

src/baseTrie.js:770-775

Checks if a given root exists

检查给定的root是否存在

Parameters

  • root Buffer
  • cb Function

 

Merkle Proof  Merkle证明

Static functions for creating/verifying a merkle proof.

创建/验证Merkle证明的静态函数

prove

src/proof.js:12-29

Returns a merkle proof for a given key

根据给定key返回merkle证明

Parameters

  • trie Trie
  • key String
  • cb Function A callback Function (arguments {Error} err, {Array.} proof) 回调函数fun(err,proof)

 

 

verifyProof

src/proof.js:39-100

Verifies a merkle proof for a given key

根据给定key验证merkle证明

Parameters

  • rootHash Buffer
  • key String
  • proof Array<TrieNode>
  • cb Function A callback Function (arguments {Error} err, {String} val回调函数fun(err,val)

 

Internal Util Functions 内部Util函数

These are not exposed.这些函数是不暴露给外部用户的

addHexPrefix

src/trieNode.js:164-179

Parameters

  • key
  • terminator
  • dataArr Array

Returns Buffer returns buffer of encoded data hexPrefix *

返回类型为Buffer,返回添加了十六进制前缀的编码数据的buffer

 

 

asyncFirstSeries

src/util.js:63-79

Take a collection of async fns, call the cb on the first to return a truthy value. If all run without a truthy result, return undefined

异步函数的收集,调用第一个参数上的回调返回可信value。如果所有运行没有可信结果,返回undefined

Parameters

  • array
  • iterator
  • cb

 

callTogether

src/util.js:37-57

Take two or more functions and returns a function that will execute all of the given functions

调用两个或更多函数,然后返回一个执行所有给定函数的函数

 

doKeysMatch

src/util.js:28-31

Compare two 'nibble array' keys

比较两个半字节数组keys

Parameters

  • keyA
  • keyB
 

 

 

 

 

转载于:https://www.cnblogs.com/wanghui-garcia/p/10098474.html

相关文章:

  • 腾讯音乐赴美IPO仅11亿美元,疑受科技股抛售和中美贸易战影响
  • 【quick-cocos2d-lua】 基本类及用法
  • mysql安装时无法启动服务解决方案
  • Linux初级运维(十五)——bash脚本编程之函数
  • Hystrix断路器在微服务网关中的应用
  • 怎么把工作型PPT制作的好看又专业?
  • git切换分支
  • 数据加密:RSA 加解密
  • react 前端项目技术选型、开发工具、周边生态
  • Keras笔记
  • JQ和Js获取span标签的内容
  • yaml 配置文件
  • 前端之JQuery:JQuery属性操作
  • canvas 绘制双线技巧
  • 软件工程期末考试复习
  • 【vuex入门系列02】mutation接收单个参数和多个参数
  • docker-consul
  • iOS帅气加载动画、通知视图、红包助手、引导页、导航栏、朋友圈、小游戏等效果源码...
  • Java 9 被无情抛弃,Java 8 直接升级到 Java 10!!
  • js操作时间(持续更新)
  • LintCode 31. partitionArray 数组划分
  • PHP的类修饰符与访问修饰符
  • 翻译 | 老司机带你秒懂内存管理 - 第一部(共三部)
  • 关于extract.autodesk.io的一些说明
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 使用parted解决大于2T的磁盘分区
  • ![CDATA[ ]] 是什么东东
  • ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTr
  • #Java第九次作业--输入输出流和文件操作
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (4) openssl rsa/pkey(查看私钥、从私钥中提取公钥、查看公钥)
  • (42)STM32——LCD显示屏实验笔记
  • (7)STL算法之交换赋值
  • (day6) 319. 灯泡开关
  • (Matlab)遗传算法优化的BP神经网络实现回归预测
  • (WSI分类)WSI分类文献小综述 2024
  • (汇总)os模块以及shutil模块对文件的操作
  • (三)centos7案例实战—vmware虚拟机硬盘挂载与卸载
  • (三十五)大数据实战——Superset可视化平台搭建
  • (四)Controller接口控制器详解(三)
  • (一) springboot详细介绍
  • (原創) 如何使用ISO C++讀寫BMP圖檔? (C/C++) (Image Processing)
  • (转)程序员技术练级攻略
  • .gitignore文件—git忽略文件
  • .mysql secret在哪_MYSQL基本操作(上)
  • .NET Core MongoDB数据仓储和工作单元模式封装
  • .net core 调用c dll_用C++生成一个简单的DLL文件VS2008
  • .NET Framework 服务实现监控可观测性最佳实践
  • .NET开源全面方便的第三方登录组件集合 - MrHuo.OAuth
  • .net之微信企业号开发(一) 所使用的环境与工具以及准备工作
  • .考试倒计时43天!来提分啦!
  • @param注解什么意思_9000字,通俗易懂的讲解下Java注解
  • @RequestMapping处理请求异常
  • [ 数据结构 - C++] AVL树原理及实现
  • [2019.2.28]BZOJ4033 [HAOI2015]树上染色