ethereumjs/ethereumjs-blockchain-1-简介和API
https://github.com/ethereumjs/ethereumjs-blockchain
SYNOPSIS概要
A module to store and interact with blocks 存储区块和与区块进行交互的模块
INSTALL安装
npm install ethereumjs-blockchain
EXAMPLE
The following is an example to iterate through an existing Geth DB (needs level to be installed separately):
const level = require('level')
const Blockchain = require('ethereumjs-blockchain')
const utils = require('ethereumjs-util')
const gethDbPath = './chaindata' // Add your own path here
const db = level(gethDbPath)
new Blockchain({db: db}).iterator('i', (block, reorg, cb) => {
const blockNumber = utils.bufferToInt(block.header.number)
const blockHash = block.hash().toString('hex')
console.log(`BLOCK ${blockNumber}: ${blockHash}`)
cb()
}, (err) => console.log(err || 'Done.'))
WARNING: Since ethereumjs-blockchain is also doing write operations on the DB for safety reasons only run this on a copy of your database, otherwise this might lead to a compromised DB state.
警告:当 ethereumjs-blockchain也在数据库进行写操作时,为了安全性,只在数据库的副本上运行,否则将会导致数据状态破坏
API
Blockchain
Implements functions for retrieving, manipulating and storing Ethereum's blockchain
实现检索函数,操作并存储以太坊区块链
new Blockchain(opts)
Creates new Blockchain object
创建新的区块链对象
opts.db- Database to store blocks and metadata. Should be a levelup instance. 存储区块和元数据的数据库 ,应该是levelup实例opts.validate- this the flag to validate blocks (e.g. Proof-of-Work), latest HF rules supported:Constantinople. 验证区块标记(比如工作量证明),最新硬分叉规则支持的是Constantinople
[DEPRECATION NOTE] The old separated DB constructor parameters opts.blockDB and opts.detailsDB from before the Geth DB-compatible v3.0.0 release are deprecated and continued usage is discouraged. When provided opts.blockDB will be used as opts.db and opts.detailsDB is ignored. On the storage level the DB formats are not compatible and it is not possible to load an old-format DB state into a post-v3.0.0 Blockchain object.
弃用声明:来自Geth的兼容数据库的v3.0.0发布版本之前的旧的单独数据库构造函数参数opts.blockDB和opts.detailsDB已经被弃用,不鼓励继续使用它。
当提供opts.blockDB时将将其作为opts.db的值,提供的opts.detailsDB将被忽略。数据库格式在存储级别上没有被兼容,所以下载一个旧格式数据状态到发布的v3.0.0版本的区块链对象中是不可能做到的。
BlockChain methods
blockchain.putGenesis(genesis, cb)
Puts the genesis block in the database.
将初始区块放到数据库中
genesis- the genesis block to be added 添加的初始区块cb- the callback. It is given two parameterserrand the savedblock 回调函数。给定两个参数err和存储的区块
blockchain.getHead(name, cb)
Returns the specified iterator head.
返回指定迭代区块头
name- Optional name of the state root head (default: 'vm') 状态根头的可选名字cb- the callback. It is given two parameterserrand the returnedblock回调函数。给定两个参数err和返回的区块
blockchain.getLatestHeader(cb)
Returns the latest header in the canonical chain.
返回最新的区块头
cb- the callback. It is given two parameterserrand the returnedheader区块头回调函数。给定两个参数err和
blockchain.getLatestBlock(cb)
Returns the latest full block in the canonical chain.
返回规范链上最新的整个区块
cb- the callback. It is given two parameterserrand the returnedblock返回区块回调函数。给定两个参数err和
blockchain.putBlocks(blocks, cb)
Adds many blocks to the blockchain.
添加多个区块到区块链上
blocks- the blocks to be added to the blockchain 被添加到区块链上的区块cb- the callback. It is given two parameterserrand the last of the savedblocks回调函数。给定两个参数err和最后被添加的区块
blockchain.putBlock(block, cb)
Adds a block to the blockchain.
添加一个区块到区块链中
block- the block to be added to the blockchain 被添加到区块链上的区块cb- the callback. It is given two parameterserrand the savedblock存储的区块回调函数。给定两个参数err和
blockchain.getBlock(blockTag, cb)
Gets a block by its blockTag.
通过区块标签得到区块
blockTag- the block's hash or number区块的hash值或号数cb- the callback. It is given two parameterserrand the foundblock(an instance of https://github.com/ethereumjs/ethereumjs-block) if any.回调函数。给定两个参数err和如果有则返回的区块
blockchain.getBlocks(blockId, maxBlocks, skip, reverse, cb)
Looks up many blocks relative to blockId.
找到许多相关区块Id的区块
blockId- the block's hash or number 区块的hash值或号数maxBlocks- max number of blocks to return 返回的区块的最大号数skip- number of blocks to skip 跳过区块的号数(即不想要的)reverse- fetch blocks in reverse 反向取数据块cb- the callback. It is given two parameterserrand the foundblocksif any.如果有才返回的区块回调函数。给定两个参数err和
blockchain.putHeaders(headers, cb)
Adds many headers to the blockchain.
添加多个区块头到区块链上
headers- the headers to be added to the blockchain 要添加到区块链上的区块头cb- the callback. It is given two parameterserrand the last of the savedheaders最后存储的区块头回调函数。给定两个参数err和
blockchain.putHeader(header, cb)
Adds a header to the blockchain.
添加一个区块头到区块链中
header- the header to be added to the blockchain 要添加到区块链上的区块头cb- the callback. It is given two parameterserrand the savedheader回调函数。给定两个参数err和存储的区块头
blockchain.getDetails(hash, cb)
[DEPRECATED] Returns an empty object 弃用的函数,返回空对象
blockchain.selectNeededHashes(hashes, cb)
Given an ordered array, returns to the callback an array of hashes that are not in the blockchain yet.
给定排序数组,返回给回调函数一个还没有在区块链中的hash数组
hashes- Ordered array of hashes 排序hash数组cb- the callback. It is given two parameterserrand hashes found.找到的hash数组回调函数。给定两个参数err和
blockchain.delBlock(blockHash, cb)
Deletes a block from the blockchain. All child blocks in the chain are deleted and any encountered heads are set to the parent block从区块链中删除区块。所有在链上的该指定区及其子区块都被删除,并将任何遇见的区块的头设置为父区块
blockHash- the hash of the block to be deleted 要被删除的区块cb- A callback. 回调函数
blockchain.iterator(name, onBlock, cb)
Iterates through blocks starting at the specified verified state root head and calls the onBlock function on each block
通过区块从指定的核查状态根头开始迭代,然后在每个区块上调用onBlock函数
name- name of the state root head 状态根头的名字onBlock- function called on each block with params (block, reorg, cb) 在每个区块上调用的带有参数(block, reorg, cb)的onBlock韩素好cb- A callback function 回调函数
TESTS测试
Tests can be found in the test directory and run with npm run test.
在test目录中能够找到测试代码,使用npm run test命令运行它
These can also be valuable as examples/inspiration on how to run the library and invoke different parts of the API.
对于如何运行库和调用API的不同部分,这些示例/启发也很有价值。
有关测试的内容看本博客ethereumjs/ethereumjs-blockchain-2-test
ethereumjs/ethereumjs-blockchain-1-简介和API的更多相关文章
- IO流 简介 总结 API 案例 MD
目录 IO 流 简介 关闭流的正确方式 关闭流的封装方法 InputStream 转 String 的方式 转换流 InputStreamReader OutputStreamWriter 测试代码 ...
- Servlet基础(一) Servlet简介 关键API介绍及结合源码讲解
Servlet基础(一) Servlet基础和关键的API介绍 Servlet简介 Java Servlet是和平台无关的服务器端组件,它运行在Servlet容器中. Servlet容器负责Servl ...
- Sentinel 简介与API订阅发布
Sentinel 简介 Redis 的 Sentinel 系统用于管理多个 redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断 ...
- API Monitor简介(API监控工具)
API Monitor是一个免费软件,可以让你监视和控制应用程序和服务,取得了API调用. 它是一个强大的工具,看到的应用程序和服务是如何工作的,或跟踪,你在自己的应用程序的问题. 64位支持 API ...
- JavaMail入门第一篇 邮件简介及API概述
现如今,电子邮件在我们的生活当中扮演着越来越重要的角色,我们每个人几乎都会与其打交道(至少时不时我们都会接收到莫名其妙的垃圾邮件),在工作中,使用邮件进行交流沟通,可以使我们的工作有迹可循,也显的较为 ...
- Linux PWM framework简介和API描述【转】
本文转载自:https://blog.csdn.net/mike8825/article/details/51656400 1. 前言 PWM是Pulse Width Modulation(脉冲宽度调 ...
- SQLite3 C/C++ 开发接口简介(API函数)
from : http://www.sqlite.com.cn/MySqlite/5/251.Html 1.0 总览 SQLite3是SQLite一个全新的版本,它虽然是在SQLite 2.8.13的 ...
- ZooKeeper系列4:ZooKeeper API简介及编程
问题导读: 1.ZooKeeper API 共包含几个包? 2.如何使用ZooKeeper API 创建zookeeper应用程序? 1)ZooKeeper API 简介 ZooKeeper AP ...
- ZABBIX API简介及使用
API简介 Zabbix API开始扮演着越来越重要的角色,尤其是在集成第三方软件和自动化日常任务时.很难想象管理数千台服务器而没有自动化是多么的困难.Zabbix API为批量操作.第三方软件集成以 ...
- [译]Quartz 框架 教程(中文版)2.2.x 之第二课 Quartz API,Jobs和Triggers简介
第二课:QuartzAPI,Jobs和Triggers简介 Quartz API Quartz API 关键的几个接口: Scheduler:跟任务调度相关的最主要的API接口. Job:你期望任务调 ...
随机推荐
- [javaSE] 集合框架(Map概述)
Map集合,将key对象映射到value对象 三个主要的子类:Hashtable,HashMap,TreeMap Hashtable:底层是哈希表数据结构,不允许使用null值,线程同步 HashMa ...
- HDU 2041--超级楼梯(递推求解)
Description 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每 ...
- ORACLE-DataGuard-重启服务器的方法
DG原理:主机向备机传送日志文件,备机执行日志文件,借此与主机数据同步. 依此原理,不难推导出DG的开关机顺序 关机顺序 先主机再备机,这样日志就不会断了 开机顺序 先备机再主机 ,这样的目标也是日 ...
- SqlServer 2005升级至SqlServer 2008 解析Json 字符集问题
如果你数据库是通过sqlserver 2008以上版本创建的请绕过: 客户以前用的是sqlserver2005 创建的数据库.后来升级到 sqlserver 2008 . 有个业务用到了json查询 ...
- MySQL:入门
一.前言 MySQL :是用于管理数据的软件 MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性. 分为服务端和客户 ...
- 理解position:relative
前言:position有5个属性:static.absolute.relative.fixed和inherit.本篇博客主要介绍relative属性,因为似乎很多人对这个属性的理解很模糊,而且不清楚r ...
- ThreeJS geometry的顶点世界坐标
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java内存模型(JMM)以及 垃圾回收机制 小结
内存模型: 内存模型描述了程序中各个变量(实例域.静态域和数组元素)之间的关系,以及在实际计算机系统中将变量存储到内存和从内存中取出变量这样的底层细节,对象最终是存储在内存里面的,这点没有错,但是编译 ...
- LeetCode 533----Lonely Pixel II
问题描述 Given a picture consisting of black and white pixels, and a positive integer N, find the number ...
- MySQL Database on Azure服务在中国正式商用
基于由世纪互联运营的Windows Azure平台,MySQL Database on Azure服务助力中国用户实现数据库在云端的快速部署.推进用户的创新开发 2015年9月10日,北京——微软中国 ...