Skip to content

Commit c1265a4

Browse files
Add handling of completion message to signalr.
1 parent 7dfc819 commit c1265a4

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,15 @@ if args.Help {
2222

2323
#### `config`
2424

25-
DipDup YAML [configuration](https://docs.dipdup.net/config-file-reference) parser.
25+
DipDup YAML [configuration](https://docs.dipdup.net/config-file-reference) parser. You can validate config by `validate` tag from [validator package](https://github.com/go-playground/validator).
2626

2727
```go
2828
import "github.com/dipdup-net/go-lib/config"
2929

3030
type MyConfig struct {
3131
config.Config `yaml:",inline"`
3232
// Custom field here
33-
Fields Fields `yaml:"fields"`
34-
}
35-
36-
// Validate - required by Configurable interface
37-
func (c *MyConfig) Validate() error {
38-
return c.Fields.Validate() // if needed
33+
Fields Fields `yaml:"fields" validate:"required"`
3934
}
4035

4136
// Substitute - required by Configurable interface
@@ -47,11 +42,6 @@ type Fields struct {
4742
First string `yaml:"first"`
4843
}
4944

50-
// Validate -
51-
func (f *Fields) Validate() error {
52-
return nil
53-
}
54-
5545
var cfg MyConfig
5646
if err := config.Parse("config.yaml", &cfg); err != nil {
5747
panic(err)
@@ -86,6 +76,7 @@ type State struct {
8676
IndexType string
8777
Hash string
8878
Level uint64
79+
UpdatedAt int `gorm:"autoUpdateTime"`
8980
}
9081
```
9182

@@ -164,6 +155,8 @@ func main() {
164155
log.Print("reorg")
165156
case events.MessageTypeState:
166157
log.Print("initialized")
158+
case events.MessageTypeSubscribed:
159+
log.Println("subscribed", msg)
167160
}
168161
}
169162
}

tzkt/events/message.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
MessageTypeState MessageType = iota
1717
MessageTypeData
1818
MessageTypeReorg
19+
MessageTypeSubscribed
1920
)
2021

2122
// Message - message struct

tzkt/events/signalr/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type StreamItem struct {
6767
// Completion - a `Completion` message
6868
type Completion struct {
6969
Message
70-
Result string `json:"result,omitempty"`
70+
Result uint64 `json:"result,omitempty"`
7171
Error string `json:"string,omitempty"`
7272
}
7373

tzkt/events/tzkt.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewTzKT(url string) *TzKT {
3030
}
3131
return &TzKT{
3232
s: signalr.NewSignalR(url),
33-
msgs: make(chan Message),
33+
msgs: make(chan Message, 1024),
3434
stop: make(chan struct{}),
3535
subscriptions: make([]signalr.Invocation, 0),
3636
}
@@ -163,7 +163,17 @@ func (tzkt *TzKT) listen() {
163163

164164
tzkt.msgs <- message
165165
case signalr.Completion:
166-
log.Trace("subscribed")
166+
for i := range tzkt.subscriptions {
167+
if tzkt.subscriptions[i].ID != typ.ID {
168+
continue
169+
}
170+
tzkt.msgs <- Message{
171+
Channel: tzkt.subscriptions[i].Target,
172+
Type: MessageTypeSubscribed,
173+
State: typ.Result,
174+
}
175+
break
176+
}
167177
}
168178
}
169179
}

0 commit comments

Comments
 (0)