Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Filter out incoming transactions from etherscan response (#130)
Browse files Browse the repository at this point in the history
* fix: filter out incoming transactions from etherscan response

* chore: bump version
  • Loading branch information
michalsidzej authored Feb 7, 2024
1 parent 6078d28 commit 2354d3b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/discovery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @l2beat/discovery

## 0.40.1

### Patch Changes

- Filter out incoming transactions from etherscan response

## 0.40.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/discovery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@l2beat/discovery",
"description": "L2Beat discovery - engine & tooling utilized for keeping an eye on L2s",
"version": "0.40.0",
"version": "0.40.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export class OpStackDAHandler implements ClassicHandler {
previousResults,
)
const sequencerAddress = valueToAddress(resolved)
const last10Txs = await provider.getLast10Txs(sequencerAddress, blockNumber)
const last10Txs = await provider.getLast10OutgoingTxs(
sequencerAddress,
blockNumber,
)

const isSomeTxsLengthEqualToCelestiaDAExample = last10Txs.some(
(tx) => tx.input.length === OP_STACK_CELESTIA_DA_EXAMPLE_INPUT.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export class OpStackSequencerInboxHandler implements ClassicHandler {
)
const sequencerAddress = valueToAddress(resolved)

const last10Txs = await provider.getLast10Txs(sequencerAddress, blockNumber)
const last10Txs = await provider.getLast10OutgoingTxs(
sequencerAddress,
blockNumber,
)

// check if all last 10 txs have the same to address
const toAddress = last10Txs[0]?.to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ export class DiscoveryProvider {
return this.etherscanLikeClient.getBlockNumberAtOrBefore(timestampNumber)
}

async getLast10Txs(
async getLast10OutgoingTxs(
address: EthereumAddress,
toBlock: number,
): ReturnType<EtherscanLikeClient['getLast10Txs']> {
return await this.etherscanLikeClient.getLast10Txs(address, toBlock)
): ReturnType<EtherscanLikeClient['getLast10OutgoingTxs']> {
return await this.etherscanLikeClient.getLast10OutgoingTxs(address, toBlock)
}
}
22 changes: 17 additions & 5 deletions packages/discovery/src/utils/EtherscanLikeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class EtherscanLikeClient {
return new UnixTime(parseInt(resp.timeStamp, 10))
}

async getLast10Txs(
async getLast10OutgoingTxs(
address: EthereumAddress,
blockNumber: number,
): Promise<{ input: string; to: EthereumAddress }[]> {
Expand All @@ -146,14 +146,26 @@ export class EtherscanLikeClient {
startblock: '0',
endblock: blockNumber.toString(),
page: '1',
offset: '10',
offset: '20',
sort: 'desc',
})

const resp = TenTransactionListResult.parse(response)
const resp = TwentyTransactionListResult.parse(response)
assert(resp)
const outgoingTxs = resp
.filter((tx) => EthereumAddress(tx.from) === address)
.slice(0, 10)

assert(
outgoingTxs.length === 10,
'Not enough outgoing transactions, expected 10, received ' +
outgoingTxs.length.toString(),
)

return resp.map((r) => ({ input: r.input, to: EthereumAddress(r.to) }))
return outgoingTxs.map((r) => ({
input: r.input,
to: EthereumAddress(r.to),
}))
}

async call(
Expand Down Expand Up @@ -285,4 +297,4 @@ export const TransactionListEntry = z.object({
})

const OneTransactionListResult = z.array(TransactionListEntry).length(1)
const TenTransactionListResult = z.array(TransactionListEntry).length(10)
const TwentyTransactionListResult = z.array(TransactionListEntry).length(20)

0 comments on commit 2354d3b

Please sign in to comment.