storage

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTx = errors.New("transaction not found")

Functions

func AllFromRowsStream

func AllFromRowsStream[T any](ch <-chan RowsStream[T]) ([]T, error)

func GetRowsStream

func GetRowsStream[T any](
	ctx context.Context,
	pool *pgxpool.Pool,
	scanRow func(rows pgx.Rows) (T, error),
	sql string,
	args ...any,
) <-chan RowsStream[T]

GetRowsStream TLDR: fetch rows from db with a non-buffered channel to control concurrency by data-consumer

Types

type CreateTxDto

type CreateTxDto struct {
	PluginID      types.PluginID
	ChainID       common.Chain
	PolicyID      uuid.UUID
	TokenID       string
	FromPublicKey string
	ToPublicKey   string
	ProposedTxHex string
	Amount        string
}

type PostgresTxIndexStore

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

func NewPostgresTxIndexStore

func NewPostgresTxIndexStore(c context.Context, dsn string) (*PostgresTxIndexStore, error)

func NewRepo

func NewRepo(pool *pgxpool.Pool) *PostgresTxIndexStore

func (*PostgresTxIndexStore) CountByPluginIDAndPublicKey added in v0.1.16

func (p *PostgresTxIndexStore) CountByPluginIDAndPublicKey(c context.Context, pluginID types.PluginID, publicKey string) (uint32, error)

func (*PostgresTxIndexStore) CountByPolicyID

func (p *PostgresTxIndexStore) CountByPolicyID(c context.Context, policyID uuid.UUID) (uint32, error)

func (*PostgresTxIndexStore) CountByPublicKey added in v0.1.16

func (p *PostgresTxIndexStore) CountByPublicKey(c context.Context, publicKey string) (uint32, error)

func (*PostgresTxIndexStore) CreateTx

func (p *PostgresTxIndexStore) CreateTx(c context.Context, req CreateTxDto) (Tx, error)

func (*PostgresTxIndexStore) GetByPluginIDAndPublicKey added in v0.1.16

func (p *PostgresTxIndexStore) GetByPluginIDAndPublicKey(
	c context.Context,
	pluginID types.PluginID,
	publicKey string,
	skip, take uint32,
) <-chan RowsStream[Tx]

func (*PostgresTxIndexStore) GetByPolicyID

func (p *PostgresTxIndexStore) GetByPolicyID(
	c context.Context,
	policyID uuid.UUID,
	skip, take uint32,
) <-chan RowsStream[Tx]

func (*PostgresTxIndexStore) GetByPublicKey added in v0.1.16

func (p *PostgresTxIndexStore) GetByPublicKey(
	c context.Context,
	publicKey string,
	skip, take uint32,
) <-chan RowsStream[Tx]

func (*PostgresTxIndexStore) GetPendingTxs

func (p *PostgresTxIndexStore) GetPendingTxs(ctx context.Context) <-chan RowsStream[Tx]

func (*PostgresTxIndexStore) GetTxByID

func (p *PostgresTxIndexStore) GetTxByID(c context.Context, id uuid.UUID) (Tx, error)

func (*PostgresTxIndexStore) GetTxsInTimeRange

func (p *PostgresTxIndexStore) GetTxsInTimeRange(
	c context.Context,
	policyID uuid.UUID,
	from, to time.Time,
) <-chan RowsStream[Tx]

func (*PostgresTxIndexStore) SetLost

func (p *PostgresTxIndexStore) SetLost(c context.Context, id uuid.UUID, errorMessage string) error

func (*PostgresTxIndexStore) SetOnChainStatus

func (p *PostgresTxIndexStore) SetOnChainStatus(c context.Context, id uuid.UUID, status rpc.TxOnChainStatus, errorMessage *string) error

func (*PostgresTxIndexStore) SetSignedAndBroadcasted

func (p *PostgresTxIndexStore) SetSignedAndBroadcasted(c context.Context, id uuid.UUID, txHash string) error

func (*PostgresTxIndexStore) SetStatus

func (p *PostgresTxIndexStore) SetStatus(c context.Context, id uuid.UUID, status TxStatus) error

type RowsStream

type RowsStream[T any] struct {
	Row T
	Err error
}

type Tx

type Tx struct {
	ID            uuid.UUID            `json:"id" validate:"required"`
	PluginID      types.PluginID       `json:"plugin_id" validate:"required"`
	TxHash        *string              `json:"tx_hash"`
	ChainID       int                  `json:"chain_id" validate:"required"`
	PolicyID      uuid.UUID            `json:"policy_id" validate:"required"`
	TokenID       string               `json:"token_id" validate:"required"`
	FromPublicKey string               `json:"from_public_key" validate:"required"`
	ToPublicKey   string               `json:"to_public_key" validate:"required"`
	ProposedTxHex string               `json:"proposed_tx_hex" validate:"required"`
	Amount        *string              `json:"amount"`
	Status        TxStatus             `json:"status" validate:"required"`
	StatusOnChain *rpc.TxOnChainStatus `json:"status_onchain"`
	ErrorMessage  *string              `json:"error_message"`
	Lost          bool                 `json:"lost"`
	BroadcastedAt *time.Time           `json:"broadcasted_at"`
	CreatedAt     time.Time            `json:"created_at"  validate:"required"`
	UpdatedAt     time.Time            `json:"updated_at" validate:"required"`
}

func TxFromRow

func TxFromRow(rows pgx.Rows) (Tx, error)

func (*Tx) Fields

func (t *Tx) Fields() logrus.Fields

type TxIndexerRepo

type TxIndexerRepo interface {
	SetStatus(ctx context.Context, id uuid.UUID, status TxStatus) error
	SetLost(ctx context.Context, id uuid.UUID, errorMessage string) error
	SetSignedAndBroadcasted(ctx context.Context, id uuid.UUID, txHash string) error
	SetOnChainStatus(ctx context.Context, id uuid.UUID, status rpc.TxOnChainStatus, errorMessage *string) error
	GetPendingTxs(ctx context.Context) <-chan RowsStream[Tx]
	CreateTx(ctx context.Context, req CreateTxDto) (Tx, error)
	GetTxByID(ctx context.Context, id uuid.UUID) (Tx, error)
	GetTxsInTimeRange(ctx context.Context, policyID uuid.UUID, from, to time.Time) <-chan RowsStream[Tx]
	GetByPolicyID(ctx context.Context, policyID uuid.UUID, skip, take uint32) <-chan RowsStream[Tx]
	CountByPolicyID(ctx context.Context, policyID uuid.UUID) (uint32, error)
	GetByPluginIDAndPublicKey(ctx context.Context, pluginID types.PluginID, publicKey string, skip, take uint32) <-chan RowsStream[Tx]
	CountByPluginIDAndPublicKey(ctx context.Context, pluginID types.PluginID, publicKey string) (uint32, error)
	GetByPublicKey(ctx context.Context, publicKey string, skip, take uint32) <-chan RowsStream[Tx]
	CountByPublicKey(ctx context.Context, publicKey string) (uint32, error)
}

type TxStatus

type TxStatus string
const (
	TxProposed TxStatus = "PROPOSED"
	TxVerified TxStatus = "VERIFIED"
	TxSigned   TxStatus = "SIGNED"
)

Jump to

Keyboard shortcuts

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