fraud

package
v0.0.0-...-4e9d6c2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstructModule

func ConstructModule(tp node.Type) fx.Option

Types

type API

type API struct {
	Internal struct {
		Subscribe func(context.Context, fraud.ProofType) (<-chan Proof, error) `perm:"public"`
		Get       func(context.Context, fraud.ProofType) ([]Proof, error)      `perm:"public"`
	}
}

API is a wrapper around Module for the RPC. TODO(@distractedm1nd): These structs need to be autogenerated.

func (*API) Get

func (api *API) Get(ctx context.Context, proofType fraud.ProofType) ([]Proof, error)

func (*API) Subscribe

func (api *API) Subscribe(ctx context.Context, proofType fraud.ProofType) (<-chan Proof, error)

type Module

type Module interface {
	// Subscribe allows to subscribe on a Proof pub sub topic by its type.
	Subscribe(context.Context, fraud.ProofType) (<-chan Proof, error)
	// Get fetches fraud proofs from the disk by its type.
	Get(context.Context, fraud.ProofType) ([]Proof, error)
}

Module encompasses the behavior necessary to subscribe and broadcast fraud proofs within the network. Any method signature changed here needs to also be changed in the API struct.

type Proof

type Proof struct {
	fraud.Proof
}

Proof embeds the fraud.Proof interface type to provide a concrete type for JSON serialization.

func (*Proof) MarshalJSON

func (f *Proof) MarshalJSON() ([]byte, error)

func (*Proof) UnmarshalJSON

func (f *Proof) UnmarshalJSON(data []byte) error

type Service

type Service struct {
	fraud.Service
}

Service is an implementation of Module that uses fraud.Service as a backend. It is used to provide fraud proofs as a non-interface type to the API, and wrap fraud.Subscriber with a channel of Proofs.

func (*Service) Get

func (s *Service) Get(ctx context.Context, proofType fraud.ProofType) ([]Proof, error)

func (*Service) Subscribe

func (s *Service) Subscribe(ctx context.Context, proofType fraud.ProofType) (<-chan Proof, error)

type ServiceBreaker

type ServiceBreaker[S service] struct {
	Service   S
	FraudType fraud.ProofType
	FraudServ fraud.Service
	// contains filtered or unexported fields
}

ServiceBreaker wraps any service with fraud proof subscription of a specific type. If proof happens the service is Stopped automatically. TODO(@Wondertan): Support multiple fraud types.

func (*ServiceBreaker[S]) Start

func (breaker *ServiceBreaker[S]) Start(ctx context.Context) error

Start starts the inner service if there are no fraud proofs stored. Subscribes for fraud and stops the service whenever necessary.

func (*ServiceBreaker[S]) Stop

func (breaker *ServiceBreaker[S]) Stop(ctx context.Context) error

Stop stops the service and cancels subscription.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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