storage

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 23 Imported by: 8

Documentation

Overview

Package storage provides abstractions and implementations for storing and retrieving transaction outputs in overlay services.

The package includes implementations for:

  • Redis: High-performance in-memory storage with persistence
  • MongoDB: Document-based storage with flexible querying
  • SQLite: Embedded database with full SQL support and WAL mode

Key Features:

  • Transaction output storage and retrieval
  • Topic-based output organization
  • Interaction tracking between hosts and topics
  • Integration with BEEF storage and event publishing
  • Database-agnostic queue management operations

EventDataStorage Interface:

All storage backends implement the EventDataStorage interface which extends engine.Storage with event-based querying and data management.

Storage implementations handle:

  • Output insertion and updates
  • Spent/unspent status tracking
  • Block height updates
  • Topic membership management
  • Applied transaction tracking
  • Event management and querying

Example Usage:

// Create Redis storage with EventDataStorage interface
storage, err := storage.NewRedisEventDataStorage(
    "redis://localhost:6379",
    beefStore,
    publisher
)

// Insert an output
err = storage.InsertOutput(ctx, output)

// Find outputs for a topic
outputs, err := storage.FindUTXOsForTopic(ctx, "my-topic", 0, 100)

// Save events for an output
err = storage.SaveEvents(ctx, outpoint, []string{"event1", "event2"}, 850000, 123, eventData)

// Create SQLite storage with EventDataStorage interface
sqliteStorage, err := storage.NewSQLiteEventDataStorage(
    "/path/to/database.db",
    beefStore,
    publisher
)

Index

Constants

View Source
const SpendsKey = "spends"

Variables

This section is empty.

Functions

func OutMembershipKey

func OutMembershipKey(topic string) string

func OutputTopicKey

func OutputTopicKey(outpoint *transaction.Outpoint, topic string) string

func TxMembershipKey

func TxMembershipKey(topic string) string

Types

type BSONBeef

type BSONBeef struct {
	Txid   string   `bson:"_id"`
	Beef   []byte   `bson:"beef"`
	Topics []string `bson:"topics"`
}

type BSONOutput

type BSONOutput struct {
	Outpoint        string      `bson:"outpoint"`
	Txid            string      `bson:"txid"`
	Topic           string      `bson:"topic"`
	Script          []byte      `bson:"script"`
	Satoshis        uint64      `bson:"satoshis"`
	Spend           *string     `bson:"spend"` // Changed from Spent bool to Spend *string
	OutputsConsumed []string    `bson:"outputsConsumed"`
	ConsumedBy      []string    `bson:"consumedBy"`
	BlockHeight     uint32      `bson:"blockHeight"`
	BlockIdx        uint64      `bson:"blockIdx"`
	Score           float64     `bson:"score"`
	AncillaryTxids  []string    `bson:"ancillaryTxids"`
	AncillaryBeef   []byte      `bson:"ancillaryBeef"`
	Events          []string    `bson:"events"`         // Event names this output is associated with
	Data            interface{} `bson:"data,omitempty"` // Arbitrary data associated with the output
}

func NewBSONOutput

func NewBSONOutput(o *engine.Output) *BSONOutput

func (*BSONOutput) ToEngineOutput

func (o *BSONOutput) ToEngineOutput() *engine.Output

type BaseEventDataStorage

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

BaseEventDataStorage provides common fields and methods for all EventDataStorage implementations This uses Go's struct embedding to achieve code reuse across different storage backends

func NewBaseEventDataStorage

func NewBaseEventDataStorage(beefStore beef.BeefStorage, pubsub pubsub.PubSub) BaseEventDataStorage

NewBaseEventDataStorage creates a new BaseEventDataStorage with the given dependencies

func (*BaseEventDataStorage) GetBeefStorage

func (b *BaseEventDataStorage) GetBeefStorage() beef.BeefStorage

GetBeefStorage returns the underlying BEEF storage implementation

func (*BaseEventDataStorage) GetPubSub

func (b *BaseEventDataStorage) GetPubSub() pubsub.PubSub

GetPubSub returns the PubSub interface for event publishing and buffering Returns nil if no pubsub is configured

type EventDataStorage

type EventDataStorage interface {
	engine.Storage

	// GetBeefStorage returns the underlying BEEF storage implementation
	GetBeefStorage() beef.BeefStorage

	// GetPubSub returns the PubSub interface for event publishing and buffering
	// Returns nil if no pubsub is configured
	GetPubSub() pubsub.PubSub

	// LoadBeefByTxidAndTopic loads merged BEEF for a transaction within a topic context
	// Finds any output for the txid in the topic, merges main BEEF with AncillaryBeef,
	// and returns atomic BEEF bytes for the transaction
	LoadBeefByTxidAndTopic(ctx context.Context, txid *chainhash.Hash, topic string) ([]byte, error)

	// Block Data Methods
	// GetTransactionsByTopicAndHeight returns all transactions for a topic at a specific block height
	// Returns transaction structure with inputs/outputs but no protocol-specific data fields
	GetTransactionsByTopicAndHeight(ctx context.Context, topic string, height uint32) ([]*TransactionData, error)

	// Event Management Methods
	// SaveEvents associates multiple events with a single output, storing arbitrary data
	SaveEvents(ctx context.Context, outpoint *transaction.Outpoint, events []string, topic string, height uint32, idx uint64, data interface{}) error

	// FindEvents returns all events associated with a given outpoint
	FindEvents(ctx context.Context, outpoint *transaction.Outpoint) ([]string, error)

	// Event Query Methods
	// LookupOutpoints returns outpoints matching the given query criteria
	LookupOutpoints(ctx context.Context, question *EventQuestion, includeData ...bool) ([]*OutpointResult, error)

	// LookupEventScores returns lightweight event scores for simple queries (no parsing/data loading)
	LookupEventScores(ctx context.Context, topic string, event string, fromScore float64) ([]ScoredMember, error)

	// GetOutputData retrieves the data associated with a specific output
	GetOutputData(ctx context.Context, outpoint *transaction.Outpoint) (interface{}, error)

	// FindOutputData returns outputs matching the given query criteria as OutputData objects
	// Supports paging with score-based 'from' parameter and can include spent outputs for history
	FindOutputData(ctx context.Context, question *EventQuestion) ([]*OutputData, error)

	// Set Operations - for whitelists, topic management, etc.
	SAdd(ctx context.Context, key string, members ...string) error
	SMembers(ctx context.Context, key string) ([]string, error)
	SRem(ctx context.Context, key string, members ...string) error
	SIsMember(ctx context.Context, key, member string) (bool, error)

	// Hash Operations - for peer configurations, output data, etc.
	HSet(ctx context.Context, key, field, value string) error
	HGet(ctx context.Context, key, field string) (string, error)
	HGetAll(ctx context.Context, key string) (map[string]string, error)
	HDel(ctx context.Context, key string, fields ...string) error

	// Sorted Set Operations - for queues, progress tracking, event scoring, etc.
	ZAdd(ctx context.Context, key string, members ...ScoredMember) error
	ZRem(ctx context.Context, key string, members ...string) error
	ZRangeByScore(ctx context.Context, key string, min, max float64, offset, count int64) ([]ScoredMember, error)
	ZScore(ctx context.Context, key, member string) (float64, error)
	ZCard(ctx context.Context, key string) (int64, error)
}

EventDataStorage extends the base Storage interface with event data and lookup capabilities This consolidates all database operations into a single storage interface

func CreateEventDataStorage

func CreateEventDataStorage(connectionString string, beefStore beef.BeefStorage, pubSubURL string) (EventDataStorage, error)

CreateEventDataStorage creates the appropriate EventDataStorage implementation from a connection string. Auto-detects the storage type from the URL scheme.

Supported formats:

  • redis://localhost:6379
  • mongodb://localhost:27017/dbname
  • sqlite:///path/to/overlay.db or sqlite://overlay.db
  • ./overlay.db (inferred as SQLite)

If no connection string is provided, defaults to ./overlay.db The pubSubURL parameter is optional and specifies the pub/sub backend:

  • redis://localhost:6379 (for Redis pub/sub)
  • channels:// (for in-memory channel-based pub/sub)
  • "" (defaults to channels://)

type EventQuestion

type EventQuestion struct {
	Event       string    `json:"event"`
	Events      []string  `json:"events"`
	Topic       string    `json:"topic"` // Required topic scoping
	JoinType    *JoinType `json:"join"`
	From        float64   `json:"from"`
	Until       float64   `json:"until"`
	Limit       int       `json:"limit"`
	UnspentOnly bool      `json:"unspentOnly"`
	Reverse     bool      `json:"rev"`
}

EventQuestion defines query parameters for event-based lookups

type JoinType

type JoinType int

JoinType defines how multiple events are combined in queries

const (
	// JoinTypeIntersect returns outputs that have ALL specified events
	JoinTypeIntersect JoinType = iota
	// JoinTypeUnion returns outputs that have ANY of the specified events
	JoinTypeUnion
	// JoinTypeDifference returns outputs from first event minus those in subsequent events
	JoinTypeDifference
)

type MongoEventDataStorage

type MongoEventDataStorage struct {
	BaseEventDataStorage
	DB *mongo.Database
}

func NewMongoEventDataStorage

func NewMongoEventDataStorage(connString string, beefStore beef.BeefStorage, pubsub pubsub.PubSub) (*MongoEventDataStorage, error)

func (*MongoEventDataStorage) DeleteOutput

func (s *MongoEventDataStorage) DeleteOutput(ctx context.Context, outpoint *transaction.Outpoint, topic string) error

func (*MongoEventDataStorage) DoesAppliedTransactionExist

func (s *MongoEventDataStorage) DoesAppliedTransactionExist(ctx context.Context, tx *overlay.AppliedTransaction) (bool, error)

func (*MongoEventDataStorage) FindEvents

func (s *MongoEventDataStorage) FindEvents(ctx context.Context, outpoint *transaction.Outpoint) ([]string, error)

FindEvents returns all events associated with a given outpoint

func (*MongoEventDataStorage) FindOutput

func (s *MongoEventDataStorage) FindOutput(ctx context.Context, outpoint *transaction.Outpoint, topic *string, spent *bool, includeBEEF bool) (o *engine.Output, err error)

func (*MongoEventDataStorage) FindOutputData

func (s *MongoEventDataStorage) FindOutputData(ctx context.Context, question *EventQuestion) ([]*OutputData, error)

FindOutputData returns outputs matching the given query criteria as OutputData objects

func (*MongoEventDataStorage) FindOutputs

func (s *MongoEventDataStorage) FindOutputs(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spent *bool, includeBEEF bool) ([]*engine.Output, error)

func (*MongoEventDataStorage) FindOutputsForTransaction

func (s *MongoEventDataStorage) FindOutputsForTransaction(ctx context.Context, txid *chainhash.Hash, includeBEEF bool) ([]*engine.Output, error)

func (*MongoEventDataStorage) FindUTXOsForTopic

func (s *MongoEventDataStorage) FindUTXOsForTopic(ctx context.Context, topic string, since float64, limit uint32, includeBEEF bool) ([]*engine.Output, error)

func (*MongoEventDataStorage) GetLastInteraction

func (s *MongoEventDataStorage) GetLastInteraction(ctx context.Context, host string, topic string) (float64, error)

func (*MongoEventDataStorage) GetOutputData

func (s *MongoEventDataStorage) GetOutputData(ctx context.Context, outpoint *transaction.Outpoint) (interface{}, error)

GetOutputData retrieves the data associated with a specific output

func (*MongoEventDataStorage) GetTransactionsByTopicAndHeight

func (s *MongoEventDataStorage) GetTransactionsByTopicAndHeight(ctx context.Context, topic string, height uint32) ([]*TransactionData, error)

GetTransactionsByTopicAndHeight returns all transactions for a topic at a specific block height

func (*MongoEventDataStorage) HDel

func (s *MongoEventDataStorage) HDel(ctx context.Context, key string, fields ...string) error

func (*MongoEventDataStorage) HGet

func (s *MongoEventDataStorage) HGet(ctx context.Context, key, field string) (string, error)

func (*MongoEventDataStorage) HGetAll

func (s *MongoEventDataStorage) HGetAll(ctx context.Context, key string) (map[string]string, error)

func (*MongoEventDataStorage) HSet

func (s *MongoEventDataStorage) HSet(ctx context.Context, key, field, value string) error

Hash Operations - store fields directly in document (no nested fields object)

func (*MongoEventDataStorage) InsertAppliedTransaction

func (s *MongoEventDataStorage) InsertAppliedTransaction(ctx context.Context, tx *overlay.AppliedTransaction) error

func (*MongoEventDataStorage) InsertOutput

func (s *MongoEventDataStorage) InsertOutput(ctx context.Context, utxo *engine.Output) (err error)

func (*MongoEventDataStorage) LoadBeefByTxidAndTopic added in v0.3.0

func (s *MongoEventDataStorage) LoadBeefByTxidAndTopic(ctx context.Context, txid *chainhash.Hash, topic string) ([]byte, error)

LoadBeefByTxidAndTopic loads merged BEEF for a transaction within a topic context

func (*MongoEventDataStorage) LookupEventScores

func (s *MongoEventDataStorage) LookupEventScores(ctx context.Context, topic string, event string, fromScore float64) ([]ScoredMember, error)

LookupEventScores returns lightweight event scores for simple queries

func (*MongoEventDataStorage) LookupOutpoints

func (s *MongoEventDataStorage) LookupOutpoints(ctx context.Context, question *EventQuestion, includeData ...bool) ([]*OutpointResult, error)

LookupOutpoints returns outpoints matching the given query criteria using aggregations for performance

func (*MongoEventDataStorage) MarkUTXOAsSpent

func (s *MongoEventDataStorage) MarkUTXOAsSpent(ctx context.Context, outpoint *transaction.Outpoint, topic string, beef []byte) error

func (*MongoEventDataStorage) MarkUTXOsAsSpent

func (s *MongoEventDataStorage) MarkUTXOsAsSpent(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spendTxid *chainhash.Hash) error

func (*MongoEventDataStorage) SAdd

func (s *MongoEventDataStorage) SAdd(ctx context.Context, key string, members ...string) error

Set Operations - implemented using MongoDB's native $addToSet operations

func (*MongoEventDataStorage) SIsMember

func (s *MongoEventDataStorage) SIsMember(ctx context.Context, key, member string) (bool, error)

func (*MongoEventDataStorage) SMembers

func (s *MongoEventDataStorage) SMembers(ctx context.Context, key string) ([]string, error)

func (*MongoEventDataStorage) SRem

func (s *MongoEventDataStorage) SRem(ctx context.Context, key string, members ...string) error

func (*MongoEventDataStorage) SaveEvents

func (s *MongoEventDataStorage) SaveEvents(ctx context.Context, outpoint *transaction.Outpoint, events []string, topic string, height uint32, idx uint64, data interface{}) error

SaveEvents associates multiple events with a single output, storing arbitrary data

func (*MongoEventDataStorage) UpdateConsumedBy

func (s *MongoEventDataStorage) UpdateConsumedBy(ctx context.Context, outpoint *transaction.Outpoint, topic string, consumedBy []*transaction.Outpoint) error

func (*MongoEventDataStorage) UpdateLastInteraction

func (s *MongoEventDataStorage) UpdateLastInteraction(ctx context.Context, host string, topic string, since float64) error

func (*MongoEventDataStorage) UpdateOutputBlockHeight

func (s *MongoEventDataStorage) UpdateOutputBlockHeight(ctx context.Context, outpoint *transaction.Outpoint, topic string, blockHeight uint32, blockIndex uint64, ancelliaryBeef []byte) error

func (*MongoEventDataStorage) UpdateTransactionBEEF

func (s *MongoEventDataStorage) UpdateTransactionBEEF(ctx context.Context, txid *chainhash.Hash, beef []byte) error

func (*MongoEventDataStorage) ZAdd

func (s *MongoEventDataStorage) ZAdd(ctx context.Context, key string, members ...ScoredMember) error

Sorted Set Operations - using individual documents with indexed scores

func (*MongoEventDataStorage) ZCard

func (s *MongoEventDataStorage) ZCard(ctx context.Context, key string) (int64, error)

func (*MongoEventDataStorage) ZRangeByScore

func (s *MongoEventDataStorage) ZRangeByScore(ctx context.Context, key string, min, max float64, offset, count int64) ([]ScoredMember, error)

func (*MongoEventDataStorage) ZRem

func (s *MongoEventDataStorage) ZRem(ctx context.Context, key string, members ...string) error

func (*MongoEventDataStorage) ZScore

func (s *MongoEventDataStorage) ZScore(ctx context.Context, key, member string) (float64, error)

type OutpointResult

type OutpointResult struct {
	Outpoint *transaction.Outpoint `json:"outpoint"`
	Score    float64               `json:"score"`
	Data     interface{}           `json:"data,omitempty"`
}

OutpointResult contains the result of an outpoint lookup

type OutputData

type OutputData struct {
	TxID     *chainhash.Hash `json:"txid,omitempty"` // Transaction ID (for inputs: source txid, for outputs: current txid)
	Vout     uint32          `json:"vout"`
	Data     interface{}     `json:"data,omitempty"`
	Script   []byte          `json:"script"`
	Satoshis uint64          `json:"satoshis"`
	Spend    *chainhash.Hash `json:"spend,omitempty"` // Spending transaction ID (only populated if spent)
	Score    float64         `json:"score"`           // Sort score for ordering/pagination
}

OutputData represents an input or output with its data

type RedisEventDataStorage

type RedisEventDataStorage struct {
	BaseEventDataStorage
	DB *redis.Client
}

func NewRedisEventDataStorage

func NewRedisEventDataStorage(connString string, beefStore beef.BeefStorage, pubsub pubsub.PubSub) (r *RedisEventDataStorage, err error)

func (*RedisEventDataStorage) Close

func (s *RedisEventDataStorage) Close() error

func (*RedisEventDataStorage) DeleteOutput

func (s *RedisEventDataStorage) DeleteOutput(ctx context.Context, outpoint *transaction.Outpoint, topic string) error

func (*RedisEventDataStorage) DoesAppliedTransactionExist

func (s *RedisEventDataStorage) DoesAppliedTransactionExist(ctx context.Context, tx *overlay.AppliedTransaction) (bool, error)

func (*RedisEventDataStorage) FindEvents

func (s *RedisEventDataStorage) FindEvents(ctx context.Context, outpoint *transaction.Outpoint) ([]string, error)

FindEvents returns all events associated with a given outpoint

func (*RedisEventDataStorage) FindOutput

func (s *RedisEventDataStorage) FindOutput(ctx context.Context, outpoint *transaction.Outpoint, topic *string, spent *bool, includeBEEF bool) (o *engine.Output, err error)

func (*RedisEventDataStorage) FindOutputData

func (s *RedisEventDataStorage) FindOutputData(ctx context.Context, question *EventQuestion) ([]*OutputData, error)

FindOutputData returns outputs matching the given query criteria as OutputData objects

func (*RedisEventDataStorage) FindOutputs

func (s *RedisEventDataStorage) FindOutputs(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spent *bool, includeBEEF bool) ([]*engine.Output, error)

func (*RedisEventDataStorage) FindOutputsForTransaction

func (s *RedisEventDataStorage) FindOutputsForTransaction(ctx context.Context, txid *chainhash.Hash, includeBEEF bool) ([]*engine.Output, error)

func (*RedisEventDataStorage) FindUTXOsForTopic

func (s *RedisEventDataStorage) FindUTXOsForTopic(ctx context.Context, topic string, since float64, limit uint32, includeBEEF bool) ([]*engine.Output, error)

func (*RedisEventDataStorage) GetLastInteraction

func (s *RedisEventDataStorage) GetLastInteraction(ctx context.Context, host string, topic string) (float64, error)

func (*RedisEventDataStorage) GetOutputData

func (s *RedisEventDataStorage) GetOutputData(ctx context.Context, outpoint *transaction.Outpoint) (interface{}, error)

GetOutputData retrieves the data associated with a specific output

func (*RedisEventDataStorage) GetRedisClient

func (s *RedisEventDataStorage) GetRedisClient() *redis.Client

GetRedisClient returns the underlying Redis client for direct access

func (*RedisEventDataStorage) GetTransactionsByTopicAndHeight

func (s *RedisEventDataStorage) GetTransactionsByTopicAndHeight(ctx context.Context, topic string, height uint32) ([]*TransactionData, error)

GetTransactionsByTopicAndHeight returns all transactions for a topic at a specific block height

func (*RedisEventDataStorage) HDel

func (s *RedisEventDataStorage) HDel(ctx context.Context, key string, fields ...string) error

func (*RedisEventDataStorage) HGet

func (s *RedisEventDataStorage) HGet(ctx context.Context, key, field string) (string, error)

func (*RedisEventDataStorage) HGetAll

func (s *RedisEventDataStorage) HGetAll(ctx context.Context, key string) (map[string]string, error)

func (*RedisEventDataStorage) HSet

func (s *RedisEventDataStorage) HSet(ctx context.Context, key, field, value string) error

Hash Operations

func (*RedisEventDataStorage) InsertAppliedTransaction

func (s *RedisEventDataStorage) InsertAppliedTransaction(ctx context.Context, tx *overlay.AppliedTransaction) error

func (*RedisEventDataStorage) InsertOutput

func (s *RedisEventDataStorage) InsertOutput(ctx context.Context, utxo *engine.Output) (err error)

func (*RedisEventDataStorage) LoadBeefByTxidAndTopic added in v0.3.0

func (s *RedisEventDataStorage) LoadBeefByTxidAndTopic(ctx context.Context, txid *chainhash.Hash, topic string) ([]byte, error)

LoadBeefByTxidAndTopic loads merged BEEF for a transaction within a topic context

func (*RedisEventDataStorage) LookupEventScores

func (s *RedisEventDataStorage) LookupEventScores(ctx context.Context, topic string, event string, fromScore float64) ([]ScoredMember, error)

LookupEventScores returns lightweight event scores for simple queries

func (*RedisEventDataStorage) LookupOutpoints

func (s *RedisEventDataStorage) LookupOutpoints(ctx context.Context, question *EventQuestion, includeData ...bool) ([]*OutpointResult, error)

LookupOutpoints returns outpoints matching the given query criteria

func (*RedisEventDataStorage) MarkUTXOAsSpent

func (s *RedisEventDataStorage) MarkUTXOAsSpent(ctx context.Context, outpoint *transaction.Outpoint, topic string, beef []byte) error

func (*RedisEventDataStorage) MarkUTXOsAsSpent

func (s *RedisEventDataStorage) MarkUTXOsAsSpent(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spendTxid *chainhash.Hash) error

func (*RedisEventDataStorage) SAdd

func (s *RedisEventDataStorage) SAdd(ctx context.Context, key string, members ...string) error

Set Operations

func (*RedisEventDataStorage) SIsMember

func (s *RedisEventDataStorage) SIsMember(ctx context.Context, key, member string) (bool, error)

func (*RedisEventDataStorage) SMembers

func (s *RedisEventDataStorage) SMembers(ctx context.Context, key string) ([]string, error)

func (*RedisEventDataStorage) SRem

func (s *RedisEventDataStorage) SRem(ctx context.Context, key string, members ...string) error

func (*RedisEventDataStorage) SaveEvents

func (s *RedisEventDataStorage) SaveEvents(ctx context.Context, outpoint *transaction.Outpoint, events []string, topic string, height uint32, idx uint64, data interface{}) error

SaveEvents associates multiple events with a single output, storing arbitrary data

func (*RedisEventDataStorage) UpdateConsumedBy

func (s *RedisEventDataStorage) UpdateConsumedBy(ctx context.Context, outpoint *transaction.Outpoint, topic string, consumedBy []*transaction.Outpoint) error

func (*RedisEventDataStorage) UpdateLastInteraction

func (s *RedisEventDataStorage) UpdateLastInteraction(ctx context.Context, host string, topic string, since float64) error

func (*RedisEventDataStorage) UpdateOutputBlockHeight

func (s *RedisEventDataStorage) UpdateOutputBlockHeight(ctx context.Context, outpoint *transaction.Outpoint, topic string, blockHeight uint32, blockIndex uint64, ancelliaryBeef []byte) error

func (*RedisEventDataStorage) UpdateTransactionBEEF

func (s *RedisEventDataStorage) UpdateTransactionBEEF(ctx context.Context, txid *chainhash.Hash, beef []byte) error

func (*RedisEventDataStorage) ZAdd

func (s *RedisEventDataStorage) ZAdd(ctx context.Context, key string, members ...ScoredMember) error

Sorted Set Operations

func (*RedisEventDataStorage) ZCard

func (s *RedisEventDataStorage) ZCard(ctx context.Context, key string) (int64, error)

func (*RedisEventDataStorage) ZRangeByScore

func (s *RedisEventDataStorage) ZRangeByScore(ctx context.Context, key string, min, max float64, offset, count int64) ([]ScoredMember, error)

func (*RedisEventDataStorage) ZRem

func (s *RedisEventDataStorage) ZRem(ctx context.Context, key string, members ...string) error

func (*RedisEventDataStorage) ZScore

func (s *RedisEventDataStorage) ZScore(ctx context.Context, key, member string) (float64, error)

type SQLiteEventDataStorage

type SQLiteEventDataStorage struct {
	BaseEventDataStorage
	// contains filtered or unexported fields
}

func NewSQLiteEventDataStorage

func NewSQLiteEventDataStorage(dbPath string, beefStore beef.BeefStorage, pubsub pubsub.PubSub) (*SQLiteEventDataStorage, error)

func (*SQLiteEventDataStorage) Close

func (s *SQLiteEventDataStorage) Close() error

func (*SQLiteEventDataStorage) DeleteOutput

func (s *SQLiteEventDataStorage) DeleteOutput(ctx context.Context, outpoint *transaction.Outpoint, topic string) error

func (*SQLiteEventDataStorage) DoesAppliedTransactionExist

func (s *SQLiteEventDataStorage) DoesAppliedTransactionExist(ctx context.Context, tx *overlay.AppliedTransaction) (bool, error)

func (*SQLiteEventDataStorage) FindEvents

func (s *SQLiteEventDataStorage) FindEvents(ctx context.Context, outpoint *transaction.Outpoint) ([]string, error)

FindEvents returns all events associated with a given outpoint

func (*SQLiteEventDataStorage) FindOutput

func (s *SQLiteEventDataStorage) FindOutput(ctx context.Context, outpoint *transaction.Outpoint, topic *string, spent *bool, includeBEEF bool) (*engine.Output, error)

func (*SQLiteEventDataStorage) FindOutputData

func (s *SQLiteEventDataStorage) FindOutputData(ctx context.Context, question *EventQuestion) ([]*OutputData, error)

FindOutputData returns outputs matching the given query criteria as OutputData objects

func (*SQLiteEventDataStorage) FindOutputs

func (s *SQLiteEventDataStorage) FindOutputs(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spent *bool, includeBEEF bool) ([]*engine.Output, error)

func (*SQLiteEventDataStorage) FindOutputsForTransaction

func (s *SQLiteEventDataStorage) FindOutputsForTransaction(ctx context.Context, txid *chainhash.Hash, includeBEEF bool) ([]*engine.Output, error)

func (*SQLiteEventDataStorage) FindUTXOsForTopic

func (s *SQLiteEventDataStorage) FindUTXOsForTopic(ctx context.Context, topic string, since float64, limit uint32, includeBEEF bool) ([]*engine.Output, error)

func (*SQLiteEventDataStorage) GetLastInteraction

func (s *SQLiteEventDataStorage) GetLastInteraction(ctx context.Context, host string, topic string) (float64, error)

func (*SQLiteEventDataStorage) GetOutputData

func (s *SQLiteEventDataStorage) GetOutputData(ctx context.Context, outpoint *transaction.Outpoint) (interface{}, error)

GetOutputData retrieves the data associated with a specific output

func (*SQLiteEventDataStorage) GetTransactionsByTopicAndHeight

func (s *SQLiteEventDataStorage) GetTransactionsByTopicAndHeight(ctx context.Context, topic string, height uint32) ([]*TransactionData, error)

GetTransactionsByTopicAndHeight returns all transactions for a topic at a specific block height

func (*SQLiteEventDataStorage) HDel

func (s *SQLiteEventDataStorage) HDel(ctx context.Context, key string, fields ...string) error

func (*SQLiteEventDataStorage) HGet

func (s *SQLiteEventDataStorage) HGet(ctx context.Context, key, field string) (string, error)

func (*SQLiteEventDataStorage) HGetAll

func (s *SQLiteEventDataStorage) HGetAll(ctx context.Context, key string) (map[string]string, error)

func (*SQLiteEventDataStorage) HSet

func (s *SQLiteEventDataStorage) HSet(ctx context.Context, key, field, value string) error

Hash Operations - implemented using SQLite tables

func (*SQLiteEventDataStorage) InsertAppliedTransaction

func (s *SQLiteEventDataStorage) InsertAppliedTransaction(ctx context.Context, tx *overlay.AppliedTransaction) error

func (*SQLiteEventDataStorage) InsertOutput

func (s *SQLiteEventDataStorage) InsertOutput(ctx context.Context, utxo *engine.Output) error

func (*SQLiteEventDataStorage) LoadBeefByTxidAndTopic added in v0.3.0

func (s *SQLiteEventDataStorage) LoadBeefByTxidAndTopic(ctx context.Context, txid *chainhash.Hash, topic string) ([]byte, error)

LoadBeefByTxidAndTopic loads merged BEEF for a transaction within a topic context

func (*SQLiteEventDataStorage) LookupEventScores

func (s *SQLiteEventDataStorage) LookupEventScores(ctx context.Context, topic string, event string, fromScore float64) ([]ScoredMember, error)

LookupEventScores returns lightweight event scores for simple queries

func (*SQLiteEventDataStorage) LookupOutpoints

func (s *SQLiteEventDataStorage) LookupOutpoints(ctx context.Context, question *EventQuestion, includeData ...bool) ([]*OutpointResult, error)

LookupOutpoints returns outpoints matching the given query criteria

func (*SQLiteEventDataStorage) MarkUTXOsAsSpent

func (s *SQLiteEventDataStorage) MarkUTXOsAsSpent(ctx context.Context, outpoints []*transaction.Outpoint, topic string, spendTxid *chainhash.Hash) error

func (*SQLiteEventDataStorage) SAdd

func (s *SQLiteEventDataStorage) SAdd(ctx context.Context, key string, members ...string) error

Set Operations - implemented using SQLite tables

func (*SQLiteEventDataStorage) SIsMember

func (s *SQLiteEventDataStorage) SIsMember(ctx context.Context, key, member string) (bool, error)

func (*SQLiteEventDataStorage) SMembers

func (s *SQLiteEventDataStorage) SMembers(ctx context.Context, key string) ([]string, error)

func (*SQLiteEventDataStorage) SRem

func (s *SQLiteEventDataStorage) SRem(ctx context.Context, key string, members ...string) error

func (*SQLiteEventDataStorage) SaveEvents

func (s *SQLiteEventDataStorage) SaveEvents(ctx context.Context, outpoint *transaction.Outpoint, events []string, topic string, height uint32, idx uint64, data interface{}) error

SaveEvents associates multiple events with a single output, storing arbitrary data

func (*SQLiteEventDataStorage) UpdateConsumedBy

func (s *SQLiteEventDataStorage) UpdateConsumedBy(ctx context.Context, outpoint *transaction.Outpoint, topic string, consumedBy []*transaction.Outpoint) error

func (*SQLiteEventDataStorage) UpdateLastInteraction

func (s *SQLiteEventDataStorage) UpdateLastInteraction(ctx context.Context, host string, topic string, since float64) error

func (*SQLiteEventDataStorage) UpdateOutputBlockHeight

func (s *SQLiteEventDataStorage) UpdateOutputBlockHeight(ctx context.Context, outpoint *transaction.Outpoint, topic string, blockHeight uint32, blockIndex uint64, ancillaryBeef []byte) error

func (*SQLiteEventDataStorage) UpdateTransactionBEEF

func (s *SQLiteEventDataStorage) UpdateTransactionBEEF(ctx context.Context, txid *chainhash.Hash, beef []byte) error

func (*SQLiteEventDataStorage) ZAdd

func (s *SQLiteEventDataStorage) ZAdd(ctx context.Context, key string, members ...ScoredMember) error

Sorted Set Operations - implemented using SQLite tables

func (*SQLiteEventDataStorage) ZCard

func (s *SQLiteEventDataStorage) ZCard(ctx context.Context, key string) (int64, error)

func (*SQLiteEventDataStorage) ZRangeByScore

func (s *SQLiteEventDataStorage) ZRangeByScore(ctx context.Context, key string, min, max float64, offset, count int64) ([]ScoredMember, error)

func (*SQLiteEventDataStorage) ZRem

func (s *SQLiteEventDataStorage) ZRem(ctx context.Context, key string, members ...string) error

func (*SQLiteEventDataStorage) ZScore

func (s *SQLiteEventDataStorage) ZScore(ctx context.Context, key, member string) (float64, error)

type ScoredMember

type ScoredMember struct {
	Member string
	Score  float64
}

ScoredMember represents a member with its score in sorted set operations

type TransactionData

type TransactionData struct {
	TxID    chainhash.Hash `json:"txid"`
	Inputs  []*OutputData  `json:"inputs"`
	Outputs []*OutputData  `json:"outputs"`
}

TransactionData represents a transaction with its inputs and outputs

Jump to

Keyboard shortcuts

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