为了了解ethereumjs/ethereumjs-block-3-代码的使用需要了解的一个模块

https://github.com/ethereumjs/ethereumjs-common

Common Ethereum resources (successor for ethereum/common library)公共以太坊资源(以太坊/公共库后续)

SYNOPSIS概要

ETHEREUMJS-COMMON

Resources common to all Ethereum implementations 对所有以太坊实现公用的资源

Succeeds the old ethereum/common library.  继承了旧的ethereum/common

INSTALL安装

npm install ethereumjs-common

USAGE使用

All parameters can be accessed through the Common class which can be required through the main package and instantiated either with just the chain (e.g. 'mainnet') or the chain together with a specific hardfork provided.

所有参数都可以通过Common类接收,Common类可以使用main包请求,也可以要么和只带着链(如'mainnet')或与提供的具体分支一起的链作为参数来初始化一个Common对象

Here are some simple usage examples:下面是简单的使用例子

const Common = require('ethereumjs-common')

// Instantiate with only the chain,这个就是只使用ropsten链进行初始化
let c = new Common('ropsten')
c.param('gasPrices', 'ecAddGas', 'byzantium') // 500 // Chain and hardfork provided,这个是用链和硬分支来初始化对象的方法
c = new Common('ropsten', 'byzantium')
c.param('pow', 'minerReward') // 3000000000000000000 // Access genesis data for Ropsten network 访问Ropsten网络的初始数据
c.genesis().hash // 0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d // Get bootstrap nodes for chain/network 获取链/网络的引导节点
c.bootstrapNodes() // Array with current nodes 带着目前节点的数组

It is encouraged to also explicitly set the supportedHardforks if the initializing library only supports a certain range of hardforks:

如果初始化的库只支持某范围内的硬分支,则鼓励显示地设置supportedHardforks

let c = new Common('ropsten', null, ['byzantium', 'constantinople'])

This will e.g. throw an error when a param is requested for an unsupported hardfork and like this prevents unpredicted behaviour.

当一个参数请求不支持的硬分支时,这将抛出一个错误,像这样将防止不可预测的行为

API(看本博客ethereumjs/ethereumjs-common-2-API文档

See the API documentation for a full list of functions for accessing specific chain and depending hardfork parameters. There are also additional helper functions like paramByBlock (topic, name, blockNumber) or hardforkIsActiveOnBlock (hardfork, blockNumber) to ease blockNumber based access to parameters.

有关访问特定链和依赖硬分支参数的函数的完整列表,请参阅API文档。

这里有额外的帮助函数,像paramByBlock (topic, name, blockNumber)hardforkIsActiveOnBlock (hardfork, blockNumber)去简化基于块数的参数访问

Hardfork Params硬分叉参数

There are currently parameter changes by the following past and future hardfork by the library supported:以下库支持的旧的和新的硬分叉决定了目前硬分叉参数的变化

  • chainstart
  • homestead
  • dao
  • tangerineWhistle
  • spuriousDragon
  • byzantium
  • constantinople

For hardfork-specific parameter access with the param() and paramByBlock() functions you can use the following topics:

为了使用param()paramByBlock()函数访问具体的硬分叉参数,你可以使用下面的主题,上面的例子有:

  • gasConfig
  • gasPrices
  • vm
  • pow
  • casper
  • sharding

See one of the hardfork files like byzantium.json in the hardforks directory for an overview. For consistency, the chain start (chainstart) is considered an own hardfork.

为了简要了解可以查看其中的一个硬分叉文件如在hardforks目录下的byzantium.json。为了一致性,链的开始 (chainstart)将考虑一个自己的分叉

byzantium.json

{
"name": "byzantium",
"comment": "Hardfork with new precompiles, instructions and other protocol changes",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-609",
"status": "Final"
},
"gasConfig": {},
"gasPrices": {
"modexpGquaddivisor": {
"v": ,
"d": "Gquaddivisor from modexp precompile for gas calculation"
},
"ecAdd": {
"v": ,
"d": "Gas costs for curve addition precompile"
},
"ecMul": {
"v": ,
"d": "Gas costs for curve multiplication precompile"
},
"ecPairing": {
"v": ,
"d": "Base gas costs for curve pairing precompile"
},
"ecPairingWord": {
"v": ,
"d": "Gas costs regarding curve pairing precompile input length"
}
},
"vm": {},
"pow": {
"minerReward": {
"v": "",
"d": "the amount a miner get rewarded for mining a block"
}
},
"casper": {},
"sharding": {}
}

