https://github.com/ethereumjs/ethereumjs-common/blob/master/docs/index.md

该API的调用的详细例子可见ethereumjs/ethereumjs-common-3-test

Common

Common class to access chain and hardfork parameters

访问链和硬分叉参数的Common类

Parameters输入参数

  • chain (String | Number | Dictionary) String ('mainnet') or Number (1) chain  可以使用字符串(如'mainnet')或数字(如1)表示链
  • hardfork String String identifier ('byzantium') for hardfork (optional) (可选项)使用字符串标识('byzantium')表示
  • supportedHardforks Array Limit parameter returns to the given hardforks (optional) (可选项)返回给硬分叉的限制参数

调用:

let c = new Common('mainnet')//使用的是mainnet链
let c = new Common('mainnet', 'byzantium')
let c = new Common('mainnet', 'byzantium', ['byzantium', 'constantinople'])

⚠️如果你连接的是自己私有的chain,初始化的方式是:

let chainParams = require('./testnet.json') //testnet.json中是具体的链描述信息
let c = new Common(chainParams, 'byzantium')

testnet.json为:

{
"name": "testnet",
"chainId": 12345,
"networkId": 12345,
"comment": "Private test network",
"genesis": {
"hash": "0xaa00000000000000000000000000000000000000000000000000000000000000",
"timestamp": null,
"gasLimit": 1000000,
"difficulty": 1,
"nonce": "0xbb00000000000000",
"extraData": "0xcc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"stateRoot": "0xdd00000000000000000000000000000000000000000000000000000000000000"
},
"hardforks": [
{
"name": "chainstart",
"block": 0,
"consensus": "poa",
"finality": null
},
{
"name": "homestead",
"block": 1,
"consensus": "poa",
"finality": null
},
{
"name": "tangerineWhistle",
"block": 2,
"consensus": "poa",
"finality": null
},
{
"name": "spuriousDragon",
"block": 3,
"consensus": "poa",
"finality": null
},
{
"name": "byzantium",
"block": 4,
"consensus": "poa",
"finality": null
}
],
"bootstrapNodes": [
{
"ip": "10.0.0.1",
"port": 30303,
"id": "11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"location": "",
"comment": ""
},
{
"ip": "10.0.0.2",
"port": 30303,
"id": "22000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"location": "",
"comment": ""
}
]
}

注意:

let chainParams = require('./testnet.json')
delete chainParams['hardforks'] //如果有任何内容的缺失,初始化时将报错
let c = new Common(chainParams, 'byzantium') //报错

setChain

Sets the chain 设置链

Parameters

  • chain (String | Number | Dictionary) String ('mainnet') or Number (1) chain representation. Or, a Dictionary of chain parameters for a private network. 可以使用字符串(如'mainnet')或数字(如1)表示链。或者对于私有网络则使用链参数字典

调用:

let c = new Common('mainnet')
c.setChain('ropsten') //重新将链设置为ropsten

setHardfork

Sets the hardfork to get params for

设置硬叉以获取参数

Parameters

  • hardfork String String identifier ('byzantium')使用字符串标识('byzantium')表示

调用:

let c = new Common('mainnet')
c.param('gasPrices', 'ecAdd', 'byzantium') //500 c.setHardfork('byzantium')
st.equal(c.param('gasPrices', 'ecAdd') //

_chooseHardfork

Internal helper function to choose between hardfork set and hardfork provided as param

内部帮助函数,用于在硬分叉集中选择并提供其为参数

Parameters

  • hardfork String Hardfork given to function as a parameter 作为函数参数的硬分叉
  • onlySupported

Returns String Hardfork chosen to be used 返回选择使用的硬分叉

_getHardfork

Internal helper function, returns the params for the given hardfork for the chain set

内部帮助函数,返回链集的给定硬分叉的参数

Parameters

  • hardfork String Hardfork name 硬分叉名字

Returns Dictionary

_isSupportedHardfork

Internal helper function to check if a hardfork is set to be supported by the library

内部帮助函数,查看设置的硬分叉是否被库支持

Parameters

  • hardfork String Hardfork name 硬分叉的名字

Returns Boolean True if hardfork is supported 如果硬分叉被支持则返回true

调用:

let c = new Common('mainnet', 'byzantium', ['byzantium', 'constantinople'])
c._isSupportedHardfork('byzantium') //返回true
c._isSupportedHardfork('spuriousDragon') //返回false

param

Returns the parameter corresponding to a hardfork

返回与硬分叉相关联的参数

Parameters

  • topic String Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding') 参数主题(有'gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding')
  • name String Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic) 参数名字 (比如'gasConfig' 主题中的 'minGasLimit' )
  • hardfork String Hardfork name, optional if hardfork set 影分叉的名字,如果硬分叉集可选

