-
Notifications
You must be signed in to change notification settings - Fork 5
/
peerchannels.go
83 lines (72 loc) · 3.01 KB
/
peerchannels.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
package payd
import (
"context"
"time"
"github.com/libsv/go-spvchannels"
)
// PeerChannelsService a service for interacting with peer channels.
type PeerChannelsService interface {
PeerChannelCreate(ctx context.Context, req spvchannels.ChannelCreateRequest) (*PeerChannel, error)
PeerChannelAPITokensCreate(ctx context.Context, reqs ...*PeerChannelAPITokenCreateArgs) ([]*spvchannels.TokenCreateReply, error)
PeerChannelsMessage(ctx context.Context, args *PeerChannelMessageArgs) (spvchannels.MessagesReply, error)
ActiveProofChannels(ctx context.Context) ([]PeerChannel, error)
CloseChannel(ctx context.Context, channelID string) error
}
// PeerChannelsStore for interfacing with a peer channel data store.
type PeerChannelsStore interface {
PeerChannelAccount(ctx context.Context, args *PeerChannelIDArgs) (*PeerChannelAccount, error)
PeerChannelCreate(ctx context.Context, args *PeerChannelCreateArgs) error
PeerChannelCloseChannel(ctx context.Context, channelID string) error
PeerChannelsOpened(ctx context.Context, channelType PeerChannelHandlerType) ([]PeerChannel, error)
PeerChannelAPITokenCreate(ctx context.Context, args *PeerChannelAPITokenStoreArgs) error
PeerChannelAPITokensCreate(ctx context.Context, args ...*PeerChannelAPITokenStoreArgs) error
}
// PeerChannel data.
type PeerChannel struct {
ID string `db:"channel_id"`
Token string `db:"tok"`
Host string `db:"channel_host"`
Path string `db:"channel_path"`
CreatedAt time.Time `db:"created_at"`
Type PeerChannelHandlerType `db:"channel_type"`
}
// PeerChannelIDArgs for getting a peerchannel account of a user.
type PeerChannelIDArgs struct {
UserID int64
}
// PeerChannelAccount a peer channel account.
type PeerChannelAccount struct {
ID int64
Username string
Password string
}
// PeerChannelCreateArgs for creating a peer channel.
type PeerChannelCreateArgs struct {
PeerChannelAccountID int64 `db:"peerchannels_account_id"`
ChannelType PeerChannelHandlerType `db:"channel_type"`
ChannelHost string `db:"channel_host"`
ChannelPath string `db:"channel_path"`
ChannelID string `db:"channel_id"`
CreatedAt time.Time `db:"created_at"`
}
// PeerChannelAPITokenCreateArgs for creating a peer channel token.
type PeerChannelAPITokenCreateArgs struct {
Role string
Persist bool
Request spvchannels.TokenCreateRequest
}
// PeerChannelAPITokenStoreArgs for storing a peer channel token.
type PeerChannelAPITokenStoreArgs struct {
PeerChannelsChannelID string `db:"peerchannels_channel_id"`
Token string `db:"tok"`
Role string `db:"role"`
CanRead bool `db:"can_read"`
CanWrite bool `db:"can_write"`
}
// PeerChannelMessageArgs for quering a peer channel message.
type PeerChannelMessageArgs struct {
ChannelID string
Host string
Path string
Token string
}