max: parse debt

This commit is contained in:
c9s 2022-05-25 20:12:16 +08:00
parent 2ffbb2ed82
commit 459d839c1a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -218,9 +218,32 @@ func parseADRatio(v *fastjson.Value) (*ADRatio, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
adRatio := ADRatio{}
adRatio := struct {
ADRatio ADRatio `json:"ad"`
}{}
err = json.Unmarshal(o, &adRatio) err = json.Unmarshal(o, &adRatio)
return &adRatio, err return &adRatio.ADRatio, err
}
type Debt struct {
Currency string `json:"cu"`
DebtPrincipal fixedpoint.Value `json:"dbp"`
DebtInterest fixedpoint.Value `json:"dbi"`
TU types.MillisecondTimestamp `json:"TU"`
}
func parseDebts(v *fastjson.Value) ([]Debt, error) {
o, err := v.StringBytes()
if err != nil {
return nil, err
}
m := struct {
Debts []Debt `json:"db"`
}{}
err = json.Unmarshal(o, &m)
return m.Debts, err
} }
func ParseUserEvent(v *fastjson.Value) (interface{}, error) { func ParseUserEvent(v *fastjson.Value) (interface{}, error) {
@ -241,10 +264,17 @@ func ParseUserEvent(v *fastjson.Value) (interface{}, error) {
case "ad_ratio_snapshot", "ad_ratio_update": case "ad_ratio_snapshot", "ad_ratio_update":
return parseADRatio(v) return parseADRatio(v)
case "borrowing_snapshot", "borrowing_update":
return parseDebts(v)
case "account_snapshot", "account_update", "mwallet_account_snapshot", "mwallet_account_update": case "account_snapshot", "account_update", "mwallet_account_snapshot", "mwallet_account_update":
var e AccountUpdateEvent var e AccountUpdateEvent
o := v.String() o, err := v.StringBytes()
err := json.Unmarshal([]byte(o), &e) if err != nil {
return nil, err
}
err = json.Unmarshal(o, &e)
return &e, err return &e, err
case "error": case "error":