Documentation ¶
Index ¶
Constants ¶
const (
Header = "Computantis-Validator"
)
Variables ¶
Functions ¶
func Run ¶
func Run(ctx context.Context, cfg Config, srw StatusReadWriter, log logger.Logger, ver Verifier, wh WebhookCreateRemovePoster, wallet *wallet.Wallet) error
Run initializes routing and runs the validator. To stop the validator cancel the context. Validator connects to the central server via websocket and listens for new blocks. It will block until the context is canceled.
Types ¶
type Config ¶
type Config struct { Token string `yaml:"token"` // token is used to authenticate validator in the central server Websocket string `yaml:"websocket"` // websocket address of the central server Port int `yaml:"port"` // port on which validator will listen for http requests }
Config contains configuration of the validator.
type CreateRemoveUpdateHookRequest ¶
type CreateRemoveUpdateHookRequest struct { URL string `json:"address"` // URL is a url of the webhook. Hook string `json:"hook"` // Hook is a type of the webhook. It describes on what event the webhook is triggered. Address string `json:"wallet_address"` // Address is the address of the wallet that is used to sign the webhook. Token string `json:"token"` // Token is the token added to the webhook to verify that the message comes from the valid source. Data []byte `json:"data"` // Data is the data is a subject of the signature. It is signed by the wallet address. Digest []byte `json:"digest"` // Digest is the digest of the data. It is used to verify that the data is not changed. Signature []byte `json:"signature"` // Signature is the signature of the data. It is used to verify that the data is not changed. }
CreateRemoveUpdateHookRequest is the request sent to create, remove or update the webhook.
type Status ¶
type Status struct { ID any `json:"-" bson:"_id,omitempty" db:"id"` Index int64 `json:"index" bson:"index" db:"index"` Block block.Block `json:"block" bson:"block" db:"-"` Valid bool `json:"valid" bson:"valid" db:"valid"` CreatedAt time.Time `json:"created_at" bson:"created_at" db:"created_at"` }
Status is a status of each received block by the validator. It keeps track of invalid blocks in case of blockchain corruption.
type StatusReadWriter ¶
type StatusReadWriter interface { WriteValidatorStatus(ctx context.Context, vs *Status) error ReadLastNValidatorStatuses(ctx context.Context, last int64) ([]Status, error) }
StatusReadWriter provides methods to bulk read and single write validator status.
type WebHookNewBlockMessage ¶
type WebHookNewBlockMessage struct { Token string `json:"token"` // Token given to the webhook by the webhooks creator to validate the message source. Block block.Block `json:"block"` // Block is the block that was mined. Valid bool `json:"valid"` // Valid is the flag that indicates if the block is valid. }
WebHookNewBlockMessage is the message sent to the webhook url that was created.
type WebhookCreateRemovePoster ¶
type WebhookCreateRemovePoster interface { CreateWebhook(trigger string, h webhooks.Hook) error RemoveWebhook(trigger string, h webhooks.Hook) error PostWebhookBlock(blc *block.Block) }
WebhookCreateRemovePoster provides methods to create, remove webhooks and post messages to webhooks.