/
events.go
48 lines (39 loc) · 1.1 KB
/
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
package server
import (
"fmt"
types2 "github.com/make-os/kit/mempool/types"
"github.com/make-os/kit/types"
"github.com/make-os/kit/types/txns"
"github.com/make-os/kit/util"
"github.com/olebedev/emitter"
)
// subscribe to various incoming events
func (sv *Server) subscribe() {
// On EvtMempoolTxRemoved:
// Remove the transaction from the push pool
go func() {
for evt := range sv.cfg.G().Bus.On(types2.EvtMempoolTxRemoved) {
_ = handleFailedPushTxEvt(sv, evt)
}
}()
// On EvtMempoolTxRejected:
// Remove the transaction from the push pool
go func() {
for evt := range sv.cfg.G().Bus.On(types2.EvtMempoolTxRejected) {
_ = handleFailedPushTxEvt(sv, evt)
}
}()
}
// handleFailedPushTxEvt responds to a failed push transaction
// event by removing the corresponding push note from the push pool
func handleFailedPushTxEvt(sv *Server, evt emitter.Event) error {
_ = util.CheckEvtArgs(evt.Args)
tx, ok := evt.Args[1].(types.BaseTx)
if !ok {
return fmt.Errorf("unexpected type (types.BaseTx)")
}
if tx.Is(txns.TxTypePush) {
sv.pushPool.Remove(tx.(*txns.TxPush).Note)
}
return nil
}