-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathstore.go
74 lines (63 loc) · 1.9 KB
/
store.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
package lsps2
import (
"context"
"errors"
"log"
"time"
"github.com/GoWebProd/uuid7"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0"
"github.com/btcsuite/btcd/wire"
)
type SavePromises struct {
Menu []*common.OpeningFeeParams
Token string
}
type RegisterBuy struct {
LspId string
PeerId string
Scid lightning.ShortChannelID
OpeningFeeParams common.OpeningFeeParams
PaymentSizeMsat *uint64
Mode OpeningMode
}
type BuyRegistration struct {
Id uuid7.UUID
LspId string
PeerId string // TODO: Make peerId in the registration a byte array.
Token string
Scid lightning.ShortChannelID
OpeningFeeParams common.OpeningFeeParams
PaymentSizeMsat *uint64
Mode OpeningMode
ChannelPoint *wire.OutPoint
IsComplete bool
}
func (b *BuyRegistration) IsExpired() bool {
t, err := time.Parse(lsps0.TIME_FORMAT, b.OpeningFeeParams.ValidUntil)
if err != nil {
log.Printf("BuyRegistration.IsExpired(): time.Parse(%v, %v) error: %v", lsps0.TIME_FORMAT, b.OpeningFeeParams.ValidUntil, err)
return true
}
if time.Now().UTC().After(t) {
return true
}
return false
}
type ChannelOpened struct {
RegistrationId uuid7.UUID
Outpoint *wire.OutPoint
FeeMsat uint64
PaymentSizeMsat uint64
}
var ErrScidExists = errors.New("scid exists")
var ErrNotFound = errors.New("not found")
type Lsps2Store interface {
SavePromises(ctx context.Context, req *SavePromises) error
RegisterBuy(ctx context.Context, req *RegisterBuy) error
GetBuyRegistration(ctx context.Context, scid lightning.ShortChannelID) (*BuyRegistration, error)
SetChannelOpened(ctx context.Context, channelOpened *ChannelOpened) error
SetCompleted(ctx context.Context, registrationId uuid7.UUID) error
RemoveUnusedExpired(ctx context.Context, before time.Time) error
}