domain

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 12 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 BaseConviction added in v0.8.0

type BaseConviction struct {
	ID        string
	Type      ConvictionType
	CreatedAt time.Time
	ExpiresAt *time.Time
	Crime     Crime
	Pardoned  bool
}

func (BaseConviction) GetCreatedAt added in v0.8.0

func (b BaseConviction) GetCreatedAt() time.Time

func (BaseConviction) GetCrime added in v0.8.0

func (b BaseConviction) GetCrime() Crime

func (BaseConviction) GetExpiresAt added in v0.8.0

func (b BaseConviction) GetExpiresAt() *time.Time

func (BaseConviction) GetID added in v0.8.0

func (b BaseConviction) GetID() string

func (BaseConviction) GetType added in v0.8.0

func (b BaseConviction) GetType() ConvictionType

func (BaseConviction) IsPardoned added in v0.8.0

func (b BaseConviction) IsPardoned() bool

type BatchSwept

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

type Conviction added in v0.8.0

type Conviction interface {
	GetType() ConvictionType
	GetID() string
	GetCreatedAt() time.Time
	GetExpiresAt() *time.Time
	GetCrime() Crime
	String() string
	IsPardoned() bool
}

func NewScriptConviction added in v0.8.0

func NewScriptConviction(script string, crime Crime, banDuration *time.Duration) Conviction

type ConvictionRepository added in v0.8.0

type ConvictionRepository interface {
	Get(ctx context.Context, id string) (Conviction, error)
	GetAll(ctx context.Context, from, to time.Time) ([]Conviction, error)
	GetByRoundID(ctx context.Context, roundID string) ([]Conviction, error)
	// GetActiveScriptConviction returns all not-expired convictions associated with a given script
	GetActiveScriptConvictions(ctx context.Context, script string) ([]ScriptConviction, error)
	Add(ctx context.Context, convictions ...Conviction) error
	Pardon(ctx context.Context, id string) error
	Close()
}

type ConvictionType added in v0.8.0

type ConvictionType uint8
const (
	ConvictionTypeScript ConvictionType = iota
)

type Crime added in v0.8.0

type Crime struct {
	Type    CrimeType
	RoundID string
	Reason  string
}

type CrimeType added in v0.8.0

type CrimeType uint8
const (
	CrimeTypeUnknown CrimeType = iota
	CrimeTypeMusig2NonceSubmission
	CrimeTypeMusig2SignatureSubmission
	CrimeTypeMusig2InvalidSignature
	CrimeTypeForfeitSubmission
	CrimeTypeForfeitInvalidSignature
	CrimeTypeBoardingInputSubmission
	CrimeTypeManualBan
)

func (CrimeType) String added in v0.8.0

func (c CrimeType) String() string

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 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) FromString added in v0.8.0

func (k *Outpoint) FromString(s string) error

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(
	leafVtxos []Outpoint,
	preconfirmedVtxos []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, startedBefore int64,
		withFailed, withCompleted bool,
	) ([]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 ScheduledSession added in v0.8.0

type ScheduledSession struct {
	StartTime                 time.Time
	EndTime                   time.Time
	Period                    time.Duration
	Duration                  time.Duration
	RoundMinParticipantsCount int64
	RoundMaxParticipantsCount int64
	UpdatedAt                 time.Time
}

func NewScheduledSession added in v0.8.0

func NewScheduledSession(
	startTime, endTime time.Time, period, duration time.Duration,
	roundMinParticipantsCount, roundMaxParticipantsCount int64,
) *ScheduledSession

type ScheduledSessionRepo added in v0.8.0

type ScheduledSessionRepo interface {
	Get(ctx context.Context) (*ScheduledSession, error)
	Upsert(ctx context.Context, scheduledSession ScheduledSession) error
	Close()
}

type ScriptConviction added in v0.8.0

type ScriptConviction struct {
	BaseConviction
	Script string
}

ScriptConviction bans all vtxos with the given script

func (ScriptConviction) String added in v0.8.0

func (s ScriptConviction) String() string

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) OutputScript added in v0.8.0

func (v Vtxo) OutputScript() ([]byte, error)

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) (int, 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)
	GetAllSweepableUnrolledVtxos(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)
	GetAllChildrenVtxos(ctx context.Context, txid string) ([]Outpoint, error)
	Close()
}

Jump to

Keyboard shortcuts

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