Skip to content

Commit

Permalink
remove deps on firecore to launch the poller
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Jan 16, 2024
1 parent e14e3cf commit de640ea
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 159 deletions.
6 changes: 1 addition & 5 deletions block/fetcher/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"math"
"time"
Expand Down Expand Up @@ -179,14 +178,11 @@ func toPbTransactions(transactions []rpc.TransactionWithMeta) (out []*pbsol.Conf
if err != nil {
return nil, fmt.Errorf(`decoding transaction meta: %w`, err)
}
solanaTrx := &solana.Transaction{}
transaction.Transaction.GetRawJSON()
err = json.Unmarshal(transaction.Transaction.GetRawJSON(), solanaTrx)
if err != nil {
return nil, fmt.Errorf(`decoding transaction: %w`, err)
}
out = append(out, &pbsol.ConfirmedTransaction{
Transaction: toPbTransaction(solanaTrx),
Transaction: toPbTransaction(transaction.MustGetTransaction()),
Meta: meta,
})
}
Expand Down
16 changes: 0 additions & 16 deletions cmd/firesol/bigtable/commands.go

This file was deleted.

79 changes: 0 additions & 79 deletions cmd/firesol/bigtable/poller.go

This file was deleted.

58 changes: 25 additions & 33 deletions cmd/firesol/main.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"
firecore "github.com/streamingfast/firehose-core"
fhCmd "github.com/streamingfast/firehose-core/cmd"
"github.com/streamingfast/firehose-core/node-manager/mindreader"
pbsol "github.com/streamingfast/firehose-solana/pb/sf/solana/type/v1"
"github.com/streamingfast/firehose-solana/cmd/firesol/rpc"
"github.com/streamingfast/logging"
"go.uber.org/zap"
"google.golang.org/protobuf/reflect/protoreflect"
)

func main() {
fhCmd.Main(Chain())
var logger, tracer = logging.PackageLogger("firesol", "github.com/streamingfast/firehose-solana")
var rootCmd = &cobra.Command{
Use: "firesol",
Short: "firesol poller and tooling",
}

func Chain() *firecore.Chain[*pbsol.Block] {
return &firecore.Chain[*pbsol.Block]{
ShortName: "sol",
LongName: "Solana",
ExecutableName: "firesol",
FullyQualifiedModule: "github.com/streamingfast/firehose-solana",
Version: version,

BlockFactory: func() firecore.Block { return new(pbsol.Block) },

BlockIndexerFactories: map[string]firecore.BlockIndexerFactory[*pbsol.Block]{},

BlockTransformerFactories: map[protoreflect.FullName]firecore.BlockTransformerFactory{},
ConsoleReaderFactory: func(lines chan string, blockEncoder firecore.BlockEncoder, logger *zap.Logger, tracer logging.Tracer) (mindreader.ConsolerReader, error) {
panic("should not be used!")
},

Tools: &firecore.ToolsConfig[*pbsol.Block]{
func init() {
logging.InstantiateLoggers(logging.WithDefaultLevel(zap.InfoLevel))
rootCmd.AddCommand(newPollerCmd(logger, tracer))
}

RegisterExtraCmd: func(chain *firecore.Chain[*pbsol.Block], toolsCmd *cobra.Command, zlog *zap.Logger, tracer logging.Tracer) error {
toolsCmd.AddCommand(newPollerCmd(zlog, tracer))
//toolsCmd.AddCommand(bigtable.NewBigTableCmd(zlog, tracer))
return nil
},
},
func main() {
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Whoops. There was an error while executing your CLI '%s'", err)
os.Exit(1)
}
}

// Version value, injected via go build `ldflags` at build time, **must** not be removed or inlined
var version = "dev"
func newPollerCmd(logger *zap.Logger, tracer logging.Tracer) *cobra.Command {
cmd := &cobra.Command{
Use: "poller",
Short: "poll blocks from different sources",
Args: cobra.ExactArgs(2),
}
cmd.AddCommand(rpc.NewPollerCmd(logger, tracer))
return cmd
}
22 changes: 0 additions & 22 deletions cmd/firesol/poller.go

This file was deleted.

6 changes: 2 additions & 4 deletions cmd/firesol/rpc/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rpc

import (
"fmt"
"path"
"strconv"
"time"

Expand All @@ -25,6 +24,7 @@ func NewPollerCmd(logger *zap.Logger, tracer logging.Tracer) *cobra.Command {
RunE: pollerRunE(logger, tracer),
}

cmd.Flags().String("state-dir", "/data/poller", "interval between fetch")
cmd.Flags().Duration("interval-between-fetch", 0, "interval between fetch")

return cmd
Expand All @@ -35,8 +35,7 @@ func pollerRunE(logger *zap.Logger, tracer logging.Tracer) firecore.CommandExecu
ctx := cmd.Context()
rpcEndpoint := args[0]

dataDir := sflags.MustGetString(cmd, "data-dir")
stateDir := path.Join(dataDir, "poller-state")
stateDir := sflags.MustGetString(cmd, "state-dir")

startBlock, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
Expand All @@ -48,7 +47,6 @@ func pollerRunE(logger *zap.Logger, tracer logging.Tracer) firecore.CommandExecu
logger.Info(
"launching firehose-solana poller",
zap.String("rpc_endpoint", rpcEndpoint),
zap.String("data_dir", dataDir),
zap.String("state_dir", stateDir),
zap.Uint64("first_streamable_block", startBlock),
zap.Duration("interval_between_fetch", fetchInterval),
Expand Down
Loading

0 comments on commit de640ea

Please sign in to comment.