eosws

package
v0.9.0-beta9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 62 Imported by: 0

README

eosws - EOSIO websocket and REST service

EOSIO-specific websocket interface, REST interface, Push guarantee instrumented /v1/chain/push_transaction endpoint, and pass-through to statedb.

DEPRECATION NOTICE

The features herein are scheduled to be migrated to separate REST service, push-guarantee service, some are to be moved to a better unified GraphQL interface. The Websocket interface is to be carried over to the GraphQL subscriptions eventually.

New things are not to be built on this project.

Usage

You can view rendered documentation for the REST and Websocket endpoints here:

Overview

This service provides REST endpoints for:

  • transaction push guarantee
  • paginated search
  • websocket streaming services
  • pass-through to nodeos nodes
  • pass-through to reach StateDB (historical state database)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DisabledWsMessage map[string]interface{}
View Source
var NowFunc func() time.Time

Functions

func AppHeadInfoNotReadyError

func AppHeadInfoNotReadyError(ctx context.Context) *derr.ErrorResponse

func AppPriceNotReadyError

func AppPriceNotReadyError(ctx context.Context) *derr.ErrorResponse

func AppTableRowsCannotFetchInFutureError

func AppTableRowsCannotFetchInFutureError(ctx context.Context, blockNum uint32) *derr.ErrorResponse

func AppUnableToGetIrreversibleBlockIDError

func AppUnableToGetIrreversibleBlockIDError(ctx context.Context, identifier string) *derr.ErrorResponse

func AppVoteTallyNotReadyError

func AppVoteTallyNotReadyError(ctx context.Context) *derr.ErrorResponse

func AuthInvalidStreamingStartBlockError

func AuthInvalidStreamingStartBlockError(
	ctx context.Context,
	actualBlockNum uint32,
	requestedStartBlock uint32,
	authStartBlock uint32,
) *derr.ErrorResponse

func AuthInvalidTierError

func AuthInvalidTierError(ctx context.Context, tier string, expectedTier string) *derr.ErrorResponse

func AuthInvalidTokenError

func AuthInvalidTokenError(ctx context.Context, cause error, token string) *derr.ErrorResponse

func AuthTokenMissingError

func AuthTokenMissingError(ctx context.Context) *derr.ErrorResponse

func CompressionMiddleware

func CompressionMiddleware(next http.Handler) http.Handler

func DBABINotFoundError

func DBABINotFoundError(ctx context.Context, account string) *derr.ErrorResponse

func DBAccountNotFoundError

func DBAccountNotFoundError(ctx context.Context, account string) *derr.ErrorResponse

func DBBlockNotFoundError

func DBBlockNotFoundError(ctx context.Context, identifier string) *derr.ErrorResponse

func DBForumProposalNotFoundError

func DBForumProposalNotFoundError(ctx context.Context, proposalName string) *derr.ErrorResponse

func DBTrxAppearanceTimeoutError

func DBTrxAppearanceTimeoutError(ctx context.Context, blockID string, trxID string) *derr.ErrorResponse

func DBTrxNotFoundError

func DBTrxNotFoundError(ctx context.Context, trxID string) *derr.ErrorResponse

func DfuseErrorHandler

func DfuseErrorHandler(w http.ResponseWriter, ctx context.Context, err error)

func EOSChainErrorHandler

func EOSChainErrorHandler(w http.ResponseWriter, ctx context.Context, err error)

func FowardErrorResponse

func FowardErrorResponse(w http.ResponseWriter, r *http.Request, response *http.Response)

func GetBinanceData

func GetBinanceData() (d *wsmsg.PriceResp, err error)

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

func NewCORSMiddleware

func NewCORSMiddleware() mux.MiddlewareFunc

func NewParameterizedTestContext

func NewParameterizedTestContext(hexTraceID string, spanName string) context.Context

func NewTestContext

func NewTestContext() context.Context

func OpenCensusMiddleware

func OpenCensusMiddleware(next http.Handler) http.Handler

func PreTrackingMiddleware

func PreTrackingMiddleware(next http.Handler) http.Handler

func RESTTrackingMiddleware

func RESTTrackingMiddleware(next http.Handler) http.Handler

func Retry

