forked from cerc-io/ipld-eth-server
wrap generic top-level interfaces with loose types
This commit is contained in:
@@ -16,7 +16,10 @@
|
||||
|
||||
package shared
|
||||
|
||||
import "bytes"
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// ListContainsString used to check if a list of strings contains a particular string
|
||||
func ListContainsString(sss []string, s string) bool {
|
||||
@@ -47,3 +50,8 @@ func ListContainsGap(gapList []Gap, gap Gap) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsPointer returns true if the concrete type underneath the provided interface is a pointer
|
||||
func IsPointer(i interface{}) bool {
|
||||
return reflect.ValueOf(i).Type().Kind() == reflect.Ptr
|
||||
}
|
||||
|
||||
@@ -16,39 +16,45 @@
|
||||
|
||||
package shared
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/vulcanize/vulcanizedb/pkg/super_node/config"
|
||||
)
|
||||
|
||||
// PayloadStreamer streams chain-specific payloads to the provided channel
|
||||
type PayloadStreamer interface {
|
||||
Stream(payloadChan chan interface{}) (ClientSubscription, error)
|
||||
Stream(payloadChan chan RawChainData) (ClientSubscription, error)
|
||||
}
|
||||
|
||||
// PayloadFetcher fetches chain-specific payloads
|
||||
type PayloadFetcher interface {
|
||||
FetchAt(blockHeights []uint64) ([]interface{}, error)
|
||||
FetchAt(blockHeights []uint64) ([]RawChainData, error)
|
||||
}
|
||||
|
||||
// PayloadConverter converts chain-specific payloads into IPLD payloads for publishing
|
||||
type PayloadConverter interface {
|
||||
Convert(payload interface{}) (interface{}, error)
|
||||
Convert(payload RawChainData) (StreamedIPLDs, error)
|
||||
}
|
||||
|
||||
// IPLDPublisher publishes IPLD payloads and returns a CID payload for indexing
|
||||
type IPLDPublisher interface {
|
||||
Publish(payload interface{}) (interface{}, error)
|
||||
Publish(payload StreamedIPLDs) (CIDsForIndexing, error)
|
||||
}
|
||||
|
||||
// CIDIndexer indexes a CID payload in Postgres
|
||||
type CIDIndexer interface {
|
||||
Index(cids interface{}) error
|
||||
Index(cids CIDsForIndexing) error
|
||||
}
|
||||
|
||||
// ResponseFilterer applies a filter to an IPLD payload to return a subscription response packet
|
||||
type ResponseFilterer interface {
|
||||
Filter(filter, payload interface{}) (response interface{}, err error)
|
||||
Filter(filter SubscriptionSettings, payload StreamedIPLDs) (response ServerResponse, err error)
|
||||
}
|
||||
|
||||
// CIDRetriever retrieves cids according to a provided filter and returns a CID wrapper
|
||||
type CIDRetriever interface {
|
||||
Retrieve(filter interface{}, blockNumber int64) (interface{}, bool, error)
|
||||
Retrieve(filter SubscriptionSettings, blockNumber int64) (CIDsForFetching, bool, error)
|
||||
RetrieveFirstBlockNumber() (int64, error)
|
||||
RetrieveLastBlockNumber() (int64, error)
|
||||
RetrieveGapsInData() ([]Gap, error)
|
||||
@@ -56,12 +62,12 @@ type CIDRetriever interface {
|
||||
|
||||
// IPLDFetcher uses a CID wrapper to fetch an IPLD wrapper
|
||||
type IPLDFetcher interface {
|
||||
Fetch(cids interface{}) (interface{}, error)
|
||||
Fetch(cids CIDsForFetching) (FetchedIPLDs, error)
|
||||
}
|
||||
|
||||
// IPLDResolver resolves an IPLD wrapper into chain-specific payloads
|
||||
type IPLDResolver interface {
|
||||
Resolve(iplds interface{}) (interface{}, error)
|
||||
Resolve(iplds FetchedIPLDs) (ServerResponse, error)
|
||||
}
|
||||
|
||||
// ClientSubscription is a general interface for chain data subscriptions
|
||||
@@ -74,3 +80,15 @@ type ClientSubscription interface {
|
||||
type DagPutter interface {
|
||||
DagPut(raw interface{}) ([]string, error)
|
||||
}
|
||||
|
||||
// SubscriptionSettings is the interface every subscription filter type needs to satisfy, no matter the chain
|
||||
// Further specifics of the underlying filter type depend on the internal needs of the types
|
||||
// which satisfy the ResponseFilterer and CIDRetriever interfaces for a specific chain
|
||||
// The underlying type needs to be rlp serializable
|
||||
type SubscriptionSettings interface {
|
||||
StartingBlock() *big.Int
|
||||
EndingBlock() *big.Int
|
||||
ChainType() config.ChainType
|
||||
HistoricalData() bool
|
||||
HistoricalDataOnly() bool
|
||||
}
|
||||
|
||||
@@ -16,6 +16,29 @@
|
||||
|
||||
package shared
|
||||
|
||||
// These types serve as very loose wrappers around a generic underlying interface{}
|
||||
type RawChainData interface{}
|
||||
|
||||
// The concrete type underneath StreamedIPLDs can be a pointer only if the Value() method returns a copy of the values
|
||||
// stored at that memory location and not a copy of the pointer itself.
|
||||
// We want to avoid sending a pointer to publishAndIndex and screenAndServe channels; sharing memory across these processes
|
||||
type StreamedIPLDs interface {
|
||||
Value() StreamedIPLDs
|
||||
}
|
||||
|
||||
type CIDsForIndexing interface{}
|
||||
|
||||
type CIDsForFetching interface{}
|
||||
|
||||
type FetchedIPLDs interface{}
|
||||
|
||||
// The concrete type underneath StreamedIPLDs can be a pointer only if the Value() method returns a copy of the values
|
||||
// stored at that memory location and not a copy of the pointer itself.
|
||||
// We want to avoid sending a pointer to subscription channels; sharing memory across all subscriptions
|
||||
type ServerResponse interface {
|
||||
Value() ServerResponse
|
||||
}
|
||||
|
||||
type Gap struct {
|
||||
Start uint64
|
||||
Stop uint64
|
||||
|
||||
Reference in New Issue
Block a user