Skip to content
This repository was archived by the owner on Apr 6, 2020. It is now read-only.

Commit 35713f0

Browse files
authored
Merge pull request #10 from ethereumjs/add-allowed-hardforks-init
Optional supportedHardforks init parameter
2 parents e7d113a + 854203b commit 35713f0

File tree

6 files changed

+163
-73
lines changed

6 files changed

+163
-73
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ c.genesis().hash // 0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1
3939
c.bootstrapNodes() // Array with current nodes
4040
```
4141

42+
It is encouraged to also explicitly set the ``supportedHardforks`` if the initializing library
43+
only supports a certain range of ``hardforks``:
44+
45+
```javascript
46+
let c = new Common('ropsten', null, ['byzantium', 'constantinople'])
47+
```
48+
49+
This will e.g. throw an error when a param is requested for an unsupported hardfork and
50+
like this prevents unpredicted behaviour.
51+
4252
# API
4353

4454
See the API documentation for a full list of functions for accessing specific chain and

docs/index.md

Lines changed: 87 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,116 +7,134 @@
77
- [setHardfork][3]
88
- [\_chooseHardfork][4]
99
- [\_getHardfork][5]
10-
- [param][6]
11-
- [paramByBlock][7]
12-
- [hardforkIsActiveOnBlock][8]
13-
- [hardforkIsActiveOnChain][9]
14-
- [activeHardforks][10]
15-
- [hardforkBlock][11]
16-
- [isHardforkBlock][12]
17-
- [consensus][13]
18-
- [finality][14]
19-
- [genesis][15]
20-
- [hardforks][16]
21-
- [bootstrapNodes][17]
22-
- [hardfork][18]
23-
- [chainId][19]
24-
- [chainName][20]
25-
- [networkId][21]
10+
- [\_isSupportedHardfork][6]
11+
- [param][7]
12+
- [paramByBlock][8]
13+
- [hardforkIsActiveOnBlock][9]
14+
- [hardforkIsActiveOnChain][10]
15+
- [activeHardforks][11]
16+
- [hardforkBlock][12]
17+
- [isHardforkBlock][13]
18+
- [consensus][14]
19+
- [finality][15]
20+
- [genesis][16]
21+
- [hardforks][17]
22+
- [bootstrapNodes][18]
23+
- [hardfork][19]
24+
- [chainId][20]
25+
- [chainName][21]
26+
- [networkId][22]
2627

2728
## Common
2829

2930
Common class to access chain and hardfork parameters
3031

3132
**Parameters**
3233

33-
- `chain` **([String][22] \| [Number][23])** String ('mainnet') or Number (1) chain representation
34-
- `hardfork` **[String][22]** String identifier ('byzantium') for hardfork (optional)
34+
- `chain` **([String][23] \| [Number][24])** String ('mainnet') or Number (1) chain representation
35+
- `hardfork` **[String][23]** String identifier ('byzantium') for hardfork (optional)
36+
- `supportedHardforks` **[Array][25]** Limit parameter returns to the given hardforks (optional)
3537

3638
### setChain
3739

3840
Sets the chain
3941

4042
**Parameters**
4143

42-
- `chain` **([String][22] \| [Number][23])** String ('mainnet') or Number (1) chain representation
44+
- `chain` **([String][23] \| [Number][24])** String ('mainnet') or Number (1) chain representation
4345

4446
### setHardfork
4547

4648
Sets the hardfork to get params for
4749

4850
**Parameters**
4951

50-
- `hardfork` **[String][22]** String identifier ('byzantium')
52+
- `hardfork` **[String][23]** String identifier ('byzantium')
5153

5254
### \_chooseHardfork
5355

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

5658
**Parameters**
5759

58-
- `hardfork` **[String][22]** Hardfork given to function as a parameter
60+
- `hardfork` **[String][23]** Hardfork given to function as a parameter
5961

60-
Returns **[String][22]** Hardfork chosen to be used
62+
Returns **[String][23]** Hardfork chosen to be used
6163

6264
### \_getHardfork
6365

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

6668
**Parameters**
6769

68-
- `hardfork` **[String][22]** Hardfork name
70+
- `hardfork` **[String][23]** Hardfork name
6971

7072
Returns **Dictionary**
7173

74+
### \_isSupportedHardfork
75+
76+
Internal helper function to check if a hardfork is set to be supported by the library
77+
78+
**Parameters**
79+
80+
- `hardfork` **[String][23]** Hardfork name
81+
82+
Returns **[Boolean][26]** True if hardfork is supported
83+
7284
### param
7385

7486
Returns the parameter corresponding to a hardfork
7587

7688
**Parameters**
7789

78-
- `topic` **[String][22]** Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding')
79-
- `name` **[String][22]** Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)
80-
- `hardfork` **[String][22]** Hardfork name, optional if hardfork set
90+
- `topic` **[String][23]** Parameter topic ('gasConfig', 'gasPrices', 'vm', 'pow', 'casper', 'sharding')
91+
- `name` **[String][23]** Parameter name (e.g. 'minGasLimit' for 'gasConfig' topic)
92+
- `hardfork` **[String][23]** Hardfork name, optional if hardfork set
8193

8294
### paramByBlock
8395

8496
Returns a parameter for the hardfork active on block number
8597

8698
**Parameters**
8799

88-
- `topic` **[String][22]** Parameter topic
89-
- `name` **[String][22]** Parameter name
90-
- `blockNumber` **[Number][23]** Block number
100+
- `topic` **[String][23]** Parameter topic
101+
- `name` **[String][23]** Parameter name
102+
- `blockNumber` **[Number][24]** Block number
91103

92104
### hardforkIsActiveOnBlock
93105

94106
Checks if a hardfork is active for a given block number
95107

96108
**Parameters**
97109

98-
- `hardfork` **[String][22]** Hardfork name
99-
- `blockNumber` **[Number][23]**
110+
- `hardfork` **[String][23]** Hardfork name
111+
- `blockNumber` **[Number][24]**
112+
- `opts` **[Array][25]**
113+
- `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false)
100114

