Skip to content

Commit

Permalink
Added prevRandao to block (#3372).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 12, 2024
1 parent 501de23 commit ec6a754
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src.ts/providers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ const _formatBlock = object({
excessBlobGas: allowNull(getBigInt, null),

miner: allowNull(getAddress),
prevRandao: allowNull(formatHash, null),
extraData: formatData,

baseFeePerGas: allowNull(getBigInt)
}, {
prevRandao: [ "mixHash" ]
});

export function formatBlock(value: any): BlockParams {
Expand Down
6 changes: 6 additions & 0 deletions src.ts/providers/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export interface BlockParams {
*/
miner: string;

/**
* The latest RANDAO mix of the post beacon state of
* the previous block.
*/
prevRandao?: null | string;

/**
* Additional data the miner choose to include.
*/
Expand Down
11 changes: 9 additions & 2 deletions src.ts/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ export class Block implements BlockParams, Iterable<string> {
*/
readonly miner!: string;

/**
* The latest RANDAO mix of the post beacon state of
* the previous block.
*/
readonly prevRandao!: null | string;

/**
* Any extra data the validator wished to include.
*/
Expand Down Expand Up @@ -592,6 +598,7 @@ export class Block implements BlockParams, Iterable<string> {
blobGasUsed: block.blobGasUsed,
excessBlobGas: block.excessBlobGas,
miner: block.miner,
prevRandao: getValue(block.prevRandao),
extraData: block.extraData,

baseFeePerGas: getValue(block.baseFeePerGas),
Expand Down Expand Up @@ -640,7 +647,7 @@ export class Block implements BlockParams, Iterable<string> {
toJSON(): any {
const {
baseFeePerGas, difficulty, extraData, gasLimit, gasUsed, hash,
miner, nonce, number, parentHash, parentBeaconBlockRoot,
miner, prevRandao, nonce, number, parentHash, parentBeaconBlockRoot,
stateRoot, receiptsRoot, timestamp, transactions
} = this;

Expand All @@ -653,7 +660,7 @@ export class Block implements BlockParams, Iterable<string> {
gasUsed: toJson(gasUsed),
blobGasUsed: toJson(this.blobGasUsed),
excessBlobGas: toJson(this.excessBlobGas),
hash, miner, nonce, number, parentHash, timestamp,
hash, miner, prevRandao, nonce, number, parentHash, timestamp,
parentBeaconBlockRoot, stateRoot, receiptsRoot,
transactions,
};
Expand Down

0 comments on commit ec6a754

Please sign in to comment.