forked from lightninglabs/loop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.go
98 lines (77 loc) · 3.48 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package loopdb
import (
"context"
"time"
"github.com/lightninglabs/loop/loopdb/sqlc"
"github.com/lightningnetwork/lnd/lntypes"
)
// SwapStore is the primary database interface used by the loopd system. It
// houses information for all pending completed/failed swaps.
type SwapStore interface {
// FetchLoopOutSwaps returns all swaps currently in the store.
FetchLoopOutSwaps(ctx context.Context) ([]*LoopOut, error)
// FetchLoopOutSwap returns the loop out swap with the given hash.
FetchLoopOutSwap(ctx context.Context, hash lntypes.Hash) (*LoopOut, error)
// CreateLoopOut adds an initiated swap to the store.
CreateLoopOut(ctx context.Context, hash lntypes.Hash,
swap *LoopOutContract) error
// BatchCreateLoopOut creates a batch of loop out swaps to the store.
BatchCreateLoopOut(ctx context.Context,
swaps map[lntypes.Hash]*LoopOutContract) error
// UpdateLoopOut stores a new event for a target loop out swap. This
// appends to the event log for a particular swap as it goes through
// the various stages in its lifetime.
UpdateLoopOut(ctx context.Context, hash lntypes.Hash, time time.Time,
state SwapStateData) error
// UpdateLoopOutAssetInfo updates the asset information for a loop out
// swap.
UpdateLoopOutAssetInfo(ctx context.Context, hash lntypes.Hash,
asset *LoopOutAssetSwap) error
// FetchLoopInSwaps returns all swaps currently in the store.
FetchLoopInSwaps(ctx context.Context) ([]*LoopIn, error)
// CreateLoopIn adds an initiated swap to the store.
CreateLoopIn(ctx context.Context, hash lntypes.Hash,
swap *LoopInContract) error
// BatchCreateLoopIn creates a batch of loop in swaps to the store.
BatchCreateLoopIn(ctx context.Context,
swaps map[lntypes.Hash]*LoopInContract) error
// UpdateLoopIn stores a new event for a target loop in swap. This
// appends to the event log for a particular swap as it goes through
// the various stages in its lifetime.
UpdateLoopIn(ctx context.Context, hash lntypes.Hash, time time.Time,
state SwapStateData) error
// BatchInsertUpdate inserts batch of swap updates to the store.
BatchInsertUpdate(ctx context.Context,
updateData map[lntypes.Hash][]BatchInsertUpdateData) error
// PutLiquidityParams writes the serialized `manager.Parameters` bytes
// into the bucket.
//
// NOTE: it's the caller's responsibility to encode the param. Atm,
// it's encoding using the proto package's `Marshal` method.
PutLiquidityParams(ctx context.Context, assetId string,
params []byte) error
// FetchLiquidityParams reads the serialized `manager.Parameters` bytes
// from the bucket.
//
// NOTE: it's the caller's responsibility to decode the param. Atm,
// it's decoding using the proto package's `Unmarshal` method.
FetchLiquidityParams(ctx context.Context) ([]sqlc.LiquidityParam, error)
// BatchUpdateLoopOutSwapCosts updates the swap costs for a batch of
// loop out swaps.
BatchUpdateLoopOutSwapCosts(ctx context.Context,
swaps map[lntypes.Hash]SwapCost) error
// HasMigration returns true if the migration with the given ID has
// been done.
HasMigration(ctx context.Context, migrationID string) (bool, error)
// SetMigration marks the migration with the given ID as done.
SetMigration(ctx context.Context, migrationID string) error
// Close closes the underlying database.
Close() error
}
// BatchInsertUpdateData is a struct that holds the data for the
// BatchInsertUpdate function.
type BatchInsertUpdateData struct {
Time time.Time
State SwapStateData
}
// TODO(roasbeef): back up method in interface?