gater

package
v0.2.1-test Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGatewayDomain    = "localhost:9133"
	DefaultMaxListReadQuota = 100
	DefaultMaxPayloadSize   = 2 * 1024 * 1024 * 1024
)

Variables

View Source
var (
	ErrUnsupportedSignType    = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50001, "unsupported sign type")
	ErrAuthorizationFormat    = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50002, "authorization format error")
	ErrRequestConsistent      = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50003, "request is tampered")
	ErrNoPermission           = gfsperrors.Register(module.GateModularName, http.StatusUnauthorized, 50004, "no permission")
	ErrDecodeMsg              = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50005, "gnfd msg encoding error")
	ErrValidateMsg            = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50006, "gnfd msg validate error")
	ErrRefuseApproval         = gfsperrors.Register(module.GateModularName, http.StatusOK, 50007, "approval request is refuse")
	ErrUnsupportedRequestType = gfsperrors.Register(module.GateModularName, http.StatusNotFound, 50008, "unsupported request type")
	ErrInvalidHeader          = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50009, "invalid request header")
	ErrInvalidQuery           = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50010, "invalid request header params for query")
	ErrEncodeResponse         = gfsperrors.Register(module.GateModularName, http.StatusInternalServerError, 50011, "server slipped away, try again later")
	ErrInvalidRange           = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50012, "invalid range params")
	ErrExceptionStream        = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 50013, "stream exception")
	ErrMismatchSp             = gfsperrors.Register(module.GateModularName, http.StatusNotAcceptable, 50014, "mismatch sp")
	ErrSignature              = gfsperrors.Register(module.GateModularName, http.StatusNotAcceptable, 50015, "signature verification failed")
	ErrInvalidPayloadSize     = gfsperrors.Register(module.GateModularName, http.StatusForbidden, 50016, "invalid payload")
	ErrApprovalExpired        = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 550015, "approval expired")
	ErrConsensus              = gfsperrors.Register(module.GateModularName, http.StatusBadRequest, 55001, "server slipped away, try again later")
)

Functions

func DefaultGaterOptions

func DefaultGaterOptions(gater *GateModular, cfg *gfspconfig.GfSpConfig) error

func MakeErrorResponse

func MakeErrorResponse(w http.ResponseWriter, err error)

func RecoverAddr

func RecoverAddr(msg []byte, sig []byte) (sdk.AccAddress, ethsecp256k1.PubKey, error)

RecoverAddr recovers the sender address from msg and signature TODO: move it to greenfield-common

Types

type GateModular

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

func (*GateModular) Name

func (g *GateModular) Name() string

func (*GateModular) RegisterHandler

func (g *GateModular) RegisterHandler(router *mux.Router)

RegisterHandler registers the handlers to the gateway router.

func (*GateModular) ReleaseResource

func (g *GateModular) ReleaseResource(
	ctx context.Context,
	span rcmgr.ResourceScopeSpan)

func (*GateModular) ReserveResource

func (g *GateModular) ReserveResource(
	ctx context.Context,
	state *rcmgr.ScopeStat) (
	rcmgr.ResourceScopeSpan, error)

func (*GateModular) Start

func (g *GateModular) Start(ctx context.Context) error

func (*GateModular) Stop

func (g *GateModular) Stop(ctx context.Context) error

type RequestContext

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

RequestContext generates from http request, it records the common info for handler to use.

func NewRequestContext

func NewRequestContext(r *http.Request) (*RequestContext, error)

NewRequestContext returns an instance of RequestContext, and verify the request signature, returns the instance regardless of the success or failure of the verification.

func (*RequestContext) Account

func (r *RequestContext) Account() string

Account returns the account who send the request.

func (*RequestContext) Cancel

func (r *RequestContext) Cancel()

Cancel releases the runtime context.

func (*RequestContext) Context

func (r *RequestContext) Context() context.Context

Context returns the RequestContext runtime context.

func (*RequestContext) NeedVerifyAuthorizer

func (r *RequestContext) NeedVerifyAuthorizer() bool

NeedVerifyAuthorizer is temporary to Compatible SignatureV2

func (*RequestContext) SetError

func (r *RequestContext) SetError(err error)

SetError sets the request err to RequestContext for logging and debugging.

func (*RequestContext) SetHttpCode

func (r *RequestContext) SetHttpCode(code int)

SetHttpCode sets the http status code for logging and debugging.

func (*RequestContext) String

func (r *RequestContext) String() string

String shows the detail result of the request for logging and debugging.

func (*RequestContext) VerifySignature

func (r *RequestContext) VerifySignature() (string, error)

Jump to

Keyboard shortcuts

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