Documentation ¶
Index ¶
- Constants
- func GetBigInt(md metadata.MD, key string) (value *big.Int, err *status.Status)
- func GetBytes(md metadata.MD, key string) (result []byte, err *status.Status)
- func GetBytesFromHex(md metadata.MD, key string) (value []byte, err *status.Status)
- func GetSingleValue(md metadata.MD, key string) (value string, err *status.Status)
- func GrpcStreamInterceptor(defaultPaymentHandler PaymentHandler, paymentHandler ...PaymentHandler) grpc.StreamServerInterceptor
- func NewGrpcHandler() grpc.StreamHandler
- func NoOpInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- type GrpcStreamContext
- type Payment
- type PaymentHandler
Constants ¶
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 GetBytes ¶ added in v0.1.2
GetBytes gets bytes array value from gRPC metadata for key with '-bin' suffix, internally this data is encoded as base64
func GetBytesFromHex ¶ added in v0.1.2
GetBytesFromHex gets bytes array value from gRPC metadata, bytes array is encoded as hex string
func GetSingleValue ¶ added in v0.1.2
GetSingleValue gets string value from gRPC metadata
func GrpcStreamInterceptor ¶ added in v0.1.2
func GrpcStreamInterceptor(defaultPaymentHandler PaymentHandler, paymentHandler ...PaymentHandler) grpc.StreamServerInterceptor
GrpcStreamInterceptor returns gRPC interceptor to validate payment. If blockchain is disabled then noOpInterceptor is returned.
func NewGrpcHandler ¶
func NewGrpcHandler() grpc.StreamHandler
func NoOpInterceptor ¶ added in v0.1.2
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 GrpcStreamContext ¶ added in v0.1.2
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 ¶ added in v0.1.2
func (context *GrpcStreamContext) String() string
type Payment ¶ added in v0.1.2
type Payment interface{}
Payment represents payment handler specific data which is validated and used to complete payment.
type PaymentHandler ¶ added in v0.1.2
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. Payment(context *GrpcStreamContext) (payment Payment, err *status.Status) // Validate checks validity of payment data, it returns nil if data is // valid or appropriate gRPC error otherwise. Validate(payment Payment) (err *status.Status) // Complete completes payment if gRPC call was successfully proceeded by // service. Complete(payment Payment) (err *status.Status) // CompleteAfterError completes payment if service returns error. CompleteAfterError(payment Payment, result error) (err *status.Status) }
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.