Documentation
¶
Index ¶
- Constants
- Variables
- func CreateMigration(name, migrationsDir string) (string, error)
- func DefaultSqliteConnOptions() map[string]string
- func MigrationsSource(dbType string) (migrate.MigrationSource, error)
- func ValidateConfigLive(cfg config.Config) error
- type MigrationStatus
- type Migrator
- type Packet
- type PacketFilter
- type PacketKey
- type PacketTx
- type Page
- type PostgresDB
- func (db *PostgresDB) ClearPacketAckTx(ctx context.Context, key PacketKey) error
- func (db *PostgresDB) ClearPacketRecvTx(ctx context.Context, key PacketKey) error
- func (db *PostgresDB) ClearPacketTimeoutTx(ctx context.Context, key PacketKey) error
- func (db *PostgresDB) Close() error
- func (db *PostgresDB) ListDispatchablePackets(ctx context.Context) ([]Packet, error)
- func (db *PostgresDB) ListPackets(ctx context.Context, filter PacketFilter, page Page) ([]Packet, error)
- func (db *PostgresDB) ListPacketsBySourceTx(ctx context.Context, chainID string, txHash string) ([]Packet, error)
- func (db *PostgresDB) MigrateDown() (int, error)
- func (db *PostgresDB) MigrateUp() (int, error)
- func (db *PostgresDB) MigrationStatus() ([]MigrationStatus, error)
- func (db *PostgresDB) Ping(ctx context.Context) error
- func (db *PostgresDB) Transact(ctx context.Context, call func(repo Repository) error) error
- func (db *PostgresDB) UpdatePacketAckTx(ctx context.Context, key PacketKey, tx PacketTx) error
- func (db *PostgresDB) UpdatePacketRecvTx(ctx context.Context, key PacketKey, tx PacketTx) error
- func (db *PostgresDB) UpdatePacketStatus(ctx context.Context, key PacketKey, status RelayStatus) error
- func (db *PostgresDB) UpdatePacketTimeoutTx(ctx context.Context, key PacketKey, tx PacketTx) error
- func (db *PostgresDB) UpdatePacketWriteAck(ctx context.Context, key PacketKey, ack WriteAck) error
- func (db *PostgresDB) UpsertPacket(ctx context.Context, input UpsertPacket) error
- type RelayStatus
- type Repository
- type SqliteDB
- func (db *SqliteDB) ClearPacketAckTx(ctx context.Context, key PacketKey) error
- func (db *SqliteDB) ClearPacketRecvTx(ctx context.Context, key PacketKey) error
- func (db *SqliteDB) ClearPacketTimeoutTx(ctx context.Context, key PacketKey) error
- func (db *SqliteDB) Close() error
- func (db *SqliteDB) ListDispatchablePackets(ctx context.Context) ([]Packet, error)
- func (db *SqliteDB) ListPackets(ctx context.Context, filter PacketFilter, page Page) ([]Packet, error)
- func (db *SqliteDB) ListPacketsBySourceTx(ctx context.Context, chainID string, txHash string) ([]Packet, error)
- func (db *SqliteDB) MigrateDown() (int, error)
- func (db *SqliteDB) MigrateUp() (int, error)
- func (db *SqliteDB) MigrationStatus() ([]MigrationStatus, error)
- func (db *SqliteDB) Ping(ctx context.Context) error
- func (db *SqliteDB) Transact(ctx context.Context, call func(repo Repository) error) error
- func (db *SqliteDB) UpdatePacketAckTx(ctx context.Context, key PacketKey, tx PacketTx) error
- func (db *SqliteDB) UpdatePacketRecvTx(ctx context.Context, key PacketKey, tx PacketTx) error
- func (db *SqliteDB) UpdatePacketStatus(ctx context.Context, key PacketKey, status RelayStatus) error
- func (db *SqliteDB) UpdatePacketTimeoutTx(ctx context.Context, key PacketKey, tx PacketTx) error
- func (db *SqliteDB) UpdatePacketWriteAck(ctx context.Context, key PacketKey, ack WriteAck) error
- func (db *SqliteDB) UpsertPacket(ctx context.Context, input UpsertPacket) error
- type Store
- type UpsertPacket
- type WriteAck
- type WriteAckStatus
Constants ¶
const SqliteInMemory = ":memory:"
SqliteInMemory tells sqlite to use a fully in-memory database Useful for testing and development.
Variables ¶
var (
ErrNotFound = errors.New("not found")
)
Repository errors
Functions ¶
func CreateMigration ¶
func MigrationsSource ¶
func MigrationsSource(dbType string) (migrate.MigrationSource, error)
func ValidateConfigLive ¶
ValidateConfigLive assumes the config.Config is valid, and checks if the database is reachable.
Types ¶
type MigrationStatus ¶
type MigrationStatus struct {
ID string `json:"id"`
Applied bool `json:"applied"`
AppliedAt *time.Time `json:"appliedAt,omitempty"`
}
MigrationStatus represents migration entry in the database.
type Migrator ¶
type Migrator interface {
MigrateUp() (int, error)
MigrateDown() (int, error)
MigrationStatus() ([]MigrationStatus, error)
}
Migrator abstracts schema migrations
type Packet ¶
type Packet struct {
ID int64
CreatedAt time.Time
UpdatedAt time.Time
Status RelayStatus
SourceChainID string
DestinationChainID string
SourceTxHash string
SourceTxTime time.Time
PacketSequenceNumber uint64
PacketSourceClientID string
PacketDestinationClientID string
PacketTimeoutTimestamp time.Time
RecvTxHash *string
RecvTxTime *time.Time
RecvTxRelayerAddress *string
WriteAckTxHash *string
WriteAckTxTime *time.Time
WriteAckStatus *WriteAckStatus
AckTxHash *string
AckTxTime *time.Time
AckTxRelayerAddress *string
TimeoutTxHash *string
TimeoutTxTime *time.Time
TimeoutTxRelayerAddress *string
}
Packet a packet tracked through its relay lifecycle.
type PacketFilter ¶
type PacketFilter struct {
Statuses []RelayStatus
SourceChainID string
DestinationChainID string
SourceClientID string
DestinationClientID string
SourceTxHash string
SequenceNumber uint64
}
PacketFilter narrows a ListPackets query.
type PostgresDB ¶
type PostgresDB struct {
// contains filtered or unexported fields
}
PostgresDB is a wrapper around the postgres database.
func NewPostgres ¶
func NewPostgres(ctx context.Context, url string) (*PostgresDB, error)
NewPostgres creates a new PostgresDB instance with pgx connection pool. Context must be long-lived. URL example: "postgres://username:password@localhost:5432/database_name"
func NewPostgresWithConfig ¶
func NewPostgresWithConfig(ctx context.Context, config *pgxpool.Config, ping bool) (*PostgresDB, error)
NewPostgresWithConfig creates a new PostgresDB instance based on pgxpool.Config Allows to modify the config before creation.
func (*PostgresDB) ClearPacketAckTx ¶
func (db *PostgresDB) ClearPacketAckTx(ctx context.Context, key PacketKey) error
func (*PostgresDB) ClearPacketRecvTx ¶
func (db *PostgresDB) ClearPacketRecvTx(ctx context.Context, key PacketKey) error
func (*PostgresDB) ClearPacketTimeoutTx ¶
func (db *PostgresDB) ClearPacketTimeoutTx(ctx context.Context, key PacketKey) error
func (*PostgresDB) Close ¶
func (db *PostgresDB) Close() error
func (*PostgresDB) ListDispatchablePackets ¶
func (db *PostgresDB) ListDispatchablePackets(ctx context.Context) ([]Packet, error)
func (*PostgresDB) ListPackets ¶
func (db *PostgresDB) ListPackets( ctx context.Context, filter PacketFilter, page Page, ) ([]Packet, error)
func (*PostgresDB) ListPacketsBySourceTx ¶
func (*PostgresDB) MigrateDown ¶
func (db *PostgresDB) MigrateDown() (int, error)
MigrateDown migrates only ONE migration down
func (*PostgresDB) MigrateUp ¶
func (db *PostgresDB) MigrateUp() (int, error)
MigrateUp migrates ALL available migrations
func (*PostgresDB) MigrationStatus ¶
func (db *PostgresDB) MigrationStatus() ([]MigrationStatus, error)
func (*PostgresDB) Transact ¶
func (db *PostgresDB) Transact(ctx context.Context, call func(repo Repository) error) error
func (*PostgresDB) UpdatePacketAckTx ¶
func (*PostgresDB) UpdatePacketRecvTx ¶
func (*PostgresDB) UpdatePacketStatus ¶
func (db *PostgresDB) UpdatePacketStatus(ctx context.Context, key PacketKey, status RelayStatus) error
func (*PostgresDB) UpdatePacketTimeoutTx ¶
func (*PostgresDB) UpdatePacketWriteAck ¶
func (*PostgresDB) UpsertPacket ¶
func (db *PostgresDB) UpsertPacket(ctx context.Context, input UpsertPacket) error
type RelayStatus ¶
type RelayStatus string
RelayStatus the relay state of a packet.
const ( RelayStatusNotSelected RelayStatus = "NOT_SELECTED" RelayStatusPending RelayStatus = "PENDING" RelayStatusAwaitingSendFinality RelayStatus = "AWAITING_SEND_FINALITY" RelayStatusCheckRecvPacketDelivery RelayStatus = "CHECK_RECV_PACKET_DELIVERY" RelayStatusGetRecvPacket RelayStatus = "GET_RECV_PACKET" RelayStatusDeliverRecvPacket RelayStatus = "DELIVER_RECV_PACKET" RelayStatusWaitForWriteAck RelayStatus = "WAIT_FOR_WRITE_ACK" RelayStatusAwaitingWriteAckFinality RelayStatus = "AWAITING_WRITE_ACK_FINALITY" RelayStatusCheckAckPacketDelivery RelayStatus = "CHECK_ACK_PACKET_DELIVERY" RelayStatusGetAckPacket RelayStatus = "GET_ACK_PACKET" RelayStatusDeliverAckPacket RelayStatus = "DELIVER_ACK_PACKET" RelayStatusAwaitingTimeoutFinality RelayStatus = "AWAITING_TIMEOUT_FINALITY" RelayStatusCheckTimeoutPacketDelivery RelayStatus = "CHECK_TIMEOUT_PACKET_DELIVERY" RelayStatusGetTimeoutPacket RelayStatus = "GET_TIMEOUT_PACKET" RelayStatusDeliverTimeoutPacket RelayStatus = "DELIVER_TIMEOUT_PACKET" RelayStatusCompleteWithAck RelayStatus = "COMPLETE_WITH_ACK" RelayStatusCompleteWithWriteAckError RelayStatus = "COMPLETE_WITH_WRITE_ACK_ERROR" RelayStatusCompleteWithTimeout RelayStatus = "COMPLETE_WITH_TIMEOUT" RelayStatusFailed RelayStatus = "FAILED" )
Packet statuses
func AllRelayStatuses ¶
func AllRelayStatuses() []RelayStatus
AllRelayStatuses enumerates possible packet states
type Repository ¶
type Repository interface {
// UpsertPacket records a packet. A new packet is inserted; an existing
// NOT_SELECTED packet is refreshed with the input's metadata and status,
// but only when the input status is NOT_SELECTED or PENDING, the latter
// selecting it for relay. Existing packets in any other status are never
// modified.
UpsertPacket(ctx context.Context, input UpsertPacket) error
ListPacketsBySourceTx(ctx context.Context, chainID string, txHash string) ([]Packet, error)
ListPackets(ctx context.Context, filter PacketFilter, page Page) ([]Packet, error)
// ListDispatchablePackets returns selected packets that have not reached a terminal status.
ListDispatchablePackets(ctx context.Context) ([]Packet, error)
UpdatePacketStatus(ctx context.Context, key PacketKey, status RelayStatus) error
UpdatePacketRecvTx(ctx context.Context, key PacketKey, tx PacketTx) error
ClearPacketRecvTx(ctx context.Context, key PacketKey) error
UpdatePacketWriteAck(ctx context.Context, key PacketKey, ack WriteAck) error
UpdatePacketAckTx(ctx context.Context, key PacketKey, tx PacketTx) error
ClearPacketAckTx(ctx context.Context, key PacketKey) error
UpdatePacketTimeoutTx(ctx context.Context, key PacketKey, tx PacketTx) error
ClearPacketTimeoutTx(ctx context.Context, key PacketKey) error
}
Repository represents database CRUD operations.
type SqliteDB ¶
type SqliteDB struct {
// contains filtered or unexported fields
}
SqliteDB is a wrapper around the sqlite database.
func NewSqliteInMemory ¶
func NewSqliteWithOptions ¶
func (*SqliteDB) ClearPacketAckTx ¶
func (*SqliteDB) ClearPacketRecvTx ¶
func (*SqliteDB) ClearPacketTimeoutTx ¶
func (*SqliteDB) ListDispatchablePackets ¶
func (*SqliteDB) ListPackets ¶
func (*SqliteDB) ListPacketsBySourceTx ¶
func (*SqliteDB) MigrateDown ¶
MigrateDown migrates only ONE migration down
func (*SqliteDB) MigrationStatus ¶
func (db *SqliteDB) MigrationStatus() ([]MigrationStatus, error)
func (*SqliteDB) UpdatePacketAckTx ¶
func (*SqliteDB) UpdatePacketRecvTx ¶
func (*SqliteDB) UpdatePacketStatus ¶
func (*SqliteDB) UpdatePacketTimeoutTx ¶
func (*SqliteDB) UpdatePacketWriteAck ¶
func (*SqliteDB) UpsertPacket ¶
func (db *SqliteDB) UpsertPacket(ctx context.Context, input UpsertPacket) error
type Store ¶
type Store interface {
Repository
Migrator
// Transact runs call in a transaction; call's Repository is bound to it and rolled back on error.
Transact(ctx context.Context, call func(repo Repository) error) error
Ping(ctx context.Context) error
Close() error
}
Store a unified, database-agnostic API for persistence.
type UpsertPacket ¶
type UpsertPacket struct {
Status RelayStatus
SourceChainID string
DestinationChainID string
SourceTxHash string
SourceTxTime time.Time
PacketSequenceNumber uint64
PacketSourceClientID string
PacketDestinationClientID string
PacketTimeoutTimestamp time.Time
}
UpsertPacket the fields callers provide when recording a packet; the remaining Packet fields are database-assigned or set later in the lifecycle.
func (UpsertPacket) Validate ¶
func (t UpsertPacket) Validate() error
type WriteAck ¶
type WriteAck struct {
TxHash string
TxTime time.Time
Status WriteAckStatus
}
WriteAck the write acknowledgement observed for a packet.
type WriteAckStatus ¶
type WriteAckStatus string
WriteAckStatus the execution result carried by a write ack.
const ( WriteAckStatusSuccess WriteAckStatus = "SUCCESS" WriteAckStatusError WriteAckStatus = "ERROR" WriteAckStatusUnknown WriteAckStatus = "UNKNOWN" )
Write ack statuses