server

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 148

README

Server

GoDoc

The Server package reduces the work required to write your own Rosetta server. In short, this package takes care of the basics (boilerplate server code and request validation) so that you can focus on code that is unique to your implementation.

Installation

go get github.com/coinbase/rosetta-sdk-go/server

Components

Router

The router is a Mux router that routes traffic to the correct controller.

Controller

Controllers are automatically generated code that specify an interface that a service must implement.

Services

Services are implemented by you to populate responses. These services are invoked by controllers.

main.go
/services
  block_service.go
  network_service.go
  ...

Examples

Check out the examples to see how easy it is to create your own server.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CorsMiddleware

func CorsMiddleware(next http.Handler) http.Handler

CorsMiddleware handles CORS and ensures OPTIONS requests are handled properly.

This may be used to expose a Rosetta server instance to requests made by web apps served over a different domain. Note that his currently allows _all_ third party domains so callers might want to adapt this middleware for their own use-cases.

func EncodeJSONResponse

func EncodeJSONResponse(i interface{}, status int, w http.ResponseWriter)

EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code

func LoggerMiddleware added in v0.3.3

func LoggerMiddleware(inner http.Handler) http.Handler

LoggerMiddleware is a simple logger middleware that prints the requests in an ad-hoc fashion to the stdlib's log.

func NewRouter

func NewRouter(routers ...Router) http.Handler

NewRouter creates a new router for any number of api routers

Types

type AccountAPIController

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

A AccountAPIController binds http requests to an api service and writes the service results to the http response

func (*AccountAPIController) AccountBalance

func (c *AccountAPIController) AccountBalance(w http.ResponseWriter, r *http.Request)

AccountBalance - Get an Account's Balance

func (*AccountAPIController) AccountCoins added in v0.6.0

func (c *AccountAPIController) AccountCoins(w http.ResponseWriter, r *http.Request)

AccountCoins - Get an Account's Unspent Coins

func (*AccountAPIController) Routes

func (c *AccountAPIController) Routes() Routes

Routes returns all of the api route for the AccountAPIController

type AccountAPIRouter

type AccountAPIRouter interface {
	AccountBalance(http.ResponseWriter, *http.Request)
	AccountCoins(http.ResponseWriter, *http.Request)
}

AccountAPIRouter defines the required methods for binding the api requests to a responses for the AccountAPI The AccountAPIRouter implementation should parse necessary information from the http request, pass the data to a AccountAPIServicer to perform the required actions, then write the service results to the http response.

type AccountAPIServicer

type AccountAPIServicer interface {
	AccountBalance(
		context.Context,
		*types.AccountBalanceRequest,
	) (*types.AccountBalanceResponse, *types.Error)
	AccountCoins(
		context.Context,
		*types.AccountCoinsRequest,
	) (*types.AccountCoinsResponse, *types.Error)
}

AccountAPIServicer defines the api actions for the AccountAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type BlockAPIController

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

A BlockAPIController binds http requests to an api service and writes the service results to the http response

func (*BlockAPIController) Block

Block - Get a Block

func (*BlockAPIController) BlockTransaction

func (c *BlockAPIController) BlockTransaction(w http.ResponseWriter, r *http.Request)

BlockTransaction - Get a Block Transaction

func (*BlockAPIController) Routes

func (c *BlockAPIController) Routes() Routes

Routes returns all of the api route for the BlockAPIController

type BlockAPIRouter

type BlockAPIRouter interface {
	Block(http.ResponseWriter, *http.Request)
	BlockTransaction(http.ResponseWriter, *http.Request)
}

BlockAPIRouter defines the required methods for binding the api requests to a responses for the BlockAPI The BlockAPIRouter implementation should parse necessary information from the http request, pass the data to a BlockAPIServicer to perform the required actions, then write the service results to the http response.

type BlockAPIServicer

type BlockAPIServicer interface {
	Block(context.Context, *types.BlockRequest) (*types.BlockResponse, *types.Error)
	BlockTransaction(
		context.Context,
		*types.BlockTransactionRequest,
	) (*types.BlockTransactionResponse, *types.Error)
}

BlockAPIServicer defines the api actions for the BlockAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type CallAPIController added in v0.5.0

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

A CallAPIController binds http requests to an api service and writes the service results to the http response

func (*CallAPIController) Call added in v0.5.0

Call - Make a Network-Specific Procedure Call

func (*CallAPIController) Routes added in v0.5.0

func (c *CallAPIController) Routes() Routes

Routes returns all of the api route for the CallAPIController

type CallAPIRouter added in v0.5.0

type CallAPIRouter interface {
	Call(http.ResponseWriter, *http.Request)
}

CallAPIRouter defines the required methods for binding the api requests to a responses for the CallAPI The CallAPIRouter implementation should parse necessary information from the http request, pass the data to a CallAPIServicer to perform the required actions, then write the service results to the http response.

type CallAPIServicer added in v0.5.0

type CallAPIServicer interface {
	Call(context.Context, *types.CallRequest) (*types.CallResponse, *types.Error)
}

CallAPIServicer defines the api actions for the CallAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type ConstructionAPIController

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

