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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package market
import (
"context"
"encoding/json"
"time"
commonv1 "github.com/johnandersen777/socialweb-computer-kcp/api/common/v1alpha1"
)
const (
RoleBidder = "bidder"
RoleRequester = "requester"
)
const (
OfferKindOffering = "offering"
OfferKindRFP = "rfp"
OfferKindBid = "bid"
)
const (
StateAccepted = "accepted"
StateActive = "active"
StateSettled = "settled"
)
type Identity struct {
DID string
Handle string
Role string
}
type Peer struct {
DID string
Role string
Offering commonv1.StrongRef
SeenAt time.Time
}
type Offer struct {
Kind string
Ref commonv1.StrongRef
Author string
Subject *commonv1.StrongRef
Free bool
Cost float64
Value json.RawMessage
}
type OfferQuery struct {
Kind string
Author string
Subject *commonv1.StrongRef
Limit int
}
type Contract struct {
RFP commonv1.StrongRef
Bid commonv1.StrongRef
Accept commonv1.StrongRef
Receipt *commonv1.StrongRef
Requester string
Provider string
State string
}
type ContractEvent struct {
Ref commonv1.StrongRef
Kind string
Value json.RawMessage
Time time.Time
}
type Participant interface {
Identity(ctx context.Context) (Identity, error)
Peers(ctx context.Context) ([]Peer, error)
}
type Offers interface {
Publish(ctx context.Context, offer Offer) (commonv1.StrongRef, error)
Solicit(ctx context.Context, peer string, rfp commonv1.StrongRef) ([]Offer, error)
List(ctx context.Context, query OfferQuery) ([]Offer, error)
Withdraw(ctx context.Context, ref commonv1.StrongRef) error
}
type Contracts interface {
Accept(ctx context.Context, bid commonv1.StrongRef) (Contract, error)
Contract(ctx context.Context, accept commonv1.StrongRef) (Contract, error)
Report(ctx context.Context, contract commonv1.StrongRef, event ContractEvent) (commonv1.StrongRef, error)
Events(ctx context.Context, contract commonv1.StrongRef) ([]ContractEvent, error)
Settle(ctx context.Context, contract commonv1.StrongRef, reason string) error
}