Skip to content

Commit

Permalink
feat: store pending TXs that are not found on geth node
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderheijden86 committed Sep 7, 2022
1 parent c3ef4ff commit 699b31c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions mempoolexplorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"log"
)

var missingTxs = make([]common.Hash, 0, 20)

func main() {
pendingTxs := streamMemPoolTxs(createGethClient(), 5)
for {
Expand All @@ -35,6 +37,7 @@ func printTxDetails(txHash common.Hash) {
// If TX is not found, just print the error and return so the rest of the program can continue. If there's an other error then log and exit.
if err == ethereum.NotFound {
log.Println(err)
storeMissingTxHashes(txHash)
return
} else if err != nil {
log.Fatal(err)
Expand All @@ -49,3 +52,7 @@ func printTxDetails(txHash common.Hash) {
fmt.Println(tx.To().Hex()) // 0x55fE59D8Ad77035154dDd0AD0388D09Dd4047A8e
fmt.Println("isPending: ", isPending) // true
}

func storeMissingTxHashes(txHash common.Hash) {
missingTxs = append(missingTxs, txHash)
}
10 changes: 8 additions & 2 deletions mempoolexplorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ func TestMain_getTxDetails(t *testing.T) {
}

func TestMain_getTxDetails_Live(t *testing.T) {
pendingTxs := streamMemPoolTxs(createGethClient(), 100)
for {
pendingTxs := streamMemPoolTxs(createGethClient(), 10)
for i := 1; i < 25; i++ {
currentTxHash := <-pendingTxs
fmt.Println(currentTxHash)
printTxDetails(currentTxHash)
}

fmt.Println("Pending TXs not found on geth node:")
for _, txHash := range missingTxs {
fmt.Println(txHash.Hex())
}

}

0 comments on commit 699b31c

Please sign in to comment.