调用:

let c = new Common('mainnet')
c.param('gasPrices', 'ecAdd', 'byzantium') // c.setHardfork('byzantium')
st.equal(c.param('gasPrices', 'ecAdd') //

paramByBlock

Returns a parameter for the hardfork active on block number

返回在区块数中活跃硬分叉的参数

Parameters

  • topic String Parameter topic 参数主体
  • name String Parameter name 参数名
  • blockNumber Number Block number 区块数

调用:

let c = new Common('mainnet', 'byzantium')
c.paramByBlock('pow', 'minerReward', ) //'3000000000000000000'

hardforkIsActiveOnBlock

Checks if set or provided hardfork is active on block number

查看是否设置了或提供的硬分叉在区块数中是活跃的

Parameters

  • hardfork String Hardfork name or null (for HF set) 硬分叉名字或null
  • blockNumber Number 区块数
  • opts Array
    • opts.onlySupported Array.Boolean optional, only allow supported HFs (default: false) (可选的)表示只支持HFs ,即初始化时自己设置的supportedHardforks(默认为false)

Returns Boolean

调用:

let c = new Common('ropsten')
c.hardforkIsActiveOnBlock('byzantium', ) //返回true,等价于下面的
c.activeOnBlock() //返回true c.hardforkIsActiveOnBlock('byzantium', )//返回true
c.hardforkIsActiveOnBlock('byzantium', ) //返回false
c = new Common('ropsten', 'byzantium')
c.hardforkIsActiveOnBlock(null, ) //true,因为上面已经设置链分叉为 'byzantium',所以这里使用的是null
c.hardforkIsActiveOnBlock(null, ) //true
c.hardforkIsActiveOnBlock(null, ) //false

activeOnBlock

Alias to hardforkIsActiveOnBlock when hardfork is set

当硬分叉被设置时,其为hardforkIsActiveOnBlock的别名

Parameters

  • blockNumber Number区块数
  • opts Array
    • opts.onlySupported Array.Boolean optional, only allow supported HFs (default: false)(可选的)表示只支持HFs ,即初始化时自己设置的supportedHardforks(默认为false)

Returns Boolean

调用:

c = new Common('ropsten', 'byzantium')//当分叉已经设置时
c.hardforkIsActiveOnBlock(null, ) //true,或使用
c.activeOnBlock()

hardforkGteHardfork

Sequence based check if given or set HF1 is greater than or equal HF2

基于序列的检查是否给定的或设置的硬分叉1强过或等同于硬分叉2时

Parameters

  • hardfork1 String Hardfork name or null (if set) 硬分叉名字或null
  • hardfork2 String Hardfork name 硬分叉名字
  • opts Array
    • opts.onlyActive Array.Boolean optional, only active HFs (default: false)(可选的)表示活跃HFs(默认为false)
    • opts.onlySupported Array.Boolean optional, only allow supported HFs (default: false)(可选的)表示只支持HFs ,即初始化时自己设置的supportedHardforks(默认为false)

Returns Boolean

调用:

let c = new Common('ropsten')
c.hardforkGteHardfork('constantinople', 'byzantium') //返回true,因为constantinople >= byzantium (provided)
c.hardforkGteHardfork('spuriousDragon', 'byzantium') //false

gteHardfork

Alias to hardforkGteHardfork when hardfork is set

当硬分叉被设置时其为hardforkGteHardfork别名

Parameters

  • hardfork String Hardfork name硬分叉名字
  • opts Array
    • opts.onlyActive Array.Boolean optional, only active HFs (default: false)(可选的)表示活跃HFs(默认为false)
    • opts.onlySupported Array.Boolean optional, only allow supported HFs (default: false)(可选的)表示只支持HFs ,即初始化时自己设置的supportedHardforks(默认为false)

Returns Boolean

调用:

c = new Common('ropsten', 'byzantium') //当分叉已经被设置时
c.hardforkGteHardfork(null, 'spuriousDragon') //返回true,或使用下面
c.gteHardfork('spuriousDragon') //true

hardforkIsActiveOnChain

Checks if given or set hardfork is active on the chain

检查是否给定的或设置的硬分叉在链上是活跃的

Parameters

  • hardfork String Hardfork name, optional if HF set 硬分叉名字
  • opts Array
    • opts.onlySupported Array.Boolean optional, only allow supported HFs (default: false) 可选的)表示只支持HFs ,即初始化时自己设置的supportedHardforks(默认为false)

