storage

package
v0.0.0-...-2d88f35 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttestationVaa

type AttestationVaa struct {
	ID               string      `db:"id"`
	VaaID            string      `db:"vaa_id"`
	Version          uint8       `db:"version"`
	EmitterChain     sdk.ChainID `db:"emitter_chain_id"`
	EmitterAddress   string      `db:"emitter_address"`
	Sequence         Uint64      `db:"sequence"`
	GuardianSetIdx   uint32      `db:"guardian_set_index"`
	Raw              []byte      `db:"raw"`
	Timestamp        time.Time   `db:"timestamp"`
	Active           bool        `db:"active"`
	IsDuplicated     bool        `db:"is_duplicated"`
	ConsistencyLevel *uint8      `db:"consistency_level"`
	CreatedAt        time.Time   `db:"created_at"`
	UpdatedAt        *time.Time  `db:"updated_at"`
}

type ChainGovernorConfigChain

type ChainGovernorConfigChain struct {
	ChainId            uint32 `json:"chainId"`
	NotionalLimit      Uint64 `json:"notionalLimit"`
	BigTransactionSize Uint64 `json:"bigTransactionSize"`
}

type ChainGovernorConfigToken

type ChainGovernorConfigToken struct {
	OriginChainId uint32  `json:"originChainId"`
	OriginAddress string  `json:"originAddress"`
	Price         float32 `json:"price"`
}

type ChainGovernorConfigUpdate

type ChainGovernorConfigUpdate struct {
	NodeName  string                      `json:"nodeName"`
	Counter   int64                       `json:"counter"`
	Timestamp int64                       `json:"timestamp"`
	Chains    []*ChainGovernorConfigChain `json:"chains"`
	Tokens    []*ChainGovernorConfigToken `json:"tokens"`
}

type ChainGovernorStatusChain

type ChainGovernorStatusChain struct {
	ChainId                    uint32                        `bson:"chainid" json:"chainId"`
	RemainingAvailableNotional Uint64                        `bson:"remainingavailablenotional" json:"remainingAvailableNotional"`
	Emitters                   []*ChainGovernorStatusEmitter `bson:"emitters" json:"emitters"`
}

type ChainGovernorStatusEmitter

type ChainGovernorStatusEmitter struct {
	EmitterAddress    string                            `bson:"emitteraddress" json:"emitterAddress"`
	TotalEnqueuedVaas Uint64                            `bson:"totalenqueuedvaas" json:"totalEnqueuedVaas"`
	EnqueuedVaas      []*ChainGovernorStatusEnqueuedVAA `bson:"enqueuedvaas" json:"enqueuedVaas"`
}

type ChainGovernorStatusEnqueuedVAA

type ChainGovernorStatusEnqueuedVAA struct {
	Sequence      string `bson:"sequence" json:"sequence"`
	ReleaseTime   uint32 `bson:"releasetime" json:"releaseTime"`
	NotionalValue Uint64 `bson:"notionalvalue" json:"notionalValue"`
	TxHash        string `bson:"txhash" json:"txHash"`
}

type DuplicateVaaUpdate

type DuplicateVaaUpdate struct {
	ID               string      `bson:"_id"`
	VaaID            string      `bson:"vaaId"`
	Version          uint8       `bson:"version"`
	EmitterChain     sdk.ChainID `bson:"emitterChain"`
	EmitterAddr      string      `bson:"emitterAddr"`
	Sequence         string      `bson:"sequence"`
	GuardianSetIndex uint32      `bson:"guardianSetIndex"`
	Vaa              []byte      `bson:"vaas"`
	Digest           string      `bson:"digest"`
	ConsistencyLevel uint8       `bson:"consistencyLevel"`
	TxHash           string      `bson:"txHash,omitempty"`
	Timestamp        *time.Time  `bson:"timestamp"`
	UpdatedAt        *time.Time  `bson:"updatedAt"`
}

func (*DuplicateVaaUpdate) ToMap

func (v *DuplicateVaaUpdate) ToMap() map[string]string

ToMap returns a map representation of the VaaUpdate.

type GovernorStatusUpdate

type GovernorStatusUpdate struct {
	NodeName  string                      `bson:"nodename" json:"nodeName"`
	Counter   int64                       `bson:"counter" json:"counter"`
	Timestamp int64                       `bson:"timestamp" json:"timestamp"`
	Chains    []*ChainGovernorStatusChain `bson:"chains" json:"chains"`
}

type IndexingTimestamps

type IndexingTimestamps struct {
	IndexedAt time.Time `bson:"indexedAt"`
}

type MongoConnections

type MongoConnections struct {
	Current      int32 `bson:"current"`
	Available    int32 `bson:"available"`
	TotalCreated int32 `bson:"totalCreated"`
}

