-
Notifications
You must be signed in to change notification settings - Fork 192
/
scraper.go
66 lines (56 loc) · 1.56 KB
/
scraper.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
package notify
import (
"fmt"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/rpc"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/uniq"
)
const (
MessageChunkWritten Message = "chunkWritten"
MessageStageUpdated Message = "stageUpdated"
MessageAppearance Message = "appearance"
)
type NotificationPayloadAppearance struct {
Address string `json:"address"`
// We use string for block number to ensure it's never
// too big
BlockNumber string `json:"blockNumber"`
TransactionIndex uint32 `json:"txid"`
}
func (n *NotificationPayloadAppearance) FromString(s string) (err error) {
var bn uint32
_, err = fmt.Sscanf(
s,
uniq.AppearanceFmt,
&n.Address,
&bn,
&n.TransactionIndex,
)
n.BlockNumber = fmt.Sprint(bn)
return
}
func NewChunkWrittenNotification(meta *rpc.MetaData, chunk string) *Notification[string] {
return &Notification[string]{
Msg: MessageChunkWritten,
Meta: meta,
Payload: chunk,
}
}
func NewStageUpdatedNotification(meta *rpc.MetaData, chunkRange string) *Notification[string] {
return &Notification[string]{
Msg: MessageChunkWritten,
Meta: meta,
Payload: chunkRange,
}
}
func NewAppearanceNotification(meta *rpc.MetaData, appearances []NotificationPayloadAppearance) *Notification[[]NotificationPayloadAppearance] {
return &Notification[[]NotificationPayloadAppearance]{
Msg: MessageChunkWritten,
Meta: meta,
Payload: appearances,
}
}
type NotificationPayloadChunkWritten struct {
Cid string `json:"cid"`
Range string `json:"range"`
Author string `json:"author"`
}