所以上面例子的:

c = new Common('ropsten', 'byzantium')
c.param('pow', 'minerReward') //

意思就是查看byzantium.json文件中的['pow']['minerReward']['v']的值,即了。这是矿工在挖矿时能够得到的奖励值

The hardfork-specific json files only contain the deltas from chainstart and shouldn't be accessed directly until you have a specific reason for it.

具体分叉json文件只包含来自chainstart的deltas,且不应该直接访问,直到你有具体这么做的原因

Note: The list of gasPrices and gas price changes on hardforks is consistent but not complete, so there are currently gas price values missing (PRs welcome!).

注意:在分叉中gasPrices和gas price列表的变化是一致但不完全的,所以目前gas price的值是缺失的(即只有gasPrices

Chain Params链参数

Supported chains:支持的链

  • mainnet
  • ropsten
  • rinkeby
  • kovan
  • goerli (EXPERIMENTAL)
  • Private/custom chain parameters

The following chain-specific parameters are provided:

下面是提供的具体链参数

  • name
  • chainId
  • networkId
  • genesis block header values
  • hardforks block numbers
  • bootstrapNodes list

To get an overview of the different parameters have a look at one of the chain-specifc files like mainnet.json in the chains directory.

为了得到不同参数的概述,我们可以看看在chains目录中的具体链文件之一的mainnet.json

{
"name": "mainnet",
"chainId": ,
"networkId": ,
"comment": "The Ethereum main chain",
"url": "https://ethstats.net/",
"genesis": {
"hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"timestamp": null,
"gasLimit": ,
"difficulty": ,
"nonce": "0x0000000000000042",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"stateRoot": "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"
},
"hardforks": [
{
"name": "chainstart",
"block": ,
"consensus": "pow",
"finality": null
},
{
"name": "homestead",
"block": ,
"consensus": "pow",
"finality": null
},
{
"name": "dao",
"block": ,
"consensus": "pow",
"finality": null
},
{
"name": "tangerineWhistle",
"block": ,
"consensus": "pow",
"finality": null
},
{
"name": "spuriousDragon",
"block": ,
"consensus": "pow",
"finality": null
},
{
"name": "byzantium",
"block": ,
"consensus": "pow",
"finality": null
},
{
"name": "constantinople",
"block": null,
"consensus": "pow",
"finality": null
}
],
"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"
},
{
"ip": "13.75.154.138",
"port": ,
"id": "158f8aab45f6d19c6cbf4a089c2670541a8da11978a2f90dbf6a502a4a3bab80d288afdbeb7ec0ef6d92de563767f3b1ea9e8e334ca711e9f8e2df5a0385e8e6",
"location": "AU",
"comment": "Go Bootnode"
},
{
"ip": "52.74.57.123",
"port": ,
"id": "1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082",
"location": "SG",
"comment": "Go Bootnode"
}
]
}

If you want to set up a common instance with parameters for a private/custom chain you can pass a dictionary - conforming to the parameter format described above - with your custom values in the constructor or the setChain()method for the chain parameter.

如果你想要为私有/定制脸设置带有参数的公用实例,你可以传递一个字典-像上面一样遵循参数的格式-在构造函数中带着你的定制值或能得到链的参数的setChain()方法

Bootstrap Nodes

There is no separate config file for bootstrap nodes like in the old ethereum-common library. Instead use the common.bootstrapNodes() function to get nodes for a specific chain/network.

这里没有bootstrap节点的单独配置文件,就像在旧ethereum-common库那样。相反使用了common.bootstrapNodes()函数去得到具体chain/network的节点

Genesis States初始状态

Network-specific genesis files are located in the genesisStates folder.

具体网络初始文件在genesisStates文件夹中

Due to the large file sizes genesis states are not directly included in the index.js file but have to be accessed directly, e.g.:

因为初始文件的巨大文件大小,所以并不将其直接包含在index.js文件中,但是又必须要直接访问它,比如

const mainnetGenesisState = require('ethereumjs-common/genesisStates/mainnet')

Or by choosing dynamically或者是动态地选择使用:

const genesisStates = require('ethereumjs-common/genesisStates')
const mainnetGenesisState = genesisStates['mainnet']
const mainnetGenesisState = genesisStates[genesisStates['names'][]] // alternative via chain Id
 

