Skip to content

Commit

Permalink
fix: populate missing tx fields (#295)
Browse files Browse the repository at this point in the history
* fix: populate missing tx fields

* remove console log

* clippy

* bump to ethers 5.7
  • Loading branch information
ncitron authored Oct 25, 2023
1 parent ee67d81 commit e098b5d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
26 changes: 24 additions & 2 deletions consensus/src/types/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,31 @@ impl From<ExecutionPayload> for Block {
let txs = value
.transactions()
.iter()
.map(|tx| {
.enumerate()
.map(|(i, tx)| {
let rlp = Rlp::new(tx.as_slice());
Transaction::decode(&rlp).unwrap()
let mut tx = Transaction::decode(&rlp).unwrap();

tx.block_number = Some(value.block_number().as_u64().into());
tx.block_hash = Some(H256::from_slice(value.block_hash()));
tx.from = tx.recover_from().unwrap();
tx.transaction_index = Some(i.into());

if let (Some(max_fee), Some(max_priority_fee)) =
(tx.max_fee_per_gas, tx.max_priority_fee_per_gas)
{
let base_fee = ethers::types::U256::from_little_endian(
&value.base_fee_per_gas().to_bytes_le(),
);

tx.gas_price = if max_fee >= max_priority_fee + base_fee {
Some(base_fee + max_priority_fee)
} else {
Some(max_fee)
};
}

tx
})
.collect::<Vec<Transaction>>();

Expand Down
2 changes: 1 addition & 1 deletion helios-ts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</head>
<body>
<script src="./dist/lib.js"></script>
<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"></script>
<script src="https://cdn.ethers.io/lib/ethers-5.7.umd.min.js"></script>
<script>
const config = {
executionRpc:"http://localhost:9001/proxy",
Expand Down
5 changes: 4 additions & 1 deletion helios-ts/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ function mapToObj(map: Map<any, any> | undefined): Object | undefined {
if(!map) return undefined;

return Array.from(map).reduce((obj: any, [key, value]) => {
obj[key] = value;
if (value !== undefined) {
obj[key] = value;
}

return obj;
}, {});
}
Expand Down

0 comments on commit e098b5d

Please sign in to comment.