Files
libsam/cmd/shreder/main.go
2025-12-26 12:03:05 +08:00

76 lines
1.4 KiB
Go

package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/samlior/libsam/pkg/logger"
"github.com/samlior/libsam/pkg/shreder"
"github.com/samlior/libsam/pkg/types"
"github.com/samlior/libsam/third_party/shreder_protos"
)
func main() {
url := os.Getenv("URL")
if url == "" {
panic("URL is not set")
}
logger := logger.NewEmptyLogger()
shrederClient, cleanup, err := shreder.NewShrederClient(
logger,
url,
map[string]*shreder_protos.SubscribeRequestFilterTransactions{
"pumpfunamm": {
AccountRequired: []string{
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
},
},
"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
txCh := make(chan types.TxSignalBatch, 1000)
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:
jsonData, _ := json.MarshalIndent(txBatch, "", " ")
fmt.Println(string(jsonData))
}
}
}