erigon-pulse/cmd/rpcdaemon/commands/otterscan_search_multi.go
Willian Mitsuda 11f4978ed4
Upstream all Otterscan patches to devel (#5945)
Following our previous discussion on erigon's discord, this PR requests
to upstream all Otterscan modifications to erigon's repo.

That decision comes after getting feedback from lots of users at events
this year, and although it may introduce some friction for development,
it will make integrators life easier by having all our modifications
available out of box, e.g., dappnode users will get our RPCs since their
official packages are built from erigon repo.

I'm submitting the source-code as-is, please let me know if you think
there is a better code organization.

The current set of modifications comprises only new RPCs. There are some
proposals for extra-stages that would add new tables, but they are still
WIP and will be submitted separately in future after more testing.
2022-11-03 11:32:15 +07:00

64 lines
1.4 KiB
Go

package commands
func newCallFromToBlockProvider(isBackwards bool, callFromProvider, callToProvider BlockProvider) BlockProvider {
var nextFrom, nextTo uint64
var hasMoreFrom, hasMoreTo bool
initialized := false
return func() (uint64, bool, error) {
if !initialized {
initialized = true
var err error
if nextFrom, hasMoreFrom, err = callFromProvider(); err != nil {
return 0, false, err
}
hasMoreFrom = hasMoreFrom || nextFrom != 0
if nextTo, hasMoreTo, err = callToProvider(); err != nil {
return 0, false, err
}
hasMoreTo = hasMoreTo || nextTo != 0
}
if !hasMoreFrom && !hasMoreTo {
return 0, false, nil
}
var blockNum uint64
if !hasMoreFrom {
blockNum = nextTo
} else if !hasMoreTo {
blockNum = nextFrom
} else {
blockNum = nextFrom
if isBackwards {
if nextTo < nextFrom {
blockNum = nextTo
}
} else {
if nextTo > nextFrom {
blockNum = nextTo
}
}
}
// Pull next; it may be that from AND to contains the same blockNum
if hasMoreFrom && blockNum == nextFrom {
var err error
if nextFrom, hasMoreFrom, err = callFromProvider(); err != nil {
return 0, false, err
}
hasMoreFrom = hasMoreFrom || nextFrom != 0
}
if hasMoreTo && blockNum == nextTo {
var err error
if nextTo, hasMoreTo, err = callToProvider(); err != nil {
return 0, false, err
}
hasMoreTo = hasMoreTo || nextTo != 0
}
return blockNum, hasMoreFrom || hasMoreTo, nil
}
}