payloads

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package payloads contains the different types of RPC payloads the partials package supports. The structs defined here are used to partially unmarshal the payload and extract the minimal fields required to: generate error responses, retrieve RPC request type, determine request compute units, etc... This is done through partially unmarshalling the payload into the minimum required set of pre-defined fields that need to be explicitly determined for each RPC type supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PartialJSONPayload

type PartialJSONPayload struct {
	Id      uint64 `json:"id"`
	JsonRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
}

PartialJSONPayload is a partial representation of a JSON-RPC request payload that contains the minimal fields necessary for basic business logic such as generating an error response, handling request account, etc...

func PartiallyUnmarshalJSONPayload

func PartiallyUnmarshalJSONPayload(payloadBz []byte) (*PartialJSONPayload, error)

PartiallyUnmarshalJSONPayload receives a serialized payload and attempts to unmarshal it into the PartialJSONPayload struct. If successful this struct is returned, if however the struct does not contain all the required fields an error is returned detailing what was missing. If the payload is not a JSON request this function will return nil, nil

func (*PartialJSONPayload) GenerateErrorPayload

func (j *PartialJSONPayload) GenerateErrorPayload(err error) ([]byte, error)

GenerateErrorPayload creates a JSON-RPC error payload from the provided error with the macthing json-rpc and id fields from the request payload.

func (*PartialJSONPayload) GetRPCComputeUnits

func (j *PartialJSONPayload) GetRPCComputeUnits(ctx context.Context) (uint64, error)

GetRPCComputeUnits returns the compute units for the RPC request

func (*PartialJSONPayload) GetRPCType

func (j *PartialJSONPayload) GetRPCType() types.RPCType

GetRPCType returns the request type for the given payload.

func (PartialJSONPayload) ValidateBasic

func (j PartialJSONPayload) ValidateBasic(ctx context.Context) error

ValidateBasic ensures that all the required fields are set in the partial JSON payload. It uses a non-pointer receiver to ensure the default values of unset fields are present

type PartialRESTPayload

type PartialRESTPayload struct {
	Headers map[string]string `json:"headers"`
}

PartialRESTPayload is a partial representation of a REST request payload that contains the minimal fields necessary for basic business logic such as generating an error response, handling request account, etc...

func PartiallyUnmarshalRESTPayload

func PartiallyUnmarshalRESTPayload(payloadBz []byte) (restPayload *PartialRESTPayload, success bool)

PartiallyUnmarshalRESTPayload receives a serialized payload and attempts to unmarshal it into the PartialRESTPayload struct. If successful this struct is returned, if however the struct does not contain all the required fields the success return value is false and a nil payload is returned.

func (*PartialRESTPayload) GenerateErrorPayload

func (r *PartialRESTPayload) GenerateErrorPayload(err error) ([]byte, error)

GenerateErrorPayload creates a REST error payload using the headers from the request payload.

func (*PartialRESTPayload) GetRPCComputeUnits

func (r *PartialRESTPayload) GetRPCComputeUnits(ctx context.Context) (uint64, error)

GetRPCComputeUnits returns the compute units for the RPC request

func (*PartialRESTPayload) GetRPCType

func (r *PartialRESTPayload) GetRPCType() types.RPCType

GetRPCType returns the request type for the given payload.

func (PartialRESTPayload) ValidateBasic

func (r PartialRESTPayload) ValidateBasic(ctx context.Context) error

ValidateBasic ensures that all the required fields are set in the partial REST payload. It uses a non-pointer receiver to ensure the default values of unset fields are present

Jump to

Keyboard shortcuts

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