A ConstructionAPIController binds http requests to an api service and writes the service results to the http response

func (*ConstructionAPIController) ConstructionCombine added in v0.3.0

func (c *ConstructionAPIController) ConstructionCombine(w http.ResponseWriter, r *http.Request)

ConstructionCombine - Create Network Transaction from Signatures

func (*ConstructionAPIController) ConstructionDerive added in v0.3.0

func (c *ConstructionAPIController) ConstructionDerive(w http.ResponseWriter, r *http.Request)

ConstructionDerive - Derive an AccountIdentifier from a PublicKey

func (*ConstructionAPIController) ConstructionHash added in v0.3.0

func (c *ConstructionAPIController) ConstructionHash(w http.ResponseWriter, r *http.Request)

ConstructionHash - Get the Hash of a Signed Transaction

func (*ConstructionAPIController) ConstructionMetadata added in v0.1.2

func (c *ConstructionAPIController) ConstructionMetadata(w http.ResponseWriter, r *http.Request)

ConstructionMetadata - Get Metadata for Transaction Construction

func (*ConstructionAPIController) ConstructionParse added in v0.3.0

func (c *ConstructionAPIController) ConstructionParse(w http.ResponseWriter, r *http.Request)

ConstructionParse - Parse a Transaction

func (*ConstructionAPIController) ConstructionPayloads added in v0.3.0

func (c *ConstructionAPIController) ConstructionPayloads(w http.ResponseWriter, r *http.Request)

ConstructionPayloads - Generate an Unsigned Transaction and Signing Payloads

func (*ConstructionAPIController) ConstructionPreprocess added in v0.3.0

func (c *ConstructionAPIController) ConstructionPreprocess(w http.ResponseWriter, r *http.Request)

ConstructionPreprocess - Create a Request to Fetch Metadata

func (*ConstructionAPIController) ConstructionSubmit added in v0.1.2

func (c *ConstructionAPIController) ConstructionSubmit(w http.ResponseWriter, r *http.Request)

ConstructionSubmit - Submit a Signed Transaction

func (*ConstructionAPIController) Routes

func (c *ConstructionAPIController) Routes() Routes

Routes returns all of the api route for the ConstructionAPIController

type ConstructionAPIRouter

type ConstructionAPIRouter interface {
	ConstructionCombine(http.ResponseWriter, *http.Request)
	ConstructionDerive(http.ResponseWriter, *http.Request)
	ConstructionHash(http.ResponseWriter, *http.Request)
	ConstructionMetadata(http.ResponseWriter, *http.Request)
	ConstructionParse(http.ResponseWriter, *http.Request)
	ConstructionPayloads(http.ResponseWriter, *http.Request)
	ConstructionPreprocess(http.ResponseWriter, *http.Request)
	ConstructionSubmit(http.ResponseWriter, *http.Request)
}

ConstructionAPIRouter defines the required methods for binding the api requests to a responses for the ConstructionAPI The ConstructionAPIRouter implementation should parse necessary information from the http request, pass the data to a ConstructionAPIServicer to perform the required actions, then write the service results to the http response.

type ConstructionAPIServicer

ConstructionAPIServicer defines the api actions for the ConstructionAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type EventsAPIController added in v0.6.0

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

A EventsAPIController binds http requests to an api service and writes the service results to the http response

func (*EventsAPIController) EventsBlocks added in v0.6.0

func (c *EventsAPIController) EventsBlocks(w http.ResponseWriter, r *http.Request)

EventsBlocks - [INDEXER] Get a range of BlockEvents

func (*EventsAPIController) Routes added in v0.6.0

func (c *EventsAPIController) Routes() Routes

Routes returns all of the api route for the EventsAPIController

type EventsAPIRouter added in v0.6.0

type EventsAPIRouter interface {
	EventsBlocks(http.ResponseWriter, *http.Request)
}

EventsAPIRouter defines the required methods for binding the api requests to a responses for the EventsAPI The EventsAPIRouter implementation should parse necessary information from the http request, pass the data to a EventsAPIServicer to perform the required actions, then write the service results to the http response.

type EventsAPIServicer added in v0.6.0

type EventsAPIServicer interface {
	EventsBlocks(
		context.Context,
		*types.EventsBlocksRequest,
	) (*types.EventsBlocksResponse, *types.Error)
}

EventsAPIServicer defines the api actions for the EventsAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type MempoolAPIController

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

A MempoolAPIController binds http requests to an api service and writes the service results to the http response

func (*MempoolAPIController) Mempool

Mempool - Get All Mempool Transactions

func (*MempoolAPIController) MempoolTransaction

func (c *MempoolAPIController) MempoolTransaction(w http.ResponseWriter, r *http.Request)

MempoolTransaction - Get a Mempool Transaction

func (*MempoolAPIController) Routes

func (c *MempoolAPIController) Routes() Routes

Routes returns all of the api route for the MempoolAPIController

type MempoolAPIRouter

type MempoolAPIRouter interface {
	Mempool(http.ResponseWriter, *http.Request)
	MempoolTransaction(http.ResponseWriter, *http.Request)
}