func Retry(ctx context.Context, attempts int, sleep time.Duration, callback func() error) (err error)

func TrackUserEvent

func TrackUserEvent(ctx context.Context, name string, keyvals ...interface{})

TrackUserEvent tracks a event `name` with a set of key/value pairs for a particular user.

**Important** If your read this from a call site **DO NOT** modify call site arguments unless you correctly ensures BigQuery analytics view are ready to handle the changes. If you are not sure of what you are doing, ask someone from the devops team.

func ValidateBlocksRequest

func ValidateBlocksRequest(r *http.Request) url.Values

func ValidateListRequest

func ValidateListRequest(r *http.Request) url.Values

func WSAlreadyClosedError

func WSAlreadyClosedError(ctx context.Context) *derr.ErrorResponse

func WSBinaryMessageUnsupportedError

func WSBinaryMessageUnsupportedError(ctx context.Context) *derr.ErrorResponse

func WSInvalidJSONMessageDataError

func WSInvalidJSONMessageDataError(ctx context.Context, messageType string, err error) *derr.ErrorResponse

func WSInvalidJSONMessageError

func WSInvalidJSONMessageError(ctx context.Context, err error) *derr.ErrorResponse

func WSMessageDataValidationError

func WSMessageDataValidationError(ctx context.Context, err error) *derr.ErrorResponse

func WSStreamAlreadyExistError

func WSStreamAlreadyExistError(ctx context.Context, requestID string) *derr.ErrorResponse

func WSStreamNotFoundError

func WSStreamNotFoundError(ctx context.Context, requestID string) *derr.ErrorResponse

func WSTooMuchStreamError

func WSTooMuchStreamError(ctx context.Context, streamCount int, maxStreamCount int) *derr.ErrorResponse

func WSUnableToUpgradeConnectionError

func WSUnableToUpgradeConnectionError(ctx context.Context, status int, cause error) *derr.ErrorResponse

func WSUnavailableMessageError

func WSUnavailableMessageError(ctx context.Context, messageType string) *derr.ErrorResponse

func WSUnknownMessageError

func WSUnknownMessageError(ctx context.Context, messageType string) *derr.ErrorResponse

func WriteError

func WriteError(w http.ResponseWriter, r *http.Request, err error)

func WriteJSON

func WriteJSON(w http.ResponseWriter, r *http.Request, v interface{})

func WriterStatus

func WriterStatus(w http.ResponseWriter) (int, error)

Types

type ABIChangeHandler

type ABIChangeHandler struct {
	// contains filtered or unexported fields
}

func NewABIChangeHandler

func NewABIChangeHandler(abiGetter ABIGetter, blockNum uint32, code eos.AccountName, next bstream.Handler, ctx context.Context) (*ABIChangeHandler, error)

func (*ABIChangeHandler) CurrentABI

func (h *ABIChangeHandler) CurrentABI() *eos.ABI

func (*ABIChangeHandler) ProcessBlock

func (h *ABIChangeHandler) ProcessBlock(block *bstream.Block, obj interface{}) error

type ABIGetter

type ABIGetter interface {
	GetABI(ctx context.Context, blockNum uint32, account eos.AccountName) (*eos.ABI, error)
}

type ABIStack

type ABIStack []*eos.ABI

func (ABIStack) Peek

func (s ABIStack) Peek() *eos.ABI

func (ABIStack) Pop

func (s ABIStack) Pop() (ABIStack, *eos.ABI)

func (ABIStack) Push

func (s ABIStack) Push(abi *eos.ABI) ABIStack

type APIAccountGetter

type APIAccountGetter struct {
	// contains filtered or unexported fields
}

func NewApiAccountGetter

func NewApiAccountGetter(api *eos.API, coreSymbol eos.Symbol) *APIAccountGetter

func (*APIAccountGetter) GetAccount

func (g *APIAccountGetter) GetAccount(ctx context.Context, name string) (out *eos.AccountResp, err error)

type AccountGetter

type AccountGetter interface {
	GetAccount(ctx context.Context, name string) (out *eos.AccountResp, err error)
}
var AccountGetterInstance AccountGetter

type AuthFeatureChecker

type AuthFeatureChecker = func(ctx context.Context, credentials authenticator.Credentials) error

