Documentation ¶
Index ¶
- Constants
- func GrpcMeteringInterceptor() grpc.StreamServerInterceptor
- func GrpcPaymentValidationInterceptor(serviceData *blockchain.ServiceMetadata, defaultPaymentHandler PaymentHandler, ...) grpc.StreamServerInterceptor
- func GrpcRateLimitInterceptor(broadcast *configuration_service.MessageBroadcaster) grpc.StreamServerInterceptor
- func NewGrpcHandler(serviceMetadata *blockchain.ServiceMetadata) grpc.StreamHandler
- func NewWrapperServerStream(stream grpc.ServerStream) (grpc.ServerStream, error)
- func NoOpInterceptor(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- type GrpcError
- func GetBigInt(md metadata.MD, key string) (value *big.Int, err *GrpcError)
- func GetBytes(md metadata.MD, key string) (result []byte, err *GrpcError)
- func GetBytesFromHex(md metadata.MD, key string) (value []byte, err *GrpcError)
- func GetSingleValue(md metadata.MD, key string) (value string, err *GrpcError)
- func NewGrpcError(code codes.Code, message string) *GrpcError
- func NewGrpcErrorf(code codes.Code, format string, args ...any) *GrpcError
- type GrpcStreamContext
- type Payment
- type PaymentHandler
- type WrapperServerStream
- func (f *WrapperServerStream) Context() context.Context
- func (f *WrapperServerStream) OriginalRecvMsg() any
- func (f *WrapperServerStream) RecvMsg(m any) error
- func (f *WrapperServerStream) SendHeader(md metadata.MD) error
- func (f *WrapperServerStream) SendMsg(m any) error
- func (f *WrapperServerStream) SetHeader(md metadata.MD) error
- func (f *WrapperServerStream) SetTrailer(md metadata.MD)
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" //Client that calls the Daemon ( example can be "snet-cli","snet-dapp","snet-sdk") ClientTypeHeader = "snet-client-type" //Value is a user address , example "0x94d04332C4f5273feF69c4a52D24f42a3aF1F207" UserInfoHeader = "snet-user-info" //User Agent details set in on the server stream info UserAgentHeader = "user-agent" // PaymentChannelIDHeader is a MultiPartyEscrow contract payment channel // id. Value is a string containing a decimal number. PaymentChannelIDHeader = "snet-payment-channel-id" // PaymentChannelNonceHeader is a payment channel nonce value. Value is a // string containing a decimal number. PaymentChannelNonceHeader = "snet-payment-channel-nonce" // PaymentChannelAmountHeader is an amount of payment channel value // which server is authorized to withdraw after handling the RPC call. // Value is a string containing a decimal number. PaymentChannelAmountHeader = "snet-payment-channel-amount" // PaymentChannelSignatureHeader is a signature of the client to confirm // amount withdrawing authorization. Value is an array of bytes. PaymentChannelSignatureHeader = "snet-payment-channel-signature-bin" // This is useful information in the header sent in by the client // All clients will have this information and they need this to Sign anyways // When Daemon is running in the block chain disabled mode , it would use this // header to get the MPE address. The goal here is to keep the client oblivious to the // Daemon block chain enabled or disabled mode and also standardize the signatures. // id. Value is a string containing a decimal number. PaymentMultiPartyEscrowAddressHeader = "snet-payment-mpe-address" //The user Id of the person making the call FreeCallUserIdHeader = "snet-free-call-user-id" //Will be used to check if the Signature is still valid CurrentBlockNumberHeader = "snet-current-block-number" //Place holder to set the free call Auth Token issued FreeCallAuthTokenHeader = "snet-free-call-auth-token-bin" //Block number on when the Token was issued , to track the expiry of the token , which is ~ 1 Month FreeCallAuthTokenExpiryBlockNumberHeader = "snet-free-call-token-expiry-block" //Users may decide to sign upfront and make calls .Daemon generates and Auth Token //Users/Clients will need to use this token to make calls for the amount signed upfront. PrePaidAuthTokenHeader = "snet-prepaid-auth-token-bin" DynamicPriceDerived = "snet-derived-dynamic-price-cost" )
const ( // IncorrectNonce is returned to client when payment received 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
Variables ¶
This section is empty.
Functions ¶
func GrpcMeteringInterceptor ¶
func GrpcMeteringInterceptor() grpc.StreamServerInterceptor
func GrpcPaymentValidationInterceptor ¶
func GrpcPaymentValidationInterceptor(serviceData *blockchain.ServiceMetadata, 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(broadcast *configuration_service.MessageBroadcaster) grpc.StreamServerInterceptor
func NewGrpcHandler ¶
func NewGrpcHandler(serviceMetadata *blockchain.ServiceMetadata) grpc.StreamHandler
func NewWrapperServerStream ¶
func NewWrapperServerStream(stream grpc.ServerStream) (grpc.ServerStream, error)
func NoOpInterceptor ¶
func NoOpInterceptor(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
NoOpInterceptor is a gRPC interceptor which doesn't do payment checking.
Types ¶
type GrpcError ¶
GrpcError is an error which will be returned by interceptor via gRPC protocol. Part of information will be returned as header metadata.
func GetBytes ¶
GetBytes gets bytes array value from gRPC metadata for key with '-bin' suffix, internally this data is encoded as base64
func GetBytesFromHex ¶
GetBytesFromHex gets bytes array value from gRPC metadata, bytes array is encoded as hex string
func GetSingleValue ¶
GetSingleValue gets string value from gRPC metadata
func NewGrpcError ¶
NewGrpcError returns new error which contains gRPC status with provided code and message
func NewGrpcErrorf ¶
NewGrpcErrorf returns new error which contains gRPC status with provided code and message formed from format string and args.
type GrpcStreamContext ¶
type GrpcStreamContext struct { MD metadata.MD Info *grpc.StreamServerInfo InStream grpc.ServerStream }
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 any
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 deprecated.
type WrapperServerStream ¶
type WrapperServerStream struct {
// contains filtered or unexported fields
}
func (*WrapperServerStream) Context ¶
func (f *WrapperServerStream) Context() context.Context
func (*WrapperServerStream) OriginalRecvMsg ¶
func (f *WrapperServerStream) OriginalRecvMsg() any
func (*WrapperServerStream) RecvMsg ¶
func (f *WrapperServerStream) RecvMsg(m any) error
func (*WrapperServerStream) SendHeader ¶
func (f *WrapperServerStream) SendHeader(md metadata.MD) error
func (*WrapperServerStream) SendMsg ¶
func (f *WrapperServerStream) SendMsg(m any) error
func (*WrapperServerStream) SetHeader ¶
func (f *WrapperServerStream) SetHeader(md metadata.MD) error
func (*WrapperServerStream) SetTrailer ¶
func (f *WrapperServerStream) SetTrailer(md metadata.MD)