Skip to content

Commit

Permalink
update block structure and formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlincecum authored and rileystephens28 committed Jun 7, 2024
1 parent 07509ac commit 8c04a8f
Show file tree
Hide file tree
Showing 10 changed files with 987 additions and 910 deletions.
86 changes: 60 additions & 26 deletions src/_tests/test-providers-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,35 +206,69 @@ describe('Test Provider Block operations', function () {
before(async () => {
const rpcBlock = await fetchRPCBlock('0xA');
block = {
hash: rpcBlock.hash,
number: rpcBlock.number.map((stringNumber: string) => Number(stringNumber)),
transactions: rpcBlock.transactions,
parentHash: rpcBlock.parentHash,
parentEntropy: rpcBlock.parentEntropy.map((entropy: string) => BigInt(entropy)),
extTransactions: rpcBlock.extTransactions,
nonce: rpcBlock.nonce,
difficulty: BigInt(rpcBlock.difficulty),
gasLimit: BigInt(rpcBlock.gasLimit),
gasUsed: BigInt(rpcBlock.gasUsed),
miner: rpcBlock.miner,
extraData: rpcBlock.extraData,
transactionsRoot: rpcBlock.transactionsRoot,
evmRoot: rpcBlock.stateRoot,
utxoRoot: rpcBlock.utxoRoot,
receiptsRoot: rpcBlock.receiptsRoot,
baseFeePerGas: BigInt(rpcBlock.baseFeePerGas),
extRollupRoot: rpcBlock.extRollupRoot,
extTransactionsRoot: rpcBlock.extTransactionsRoot,
location: rpcBlock.location,
manifestHash: rpcBlock.manifestHash,
mixHash: rpcBlock.mixHash,
interlinkHashes: rpcBlock.interlinkHashes,
order: rpcBlock.order,
parentDeltaS: rpcBlock.parentDeltaS.map((delta: string) => BigInt(delta)),
sha3Uncles: rpcBlock.sha3Uncles,
size: BigInt(rpcBlock.size),
uncles: rpcBlock.uncles,
subManifest: rpcBlock.subManifest,
totalEntropy: BigInt(rpcBlock.totalEntropy),
transactions: rpcBlock.transactions,
uncles: rpcBlock.uncles,
woBody: {
extTransactions: rpcBlock.woBody.extTransactions,
header: {
baseFeePerGas: BigInt(rpcBlock.woBody.header.baseFeePerGas),
efficiencyScore: BigInt(rpcBlock.woBody.header.efficiencyScore),
etxEligibleSlices: rpcBlock.woBody.header.etxEligibleSlices,
etxSetRoot: rpcBlock.woBody.header.etxSetRoot,
evmRoot: rpcBlock.woBody.header.evmRoot,
expansionNumber: Number(rpcBlock.woBody.header.expansionNumber),
extRollupRoot: rpcBlock.woBody.header.extRollupRoot,
extTransactionsRoot: rpcBlock.woBody.header.extTransactionsRoot,
extraData: rpcBlock.woBody.header.extraData,
gasLimit: BigInt(rpcBlock.woBody.header.gasLimit),
gasUsed: BigInt(rpcBlock.woBody.header.gasUsed),
hash: rpcBlock.woBody.header.hash,
interlinkRootHash: rpcBlock.woBody.header.interlinkRootHash,
manifestHash: rpcBlock.woBody.header.manifestHash,
miner: rpcBlock.woBody.header.miner,
mixHash: rpcBlock.woBody.header.mixHash,
nonce: rpcBlock.woBody.header.nonce,
number: rpcBlock.woBody.header.number.map((stringNumber: string) => Number(stringNumber)),
parentDeltaS: rpcBlock.woBody.header.parentDeltaS.map((delta: string) => BigInt(delta)),
parentEntropy: rpcBlock.woBody.header.parentEntropy.map((entropy: string) => BigInt(entropy)),
parentHash: rpcBlock.woBody.header.parentHash,
parentUncledS: rpcBlock.woBody.header.parentUncledS.map((uncled: string | null) =>
uncled ? BigInt(uncled) : null,
),
parentUncledSubDeltaS: rpcBlock.woBody.header.parentUncledSubDeltaS.map((delta: string) =>
BigInt(delta),
),
primeTerminus: rpcBlock.woBody.header.primeTerminus,
receiptsRoot: rpcBlock.woBody.header.receiptsRoot,
sha3Uncles: rpcBlock.woBody.header.sha3Uncles,
size: BigInt(rpcBlock.woBody.header.size),
thresholdCount: BigInt(rpcBlock.woBody.header.thresholdCount),
transactionsRoot: rpcBlock.woBody.header.transactionsRoot,
uncledS: BigInt(rpcBlock.woBody.header.uncledS),
utxoRoot: rpcBlock.woBody.header.utxoRoot,
},
interlinkHashes: rpcBlock.woBody.interlinkHashes,
manifest: rpcBlock.woBody.manifest,
transactions: rpcBlock.woBody.transactions,
uncles: rpcBlock.woBody.uncles,
},
woHeader: {
difficulty: rpcBlock.woHeader.difficulty,
headerHash: rpcBlock.woHeader.headerHash,
location: rpcBlock.woHeader.location,
mixHash: rpcBlock.woHeader.mixHash,
nonce: rpcBlock.woHeader.nonce,
number: rpcBlock.woHeader.number,
parentHash: rpcBlock.woHeader.parentHash,
time: rpcBlock.woHeader.time,
txHash: rpcBlock.woHeader.txHash,
},
};
});

Expand All @@ -252,8 +286,8 @@ describe('Test Provider Block operations', function () {
});

it('should fetch block by hash', async function () {
assert.ok(block.hash != null, 'block.hash != null');
const responseBlock = (await providerC1.getBlock(Shard.Paxos2, block.hash)) as quais.Block;
assert.ok(block.woBody.header.hash != null, 'block.hash != null');
const responseBlock = (await providerC1.getBlock(Shard.Paxos2, block.woBody.header.hash)) as quais.Block;
assert.ok(responseBlock != null, 'block != null');
// TODO: `provider` is not used, remove?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
4 changes: 3 additions & 1 deletion src/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,9 @@ export class AbstractProvider<C = FetchRequest> implements Provider {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_wrapBlock(value: BlockParams, network: Network): Block {
// Handle known node by -> remove null values from the number array
value.number = Array.isArray(value.number) ? value.number.filter((n: any) => n != null) : value.number;
value.woBody.header.number = Array.isArray(value.woBody.header.number)
? value.woBody.header.number.filter((n: any) => n != null)
: value.woBody.header.number;
return new Block(formatBlock(value), this);
}

Expand Down
Loading

0 comments on commit 8c04a8f

Please sign in to comment.