Files
libsam/cmd/shreder/main.go

84 lines
1.7 KiB
Go
Raw Permalink Normal View History

2025-12-26 10:57:37 +08:00
package main
2025-12-26 11:34:45 +08:00
import (
"context"
"errors"
"fmt"
2026-01-05 12:45:32 +08:00
"log/slog"
2025-12-26 11:34:45 +08:00
"os"
"os/signal"
"syscall"
2026-01-05 12:45:32 +08:00
"github.com/gagliardetto/solana-go/rpc"
2025-12-26 11:34:45 +08:00
"github.com/samlior/libsam/pkg/shreder"
)
2025-12-26 10:57:37 +08:00
func main() {
2025-12-26 11:34:45 +08:00
url := os.Getenv("URL")
if url == "" {
panic("URL is not set")
}
2026-01-05 12:45:32 +08:00
rpcUrl := os.Getenv("RPC_URL")
if rpcUrl == "" {
panic("RPC_URL is not set")
}
rpcClient := rpc.New(rpcUrl)
shreder.SetLogLevel(slog.LevelDebug)
2025-12-26 11:34:45 +08:00
shrederClient, cleanup, err := shreder.NewShrederClient(
url,
2026-01-05 12:45:32 +08:00
rpcClient,
2025-12-30 11:03:11 +08:00
map[string]*shreder.SubscribeRequestFilterTransactions{
2025-12-26 11:34:45 +08:00
"pumpfunamm": {
2026-01-05 12:45:32 +08:00
//AccountRequired: []string{
// "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
//},
AccountInclude: []string{
2025-12-26 11:34:45 +08:00
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
2026-01-05 12:45:32 +08:00
"GS4CU59F31iL7aR2Q8zVS8DRrcRnXX1yjQ66TqNVQnaR", //Event Authority
"5PHirr8joyTMp9JMm6nW7hNDVyEYdkzDqazxPD7RaTjx", // Fee Config
2025-12-26 11:34:45 +08:00
},
},
"photon": {
AccountRequired: []string{
"BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW",
},
},
// TODO: axiom, gmgn, etc.
})
if err != nil {
panic(err)
}
defer cleanup()
exitSignal := make(chan os.Signal, 1)
ctx, cancel := context.WithCancel(context.Background())
signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-exitSignal
cancel()
}()
// async read from shreder
2025-12-30 11:03:11 +08:00
txCh := make(chan shreder.TxSignalBatch, 1000)
2025-12-26 11:34:45 +08:00
go func() {
err := shrederClient.ReadSync(ctx, txCh)
if err != nil {
if !errors.Is(err, context.Canceled) {
panic(err)
}
}
}()
for {
select {
case <-ctx.Done():
return
case txBatch := <-txCh:
2026-01-05 12:45:32 +08:00
//jsonData, _ := json.MarshalIndent(txBatch, "", " ")
fmt.Println(txBatch[0].TxHash)
2025-12-26 11:34:45 +08:00
}
}
2025-12-26 10:57:37 +08:00
}