hack/lookup_txes: be smarter about searching within a range
commit-id:944810ec
This commit is contained in:
parent
2a7c32ca3f
commit
8aedb5b315
|
@ -6,6 +6,8 @@ import (
|
||||||
"github.com/gagliardetto/solana-go/rpc"
|
"github.com/gagliardetto/solana-go/rpc"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
"log"
|
"log"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -24,21 +26,8 @@ const (
|
||||||
var (
|
var (
|
||||||
emitter = solana.MustPublicKeyFromBase58("Gv1KWf8DT1jKv5pKBmGaTmVszqa56Xn8YGx2Pg7i7qAk")
|
emitter = solana.MustPublicKeyFromBase58("Gv1KWf8DT1jKv5pKBmGaTmVszqa56Xn8YGx2Pg7i7qAk")
|
||||||
|
|
||||||
want = []string{
|
want = []int{
|
||||||
"66",
|
25958,
|
||||||
"79",
|
|
||||||
"442",
|
|
||||||
"508",
|
|
||||||
"692",
|
|
||||||
"782",
|
|
||||||
"908",
|
|
||||||
"920",
|
|
||||||
"942",
|
|
||||||
"1069",
|
|
||||||
"1075",
|
|
||||||
"1083",
|
|
||||||
"1153",
|
|
||||||
"1184",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +42,13 @@ func main() {
|
||||||
|
|
||||||
sigs := make([]solana.Signature, 0, limit*2)
|
sigs := make([]solana.Signature, 0, limit*2)
|
||||||
|
|
||||||
|
sort.Slice(want, func(i, j int) bool {
|
||||||
|
return want[i] < want[j]
|
||||||
|
})
|
||||||
|
|
||||||
|
minWant := want[0]
|
||||||
|
maxWant := want[len(want)-1]
|
||||||
|
|
||||||
for {
|
for {
|
||||||
err := limiter.Wait(ctx)
|
err := limiter.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,7 +83,15 @@ func main() {
|
||||||
|
|
||||||
log.Printf("found a total of %d transactions", len(sigs))
|
log.Printf("found a total of %d transactions", len(sigs))
|
||||||
|
|
||||||
|
skip := 0
|
||||||
|
|
||||||
|
OUTER:
|
||||||
for _, sig := range sigs {
|
for _, sig := range sigs {
|
||||||
|
if skip > 0 {
|
||||||
|
skip--
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
out, err := c.GetConfirmedTransaction(ctx, sig)
|
out, err := c.GetConfirmedTransaction(ctx, sig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("GetConfirmedTransaction %s: %v", sig, err)
|
log.Fatalf("GetConfirmedTransaction %s: %v", sig, err)
|
||||||
|
@ -96,13 +100,30 @@ func main() {
|
||||||
for _, msg := range out.Meta.LogMessages {
|
for _, msg := range out.Meta.LogMessages {
|
||||||
if strings.HasPrefix(msg, "Program log: Sequence:") {
|
if strings.HasPrefix(msg, "Program log: Sequence:") {
|
||||||
seq := msg[23:]
|
seq := msg[23:]
|
||||||
//log.Printf("%s %s", sig, seq)
|
log.Printf("%s %s", sig, seq)
|
||||||
|
|
||||||
|
seqInt, err := strconv.Atoi(seq)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed to parse seq %s: %v", seq, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, w := range want {
|
for _, w := range want {
|
||||||
if w == seq {
|
if w == seqInt {
|
||||||
log.Printf("FOUND https://explorer.solana.com/tx/%s seq %s", sig, seq)
|
log.Printf("FOUND https://explorer.solana.com/tx/%s seq %s", sig, seq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if seqInt > maxWant {
|
||||||
|
skip = (seqInt - maxWant) / 2
|
||||||
|
log.Printf("max=%d, cur=%d, skipping %d", maxWant, seqInt, skip)
|
||||||
|
continue OUTER
|
||||||
|
}
|
||||||
|
|
||||||
|
if seqInt < minWant {
|
||||||
|
log.Printf("min=%d, cur=%d, we're done", minWant, seqInt)
|
||||||
|
break OUTER
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue