chore: add shrederClient exaple

This commit is contained in:
2025-12-26 11:34:45 +08:00
parent 0d2e29cacf
commit 99010ca601
4 changed files with 126 additions and 49 deletions

View File

@@ -1,4 +1,4 @@
package shreder_client
package shreder
import (
"context"
@@ -14,20 +14,26 @@ import (
type ShrederClient struct {
log logger.Logger
conn *grpc.ClientConn
client shreder_protos.ShrederServiceClient
conn *grpc.ClientConn
client shreder_protos.ShrederServiceClient
subscription map[string]*shreder_protos.SubscribeRequestFilterTransactions
}
func NewShrederClient(logger logger.Logger, url string) (*ShrederClient, func(), error) {
func NewShrederClient(
logger logger.Logger,
url string,
subscription map[string]*shreder_protos.SubscribeRequestFilterTransactions,
) (*ShrederClient, func(), error) {
conn, err := grpc.NewClient(url, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, func() {}, err
}
s := &ShrederClient{
log: logger,
conn: conn,
client: shreder_protos.NewShrederServiceClient(conn),
log: logger,
conn: conn,
client: shreder_protos.NewShrederServiceClient(conn),
subscription: subscription,
}
return s, func() {
@@ -53,28 +59,7 @@ func (c *ShrederClient) ReadSync(ctx context.Context, txCh chan<- types.TxSignal
}
err = stream.Send(&shreder_protos.SubscribeTransactionsRequest{
Transactions: map[string]*shreder_protos.SubscribeRequestFilterTransactions{
"pumpfun": {
AccountRequired: []string{
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P",
},
},
"axiom": {
AccountRequired: []string{
"F5tfvbLog9VdGUPqBDTT8rgXvTTcq7e5UiGnupL1zvBq",
},
},
"photon": {
AccountRequired: []string{
"BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW",
},
},
"fjsz": {
AccountRequired: []string{
"FJsZbftBqRLfF7uqUKpm4s2goDr6xsQ5Q3mN7AFJB6hK",
},
},
},
Transactions: c.subscription,
})
if err != nil {
return err