Skip to content

Commit

Permalink
add --headers flag and support https://
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Dec 13, 2023
1 parent d81cb0a commit 89135ff
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 551 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See [MAINTAINERS.md](./MAINTAINERS.md)
for instructions to keep up to date.

## Unreleased

### Added

* added flag `--headers` (repeatable) to allow setting HTTP headers, e.g. "Authorization: bearer aGVsbG8K"
* added support for addresses prefixed by `http://` or `https://`

## v1.0.0-rc.1

### StreamingFast Firehose Bitcoin implementation

* Bitcoin blocks are fully compatible with the RPC blocks
* Bitcoin Block contains all transaction data, including `vins` and `vouts`*
* Bitcoin Block contains all transaction data, including `vins` and `vouts`*
34 changes: 33 additions & 1 deletion cmd/firebtc/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"strconv"
"strings"
"time"

"github.com/spf13/cobra"
Expand All @@ -26,6 +27,7 @@ func init() {
pollerCmd.Flags().Bool("ignore-cursor", false, "When enable it will ignore the cursor and start from the start block num, the cursor will still be saved as the poller progresses")
pollerCmd.Flags().Uint64("block-fetch-retry-count", 3, "The number of times to retry fetching a block before ending in error")
pollerCmd.Flags().String("reader-state-storage-path", "/localdata/", "The local path where the reader state will be stored, if blank no state will be stored")
pollerCmd.Flags().StringSliceP("headers", "H", nil, "List of HTTP headers to pass with the request (ex: 'Authorization: Basic ...')")
pollerCmd.Flags().Duration("graceful-shutdown-delay", 0*time.Millisecond, "delay before shutting down, after the health endpoint returns unhealthy")
pollerCmd.Flags().Duration("unready-period-delay", 0*time.Millisecond, "the delay starting the shutdown sequence after the health endpoint returns unhealthy")
}
Expand All @@ -37,6 +39,7 @@ func readerRunE(cmd *cobra.Command, args []string) error {
rpcEndpoint := sflags.MustGetString(cmd, "rpc-endpoint")
blockFetchRetryCount := sflags.MustGetUint64(cmd, "block-fetch-retry-count")
readerStateStoragePath := sflags.MustGetString(cmd, "reader-state-storage-path")
headerStrings := sflags.MustGetStringSlice(cmd, "headers")
gracefulShutdownDelay := sflags.MustGetDuration(cmd, "graceful-shutdown-delay")
unreadyPeriodDelay := sflags.MustGetDuration(cmd, "unready-period-delay")
ignoreCursor := sflags.MustGetBool(cmd, "ignore-cursor")
Expand All @@ -46,6 +49,7 @@ func readerRunE(cmd *cobra.Command, args []string) error {
zap.String("rpc_endpoint", rpcEndpoint),
zap.Uint64("block_fetch_retry_count", blockFetchRetryCount),
zap.String("reader_state_storage_path", readerStateStoragePath),
zap.Strings("reader_state_storage_path", headerStrings),
zap.Duration("graceful_shutdown_delay", gracefulShutdownDelay),
zap.Duration("unready_period_delay", unreadyPeriodDelay),
zap.Bool("ignore_cursor", ignoreCursor),
Expand All @@ -56,9 +60,37 @@ func readerRunE(cmd *cobra.Command, args []string) error {
return fmt.Errorf("unable to parse start block number %s: %w", startBlockNumStr, err)
}

p := poller.New(rpcEndpoint, blockFetchRetryCount, readerStateStoragePath, startBlockNum, ignoreCursor, zlog)
headers, err := parseHeaders(headerStrings)
if err != nil {
return err
}

var https bool
if strings.HasPrefix(rpcEndpoint, "https://") {
https = true
rpcEndpoint = strings.TrimPrefix(rpcEndpoint, "https://")
} else if strings.HasPrefix(rpcEndpoint, "http://") {
rpcEndpoint = strings.TrimPrefix(rpcEndpoint, "http://")
}

p := poller.New(rpcEndpoint, https, blockFetchRetryCount, readerStateStoragePath, startBlockNum, ignoreCursor, headers, zlog)
app := cli.NewApplication(ctx)
app.SuperviseAndStart(p)

return app.WaitForTermination(zlog, unreadyPeriodDelay, gracefulShutdownDelay)
}

func parseHeaders(headers []string) (map[string]string, error) {
if headers == nil {
return nil, nil
}
result := make(map[string]string)
for _, header := range headers {
parts := strings.Split(header, ":")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid header format: %s", header)
}
result[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
}
return result, nil
}
122 changes: 2 additions & 120 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ go 1.21.0

require (
github.com/btcsuite/btcd v0.23.4
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/spf13/cobra v1.8.0
github.com/streamingfast/bstream v0.0.2-0.20231123130020-ad84cce9666d
github.com/streamingfast/cli v0.0.4-0.20230825151644-8cc84512cd80
github.com/streamingfast/firehose-core v0.2.4-0.20231130152151-2e7b9f992f5b
github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091
github.com/streamingfast/shutter v1.5.0
github.com/stretchr/testify v1.8.4
github.com/test-go/testify v1.1.4
go.uber.org/zap v1.26.0
google.golang.org/protobuf v1.31.0
Expand All @@ -22,213 +20,97 @@ require (
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/monitoring v1.15.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cloud.google.com/go/trace v1.10.1 // indirect
contrib.go.opencensus.io/exporter/stackdriver v0.13.10 // indirect
contrib.go.opencensus.io/exporter/zipkin v0.1.1 // indirect
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/Azure/azure-storage-blob-go v0.14.0 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v0.32.3 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.15.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.39.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/propagator v0.0.0-20221018185641-36f91511cfd7 // indirect
github.com/KimMachineGun/automemlimit v0.2.4 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/RoaringBitmap/roaring v0.9.4 // indirect
github.com/ShinyTrinkets/meta-logger v0.2.0 // indirect
github.com/ShinyTrinkets/overseer v0.3.0 // indirect
github.com/abourget/llerrgroup v0.2.0 // indirect
github.com/aws/aws-sdk-go v1.44.325 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.3.1 // indirect
github.com/blendle/zapdriver v1.3.2-0.20200203083823-9200777f8a3d // indirect
github.com/bobg/go-generics/v2 v2.1.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/btcutil v1.1.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/bufbuild/connect-go v1.10.0 // indirect
github.com/bufbuild/connect-grpchealth-go v1.1.1 // indirect
github.com/bufbuild/connect-grpcreflect-go v1.0.0 // indirect
github.com/bufbuild/connect-opentelemetry-go v0.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chzyer/readline v1.5.0 // indirect
github.com/cilium/ebpf v0.4.0 // indirect
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/envoyproxy/go-control-plane v0.11.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-json-experiment/json v0.0.0-20231013223334-54c864be5b8d // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/boxo v0.8.0 // indirect
github.com/ipfs/go-cid v0.4.0 // indirect
github.com/ipfs/go-ipfs-api v0.6.0 // indirect
github.com/jhump/protoreflect v1.14.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josephburnett/jd v1.7.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.26.3 // indirect
github.com/lithammer/dedent v1.1.0 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-ieproxy v0.0.1 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mostynb/go-grpc-compression v1.1.17 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.8.0 // indirect
github.com/multiformats/go-multibase v0.1.1 // indirect
github.com/multiformats/go-multicodec v0.8.1 // indirect
github.com/multiformats/go-multihash v0.2.1 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/paulbellamy/ratecounter v0.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/rs/cors v1.10.0 // indirect
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/streamingfast/dauth v0.0.0-20230929180355-921f9c9be330 // indirect
github.com/streamingfast/dbin v0.9.1-0.20231117225723-59790c798e2c // indirect
github.com/streamingfast/derr v0.0.0-20230515163924-8570aaa43fe1 // indirect
github.com/streamingfast/dgrpc v0.0.0-20230929132851-893fc52687fa // indirect
github.com/streamingfast/dlauncher v0.0.0-20230607184145-76399faad89e // indirect
github.com/streamingfast/dmetering v0.0.0-20230731155453-e1df53e362aa // indirect
github.com/streamingfast/dmetrics v0.0.0-20230919161904-206fa8ebd545 // indirect
github.com/streamingfast/dstore v0.1.1-0.20230620124109-3924b3b36c77 // indirect
github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839 // indirect
github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0 // indirect
github.com/streamingfast/opaque v0.0.0-20210811180740-0c01d37ea308 // indirect
github.com/streamingfast/pbgo v0.0.6-0.20231120172814-537d034aad5e // indirect
github.com/streamingfast/sf-tracing v0.0.0-20230616174903-cd2ade641ca9 // indirect
github.com/streamingfast/snapshotter v0.0.0-20230316190750-5bcadfde44d0 // indirect
github.com/streamingfast/substreams v1.1.21-0.20231122013157-938ec26b0ef6 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf // indirect
github.com/tetratelabs/wazero v1.1.0 // indirect
github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c // indirect
github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.9.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.44.0 // indirect
go.opentelemetry.io/otel v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.15.1 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.15.1 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/sdk v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/automaxprocs v1.5.1 // indirect
go.uber.org/goleak v1.2.1 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/olivere/elastic.v3 v3.0.75 // indirect
gopkg.in/vrecan/death.v3 v3.0.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.25.0 // indirect
k8s.io/apimachinery v0.25.0 // indirect
k8s.io/client-go v0.25.0 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
lukechampine.com/blake3 v1.1.7 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

replace github.com/btcsuite/btcd => github.com/streamingfast/btcd v0.0.0-20231127171849-2aa489ba183d
Loading

0 comments on commit 89135ff

Please sign in to comment.