MongoConnections represents a mongo server connection.

type MongoRepository

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

TODO remove repository after switch to postgres db. TODO separate and maybe share between fly and web

func NewMongoRepository

func NewMongoRepository(alertService alert.AlertClient, metrics metrics.Metrics,
	db *mongo.Database,
	vaaTopicFunc producer.PushFunc,
	txHashStore txhash.TxHashStore,
	eventDispatcher event.EventDispatcher,
	log *zap.Logger) *MongoRepository

TODO wrap repository with a service that filters using redis

func (*MongoRepository) FindVaaByChainID

func (r *MongoRepository) FindVaaByChainID(ctx context.Context, chainID sdk.ChainID, page int64, pageSize int64) ([]*VaaUpdate, error)

func (*MongoRepository) FindVaaByID

func (r *MongoRepository) FindVaaByID(ctx context.Context, vaaID string) (*VaaUpdate, error)

func (*MongoRepository) FindVaasByVaaID

func (s *MongoRepository) FindVaasByVaaID(ctx context.Context, vaaID string) ([]*AttestationVaa, error)

FindDuplicateVaaByVaaID find vaas by vaaID Requiered method to support Storager interface

func (*MongoRepository) GetMongoStatus

func (r *MongoRepository) GetMongoStatus(ctx context.Context) (*MongoStatus, error)

GetMongoStatus get mongo server status

func (*MongoRepository) ReplaceVaaTxHash

func (s *MongoRepository) ReplaceVaaTxHash(ctx context.Context, vaaID, oldTxHash, newTxHash string) error

func (*MongoRepository) UpsertDuplicateVaa

func (s *MongoRepository) UpsertDuplicateVaa(ctx context.Context, v *sdk.VAA, serializedVaa []byte) error

func (*MongoRepository) UpsertGovernorConfig

func (s *MongoRepository) UpsertGovernorConfig(ctx context.Context, govC *gossipv1.SignedChainGovernorConfig) error

func (*MongoRepository) UpsertGovernorStatus

func (s *MongoRepository) UpsertGovernorStatus(ctx context.Context, govS *gossipv1.SignedChainGovernorStatus) error

func (*MongoRepository) UpsertHeartbeat

func (s *MongoRepository) UpsertHeartbeat(hb *gossipv1.Heartbeat) error

func (*MongoRepository) UpsertObservation

func (s *MongoRepository) UpsertObservation(ctx context.Context, o *gossipv1.SignedObservation, saveTxHash bool) error

func (*MongoRepository) UpsertVAA

func (s *MongoRepository) UpsertVAA(ctx context.Context, v *sdk.VAA, serializedVaa []byte) error

type MongoStatus

type MongoStatus struct {
	Ok          int32             `bson:"ok"`
	Host        string            `bson:"host"`
	Version     string            `bson:"version"`
	Process     string            `bson:"process"`
	Pid         int32             `bson:"pid"`
	Uptime      int32             `bson:"uptime"`
	Connections *MongoConnections `bson:"connections"`
}

MongoStatus represent a mongo server status.

type ObservationUpdate

type ObservationUpdate struct {
	MessageID    string      `bson:"messageId"`
	ChainID      sdk.ChainID `bson:"emitterChain"`
	Emitter      string      `bson:"emitterAddr"`
	Sequence     string      `bson:"sequence"`
	Hash         []byte      `bson:"hash"`
	TxHash       []byte      `bson:"txHash"`
	NativeTxHash string      `bson:"nativeTxHash"`
	GuardianAddr string      `bson:"guardianAddr"`
	Signature    []byte      `bson:"signature"`
	UpdatedAt    *time.Time  `bson:"updatedAt"`
}

func (*ObservationUpdate) ToMap

func (v *ObservationUpdate) ToMap() map[string]string

type PostgresRepository

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

PostgresRepository is a storage repository.

func NewPostgresRepository

func NewPostgresRepository(db *db.DB, metrics metrics.Metrics,
	eventDispatcher event.EventDispatcher, vaaTopicFunc producer.PushFunc,
	logger *zap.Logger) *PostgresRepository

NewPostgresRepository creates a new storage repository.

func (*PostgresRepository) FindVaaByChainID

func (r *PostgresRepository) FindVaaByChainID(ctx context.Context, chainID sdk.ChainID, page int64, pageSize int64) ([]*VaaUpdate, error)

FindVaaByChainID finds a VAA by chain ID. Requiered method to support Storager interface TODO: delete this methods after migration

func (*PostgresRepository) FindVaaByID

func (r *PostgresRepository) FindVaaByID(ctx context.Context, vaaID string) (*VaaUpdate, error)

