Skip to content

Commit

Permalink
🐛 Blog: Fix code bug
Browse files Browse the repository at this point in the history
  • Loading branch information
roninjin10 committed Oct 21, 2024
1 parent 236ebd2 commit 9924aea
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions docs/src/content/docs/blog/0_eip-1193-the-unsung-hero.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,38 @@ const httpTransport = loadBalance([
]);

let pendingTxs = [];
let tevmClient = createMemoryClient({
fork: { transport: httpTransport },
});

// Create our optimistic transport
const optimisticTransport = custom({
request: async (request) => {
const { method, params } = request;

if (method === 'eth_sendRawTransaction') {
pendingTxs.push(params[0]);
return '0xFakeTxHashForPending';
pendingTxs.push(request);
// refork when we send any tx
let newTevmClient = createMemoryClient({
fork: { transport: httpTransport },
});
await newTevmClient.ready()
. tevmClient = newTevmClient
return await httpTransport.request(request);
}

if (method === 'eth_getTransactionReceipt') {
const pendingIndex = pendingTxs.indexOf(params[0]);
if (pendingIndex > -1) {
const receipt = await httpTransport.request(request);
if (receipt) pendingTxs.splice(pendingIndex, 1);
return receipt;
}
const receipt = await httpTransport.request(request);
const pendingIndex = pendingTxs.findIndex(tx => tx.params[0] === params[0]);
if (receipt && pendingIndex) pendingTxs.splice(pendingIndex, 1);
return receipt;
}

if (method === 'eth_call' && params[1] === 'pending') {
const tevmClient = createMemoryClient({
fork: { transport: httpTransport },
});
for (const pendingTx of pendingTxs) {
await tevmClient.request(pendingTx);
}
await tevmClient.mine();
return tevmClient.request(request);
}

Expand Down

0 comments on commit 9924aea

Please sign in to comment.