101-
Returns **[Boolean][24]**
115+
Returns **[Boolean][26]**
102116

103117
### hardforkIsActiveOnChain
104118

105119
Checks if the hardfork provided is active on the chain
106120

107121
**Parameters**
108122

109-
- `hardfork` **[String][22]**
123+
- `hardfork` **[String][23]**
124+
- `opts` **[Array][25]**
125+
- `opts.onlySupported` **Array.Boolean** optional, only allow supported HFs (default: false)
110126

111-
Returns **[Boolean][24]**
127+
Returns **[Boolean][26]**
112128

113129
### activeHardforks
114130

115131
Returns the active hardfork switches for the current chain
116132

117133
**Parameters**
118134

119-
- `blockNumber` **[Number][23]** up to block if provided, otherwise for the whole chain
135+
- `blockNumber` **[Number][24]** up to block if provided, otherwise for the whole chain
136+
- `opts` **[Array][25]**
137+
- `opts.onlySupported` **Array.Boolean** optional, limit results to supported HFs (default: false)
120138

121139
Returns **[Array][25]** Array with hardfork arrays
122140

@@ -126,40 +144,40 @@ Returns the hardfork change block for the given hardfork
126144

127145
**Parameters**
128146

129-
- `hardfork` **[String][22]** Hardfork name
147+
- `hardfork` **[String][23]** Hardfork name
130148

131-
Returns **[Number][23]** Block number
149+
Returns **[Number][24]** Block number
132150

133151
### isHardforkBlock
134152

135153
True if block number provided is the hardfork change block of the current chain
136154

137155
**Parameters**
138156

139-
- `hardfork` **[String][22]** Hardfork name
140-
- `blockNumber` **[Number][23]** Number of the block to check
157+
- `hardfork` **[String][23]** Hardfork name
158+
- `blockNumber` **[Number][24]** Number of the block to check
141159

142-
Returns **[Boolean][24]**
160+
Returns **[Boolean][26]**
143161

144162
### consensus
145163

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

148166
**Parameters**
149167

150-
- `hardfork` **[String][22]** Hardfork name, optional if hardfork set
168+
- `hardfork` **[String][23]** Hardfork name, optional if hardfork set
151169

152-
Returns **[String][22]** Consensus type (e.g. 'pow', 'poa')
170+
Returns **[String][23]** Consensus type (e.g. 'pow', 'poa')
153171

154172
### finality
155173

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

158176
**Parameters**
159177

160-
- `hardfork` **[String][22]** Hardfork name, optional if hardfork set
178+
- `hardfork` **[String][23]** Hardfork name, optional if hardfork set
161179

162-
Returns **[String][22]** Finality type (e.g. 'pos', null of no finality)
180+
Returns **[String][23]** Finality type (e.g. 'pos', null of no finality)
163181

164182
### genesis
165183

@@ -183,25 +201,25 @@ Returns **Dictionary** Dict with bootstrap nodes
183201

184202
Returns the hardfork set
185203

186-
Returns **[String][22]** Hardfork name
204+
Returns **[String][23]** Hardfork name
187205

188206
### chainId
189207

190208
Returns the Id of current chain
191209

192-
Returns **[Number][23]** chain Id
210+
Returns **[Number][24]** chain Id
193211

194212
### chainName
195213

196214
Returns the name of current chain
197215

198-
Returns **[String][22]** chain name (lower case)
216+
Returns **[String][23]** chain name (lower case)
199217

200218
### networkId
201219

202220
Returns the Id of current network
203221

204-
Returns **[Number][23]** network Id
222+
Returns **[Number][24]** network Id
205223

206224
[1]: #common
207225

@@ -213,42 +231,44 @@ Returns **[Number][23]** network Id
213231

214232
[5]: #_gethardfork
215233

216-
[6]: #param
234+
[6]: #_issupportedhardfork
217235

218-
[7]: #parambyblock
236+
[7]: #param
219237

220-
[8]: #hardforkisactiveonblock
238+
[8]: #parambyblock
221239

222-
[9]: #hardforkisactiveonchain
240+
[9]: #hardforkisactiveonblock
223241

224-
[10]: #activehardforks
242+
[10]: #hardforkisactiveonchain
225243

226-
[11]: #hardforkblock
244+
[11]: #activehardforks
227245

228-
[12]: #ishardforkblock
246+
[12]: #hardforkblock
229247

230-
[13]: #consensus
248+
[13]: #ishardforkblock
231249

232-
[14]: #finality
250+
[14]: #consensus
233251

234-
[15]: #genesis
252+
[15]: #finality
235253

236-
[16]: #hardforks
254+
[16]: #genesis
237255

238-
[17]: #bootstrapnodes
256+
[17]: #hardforks
239257

240-
[18]: #hardfork
258+
[18]: #bootstrapnodes
241259

242-
[19]: #chainid
260+
[19]: #hardfork
243261

244-
[20]: #chainname
262+
[20]: #chainid
245263

246-
[21]: #networkid
264+
[21]: #chainname
247265

248-
[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
266+
[22]: #networkid
249267

250-
[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
268+
[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
251269

252-
[24]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
270+
[24]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
253271

254272
[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
273+
274+
[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

0 commit comments

Comments
 (0)