dapp

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 6 Imported by: 15

Documentation

Index

Constants

View Source
const (
	EventBodyBasic = 1 + iota
	EventBodyLinked

	JSONDataType = 1
)
View Source
const (
	HashSize = 32
	HashLen  = 43
)

Variables

View Source
var (
	ErrInvalidEventBodyVersion = status.New(
		pletyvo.CodeInvalidArgument, "invalid event body version",
	)
	ErrInvalidEventBodyDataType = status.New(
		pletyvo.CodeInvalidArgument, "invalid event body data type",
	)
	ErrInvalidEventType = status.New(
		pletyvo.CodeInvalidArgument, "unsupported event type",
	)

	EventBodyMetaSize = [3]int{EventBodyBasic: 4, EventBodyLinked: 36}
)
View Source
var (
	HashNil Hash

	ErrInvalidHashSize = status.New(
		pletyvo.CodeInvalidArgument, "invalid hash size",
	)
	ErrInvalidHashLen = status.New(
		pletyvo.CodeInvalidArgument, "invalid hash length",
	)
)

Functions

func DecodeHash

func DecodeHash(dst []byte, src []byte) error

Types

type AuthHeader

type AuthHeader struct {
	Schema    byte   `json:"sch"`
	PublicKey []byte `json:"pub"`
	Signature []byte `json:"sig"`
}

type Event

type Event struct {
	ID   uuid.UUID  `json:"id"`
	Body EventBody  `json:"body"`
	Auth AuthHeader `json:"auth"`
}

type EventBody

type EventBody []byte

func NewEventBody

func NewEventBody(version, dataType byte, eventType uint16, value any) EventBody

func (EventBody) Bytes

func (eb EventBody) Bytes() []byte

func (EventBody) Data

func (eb EventBody) Data() []byte

func (EventBody) DataType

func (eb EventBody) DataType() byte

func (EventBody) MarshalJSON

func (eb EventBody) MarshalJSON() ([]byte, error)

func (EventBody) Parent

func (eb EventBody) Parent() Hash

func (EventBody) SetParent

func (eb EventBody) SetParent(hash Hash)

func (EventBody) String

func (eb EventBody) String() string

func (EventBody) Type

func (eb EventBody) Type() uint16

func (EventBody) Unmarshal

func (eb EventBody) Unmarshal(v any) error

func (*EventBody) UnmarshalJSON

func (eb *EventBody) UnmarshalJSON(b []byte) error

func (EventBody) Version

func (eb EventBody) Version() byte

type EventHeader

type EventHeader struct {
	ID   uuid.UUID `json:"id"`
	Hash Hash      `json:"hash"`
}

type EventInput

type EventInput struct {
	Body EventBody  `json:"body"`
	Auth AuthHeader `json:"auth"`
}

func (*EventInput) Verify

func (ei *EventInput) Verify(f EventInputVerifierFunc) bool

type EventInputVerifierFunc

type EventInputVerifierFunc func(*EventInput) bool

type EventQuery

type EventQuery interface {
	Get(context.Context, *pletyvo.QueryOption) ([]*Event, error)
	GetByID(context.Context, uuid.UUID) (*Event, error)
}

type EventRepository

type EventRepository interface {
	EventQuery
	Create(context.Context, *SystemEvent) error
}

type EventResponse

type EventResponse struct {
	ID uuid.UUID `json:"id"`
}

type EventService

type EventService interface {
	EventQuery
	Create(context.Context, *EventInput) (*EventResponse, error)
}

type Handler

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

func NewHandler

func NewHandler() *Handler

func (Handler) Handle

func (h Handler) Handle(ctx context.Context, event *SystemEvent) error

func (*Handler) Register

func (h *Handler) Register(eventType uint16, handlerFunc HandlerFunc)

type HandlerFunc

type HandlerFunc func(context.Context, *SystemEvent) error

type Hash

type Hash [HashSize]byte

func HashFromString

func HashFromString(s string) (hash Hash, err error)

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(b []byte) error

type HashQuery

type HashQuery interface {
	GetByID(context.Context, Hash) (*EventResponse, error)
}

type HashRepository

type HashRepository interface {
	HashQuery
	Create(context.Context, *EventHeader) error
}

type HashService

type HashService interface{ HashQuery }

type Query

type Query struct {
	Event EventQuery
	Hash  HashQuery
}

type Repository

type Repository struct {
	Event EventRepository
	Hash  HashRepository
}

type Service

type Service struct {
	Event EventService
	Hash  HashService
}

type SystemEvent

type SystemEvent struct {
	*EventHeader
	*EventInput
	Author Hash
}

Directories

Path Synopsis
crypto module

Jump to

Keyboard shortcuts

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