ethereumjs/ethereumjs-common-1-简介的更多相关文章

  1. ethereumjs/ethereumjs-common-2-API文档

    https://github.com/ethereumjs/ethereumjs-common/blob/master/docs/index.md 该API的调用的详细例子可见ethereumjs/e ...

  2. ethereumjs/ethereumjs-vm-3-StateManager

    https://github.com/ethereumjs/ethereumjs-vm/blob/master/docs/stateManager.md StateManager 要与本博客的ethe ...

  3. ethereumjs/ethereumjs-block-3-tests

    之前可以先了解一下另一个模块,看本博客的ethereumjs/ethereumjs-common部分内容 通过tests测试文件能够帮助更好了解API的使用 ethereumjs-block/test ...

  4. ethereumjs/ethereumjs-block-2-api

    https://github.com/ethereumjs/ethereumjs-block/blob/master/docs/index.md 详细的调用代码可见本博客的ethereumjs/eth ...

  5. ethereumjs/ethereumjs-blockchain-2-test

    https://github.com/ethereumjs/ethereumjs-blockchain/tree/master/test 'use strict' const test = requi ...

  6. ethereumjs/ethereumjs-util

    ethereumjs/ethereumjs-util Most of the string manipulation methods are provided by ethjs-util 更多的字符串 ...

  7. ethereumjs/ethereumjs-wallet

    Utilities for handling Ethereum keys ethereumjs-wallet A lightweight wallet implementation. At the m ...

  8. ethereumjs/ethereumjs-tx

    https://github.com/ethereumjs/ethereumjs-tx A simple module for creating, manipulating and signing e ...

  9. ethereumjs/ethereumjs-icap

    https://github.com/ethereumjs/ethereumjs-icap ethereumjs-icap 安装: npm install ethereumjs-icap --save ...

随机推荐

  1. vs2017调试源代码

    最近刚入职 ,带我得导师发给我一堆项目,什么云端和医院端,各种wcf服务.window服务和一些公共类库来回调用.搞得是迷迷糊糊,晕头转向.反正是一脸大萌比... 不过经过几个日日夜夜得不停奋战,大致 ...

  2. webpack开发工具

    source map 用来调试打包后的代码 const path = require('path'); const HtmlWebpackPlugin = require('html-webpack- ...

  3. Anaconda多环境多版本python配置笔记

    一.Conda测试过程: 使用conda.首先确认已经安装好了conda 配置环境.下一步通过创建几个环境来展示conda的环境管理功能.学习如何确认在哪个环境中,以及如何做复制一个环境作为备份. 测 ...

  4. 或许你并不需要jQuery

    此文为翻译文章,原文链接:you might not need jquery jQuery 和它的相关插件都是很强大的,使用它们让我们的应用开发变得简单.如果你正在开发另一个库,请花点时间思考以下,你 ...

  5. 计时器(Chronometer)

    计时器(Chronometer) 常用属性:format(计时器的计时格式) 常用方法: setBase(long base) 设置计时器的起始时间 setFormat(String format) ...

  6. Progress数据库配置与应用

    创建database 开始->程序->OpenEdge,选择:Desktop,进行database创建. 选择创建一个空database或直接copy一个demo的database,我们选 ...

  7. redis 概述、windows版本下载启动访问退出安装、中文乱码、RedisDesktopManager下载

    redis 概述 redis的key是string类型的:value有多种类型,但放入的不是特定类型数据,添加的都是string,只是redis把这些值组织成了各种数据结构.key和相应的值都是str ...

  8. mysql 5.7数据库支持emoji符号但是程序总算报错Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F...' for column ...

    1.线上碰到个问题,端上切换搜狗输入法后,原来限制的表情符号还能输入.数据库使用的是5.7.22版本的,刚开始以为数据库不支持表情符号导致的,但是看了线上的数据库以及字段,都是支持的. show va ...

  9. Management Studio 插件生成安装包要点(以ProjkyAddin为例)

    通过Visual Studio向导生成Management 插件框架就不说了,网上能搜到不少资料.本篇重点是说明怎么设计一个插件安装包,适用于Management Studio 2005 到2014的 ...

  10. lock free数据结构内存回收技术-hazard pointer

    lock free数据结构一般来说拥有比基于lock实现的数据结构更高的性能,但是其实现比基于lock的实现更为复杂,需要处理的难题包括预防ABA问题,内存如何重用和回收等.通常,最简单最有效的处理A ...