Returns Boolean

调用:

let c = new Common('ropsten')
c.hardforkIsActiveOnChain('byzantium') //true
c.hardforkIsActiveOnChain('dao') //false
c.hardforkIsActiveOnChain('spuriousDragon', { onlySupported: true })//因为这里并没有设置,但是使用了onlySupported: true,所以会报出"spuriousDragon"为不支持的分叉的错误 c = new Common('ropsten', 'byzantium')
c.hardforkIsActiveOnChain() //true,即设置的'byzantium'在ropsten链中活跃

activeHardforks

Returns the active hardfork switches for the current chain

返回当前链的活跃硬分叉开关

Parameters

  • blockNumber Number up to block if provided, otherwise for the whole chain 如果提供则查询至该指定区块,否则为整条链
  • opts Array
    • opts.onlySupported Array.Boolean optional, limit results to supported HFs (default: false)(可选的)表示只支持HFs ,即初始化时自己设置的supportedHardforks(默认为false)

Returns Array Array with hardfork arrays 硬分叉数组

调用:

let c = new Common('ropsten')
c.activeHardforks().length //返回5,说明ropsten链中有5个活跃分叉类型
c.activeHardforks()[]['name'] //'spuriousDragon'
c.activeHardforks().length //返回3,即直到区块9有的活跃分叉个数为3
c = new Common('ropsten', null, ['spuriousDragon', 'byzantium', 'constantinople'])
c.activeHardforks(null, { onlySupported: true }).length //返回2 ,onlySupported: true说明只支持supportedHardforks里面的分叉,所以返回的结果就从5变成了2,只包含了2个活跃分叉类型

activeHardfork

Returns the latest active hardfork name for chain or block or throws if unavailable

返回链或区块最新的活跃硬分叉的名字,如果不可行则抛出错误

Parameters

  • blockNumber Number up to block if provided, otherwise for the whole chain如果提供则查询至该指定区块,否则为整条链
  • opts Array
    • opts.onlySupported Array.Boolean optional, limit results to supported HFs (default: false)(可选的)表示只支持HFs ,即初始化时自己设置的supportedHardforks(默认为false)

Returns String Hardfork name 硬分叉名

调用:

let c = new Common('ropsten')
c.activeHardfork() //返回byzantium ,说明整条链最新的分叉为byzantium
c.activeHardfork() //返回spuriousDragon,即到区块10的最新分叉类型为spuriousDragon
c = new Common('ropsten', null, ['tangerineWhistle', 'spuriousDragon'])
c.activeHardfork(null, { onlySupported: true }) //返回'spuriousDragon',因为supportedHardforks里最新的类型为它

hardforkBlock

Returns the hardfork change block for hardfork provided or set

为提供或设置的硬分叉返回硬分叉改变块

Parameters

  • hardfork String Hardfork name, optional if HF set 硬分叉名,如果硬分叉集设置则可选

Returns Number Block number 返回区块数

例子:

let c = new Common('ropsten')
c.hardforkBlock('byzantium') //返回1700000,得到byzantium分叉开始的区块数

isHardforkBlock

True if block number provided is the hardfork (given or set) change block of the current chain

如果提供的区块数是目前链的硬分叉(给定或设置的)改变区块,则返回true

Parameters

  • blockNumber Number Number of the block to check 查看的区块数
  • hardfork String Hardfork name, optional if HF set 硬分叉名,如果硬分叉集设置则可选

Returns Boolean

调用:

let c = new Common('ropsten')
c.isHardforkBlock() //返回true
c.isHardforkBlock() //返回false