type AuthFeatureMiddleware

type AuthFeatureMiddleware struct {
	// contains filtered or unexported fields
}

func NewAuthFeatureMiddleware

func NewAuthFeatureMiddleware(checker AuthFeatureChecker) *AuthFeatureMiddleware

func (*AuthFeatureMiddleware) Handler

func (middleware *AuthFeatureMiddleware) Handler(next http.Handler) http.Handler

type AuthorizedRequest

type AuthorizedRequest struct {
	StartBlockID  string // has precedence over startBlockNum
	StartBlockNum uint32
	IsFutureBlock bool
}

type CommonHub

type CommonHub struct {
	// contains filtered or unexported fields
}

func (*CommonHub) EmitAll

func (c *CommonHub) EmitAll(ctx context.Context, msg wsmsg.OutgoingMessager)

func (*CommonHub) Last

func (c *CommonHub) Last() wsmsg.OutgoingMessager

func (*CommonHub) SetLast

func (c *CommonHub) SetLast(msg wsmsg.OutgoingMessager)

func (*CommonHub) Subscribe

func (c *CommonHub) Subscribe(ctx context.Context, msg wsmsg.IncomingMessager, ws *WSConn)

func (*CommonHub) Unsubscribe

func (c *CommonHub) Unsubscribe(ctx context.Context, removeEmitter *bufferedEmitter)

type DB

type DB interface {
	trxdb.DBReader

	GetTransactionWithExpectedBlockID(ctx context.Context, id string, expectedBlockID string) (*pbcodec.TransactionLifecycle, error)
	GetTransaction(ctx context.Context, id string) (*pbcodec.TransactionLifecycle, error)
	GetTransactions(ctx context.Context, ids []string) ([]*pbcodec.TransactionLifecycle, error)
	ListTransactionsForBlockID(ctx context.Context, blockId string, startKey string, limit int) (*mdl.TransactionList, error)
	ListMostRecentTransactions(ctx context.Context, startKey string, limit int) (*mdl.TransactionList, error)
}

type DefaultABIGetter

type DefaultABIGetter struct {
	// contains filtered or unexported fields
}

func NewDefaultABIGetter

func NewDefaultABIGetter(client pbstatedb.StateClient) *DefaultABIGetter

func (*DefaultABIGetter) GetABI

func (g *DefaultABIGetter) GetABI(ctx context.Context, blockNum uint32, contract eos.AccountName) (*eos.ABI, error)

type DefaultIrreversibleFinder

type DefaultIrreversibleFinder struct {
	// contains filtered or unexported fields
}

func NewDBReaderBaseIrrFinder

func NewDBReaderBaseIrrFinder(db DB) *DefaultIrreversibleFinder

func (*DefaultIrreversibleFinder) IrreversibleIDAtBlockID

func (f *DefaultIrreversibleFinder) IrreversibleIDAtBlockID(ctx context.Context, blockID string) (out string, err error)

func (*DefaultIrreversibleFinder) IrreversibleIDAtBlockNum

func (f *DefaultIrreversibleFinder) IrreversibleIDAtBlockNum(ctx context.Context, blockNum uint32) (out string, err error)

type Emitter

type Emitter interface {
	Emit(ctx context.Context, msg wsmsg.OutgoingMessager)
	EmitReply(ctx context.Context, originatingMsg wsmsg.IncomingMessager, msg wsmsg.OutgoingMessager)
	EmitErrorReply(ctx context.Context, msg wsmsg.IncomingMessager, err error)
	EmitError(ctx context.Context, reqID string, err error)
}

type HeadInfoHub

type HeadInfoHub struct {
	CommonHub
	// contains filtered or unexported fields
}

func NewHeadInfoHub

func NewHeadInfoHub(initialStartBlock string, initialLIB string, subscriptionHub *hub.SubscriptionHub) *HeadInfoHub

func (*HeadInfoHub) Launch

func (h *HeadInfoHub) Launch(ctx context.Context)

func (*HeadInfoHub) LibID

func (h *HeadInfoHub) LibID() string

type IrreversibleFinder

type IrreversibleFinder interface {
	IrreversibleIDAtBlockNum(ctx context.Context, blockNum uint32) (string, error)
	IrreversibleIDAtBlockID(ctx context.Context, blockID string) (string, error)
}

