services

package
v0.0.0-...-e572e8e Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NodeVersion is the version of
	// oduwacoin core we are using.
	NodeVersion = "0.20.1"

	// HistoricalBalanceLookup indicates
	// that historical balance lookup is supported.
	HistoricalBalanceLookup = true

	// MempoolCoins indicates that
	// including mempool coins in the /account/coins
	// response is not supported.
	MempoolCoins = false

	// MiddlewareVersion is the version
	// of rosetta-oduwacoin. We set this as a
	// variable instead of a constant because
	// we typically need the pointer of this
	// value.
	MiddlewareVersion = "0.0.9"
)

Variables

View Source
var (
	// Errors contains all errors that could be returned
	// by this Rosetta implementation.
	Errors = []*types.Error{
		ErrUnimplemented,
		ErrUnavailableOffline,
		ErrNotReady,
		ErrOduwacoind,
		ErrBlockNotFound,
		ErrUnableToDerive,
		ErrUnclearIntent,
		ErrUnableToParseIntermediateResult,
		ErrScriptPubKeysMissing,
		ErrInvalidCoin,
		ErrUnableToDecodeAddress,
		ErrUnableToDecodeScriptPubKey,
		ErrUnableToCalculateSignatureHash,
		ErrUnsupportedScriptType,
		ErrUnableToComputePkScript,
		ErrUnableToGetCoins,
		ErrTransactionNotFound,
		ErrCouldNotGetFeeRate,
		ErrUnableToGetBalance,
	}

	// ErrUnimplemented is returned when an endpoint
	// is called that is not implemented.
	ErrUnimplemented = &types.Error{
		Code:    0,
		Message: "Endpoint not implemented",
	}

	// ErrUnavailableOffline is returned when an endpoint
	// is called that is not available offline.
	ErrUnavailableOffline = &types.Error{
		Code:    1,
		Message: "Endpoint unavailable offline",
	}

	// ErrNotReady is returned when oduwacoind is not
	// yet ready to serve queries.
	ErrNotReady = &types.Error{
		Code:      2,
		Message:   "Oduwacoind is not ready",
		Retriable: true,
	}

	// ErrOduwacoind is returned when oduwacoind
	// errors on a request.
	ErrOduwacoind = &types.Error{
		Code:    3,
		Message: "Oduwacoind error",
	}

	// ErrBlockNotFound is returned when a block
	// is not available in the indexer.
	ErrBlockNotFound = &types.Error{
		Code:    4,
		Message: "Block not found",
	}

	// ErrUnableToDerive is returned when an address
	// cannot be derived from a provided public key.
	ErrUnableToDerive = &types.Error{
		Code:    5,
		Message: "Unable to derive address",
	}

	// ErrUnclearIntent is returned when operations
	// provided in /construction/preprocess or /construction/payloads
	// are not valid.
	ErrUnclearIntent = &types.Error{
		Code:    6,
		Message: "Unable to parse intent",
	}

	// ErrUnableToParseIntermediateResult is returned
	// when a data structure passed between Construction
	// API calls is not valid.
	ErrUnableToParseIntermediateResult = &types.Error{
		Code:    7,
		Message: "Unable to parse intermediate result",
	}

	// ErrScriptPubKeysMissing is returned when
	// the indexer cannot populate the required
	// oduwacoin.ScriptPubKeys to construct a transaction.
	ErrScriptPubKeysMissing = &types.Error{
		Code:    8,
		Message: "Missing ScriptPubKeys",
	}

	// ErrInvalidCoin is returned when a *types.Coin
	// cannot be parsed during construction.
	ErrInvalidCoin = &types.Error{
		Code:    9,
		Message: "Coin is invalid",
	}

	// ErrUnableToDecodeAddress is returned when an address
	// cannot be parsed during construction.
	ErrUnableToDecodeAddress = &types.Error{
		Code:    10,
		Message: "Unable to decode address",
	}

	// ErrUnableToDecodeScriptPubKey is returned when a
	// oduwacoin.ScriptPubKey cannot be parsed during construction.
	ErrUnableToDecodeScriptPubKey = &types.Error{
		Code:    11,
		Message: "Unable to decode ScriptPubKey",
	}

	// ErrUnableToCalculateSignatureHash is returned
	// when some payload to sign cannot be generated.
	ErrUnableToCalculateSignatureHash = &types.Error{
		Code:    12,
		Message: "Unable to calculate signature hash",
	}

	// ErrUnsupportedScriptType is returned when
	// trying to sign an input with an unsupported
	// script type.
	ErrUnsupportedScriptType = &types.Error{
		Code:    13,
		Message: "Script type is not supported",
	}

	// ErrUnableToComputePkScript is returned
	// when trying to compute the PkScript in
	// ConsructionParse.
	ErrUnableToComputePkScript = &types.Error{
		Code:    14,
		Message: "Unable to compute PK script",
	}

	// ErrUnableToGetCoins is returned by the indexer
	// when it is not possible to get the coins
	// owned by a *types.AccountIdentifier.
	ErrUnableToGetCoins = &types.Error{
		Code:    15,
		Message: "Unable to get coins",
	}

	// ErrTransactionNotFound is returned by the indexer
	// when it is not possible to find a transaction.
	ErrTransactionNotFound = &types.Error{
		Code:    16,
		Message: "Transaction not found",
	}

	// ErrCouldNotGetFeeRate is returned when the fetch
	// to get the suggested fee rate fails.
	ErrCouldNotGetFeeRate = &types.Error{
		Code:    17,
		Message: "Could not get suggested fee rate",
	}

	// ErrUnableToGetBalance is returned by the indexer
	// when it is not possible to get the balance
	// of a *types.AccountIdentifier.
	ErrUnableToGetBalance = &types.Error{
		Code:    18,
		Message: "Unable to get balance",
	}
)

