forked from stellar/go
/
stellar_events.go
68 lines (54 loc) · 1.74 KB
/
stellar_events.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
package server
import (
"encoding/json"
"github.com/stellar/go/services/bifrost/sse"
)
func (s *Server) onStellarAccountCreated(destination string) {
association, err := s.Database.GetAssociationByStellarPublicKey(destination)
if err != nil {
s.log.WithField("err", err).Error("Error getting association")
return
}
if association == nil {
s.log.WithField("stellarPublicKey", destination).Error("Association not found")
return
}
s.SSEServer.BroadcastEvent(association.Address, sse.AccountCreatedAddressEvent, nil)
}
func (s *Server) onExchanged(destination string) {
association, err := s.Database.GetAssociationByStellarPublicKey(destination)
if err != nil {
s.log.WithField("err", err).Error("Error getting association")
return
}
if association == nil {
s.log.WithField("stellarPublicKey", destination).Error("Association not found")
return
}
s.SSEServer.BroadcastEvent(association.Address, sse.ExchangedEvent, nil)
}
func (s *Server) OnExchangedTimelocked(destination, transaction string) {
association, err := s.Database.GetAssociationByStellarPublicKey(destination)
if err != nil {
s.log.WithField("err", err).Error("Error getting association")
return
}
if association == nil {
s.log.WithField("stellarPublicKey", destination).Error("Association not found")
return
}
// Save tx to database
err = s.Database.AddRecoveryTransaction(destination, transaction)
if err != nil {
s.log.WithField("err", err).Error("Error saving unlock transaction to DB")
return
}
data := map[string]string{
"transaction": transaction,
}
j, err := json.Marshal(data)
if err != nil {
s.log.WithField("data", data).Error("Error marshalling json")
}
s.SSEServer.BroadcastEvent(association.Address, sse.ExchangedTimelockedEvent, j)
}