api

package
v0.0.0-...-8aa4d74 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetAccountTransactionsHandlerPattern   = "/accounts/{id}/transactions"
	GetAccountHandlerPattern               = "/accounts/{id}"
	GetAccountsHandlerPattern              = "/accounts"
	GetAccountOperationsHandlerPattern     = "/accounts/{id}/operations"
	GetAccountFrozenAccountHandlerPattern  = "/accounts/{id}/frozen-accounts"
	GetFrozenAccountHandlerPattern         = "/frozen-accounts"
	GetTransactionsHandlerPattern          = "/transactions"
	GetTransactionByHashHandlerPattern     = "/transactions/{id}"
	GetTransactionOperationsHandlerPattern = "/transactions/{id}/operations"
	GetTransactionOperationHandlerPattern  = "/transactions/{id}/operations/{opindex}"
	GetTransactionStatusHandlerPattern     = "/transactions/{id}/status"
	PostTransactionPattern                 = "/transactions"
	GetBlocksHandlerPattern                = "/blocks"
	GetBlockHandlerPattern                 = "/blocks/{hashOrHeight}"
	GetNodeInfoPattern                     = "/"
	PostSubscribePattern                   = "/subscribe"
)

API Endpoint patterns

View Source
const (
	DefaultLimit uint64 = 20
	MaxLimit     uint64 = 100
)
View Source
const APIVersionV1 = "v1"
View Source
const DefaultContentType = "application/json"

DefaultContentType is "application/json"

Variables

View Source
var RenderJSONFunc = func(args ...interface{}) ([]byte, error) {
	if len(args) <= 1 {
		return nil, fmt.Errorf("render: value is empty")
	}
	v := args[1]
	if v == nil {
		return nil, nil
	}
	bs, err := json.Marshal(v)
	if err != nil {
		return nil, err
	}
	return bs, nil
}

NewDefaultEventStream uses RenderJSONFunc by default

Functions

func NewTeeReadCloser

func NewTeeReadCloser(origin io.ReadCloser, w io.Writer) io.ReadCloser

func TriggerEvent

func TriggerEvent(st *storage.LevelDBBackend, transactions []*transaction.Transaction)

Types

type EventStream

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

EventStream handles chunked responses of a observable trigger

renderFunc uses on observable.On() and Render function

func NewDefaultEventStream

func NewDefaultEventStream(w http.ResponseWriter, r *http.Request) *EventStream

NewDefaultEventStream returns *EventStream with RenderJSONFunc and DefaultContentType

func NewEventStream

func NewEventStream(w http.ResponseWriter, r *http.Request, renderFunc RenderFunc, ct string) *EventStream

NewEventStream makes *EventStream and checks http.Flusher by type assertion.

func (*EventStream) Render

func (s *EventStream) Render(args ...interface{})

Render make a chunked response by using RenderFunc and flush it.

func (*EventStream) Run

func (s *EventStream) Run(ob *observable.Observable, events ...string)

Run start observing events.

Simple use case:

event := fmt.Sprintf("address-%s", address)
es := NewDefaultEventStream(w, r)
es.Render(blk)
es.Run(observer.BlockAccountObserver, event)

func (*EventStream) Start

func (s *EventStream) Start(ob *observable.Observable, events ...string) func()

Start prepares for observing events and returns run func.

In most case, Use Run instead of Start

func (*EventStream) Stop

func (s *EventStream) Stop()

type NetworkHandlerAPI

type NetworkHandlerAPI struct {
	GetLatestBlock func() block.Block
	// contains filtered or unexported fields
}

func NewNetworkHandlerAPI

func NewNetworkHandlerAPI(localNode *node.LocalNode, network network.Network, storage *storage.LevelDBBackend, urlPrefix string, nodeInfo node.NodeInfo) *NetworkHandlerAPI

func (NetworkHandlerAPI) GetAccountHandler

func (api NetworkHandlerAPI) GetAccountHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetAccountsHandler

func (api NetworkHandlerAPI) GetAccountsHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetBlockHandler

func (api NetworkHandlerAPI) GetBlockHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetBlocksHandler

func (api NetworkHandlerAPI) GetBlocksHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetFrozenAccountsByAccountHandler

func (api NetworkHandlerAPI) GetFrozenAccountsByAccountHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetFrozenAccountsHandler

func (api NetworkHandlerAPI) GetFrozenAccountsHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetNodeInfoHandler

func (api NetworkHandlerAPI) GetNodeInfoHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetOperationsByAccountHandler

func (api NetworkHandlerAPI) GetOperationsByAccountHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetOperationsByTxHandler

func (api NetworkHandlerAPI) GetOperationsByTxHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetOperationsByTxHashOpIndexHandler

func (api NetworkHandlerAPI) GetOperationsByTxHashOpIndexHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetTransactionByHashHandler

func (api NetworkHandlerAPI) GetTransactionByHashHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetTransactionStatusByHashHandler

func (api NetworkHandlerAPI) GetTransactionStatusByHashHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetTransactionsByAccountHandler

func (api NetworkHandlerAPI) GetTransactionsByAccountHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) GetTransactionsHandler

func (api NetworkHandlerAPI) GetTransactionsHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) HandlerURLPattern

func (api NetworkHandlerAPI) HandlerURLPattern(pattern string) string

func (NetworkHandlerAPI) PostSubscribeHandler

func (api NetworkHandlerAPI) PostSubscribeHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerAPI) PostTransactionsHandler

func (api NetworkHandlerAPI) PostTransactionsHandler(
	w http.ResponseWriter,
	r *http.Request,
	handler func([]byte, []common.CheckerFunc) (transaction.Transaction, error),
	funcs []common.CheckerFunc,
)

type PageQuery

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

func NewPageQuery

func NewPageQuery(r *http.Request, opts ...PageQueryOption) (*PageQuery, error)

func (*PageQuery) Cursor

func (p *PageQuery) Cursor() []byte

func (*PageQuery) Limit

func (p *PageQuery) Limit() uint64

func (*PageQuery) ListOptions

func (p *PageQuery) ListOptions() storage.ListOptions
func (p *PageQuery) NextLink(cursor []byte) string
func (p *PageQuery) PrevLink(cursor []byte) string

func (*PageQuery) ResourceList

func (p *PageQuery) ResourceList(rs []resource.Resource, firstCursor, lastCursor []byte) *resource.ResourceList

func (*PageQuery) Reverse

func (p *PageQuery) Reverse() bool
func (p *PageQuery) SelfLink() string

func (*PageQuery) WalkOption

func (p *PageQuery) WalkOption() *storage.WalkOption

type PageQueryOption

type PageQueryOption func(*PageQuery)

func WithDefaultReverse

func WithDefaultReverse(ok bool) PageQueryOption

func WithEncodePageCursor

func WithEncodePageCursor(ok bool) PageQueryOption

type RenderFunc

type RenderFunc func(args ...interface{}) ([]byte, error)

type TeeReadCloser

type TeeReadCloser struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

func (TeeReadCloser) Read

func (tee TeeReadCloser) Read(p []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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