MempoolAPIRouter defines the required methods for binding the api requests to a responses for the MempoolAPI The MempoolAPIRouter implementation should parse necessary information from the http request, pass the data to a MempoolAPIServicer to perform the required actions, then write the service results to the http response.

type MempoolAPIServicer

type MempoolAPIServicer interface {
	Mempool(context.Context, *types.NetworkRequest) (*types.MempoolResponse, *types.Error)
	MempoolTransaction(
		context.Context,
		*types.MempoolTransactionRequest,
	) (*types.MempoolTransactionResponse, *types.Error)
}

MempoolAPIServicer defines the api actions for the MempoolAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type NetworkAPIController

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

A NetworkAPIController binds http requests to an api service and writes the service results to the http response

func (*NetworkAPIController) NetworkList added in v0.1.2

func (c *NetworkAPIController) NetworkList(w http.ResponseWriter, r *http.Request)

NetworkList - Get List of Available Networks

func (*NetworkAPIController) NetworkOptions added in v0.1.2

func (c *NetworkAPIController) NetworkOptions(w http.ResponseWriter, r *http.Request)

NetworkOptions - Get Network Options

func (*NetworkAPIController) NetworkStatus

func (c *NetworkAPIController) NetworkStatus(w http.ResponseWriter, r *http.Request)

NetworkStatus - Get Network Status

func (*NetworkAPIController) Routes

func (c *NetworkAPIController) Routes() Routes

Routes returns all of the api route for the NetworkAPIController

type NetworkAPIRouter

type NetworkAPIRouter interface {
	NetworkList(http.ResponseWriter, *http.Request)
	NetworkOptions(http.ResponseWriter, *http.Request)
	NetworkStatus(http.ResponseWriter, *http.Request)
}

NetworkAPIRouter defines the required methods for binding the api requests to a responses for the NetworkAPI The NetworkAPIRouter implementation should parse necessary information from the http request, pass the data to a NetworkAPIServicer to perform the required actions, then write the service results to the http response.

type NetworkAPIServicer

NetworkAPIServicer defines the api actions for the NetworkAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

A Route defines the parameters for an api endpoint

type Router

type Router interface {
	Routes() Routes
}

Router defines the required methods for retrieving api routes

func NewAccountAPIController

func NewAccountAPIController(
	s AccountAPIServicer,
	asserter *asserter.Asserter,
) Router

NewAccountAPIController creates a default api controller

func NewBlockAPIController

func NewBlockAPIController(
	s BlockAPIServicer,
	asserter *asserter.Asserter,
) Router

NewBlockAPIController creates a default api controller

func NewCallAPIController added in v0.5.0

func NewCallAPIController(
	s CallAPIServicer,
	asserter *asserter.Asserter,
) Router

NewCallAPIController creates a default api controller

func NewConstructionAPIController

func NewConstructionAPIController(
	s ConstructionAPIServicer,
	asserter *asserter.Asserter,
) Router

NewConstructionAPIController creates a default api controller

func NewEventsAPIController added in v0.6.0

func NewEventsAPIController(
	s EventsAPIServicer,
	asserter *asserter.Asserter,
) Router

NewEventsAPIController creates a default api controller

func NewMempoolAPIController

func NewMempoolAPIController(
	s MempoolAPIServicer,
	asserter *asserter.Asserter,
) Router

NewMempoolAPIController creates a default api controller

func NewNetworkAPIController

func NewNetworkAPIController(
	s NetworkAPIServicer,
	asserter *asserter.Asserter,
) Router

NewNetworkAPIController creates a default api controller

func NewSearchAPIController added in v0.6.0

func NewSearchAPIController(
	s SearchAPIServicer,
	asserter *asserter.Asserter,
) Router

NewSearchAPIController creates a default api controller

type Routes

type Routes []Route

Routes are a collection of defined api endpoints

type SearchAPIController added in v0.6.0

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

A SearchAPIController binds http requests to an api service and writes the service results to the http response

func (*SearchAPIController) Routes added in v0.6.0

func (c *SearchAPIController) Routes() Routes

Routes returns all of the api route for the SearchAPIController

func (*SearchAPIController) SearchTransactions added in v0.6.0

func (c *SearchAPIController) SearchTransactions(w http.ResponseWriter, r *http.Request)

SearchTransactions - [INDEXER] Search for Transactions

type SearchAPIRouter added in v0.6.0

type SearchAPIRouter interface {
	SearchTransactions(http.ResponseWriter, *http.Request)
}

SearchAPIRouter defines the required methods for binding the api requests to a responses for the SearchAPI The SearchAPIRouter implementation should parse necessary information from the http request, pass the data to a SearchAPIServicer to perform the required actions, then write the service results to the http response.

type SearchAPIServicer added in v0.6.0

type SearchAPIServicer interface {
	SearchTransactions(
		context.Context,
		*types.SearchTransactionsRequest,
	) (*types.SearchTransactionsResponse, *types.Error)
}

SearchAPIServicer defines the api actions for the SearchAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

Jump to

Keyboard shortcuts

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