Functions

func LoggerMiddleware

func LoggerMiddleware(loggerRaw *zap.Logger, 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 NewAccountAPIService

func NewAccountAPIService(
	config *configuration.Configuration,
	i Indexer,
) server.AccountAPIServicer

NewAccountAPIService returns a new *AccountAPIService.

func NewBlockAPIService

func NewBlockAPIService(
	config *configuration.Configuration,
	i Indexer,
) server.BlockAPIServicer

NewBlockAPIService creates a new instance of a BlockAPIService.

func NewBlockchainRouter

func NewBlockchainRouter(
	config *configuration.Configuration,
	client Client,
	i Indexer,
	asserter *asserter.Asserter,
) http.Handler

NewBlockchainRouter creates a Mux http.Handler from a collection of server controllers.

func NewConstructionAPIService

func NewConstructionAPIService(
	config *configuration.Configuration,
	client Client,
	i Indexer,
) server.ConstructionAPIServicer

NewConstructionAPIService creates a new instance of a ConstructionAPIService.

func NewMempoolAPIService

func NewMempoolAPIService(
	config *configuration.Configuration,
	client Client,
) server.MempoolAPIServicer

NewMempoolAPIService creates a new instance of a MempoolAPIService.

func NewNetworkAPIService

func NewNetworkAPIService(
	config *configuration.Configuration,
	client Client,
	i Indexer,
) server.NetworkAPIServicer

NewNetworkAPIService creates a new instance of a NetworkAPIService.

Types

type AccountAPIService

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

AccountAPIService implements the server.AccountAPIServicer interface.

func (*AccountAPIService) AccountBalance

AccountBalance implements /account/balance.

func (*AccountAPIService) AccountCoins

AccountCoins implements /account/coins.

type BlockAPIService

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

BlockAPIService implements the server.BlockAPIServicer interface.

func (*BlockAPIService) Block

Block implements the /block endpoint.

func (*BlockAPIService) BlockTransaction

BlockTransaction implements the /block/transaction endpoint.

type Client

type Client interface {
	GetPeers(context.Context) ([]*types.Peer, error)
	SendRawTransaction(context.Context, string) (string, error)
	SuggestedFeeRate(context.Context, int64) (float64, error)
	RawMempool(context.Context) ([]string, error)
}

Client is used by the servicers to get Peer information and to submit transactions.

type ConstructionAPIService

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

ConstructionAPIService implements the server.ConstructionAPIServicer interface.

func (*ConstructionAPIService) ConstructionCombine

ConstructionCombine implements the /construction/combine endpoint.

func (*ConstructionAPIService) ConstructionDerive

ConstructionDerive implements the /construction/derive endpoint.

func (*ConstructionAPIService) ConstructionHash

ConstructionHash implements the /construction/hash endpoint.

func (*ConstructionAPIService) ConstructionMetadata

ConstructionMetadata implements the /construction/metadata endpoint.

func (*ConstructionAPIService) ConstructionParse

ConstructionParse implements the /construction/parse endpoint.

func (*ConstructionAPIService) ConstructionPayloads

ConstructionPayloads implements the /construction/payloads endpoint.

func (*ConstructionAPIService) ConstructionPreprocess

ConstructionPreprocess implements the /construction/preprocess endpoint.

func (*ConstructionAPIService) ConstructionSubmit

ConstructionSubmit implements the /construction/submit endpoint.

type Indexer

Indexer is used by the servicers to get block and account data.

type MempoolAPIService

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

MempoolAPIService implements the server.MempoolAPIServicer interface.

func (*MempoolAPIService) Mempool

Mempool implements the /mempool endpoint.

func (*MempoolAPIService) MempoolTransaction

MempoolTransaction implements the /mempool/transaction endpoint.

type NetworkAPIService

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

NetworkAPIService implements the server.NetworkAPIServicer interface.

func (*NetworkAPIService) NetworkList

NetworkList implements the /network/list endpoint

func (*NetworkAPIService) NetworkOptions

func (s *NetworkAPIService) NetworkOptions(
	ctx context.Context,
	request *types.NetworkRequest,
) (*types.NetworkOptionsResponse, *types.Error)

NetworkOptions implements the /network/options endpoint.

func (*NetworkAPIService) NetworkStatus

NetworkStatus implements the /network/status endpoint.

type ParseOperationMetadata

type ParseOperationMetadata struct {
	ScriptPubKey *oduwacoin.ScriptPubKey `json:"scriptPubKey"`
}

ParseOperationMetadata is returned from ConstructionParse.

type StatusRecorder

type StatusRecorder struct {
	http.ResponseWriter
	Code int
}

StatusRecorder is used to surface the status code of a HTTP response. We must use this wrapping because the status code is not exposed by the http.ResponseWriter in the http.HandlerFunc.

Inspired by: https://stackoverflow.com/questions/53272536/how-do-i-get-response-statuscode-in-golang-middleware

func NewStatusRecorder

func NewStatusRecorder(w http.ResponseWriter) *StatusRecorder

NewStatusRecorder returns a new *StatusRecorder.

func (*StatusRecorder) WriteHeader

func (r *StatusRecorder) WriteHeader(code int)

WriteHeader stores the status code of a response.

Jump to

Keyboard shortcuts

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