type MockDB

type MockDB struct {
	trxdb.TimelineExplorer
	trxdb.TransactionsReader
	// contains filtered or unexported fields
}

func NewMockDB

func NewMockDB(path string) *MockDB

func (*MockDB) GetAccount

func (db *MockDB) GetAccount(ctx context.Context, name string) (out *pbcodec.AccountCreationRef, err error)

func (*MockDB) GetBlock

func (db *MockDB) GetBlock(ctx context.Context, id string) (out *pbcodec.BlockWithRefs, err error)

func (*MockDB) GetBlockByNum

func (db *MockDB) GetBlockByNum(ctx context.Context, num uint32) (out []*pbcodec.BlockWithRefs, err error)

func (*MockDB) GetClosestIrreversibleIDAtBlockNum

func (db *MockDB) GetClosestIrreversibleIDAtBlockNum(ctx context.Context, num uint32) (out bstream.BlockRef, err error)

func (*MockDB) GetIrreversibleIDAtBlockID

func (db *MockDB) GetIrreversibleIDAtBlockID(ctx context.Context, ID string) (out bstream.BlockRef, err error)

func (*MockDB) GetLastWrittenBlockID

func (db *MockDB) GetLastWrittenBlockID(ctx context.Context) (string, error)

func (*MockDB) GetTransaction

func (db *MockDB) GetTransaction(ctx context.Context, id string) (out *pbcodec.TransactionLifecycle, err error)

func (*MockDB) GetTransactionWithExpectedBlockID

func (db *MockDB) GetTransactionWithExpectedBlockID(ctx context.Context, id string, _ string) (out *pbcodec.TransactionLifecycle, err error)

func (*MockDB) GetTransactions

func (db *MockDB) GetTransactions(ctx context.Context, ids []string) (out []*pbcodec.TransactionLifecycle, err error)

func (*MockDB) ListAccountNames

func (db *MockDB) ListAccountNames(ctx context.Context) (out []string, err error)

func (*MockDB) ListBlocks

func (db *MockDB) ListBlocks(ctx context.Context, startBlockNum uint32, limit int) ([]*pbcodec.BlockWithRefs, error)

func (*MockDB) ListMostRecentTransactions

func (db *MockDB) ListMostRecentTransactions(ctx context.Context, startKey string, limit int) (*mdl.TransactionList, error)

func (*MockDB) ListSiblingBlocks

func (db *MockDB) ListSiblingBlocks(ctx context.Context, blockNum uint32, spread uint32) ([]*pbcodec.BlockWithRefs, error)

func (*MockDB) ListTransactionsForBlockID

func (db *MockDB) ListTransactionsForBlockID(ctx context.Context, blockId string, startKey string, limit int) (*mdl.TransactionList, error)

type MultiRouterClient

type MultiRouterClient struct {
	Toggle *atomic.Bool
	// contains filtered or unexported fields
}

func NewMultiRouterClient

func NewMultiRouterClient(v1Client pbsearch.RouterClient, v2Client pbsearch.RouterClient) *MultiRouterClient

func (*MultiRouterClient) StreamMatches

type PriceHub

type PriceHub struct {
	CommonHub
}

func NewPriceHub

func NewPriceHub() *PriceHub

func (*PriceHub) Launch

func (h *PriceHub) Launch(ctx context.Context)

type ProgressHandler

type ProgressHandler struct {
	// contains filtered or unexported fields
}

func NewProgressHandler

func NewProgressHandler(next bstream.Handler, emiter Emitter, message wsmsg.IncomingMessager, context context.Context) *ProgressHandler

func (*ProgressHandler) ProcessBlock

func (h *ProgressHandler) ProcessBlock(blk *bstream.Block, obj interface{}) error

func (*ProgressHandler) SetStepFilter

func (h *ProgressHandler) SetStepFilter(s forkable.StepType)

type SearchEngine

type SearchEngine struct {
	// contains filtered or unexported fields
}

func NewSearchEngine

func NewSearchEngine(db DB, searchClient pbsearch.RouterClient) *SearchEngine

func (*SearchEngine) DoRequest

