-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common: Relocate geth genesis, state parsers to common, blockchain re…
…spectively (#2300) * common: Relocate geth genesis, state parsers to common, blockchain respectively * lint utils * relocate setForkHashes * update readme * use Common.fromGethGenesis wherever possible * relocate parseGethGenesis tests * remove unnecessary await * fix tests access across common and client * provide abs path * add test for parseGethGenesisState * add test cases for setcommon hashes and correct kiln genesis root * add stateroot match test * fix the storage trie to also use key hashing
- Loading branch information
Showing
20 changed files
with
1,252 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { Blockchain } from './blockchain' | ||
export { CasperConsensus, CliqueConsensus, Consensus, EthashConsensus } from './consensus' | ||
export { BlockchainInterface, BlockchainOptions } from './types' | ||
export * from './utils' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { addHexPrefix, bigIntToHex, isHexPrefixed } from '@ethereumjs/util' | ||
|
||
import type { GenesisState } from './genesisStates' | ||
/** | ||
* Parses the geth genesis state into Blockchain {@link GenesisState} | ||
* @param json representing the `alloc` key in a Geth genesis file | ||
*/ | ||
export function parseGethGenesisState(json: any) { | ||
const state: GenesisState = {} | ||
for (let address of Object.keys(json.alloc)) { | ||
let { balance, code, storage } = json.alloc[address] | ||
address = addHexPrefix(address) | ||
balance = isHexPrefixed(balance) ? balance : bigIntToHex(BigInt(balance)) | ||
code = code !== undefined ? addHexPrefix(code) : undefined | ||
storage = storage !== undefined ? Object.entries(storage) : undefined | ||
state[address] = [balance, code, storage] as any | ||
} | ||
return state | ||
} |
Oops, something went wrong.