-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.go
76 lines (68 loc) · 1.59 KB
/
edit.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
package cat
import (
"github.com/fox-one/pando/core"
"github.com/fox-one/pando/pkg/maker"
"github.com/fox-one/pando/pkg/number"
"github.com/fox-one/pkg/logger"
"github.com/spf13/cast"
)
func HandleEdit(collaterals core.CollateralStore) maker.HandlerFunc {
return func(r *maker.Request) error {
ctx := r.Context()
log := logger.FromContext(ctx)
if err := require(r.Gov(), "not-authorized"); err != nil {
return err
}
cats, err := List(r, collaterals)
if err != nil {
return err
}
for {
var key, value string
if err := require(r.Scan(&key, &value) == nil, ""); err != nil {
break
}
for _, c := range cats {
switch key {
case "dust":
c.Dust = number.Decimal(value)
case "price":
c.Price = number.Decimal(value)
case "mat":
c.Mat = number.Decimal(value)
case "duty":
c.Duty = number.Decimal(value)
case "chop":
c.Chop = number.Decimal(value)
case "dunk":
c.Dunk = number.Decimal(value)
case "box":
c.Box = number.Decimal(value)
case "beg":
c.Beg = number.Decimal(value)
case "ttl":
c.TTL = cast.ToInt64(value)
case "tau":
c.Tau = cast.ToInt64(value)
case "line":
if line := number.Decimal(value); line.LessThanOrEqual(c.Supply) {
c.Line = line
}
case "live":
if live := cast.ToBool(value); live {
c.Live = 1
} else {
c.Live = 0
}
}
}
}
for _, c := range cats {
if err := collaterals.Update(ctx, c, r.Version); err != nil {
log.WithError(err).Errorln("collaterals.Update")
return err
}
}
return nil
}
}