consensus共识

Provide the consensus type for the hardfork set or provided as param

为设置或提供的硬分叉集提供共识类型作为参数

Parameters

  • hardfork String Hardfork name, optional if hardfork set 硬分叉名,如果硬分叉集设置则可选

Returns String Consensus type (e.g. 'pow', 'poa') 返回共识类型(如'pow', 'poa')

let c = new Common('mainnet')
c.consensus('byzantium') //返回byzantium分叉共识为'pow'

finality

Provide the finality type for the hardfork set or provided as param

为设置或提供的硬分叉集提供结束类型作为参数

Parameters

  • hardfork String Hardfork name, optional if hardfork set 硬分叉名,如果硬分叉集设置则可选

Returns String Finality type (e.g. 'pos', null of no finality) 结束类型(如'pos',没有则为null)

调用:

let c = new Common('mainnet')
c.finality('byzantium') //null

genesis

Returns the Genesis parameters of current chain

返回当前链的初始状态参数

Returns Dictionary Genesis dict 初始字典

如:

 "genesis": {
"hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"timestamp": null,
"gasLimit": ,
"difficulty": ,
"nonce": "0x0000000000000042",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"stateRoot": "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"
}

调用:

let c = new Common('mainnet')
c.genesis().hash //返回"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"

hardforks

Returns the hardforks for current chain返回当前链的硬分叉

Returns Array Array with arrays of hardforks 硬分叉的数组

如:

 "hardforks": [
{
"name": "chainstart",
"block": ,
"consensus": "pow",
"finality": null
},
{
"name": "homestead",
"block": ,
"consensus": "pow",
"finality": null
}
]

调用:

let c = new Common('mainnet')
c.hardforks()[]['block']//返回

hardfork

Returns the hardfork set 返回硬分叉集

Returns String Hardfork name 硬分叉名字

调用:

let c = new Common('mainnet', 'byzantium')
c.hardfork() //返回'byzantium'

bootstrapNodes

Returns bootstrap nodes for the current chain 返回当前链的bootstrap节点

Returns Dictionary Dict with bootstrap nodes  bootstrap节点字典

如:

  "bootstrapNodes": [
{
"ip": "13.93.211.84",
"port": ,
"id": "3f1d12044546b76342d59d4a05532c14b85aa669704bfe1f864fe079415aa2c02d743e03218e57a33fb94523adb54032871a6c51b2cc5514cb7c7e35b3ed0a99",
"location": "US-WEST",
"comment": "Go Bootnode"
},
{
"ip": "191.235.84.50",
"port": ,
"id": "78de8a0916848093c73790ead81d1928bec737d565119932b98c6b100d944b7a95e94f847f689fc723399d2e31129d182f7ef3863f2b4c820abbf3ab2722344d",
"location": "BR",
"comment": "Go Bootnode"
}
]

调用:

let c = new Common('mainnet')
c.bootstrapNodes()[].port //返回:

chainId

Returns the Id of current chain 返回当前链的ID

Returns Number chain Id

调用:

let c = new Common('mainnet')
c.chainId() //返回1

chainName

Returns the name of current chain 返回当前链的名字

Returns String chain name (lower case) (小写)

调用:

let c = new Common('mainnet')
c.chainName() //返回'mainnet'

networkId

Returns the Id of current network 返回当前网络的ID

Returns Number network Id

调用:

let c = new Common('mainnet')
c.networkId() //返回1

