@ethereumjs/blockchain
Version:
A module to store and interact with blocks
35 lines • 1.16 kB
JavaScript
import { ChainGenesis } from '@ethereumjs/common';
import { genesisMPTStateRoot } from '@ethereumjs/mpt';
/**
* Safe creation of a new Blockchain object awaiting the initialization function,
* encouraged method to use when creating a blockchain object.
*
* @param opts Constructor options, see {@link BlockchainOptions}
*/
/**
* Verkle or Merkle genesis root
* @param genesisState
* @param common
* @returns
*/
export async function genGenesisStateRoot(genesisState, common) {
const genCommon = common.copy();
genCommon.setHardforkBy({
blockNumber: 0,
timestamp: genCommon.genesis().timestamp,
});
if (genCommon.isActivatedEIP(6800)) {
throw Error(`Verkle tree state not yet supported`);
}
else {
return genesisMPTStateRoot(genesisState);
}
}
/**
* Returns the genesis state root if chain is well known or an empty state's root otherwise
*/
export async function getGenesisStateRoot(chainId, common) {
const chainGenesis = ChainGenesis[chainId];
return chainGenesis !== undefined ? chainGenesis.stateRoot : genGenesisStateRoot({}, common);
}
//# sourceMappingURL=helpers.js.map