handler

package
v0.1.10-64-g7180dea Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IncorrectNonce is returned to client when payment recieved contains
	// incorrect nonce value. Client may use PaymentChannelStateService to get
	// latest channel state and correct nonce value.
	IncorrectNonce codes.Code = 1000
)

Custom gRPC codes to return to the client

View Source
const (
	// PaymentTypeHeader is a type of payment used to pay for a RPC call.
	// Supported types are: "escrow".
	// Note: "job" Payment type is deprecated
	PaymentTypeHeader = "snet-payment-type"
)

Variables

This section is empty.

Functions

func GrpcMonitoringInterceptor

func GrpcMonitoringInterceptor() grpc.StreamServerInterceptor

func GrpcPaymentValidationInterceptor

func GrpcPaymentValidationInterceptor(defaultPaymentHandler PaymentHandler, paymentHandler ...PaymentHandler) grpc.StreamServerInterceptor

GrpcStreamInterceptor returns gRPC interceptor to validate payment. If blockchain is disabled then noOpInterceptor is returned.

func GrpcRateLimitInterceptor

func GrpcRateLimitInterceptor() grpc.StreamServerInterceptor

func NewGrpcHandler

func NewGrpcHandler(serviceMetadata *blockchain.ServiceMetadata) grpc.StreamHandler

func NoOpInterceptor

func NoOpInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo,
	handler grpc.StreamHandler) error

NoOpInterceptor is a gRPC interceptor which doesn't do payment checking.

Types

type GrpcError

type GrpcError struct {
	// Status is a gRPC call status
	Status *status.Status
}

GrpcError is an error which will be returned by interceptor via gRPC protocol. Part of information will be returned as header metadata.

func GetBigInt

func GetBigInt(md metadata.MD, key string) (value *big.Int, err *GrpcError)

GetBigInt gets big.Int value from gRPC metadata

func GetBytes

func GetBytes(md metadata.MD, key string) (result []byte, err *GrpcError)

GetBytes gets bytes array value from gRPC metadata for key with '-bin' suffix, internally this data is encoded as base64

func GetBytesFromHex

func GetBytesFromHex(md metadata.MD, key string) (value []byte, err *GrpcError)

GetBytesFromHex gets bytes array value from gRPC metadata, bytes array is encoded as hex string

func GetSingleValue

func GetSingleValue(md metadata.MD, key string) (value string, err *GrpcError)

GetSingleValue gets string value from gRPC metadata

func NewGrpcError

func NewGrpcError(code codes.Code, message string) *GrpcError

NewGrpcError returns new error which contains gRPC status with provided code and message

func NewGrpcErrorf

func NewGrpcErrorf(code codes.Code, format string, args ...interface{}) *GrpcError

NewGrpcErrorf returns new error which contains gRPC status with provided code and message formed from format string and args.

func (*GrpcError) Err

func (err *GrpcError) Err() error

Err returns error to return correct gRPC error to the caller

func (*GrpcError) String

func (err *GrpcError) String() string

String converts GrpcError to string

type GrpcStreamContext

type GrpcStreamContext struct {
	MD   metadata.MD
	Info *grpc.StreamServerInfo
}

GrpcStreamContext contains information about gRPC call which is used to validate payment and pricing.

func (*GrpcStreamContext) String

func (context *GrpcStreamContext) String() string

type Payment

type Payment interface{}

Payment represents payment handler specific data which is validated and used to complete payment.

type PaymentHandler

type PaymentHandler interface {
	// Type is a content of PaymentTypeHeader field which triggers usage of the
	// payment handler.
	Type() (typ string)
	// Payment extracts payment data from gRPC request context and checks
	// validity of payment data. It returns nil if data is valid or
	// appropriate gRPC status otherwise.
	Payment(context *GrpcStreamContext) (payment Payment, err *GrpcError)
	// Complete completes payment if gRPC call was successfully proceeded by
	// service.
	Complete(payment Payment) (err *GrpcError)
	// CompleteAfterError completes payment if service returns error.
	CompleteAfterError(payment Payment, result error) (err *GrpcError)
}

PaymentHandler interface which is used by gRPC interceptor to get, validate and complete payment. There are two payment handler implementations so far: jobPaymentHandler and escrowPaymentHandler. jobPaymentHandler is depreactted.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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