func (s *SearchEngine) DoRequest(ctx context.Context, q *pbsearch.RouterRequest) (matches []*pbsearch.SearchMatch, rangeCompleted bool, err error)

func (*SearchEngine) ServeHTTP

func (s *SearchEngine) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SearchQuery

type SearchQuery struct {
	Query          string `json:"query"`
	StartBlock     uint32 `json:"start_block"`
	BlockCount     uint32 `json:"block_count"`
	SortDescending bool   `json:"sort_desc"`
	Limit          uint64 `json:"limit"`
	Cursor         string `json:"cursor"`
	WithReversible bool   `json:"with_reversible"`
	Format         string `json:"format"`
}

type StatusAwareResponseWriter

type StatusAwareResponseWriter struct {
	http.ResponseWriter
	Status int
}

func TurnIntoStatusAwareResponseWriter

func TurnIntoStatusAwareResponseWriter(w http.ResponseWriter) *StatusAwareResponseWriter

func (*StatusAwareResponseWriter) Hijack

func (w *StatusAwareResponseWriter) Hijack() (rwc net.Conn, buf *bufio.ReadWriter, err error)

func (*StatusAwareResponseWriter) Write

func (w *StatusAwareResponseWriter) Write(b []byte) (int, error)

func (*StatusAwareResponseWriter) WriteHeader

func (w *StatusAwareResponseWriter) WriteHeader(status int)

type TRXDB

type TRXDB struct {
	trxdb.DBReader
	// contains filtered or unexported fields
}

func NewTRXDB

func NewTRXDB(dbReader trxdb.DBReader) *TRXDB

func (*TRXDB) GetAccount

func (db *TRXDB) GetAccount(ctx context.Context, name string) (account *pbcodec.AccountCreationRef, err error)

func (*TRXDB) GetBlock

func (db *TRXDB) GetBlock(ctx context.Context, id string) (out *pbcodec.BlockWithRefs, err error)

func (*TRXDB) GetBlockByNum

func (db *TRXDB) GetBlockByNum(ctx context.Context, num uint32) (out []*pbcodec.BlockWithRefs, err error)

func (*TRXDB) GetTransaction

func (db *TRXDB) GetTransaction(ctx context.Context, id string) (out *pbcodec.TransactionLifecycle, err error)

func (*TRXDB) GetTransactionWithExpectedBlockID

func (db *TRXDB) GetTransactionWithExpectedBlockID(ctx context.Context, id string, expectedBlockID string) (out *pbcodec.TransactionLifecycle, err error)

func (*TRXDB) GetTransactions

func (db *TRXDB) GetTransactions(ctx context.Context, ids []string) (out []*pbcodec.TransactionLifecycle, err error)

func (*TRXDB) ListMostRecentTransactions

func (db *TRXDB) ListMostRecentTransactions(ctx context.Context, startKey string, limit int) (*mdl.TransactionList, error)

func (*TRXDB) ListTransactionsForBlockID

func (db *TRXDB) ListTransactionsForBlockID(ctx context.Context, blockID string, startKey string, limit int) (*mdl.TransactionList, error)

type TestABIGetter

type TestABIGetter struct {
	// contains filtered or unexported fields
}

func NewTestABIGetter

func NewTestABIGetter() *TestABIGetter

func (*TestABIGetter) GetABI

func (g *TestABIGetter) GetABI(ctx context.Context, blockNum uint32, account eos.AccountName) (*eos.ABI, error)

func (*TestABIGetter) SetABIForAccount

func (g *TestABIGetter) SetABIForAccount(abiString string, account eos.AccountName)

type TestAccountGetter

type TestAccountGetter struct {
	// contains filtered or unexported fields
}

func NewTestAccountGetter

func NewTestAccountGetter() *TestAccountGetter

func (*TestAccountGetter) GetAccount

func (g *TestAccountGetter) GetAccount(ctx context.Context, name string) (out *eos.AccountResp, err error)

func (*TestAccountGetter) SetAccount

func (g *TestAccountGetter) SetAccount(jsonData string)

type TestEmitter

type TestEmitter struct {
	// contains filtered or unexported fields
}

func NewTestEmitter

func NewTestEmitter(ctx context.Context, callBack func(wsmsg.OutgoingMessager)) *TestEmitter

