chore: add shrederClient exaple
This commit is contained in:
@@ -1,7 +1,76 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
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() {
|
||||
fmt.Println("Hello, World!")
|
||||
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()
|
||||
|
||||
txCh := make(chan types.TxSignalBatch, 1000)
|
||||
|
||||
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
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user