-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
311 additions
and
23,761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package blockreader | ||
package fetcher | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package fetcher | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/gagliardetto/solana-go/rpc" | ||
pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// todo: implement firecore.BlockFetcher | ||
type RPC struct { | ||
rpcClient *rpc.Client | ||
latest uint64 | ||
latestBlockRetryInterval time.Duration | ||
fetchInterval time.Duration | ||
lastFetchAt time.Time | ||
logger *zap.Logger | ||
} | ||
|
||
func (r *RPC) Fetch(ctx context.Context, blkNum uint64) (*pbbstream.Block, error) { | ||
blockResult, err := r.rpcClient.GetBlock(ctx, blkNum) | ||
if err != nil { | ||
return nil, fmt.Errorf("fetching block %d: %w", blkNum, err) | ||
} | ||
block := blockFromBlockResult(blockResult) | ||
return block, nil | ||
} | ||
|
||
func blockFromBlockResult(b *rpc.GetBlockResult) *pbbstream.Block { | ||
|
||
panic("implement me") | ||
block := &pbbstream.Block{ | ||
//Number: b.BlockHeight, | ||
//Id: "", | ||
//ParentId: "", | ||
//Timestamp: nil, | ||
//LibNum: 0, | ||
//PayloadKind: 0, | ||
//PayloadVersion: 0, | ||
//PayloadBuffer: nil, | ||
//HeadNum: 0, | ||
//ParentNum: 0, | ||
//Payload: nil, | ||
} | ||
|
||
return block | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,61 @@ | ||
package rpc | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/streamingfast/cli/sflags" | ||
firecore "github.com/streamingfast/firehose-core" | ||
"github.com/streamingfast/logging" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func NewPollerCmd(logger *zap.Logger, tracer logging.Tracer) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "rpc <start_block_num> <stop_block_num>", | ||
Use: "rpc <rpc-endpoint> <first-streamable-block>", | ||
Short: "poll blocks from rpc endpoint", | ||
Args: cobra.ExactArgs(2), | ||
RunE: pollerRunE(logger, tracer), | ||
} | ||
|
||
cmd.Flags().String("rpc-endpoint", "", "RPC endpoint") | ||
cmd.Flags().Duration("interval-between-fetch", 0, "interval between fetch") | ||
|
||
return cmd | ||
} | ||
|
||
func pollerRunE(logger *zap.Logger, tracer logging.Tracer) firecore.CommandExecutor { | ||
return func(cmd *cobra.Command, args []string) (err error) { | ||
//ctx := cmd.Context() | ||
rpcEndpoint := args[0] | ||
|
||
dataDir := sflags.MustGetString(cmd, "data-dir") | ||
stateDir := path.Join(dataDir, "poller-state") | ||
|
||
firstStreamableBlock, err := strconv.ParseUint(args[1], 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("unable to parse first streamable block %d: %w", firstStreamableBlock, err) | ||
} | ||
|
||
fetchInterval := sflags.MustGetDuration(cmd, "interval-between-fetch") | ||
|
||
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", firstStreamableBlock), | ||
zap.Duration("interval_between_fetch", fetchInterval), | ||
) | ||
|
||
//todo: init fetcher | ||
//todo: init poller handler | ||
//todo: init poller | ||
|
||
//todo: fetch latest block from chain rpc | ||
|
||
//todo: run the poller | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.