func (*TestEmitter) Emit

func (e *TestEmitter) Emit(ctx context.Context, msg wsmsg.OutgoingMessager)

func (*TestEmitter) EmitError

func (e *TestEmitter) EmitError(ctx context.Context, reqID string, err error)

func (*TestEmitter) EmitErrorReply

func (e *TestEmitter) EmitErrorReply(ctx context.Context, msg wsmsg.IncomingMessager, err error)

func (*TestEmitter) EmitReply

func (e *TestEmitter) EmitReply(ctx context.Context, originatingMsg wsmsg.IncomingMessager, msg wsmsg.OutgoingMessager)

type TestIrreversibleFinder

type TestIrreversibleFinder struct {
	// contains filtered or unexported fields
}

func NewTestIrreversibleFinder

func NewTestIrreversibleFinder(irrID string, err error) *TestIrreversibleFinder

func (*TestIrreversibleFinder) IrreversibleIDAtBlockID

func (f *TestIrreversibleFinder) IrreversibleIDAtBlockID(ctx context.Context, blockID string) (string, error)

func (*TestIrreversibleFinder) IrreversibleIDAtBlockNum

func (f *TestIrreversibleFinder) IrreversibleIDAtBlockNum(ctx context.Context, blockNum uint32) (string, error)

type VoteTallyHub

type VoteTallyHub struct {
	CommonHub
	// contains filtered or unexported fields
}

func NewVoteTallyHub

func NewVoteTallyHub(stateHelper statedb.StateHelper) *VoteTallyHub

func (*VoteTallyHub) FetchVoteTally

func (h *VoteTallyHub) FetchVoteTally() (*wsmsg.VoteTally, error)

func (*VoteTallyHub) Launch

func (h *VoteTallyHub) Launch(ctx context.Context)

type WSConn

type WSConn struct {
	*shutter.Shutter

	*WebsocketHandler

	Context context.Context
	// contains filtered or unexported fields
}

WSConn represents a single web socket connection.

func NewWSConn

func NewWSConn(wshand *WebsocketHandler, conn *websocket.Conn, creds authenticator.Credentials, filesourceBlockRateLimit time.Duration, ctx context.Context) *WSConn

func (*WSConn) AuthorizeRequest

func (ws *WSConn) AuthorizeRequest(ctx context.Context, msg wsmsg.IncomingMessager) (*AuthorizedRequest, bool)

func (*WSConn) Emit

func (ws *WSConn) Emit(ctx context.Context, msg wsmsg.OutgoingMessager)

func (*WSConn) EmitError

func (ws *WSConn) EmitError(ctx context.Context, reqID string, err error)

func (*WSConn) EmitErrorReply

func (ws *WSConn) EmitErrorReply(ctx context.Context, msg wsmsg.IncomingMessager, err error)

func (*WSConn) EmitReply

func (ws *WSConn) EmitReply(ctx context.Context, originatingMsg wsmsg.IncomingMessager, msg wsmsg.OutgoingMessager)

func (*WSConn) RegisterListener

func (ws *WSConn) RegisterListener(ctx context.Context, reqID string, canceler func() error) error

func (*WSConn) ShutdownAllListeners

func (ws *WSConn) ShutdownAllListeners()

func (*WSConn) ShutdownListener

func (ws *WSConn) ShutdownListener(ctx context.Context, reqID string) error

type WebsocketHandler

type WebsocketHandler struct {
	http.Handler
	// contains filtered or unexported fields
}

func NewWebsocketHandler

func NewWebsocketHandler(
	abiGetter ABIGetter,
	accountGetter AccountGetter,
	db DB,
	subscriptionHub *hub.SubscriptionHub,
	stateClient pbstatedb.StateClient,
	voteTallyHub *VoteTallyHub,
	headInfoHub *HeadInfoHub,
	priceHub *PriceHub,
	irrFinder IrreversibleFinder,
	filesourceBlockRateLimit time.Duration,
	maxStreamCount int,
) *WebsocketHandler

Directories

Path Synopsis
app
eosws
Deprecated: The features in the eosws package will be moved to other packages like Dgraphql
Deprecated: The features in the eosws package will be moved to other packages like Dgraphql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL