domain

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const OffchainTxTopic = "offchain_tx"
View Source
const RoundTopic = "round"

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchSwept

type BatchSwept struct {
	RoundEvent
	Vtxos      []Outpoint
	Txid       string
	Tx         string
	FullySwept bool
}

type Event

type Event interface {
	GetTopic() string
	GetType() EventType
}

type EventRepository

type EventRepository interface {
	Save(ctx context.Context, topic, id string, events []Event) error
	RegisterEventsHandler(topic string, handler func(events []Event))
	ClearRegisteredHandlers(topic ...string)
	Close()
}

type EventType

type EventType int
const (
	EventTypeUndefined EventType = iota

	// Round
	EventTypeIntentsRegistered
	EventTypeRoundStarted
	EventTypeRoundFinalizationStarted
	EventTypeRoundFinalized
	EventTypeRoundFailed
	EventTypeBatchSwept
)
const (
	// OffchainTx
	EventTypeOffchainTxRequested EventType = iota + 100
	EventTypeOffchainTxAccepted
	EventTypeOffchainTxFinalized
	EventTypeOffchainTxFailed
)

type ForfeitTx

type ForfeitTx struct {
	Txid string
	Tx   string
}

type Intent

type Intent struct {
	Id        string
	Inputs    []Vtxo
	Receivers []Receiver
	Proof     string
	Message   string
}

func NewIntent

func NewIntent(proof, message string, inputs []Vtxo) (*Intent, error)

func (*Intent) AddReceivers

func (i *Intent) AddReceivers(receivers []Receiver) (err error)

func (Intent) TotalInputAmount

func (i Intent) TotalInputAmount() uint64

func (Intent) TotalOutputAmount

func (i Intent) TotalOutputAmount() uint64

type Intents

type Intents []Intent

func (Intents) CountSpentVtxos

func (t Intents) CountSpentVtxos() int

func (Intents) HaveOnlyOnchainOutput

func (t Intents) HaveOnlyOnchainOutput() bool

type IntentsRegistered

type IntentsRegistered struct {
	RoundEvent
	Intents []Intent
}

type MarketHour

type MarketHour struct {
	StartTime     time.Time
	EndTime       time.Time
	Period        time.Duration
	RoundInterval time.Duration
	UpdatedAt     time.Time
}

func NewMarketHour

func NewMarketHour(startTime, endTime time.Time, period, roundInterval time.Duration) *MarketHour

type MarketHourRepo

type MarketHourRepo interface {
	Get(ctx context.Context) (*MarketHour, error)
	Upsert(ctx context.Context, marketHour MarketHour) error
	Close()
}

type OffchainTx

type OffchainTx struct {
	Stage              Stage
	StartingTimestamp  int64
	EndingTimestamp    int64
	ArkTxid            string
	ArkTx              string
	CheckpointTxs      map[string]string
	CommitmentTxids    map[string]string
	RootCommitmentTxId string
	ExpiryTimestamp    int64
	FailReason         string
	Version            uint
	// contains filtered or unexported fields
}

func NewOffchainTx

func NewOffchainTx() *OffchainTx

func NewOffchainTxFromEvents

func NewOffchainTxFromEvents(events []Event) *OffchainTx

func (*OffchainTx) Accept

func (s *OffchainTx) Accept(
	finalArkTx string, signedCheckpointTxs map[string]string,
	commitmentTxsByCheckpointTxid map[string]string, rootCommitmentTx string, expiryTimestamp int64,
) (Event, error)

func (*OffchainTx) CommitmentTxidsList

func (s *OffchainTx) CommitmentTxidsList() []string

func (*OffchainTx) Events

func (s *OffchainTx) Events() []Event

func (*OffchainTx) Fail

func (s *OffchainTx) Fail(err error) Event

func (*OffchainTx) Finalize

func (s *OffchainTx) Finalize(finalCheckpointTxs map[string]string) (Event, error)

func (*OffchainTx) IsAccepted

func (s *OffchainTx) IsAccepted() bool

func (*OffchainTx) IsFailed

func (s *OffchainTx) IsFailed() bool

func (*OffchainTx) IsFinalized

func (s *OffchainTx) IsFinalized() bool

func (*OffchainTx) IsRequested

func (s *OffchainTx) IsRequested() bool

func (*OffchainTx) Request

func (s *OffchainTx) Request(
	arkTxid, arkTx string, unsignedCheckpointTxs map[string]string,
) (Event, error)

type OffchainTxAccepted

type OffchainTxAccepted struct {
	OffchainTxEvent
	Id                  string
	CommitmentTxids     map[string]string
	RootCommitmentTxid  string
	FinalArkTx          string
	SignedCheckpointTxs map[string]string
	ExpiryTimestamp     int64
}

type OffchainTxEvent

type OffchainTxEvent struct {
	Id   string
	Type EventType
}

func (OffchainTxEvent) GetTopic

func (s OffchainTxEvent) GetTopic() string

func (OffchainTxEvent) GetType

func (s OffchainTxEvent) GetType() EventType

type OffchainTxFailed

type OffchainTxFailed struct {
	OffchainTxEvent
	Reason    string
	Timestamp int64
}

type OffchainTxFinalized

type OffchainTxFinalized struct {
	OffchainTxEvent
	FinalCheckpointTxs map[string]string
	Timestamp          int64
}

type OffchainTxRepository

type OffchainTxRepository interface {
	AddOrUpdateOffchainTx(ctx context.Context, offchainTx *OffchainTx) error
	GetOffchainTx(ctx context.Context, txid string) (*OffchainTx, error)
	Close()
}

type OffchainTxRequested

type OffchainTxRequested struct {
	OffchainTxEvent
	ArkTx                 string
	UnsignedCheckpointTxs map[string]string
	StartingTimestamp     int64
}

type OffchainTxStage

type OffchainTxStage int
const (
	OffchainTxUndefinedStage OffchainTxStage = iota
	OffchainTxRequestedStage
	OffchainTxAcceptedStage
	OffchainTxFinalizedStage
)

func (OffchainTxStage) String

func (s OffchainTxStage) String() string

type Outpoint

type Outpoint struct {
	Txid string
	VOut uint32
}

func (Outpoint) String

func (k Outpoint) String() string

type Receiver

type Receiver struct {
	Amount         uint64
	OnchainAddress string // onchain
	PubKey         string // offchain
}

func (Receiver) IsOnchain

func (r Receiver) IsOnchain() bool

type Round

type Round struct {
	Id                 string
	StartingTimestamp  int64
	EndingTimestamp    int64
	Stage              Stage
	Intents            map[string]Intent
	CommitmentTxid     string
	CommitmentTx       string
	ForfeitTxs         []ForfeitTx
	VtxoTree           tree.FlatTxTree
	Connectors         tree.FlatTxTree
	ConnectorAddress   string
	Version            uint
	Swept              bool
	VtxoTreeExpiration int64
	SweepTxs           map[string]string
	FailReason         string
	Changes            []Event
}

func NewRound

func NewRound() *Round

func NewRoundFromEvents

func NewRoundFromEvents(events []Event) *Round

func (*Round) EndFinalization

func (r *Round) EndFinalization(forfeitTxs []ForfeitTx, finalCommitmentTx string) ([]Event, error)

func (*Round) Events

func (r *Round) Events() []Event

func (*Round) ExpiryTimestamp

func (r *Round) ExpiryTimestamp() int64

func (*Round) Fail

func (r *Round) Fail(err error) []Event

func (*Round) IsEnded

func (r *Round) IsEnded() bool

func (*Round) IsFailed

func (r *Round) IsFailed() bool

func (*Round) IsStarted

func (r *Round) IsStarted() bool

func (*Round) RegisterIntents

func (r *Round) RegisterIntents(intents []Intent) ([]Event, error)

func (*Round) StartFinalization

func (r *Round) StartFinalization(
	connectorAddress string, connectors tree.FlatTxTree, vtxoTree tree.FlatTxTree,
	commitmentTxid, commitmentTx string, vtxoTreeExpiration int64,
) ([]Event, error)

func (*Round) StartRegistration

func (r *Round) StartRegistration() ([]Event, error)

func (*Round) Sweep

func (r *Round) Sweep(vtxos []Outpoint, txid, tx string) ([]Event, error)

type RoundEvent

type RoundEvent struct {
	Id   string
	Type EventType
}

func (RoundEvent) GetTopic

func (r RoundEvent) GetTopic() string

func (RoundEvent) GetType

func (r RoundEvent) GetType() EventType

type RoundFailed

type RoundFailed struct {
	RoundEvent
	Reason    string
	Timestamp int64
}

type RoundFinalizationStarted

type RoundFinalizationStarted struct {
	RoundEvent
	VtxoTree           tree.FlatTxTree
	Connectors         tree.FlatTxTree
	ConnectorAddress   string
	CommitmentTxid     string
	CommitmentTx       string
	VtxoTreeExpiration int64
}

type RoundFinalized

type RoundFinalized struct {
	RoundEvent
	ForfeitTxs        []ForfeitTx
	FinalCommitmentTx string
	Timestamp         int64
}

type RoundRepository

type RoundRepository interface {
	AddOrUpdateRound(ctx context.Context, round Round) error
	GetRoundWithId(ctx context.Context, id string) (*Round, error)
	GetRoundWithCommitmentTxid(ctx context.Context, txid string) (*Round, error)
	GetRoundStats(ctx context.Context, commitmentTxid string) (*RoundStats, error)
	GetRoundForfeitTxs(ctx context.Context, commitmentTxid string) ([]ForfeitTx, error)
	GetRoundConnectorTree(ctx context.Context, commitmentTxid string) (tree.FlatTxTree, error)
	GetRoundVtxoTree(ctx context.Context, txid string) (tree.FlatTxTree, error)
	GetSweepableRounds(ctx context.Context) ([]string, error)
	GetRoundIds(ctx context.Context, startedAfter int64, startedBefore int64) ([]string, error)
	GetSweptRoundsConnectorAddress(ctx context.Context) ([]string, error)
	GetTxsWithTxids(ctx context.Context, txids []string) ([]string, error)
	GetRoundsWithCommitmentTxids(ctx context.Context, txids []string) (map[string]any, error)
	Close()
}

type RoundStage

type RoundStage int
const (
	RoundUndefinedStage RoundStage = iota
	RoundRegistrationStage
	RoundFinalizationStage
)

func (RoundStage) String

func (s RoundStage) String() string

type RoundStarted

type RoundStarted struct {
	RoundEvent
	Timestamp int64
}

type RoundStats

type RoundStats struct {
	Swept              bool
	TotalForfeitAmount uint64
	TotalInputVtxos    int32
	TotalBatchAmount   uint64
	TotalOutputVtxos   int32
	ExpiresAt          int64
	Started            int64
	Ended              int64
}

type Stage

type Stage struct {
	Code   int
	Ended  bool
	Failed bool
}

type Tx

type Tx struct {
	Txid string
	Str  string
}

type Vtxo

type Vtxo struct {
	Outpoint
	Amount             uint64
	PubKey             string
	CommitmentTxids    []string
	RootCommitmentTxid string
	SettledBy          string // commitment txid
	SpentBy            string // forfeit txid or checkpoint txid
	ArkTxid            string // the link to the ark txid that spent the vtxos
	Spent              bool
	Unrolled           bool
	Swept              bool
	Preconfirmed       bool
	ExpiresAt          int64
	CreatedAt          int64
}

func (Vtxo) IsNote

func (v Vtxo) IsNote() bool

func (Vtxo) IsSettled

func (v Vtxo) IsSettled() bool

func (Vtxo) RequiresForfeit

func (v Vtxo) RequiresForfeit() bool

func (Vtxo) String

func (v Vtxo) String() string

func (Vtxo) TapKey

func (v Vtxo) TapKey() (*btcec.PublicKey, error)

type VtxoRepository

type VtxoRepository interface {
	AddVtxos(ctx context.Context, vtxos []Vtxo) error
	SettleVtxos(ctx context.Context, spentVtxos map[Outpoint]string, commitmentTxid string) error
	SpendVtxos(ctx context.Context, spentVtxos map[Outpoint]string, arkTxid string) error
	UnrollVtxos(ctx context.Context, outpoints []Outpoint) error
	SweepVtxos(ctx context.Context, outpoints []Outpoint) error
	GetVtxos(ctx context.Context, outpoints []Outpoint) ([]Vtxo, error)
	GetVtxosForRound(ctx context.Context, txid string) ([]Vtxo, error)
	GetAllNonUnrolledVtxos(ctx context.Context, pubkey string) ([]Vtxo, []Vtxo, error)
	GetAllSweepableVtxos(ctx context.Context) ([]Vtxo, error)
	GetAllVtxos(ctx context.Context) ([]Vtxo, error)
	GetAllVtxosWithPubKeys(ctx context.Context, pubkeys []string) ([]Vtxo, error)
	UpdateVtxosExpiration(ctx context.Context, outpoints []Outpoint, expiresAt int64) error
	GetLeafVtxosForBatch(ctx context.Context, txid string) ([]Vtxo, error)
	Close()
}

Jump to

Keyboard shortcuts

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