FindVaaByID finds a VAA by ID. Requiered method to support Storager interface TODO: delete this methods after migration

func (*PostgresRepository) FindVaasByVaaID

func (r *PostgresRepository) FindVaasByVaaID(ctx context.Context, vaaID string) ([]*AttestationVaa, error)

FindVaasByVaaID finds VAAs by VAA ID.

func (*PostgresRepository) ReplaceVaaTxHash

func (r *PostgresRepository) ReplaceVaaTxHash(ctx context.Context, vaaID string, oldTxHash string, newTxHash string) error

ReplaceVaaTxHash replaces a VAA transaction hash. Requiered method to support Storager interface TODO: delete this methods after migration

func (*PostgresRepository) UpsertDuplicateVaa

func (r *PostgresRepository) UpsertDuplicateVaa(ctx context.Context, v *sdk.VAA, serializedVaa []byte) error

UpsertDuplicateVaa upserts a duplicate VAA. Requiered method to support Storager interface TODO: delete this methods after migration

func (*PostgresRepository) UpsertGovernorConfig

func (r *PostgresRepository) UpsertGovernorConfig(ctx context.Context, govC *gossipv1.SignedChainGovernorConfig) error

UpsertGovernorConfig upserts a governor config.

func (*PostgresRepository) UpsertGovernorStatus

func (r *PostgresRepository) UpsertGovernorStatus(ctx context.Context, govS *gossipv1.SignedChainGovernorStatus) error

UpsertGovernorStatus upserts a governor status.

func (*PostgresRepository) UpsertHeartbeat

func (r *PostgresRepository) UpsertHeartbeat(hb *gossipv1.Heartbeat) error

UpsertHeartbeat upserts a heartbeat. Questions: sWe need to support this in the v2??

func (*PostgresRepository) UpsertObservation

func (r *PostgresRepository) UpsertObservation(ctx context.Context, o *gossipv1.SignedObservation, saveTxHash bool) error

UpsertObservation upserts an observation.

func (*PostgresRepository) UpsertVAA

func (r *PostgresRepository) UpsertVAA(ctx context.Context, v *sdk.VAA, serializedVaa []byte) error

UpsertVAA upserts a VAA.

type Storager

type Storager interface {
	UpsertObservation(ctx context.Context, o *gossipv1.SignedObservation, saveTxHash bool) error
	UpsertVAA(ctx context.Context, v *sdk.VAA, serializedVaa []byte) error
	ReplaceVaaTxHash(ctx context.Context, vaaID string, oldTxHash string, newTxHash string) error // TODO: evaluate backfiller process.
	UpsertHeartbeat(hb *gossipv1.Heartbeat) error
	UpsertGovernorConfig(ctx context.Context, govC *gossipv1.SignedChainGovernorConfig) error
	UpsertGovernorStatus(ctx context.Context, govS *gossipv1.SignedChainGovernorStatus) error
	FindVaaByID(ctx context.Context, vaaID string) (*VaaUpdate, error) // TODO change VaaUpdate
	FindVaasByVaaID(ctx context.Context, vaaID string) ([]*AttestationVaa, error)
	FindVaaByChainID(ctx context.Context, chainID sdk.ChainID, page int64, pageSize int64) ([]*VaaUpdate, error)
	UpsertDuplicateVaa(ctx context.Context, v *sdk.VAA, serializedVaa []byte) error
}

Storager is a storage interface.

type Uint64

type Uint64 uint64

func (Uint64) MarshalBSONValue

func (u Uint64) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Uint64) UnmarshalBSONValue

func (u *Uint64) UnmarshalBSONValue(t bsontype.Type, b []byte) error

type VaaUpdate

type VaaUpdate struct {
	ID               string      `bson:"_id"`
	Version          uint8       `bson:"version"`
	EmitterChain     sdk.ChainID `bson:"emitterChain"`
	EmitterAddr      string      `bson:"emitterAddr"`
	Sequence         string      `bson:"sequence"`
	GuardianSetIndex uint32      `bson:"guardianSetIndex"`
	Vaa              []byte      `bson:"vaas"`
	TxHash           string      `bson:"txHash,omitempty"`
	OriginTxHash     *string     `bson:"_originTxHash,omitempty"` //this is temporary field for fix enconding txHash
	Timestamp        *time.Time  `bson:"timestamp"`
	UpdatedAt        *time.Time  `bson:"updatedAt"`
	Digest           string      `bson:"digest"`
	IsDuplicated     bool        `bson:"isDuplicated"`
}

func (*VaaUpdate) ToMap

func (v *VaaUpdate) ToMap() map[string]string

ToMap returns a map representation of the VaaUpdate.

Jump to

Keyboard shortcuts

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