ethereumjs/ethereumjs-common-2-API文档的更多相关文章

  1. SpringBoot入门教程(二十)Swagger2-自动生成RESTful规范API文档

    Swagger2 方式,一定会让你有不一样的开发体验:功能丰富 :支持多种注解,自动生成接口文档界面,支持在界面测试API接口功能:及时更新 :开发过程中花一点写注释的时间,就可以及时的更新API文档 ...

  2. (转载)中文Appium API 文档

    该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...

  3. 中文Appium API 文档

    该文档是Testerhome官方翻译的源地址:https://github.com/appium/appium/tree/master/docs/cn官方网站上的:http://appium.io/s ...

  4. xadmin引入drf-yasg生成Swagger API文档

    一.安装drf-yasg: 由于django-rest-swagger已经废弃了 所以引入了drf-yasg pip install drf-yasg 安装install drf-yasg库 http ...

  5. android api文档:intent阅读笔记

    intent是几大组件之间进行通信的组件.可以包含以下几个部分: component:指明了处理该intent的对象. Action类似于一个函数名,规定了其他部分的对应用法: The action ...

  6. 使用python编写量子线路打印的简单项目,并使用Sphinx自动化生成API文档

    技术背景 该文章一方面从量子线路的打印着手,介绍了一个简单的python量子线路工程.同时基于这个简单的小工程,我们顺带的介绍了python的API文档自动化生成工具Sphinx的基本使用方法. 量子 ...

  7. Java在DOS命令下的运行及其API文档制作过程

    该文档主要描述java程序在DOS命令下的运行,以及一些常用的命令 常用DOS命令: d: 回车 盘符切换 dir(directory):列出当前目录下的文件以及文件夹 md (make direct ...

  8. 在ASP.NET Core Web API上使用Swagger提供API文档

    我在开发自己的博客系统(http://daxnet.me)时,给自己的RESTful服务增加了基于Swagger的API文档功能.当设置IISExpress的默认启动路由到Swagger的API文档页 ...

  9. 利用sphinx为python项目生成API文档

    sphinx可以根据python的注释生成可以查找的api文档,简单记录了下步骤 1:安装 pip install -U Sphinx 2:在需要生成文档的.py文件目录下执行sphinx-apido ...

  10. 如何使 WebAPI 自动生成漂亮又实用在线API文档

    1.前言 1.1 SwaggerUI SwaggerUI 是一个简单的Restful API 测试和文档工具.简单.漂亮.易用(官方demo).通过读取JSON 配置显示API. 项目本身仅仅也只依赖 ...

随机推荐

  1. 如何优雅的爬取 gzip 格式的页面并保存在本地(java实现)

    1. 引言 在爬取汽车销量数据时需要爬取 html 保存在本地后再做分析,由于一些页面的 gzip 编码格式, 获取后要先解压缩,否则看到的是一片乱码.在网络上仔细搜索了下,终于在这里找到了一个优雅的 ...

  2. git相关的简单命令

    初次使用建议看这个ppt:http://www.bootcss.com/p/git-guide/    从现有仓库克隆 这需要用到 git clone 命令.如果你熟悉其他的 VCS 比如 Subve ...

  3. 福州大学oj 1752 A^B mod C ===>数论的基本功。位运用。五星*****

    Problem 1752 A^B mod C Accept: 579    Submit: 2598Time Limit: 1000 mSec    Memory Limit : 32768 KB P ...

  4. python学习之老男孩python全栈第九期_day029知识点总结——configparser模快、logging模块

    一. configparser模块 生成文档 import configparser config = configparser.ConfigParser() config[', 'Compressi ...

  5. Tips——canvas闪屏问题的处理

    一.问题描述 在画canvas时,遇到屏幕瞬间空白的情况(大约1~2帧),造成用户体验不好. 二.原因 canvas的绘图过程是:先擦出整个画布:然后浏览器到达重绘时间点后,在空白的canvas上作画 ...

  6. 【代码笔记】iOS-gif图片播放

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  7. JavaScript 面向对象的程序设计

    面向对象(Object-oriented,OO)的语言有一个标志,那就是它们都有类的概念.而通过类可以创建任意多个具有相同属性和方法的对象.前面提到过,ECMAScript中没有类的概念,因此它的对象 ...

  8. 根据自定义区域裁剪ArcGIS切片地图服务

    切片地图服务是访问地图最快捷的服务方式.假如要根据地理区域对切图进行访问控制,往往只能针对不同地理区域制作相应的地图,并发布为切片地图服务.而一般在切图的时候又是按全区域实施的,所以给切片管理者造成不 ...

  9. ARCGIS知乎上的好文章

    http://zhihu.esrichina.com.cn/?/feature/ArcGISAndroidDevNote ArcGIS知乎上有哪些干货可以推荐? http://zhihu.esrich ...

  10. iOS上Delegate的悬垂指针问题

    文章有点长,写的过程很有收获,但读的过程不一定有收获,慎入 [摘要]   悬垂指针(dangling pointer)引起的crash问题,是我们在iOS开发过程当中经常会遇到的.其中由delegat ...