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

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

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

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
 

ethereumjs/merkle-patricia-tree-2-API的更多相关文章

  1. 014-数据结构-树形结构-基数树、Patricia树、默克尔树、梅克尔帕特里夏树( Merkle Patricia Tree, MPT)

    一.基数树 Radix树,即基数树,也称压缩前缀树,是一种提供key-value存储查找的数据结构.与Trie不同的是,它对Trie树进行了空间优化,只有一个子节点的中间节点将被压缩.同样的,Radi ...

  2. Merkle Patricia Tree (MPT) 树详解

    1.    介绍 Merkle Patricia Tree(简称MPT树,实际上是一种trie前缀树)是以太坊中的一种加密认证的数据结构,可以用来存储所有的(key,value)对.以太坊区块的头部包 ...

  3. Merkle Patricia Tree (MPT) 以太坊中的默克尔树

    本篇博文是自己学习mpt的过程,边学边记录,很多原理性内容非自己原创,好的博文将会以链接形式进行共享. 一.什么是mpt MPT是以太坊中的merkle改进树,基于基数树,即前缀树改进而来,大大提高了 ...

  4. 使用 Jackson 树模型(tree model) API 处理 JSON

    http://blog.csdn.net/gao1440156051/article/details/54091702 http://blog.csdn.net/u010003835/article/ ...

  5. Merkle Tree学习

    /*最近在看Ethereum,其中一个重要的概念是Merkle Tree,以前从来没有听说过,所以查了些资料,学习了Merkle Tree的知识,因为接触时间不长,对Merkle Tree的理解也不是 ...

  6. Merkle Tree 概念

    Merkle Tree 概念 来源 https://www.cnblogs.com/fengzhiwu/p/5524324.html /*最近在看Ethereum,其中一个重要的概念是Merkle T ...

  7. Merkle Tree(默克尔树)算法解析

    Merkle Tree概念 Merkle Tree,通常也被称作Hash Tree,顾名思义,就是存储hash值的一棵树.Merkle树的叶子是数据块(例如,文件或者文件的集合)的hash值.非叶节点 ...

  8. 转 Merkle Tree(默克尔树)算法解析

    Merkle Tree概念  Merkle Tree,通常也被称作Hash Tree,顾名思义,就是存储hash值的一棵树.Merkle树的叶子是数据块(例如,文件或者文件的集合)的hash值.非叶节 ...

  9. 区块链~Merkle Tree(默克尔树)算法解析~转载

    转载~Merkle Tree(默克尔树)算法解析 /*最近在看Ethereum,其中一个重要的概念是Merkle Tree,以前从来没有听说过,所以查了些资料,学习了Merkle Tree的知识,因为 ...

  10. ethereumjs/merkle-patricia-tree-1-简介

    https://github.com/ethereumjs/merkle-patricia-tree SYNOPSIS概要 This is an implementation of the modif ...

随机推荐

  1. 线程不安全的类不要轻易做为static变量使用,及如何使用ThreadLocal将共享变量变为独享变量

    参考原文:<关于SimpleDateFormat安全的时间格式化线程安全问题>

  2. SLF4+Logback 使用及配置

    在SpringBoot项目中使用slf4+logback ①在pom.xml中添加依赖 <dependency> <groupId>ch.qos.logback</gro ...

  3. nginx+uwsgi部署flask应用后只能在本机访问解决办法,ipv4 和ipv6

    我的系统是centos7 nginx监听8888端口 在window下  :telnet 192.168.81.224 8888  发现连接不上, 端口22能连上 关闭224的防火墙就好了 syste ...

  4. js中获取css样式的两种方式

    1. 对象.style.样式名  弊端就是只能获取行内样式 2.window.getComputedStyle(对象,null); 最好用第二种方式 <!DOCTYPE html> < ...

  5. Html5 锚 <a>的页内跳转, name=abc herf=#abc

    锚点是网页制作中超级链接的一种,又叫命名锚记.命名锚记像一个迅速定位器一样是一种页面内的超级链接,运用相当普遍. 英文名:anchor 使用命名锚记可以在文档中设置标记,这些标记通常放在文档的特定主题 ...

  6. Angular js部分关键字的理解

    模板:动态模板,是动态的,直接去处理DOM的,而不是通过处理字符串模版(静态模板) mvc:核心思想实现"数据管理-数据模型Model.应用逻辑-控制器Controller.数据表现-视图V ...

  7. BubblePopupWindow

    Android 实现各个方向的气泡弹窗,可控制气泡尖角偏移量. https://github.com/smuyyh/BubblePopupWindow 截图 使用: BubblePopupWindow ...

  8. Android知识点滴

    今天,把新作的布局状态魅族机上进行测试 发现了一个BUG,造成闪退. 看了下log,一个布局造成的. 开始分析这个布局造成这个问题的原因. 开始艰难的调试过程. 代码注释大法,发现这个问题是一个tex ...

  9. .net core系列之《sdk和runtime区别及使用CLI在Ubuntu上快速搭建Console,WebApi,MVC三大应用模型》

    一.需要安装的软件 1.虚拟机安装Ubuntu系统(本人用的是vmware-14.1.12和buntu-18.04) 2.Xshell或 Putty(连接ssh服务) 3.FileZilla(ftp上 ...

  10. SQL一次性查询一个字段不同条件下的统计结果

    参考了一下这篇文章:https://blog.csdn.net/xichenguan/article/details/51764100 , 感谢原作者 有两个表,分别存放了[操作员]和[单据],要根据 ...