loading address tables

This commit is contained in:
thloyi
2026-01-05 12:45:32 +08:00
parent 4afa412231
commit e6922e4561
7 changed files with 178 additions and 20 deletions

View File

@@ -2,35 +2,39 @@ package shreder
import (
"context"
"log/slog"
"fmt"
"github.com/gagliardetto/solana-go/rpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
type Client struct {
log *slog.Logger
conn *grpc.ClientConn
client ShrederServiceClient
tableLoader *AddressTables
subscription map[string]*SubscribeRequestFilterTransactions
}
func NewShrederClient(
url string,
rpcClient *rpc.Client,
subscription map[string]*SubscribeRequestFilterTransactions,
) (*Client, func(), error) {
if rpcClient == nil {
return nil, func() {}, fmt.Errorf("rpc client is nil")
}
conn, err := grpc.NewClient(url, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, func() {}, err
}
logger := slog.Default()
s := &Client{
log: logger,
conn: conn,
client: NewShrederServiceClient(conn),
subscription: subscription,
tableLoader: NewAddressTables(rpcClient),
}
return s, func() {
@@ -39,14 +43,14 @@ func NewShrederClient(
}
func (c *Client) Wait() {
c.log.Debug("waiting for shreder client to stop")
logger.Debug("waiting for shreder client to stop")
err := c.conn.Close()
if err != nil {
c.log.Error("failed to close connection: ", "err", err)
logger.Error("failed to close connection: ", "err", err)
}
c.log.Debug("shreder client stopped")
logger.Debug("shreder client stopped")
}
func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignalBatch) error {
@@ -68,7 +72,7 @@ func (c *Client) ReadSync(ctx context.Context, txCh chan<- TxSignalBatch) error
return err
}
txBatch := ParseTransaction(response.Transaction)
txBatch := ParseTransaction(response.Transaction, c.tableLoader)
if len(txBatch) == 0 {
continue
}