-
Notifications
You must be signed in to change notification settings - Fork 4
/
vat.go
88 lines (71 loc) · 2.03 KB
/
vat.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package notifier
import (
"context"
"github.com/fox-one/pando/core"
"github.com/fox-one/pando/pkg/number"
"github.com/fox-one/pkg/logger"
"github.com/spf13/cast"
)
func (n *notifier) handleVatTx(ctx context.Context, tx *core.Transaction, user *core.User, data *TxData) error {
vatID := tx.TraceID
if tx.Action != core.ActionVatOpen {
var parameters []interface{}
_ = tx.Parameters.Unmarshal(¶meters)
if len(parameters) > 0 {
vatID = cast.ToString(parameters[0])
}
}
vat, err := n.vats.Find(ctx, vatID)
if err != nil {
logger.FromContext(ctx).WithError(err).Errorln("vats.Find")
return err
}
if vat.ID == 0 {
return nil
}
cat, err := n.cats.Find(ctx, vat.CollateralID)
if err != nil {
logger.FromContext(ctx).WithError(err).Errorln("cats.Find")
return err
}
gem, err := n.assetz.Find(ctx, cat.Gem)
if err != nil {
logger.FromContext(ctx).WithError(err).Errorln("assetz.Find")
return err
}
dai, err := n.assetz.Find(ctx, cat.Dai)
if err != nil {
logger.FromContext(ctx).WithError(err).Errorln("assetz.Find")
return err
}
event, err := n.vats.FindEvent(ctx, vatID, tx.Version)
if err != nil {
logger.FromContext(ctx).WithError(err).Errorln("vats.FindEvent")
return err
}
args := map[string]interface{}{
"Name": cat.Name,
"ID": vat.ID,
"Dink": number.Humanize(event.Dink.Abs()),
"Debt": number.Humanize(event.Debt.Abs()),
"Gem": gem.Symbol,
"Dai": dai.Symbol,
}
data.AddLine(n.localize("vat_name", user.Lang, args))
if event.Dink.IsPositive() {
data.AddLine(n.localize("vat_deposit", user.Lang, args))
} else if event.Dink.IsNegative() {
data.AddLine(n.localize("vat_withdraw", user.Lang, args))
}
if event.Debt.IsPositive() {
data.AddLine(n.localize("vat_generate", user.Lang, args))
} else if event.Debt.IsNegative() {
data.AddLine(n.localize("vat_payback", user.Lang, args))
}
if detail, err := n.executeLink("vault_detail", map[string]string{
"vault_id": vatID,
}); err == nil {
data.AddButton(n.localize("vault_button", user.Lang), detail)
}
return nil
}