code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/market/defaults/unmarshaler.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package defaults 17 18 import ( 19 "io" 20 21 vegapb "code.vegaprotocol.io/vega/protos/vega" 22 23 "github.com/golang/protobuf/jsonpb" 24 ) 25 26 type Unmarshaler struct { 27 unmarshaler jsonpb.Unmarshaler 28 } 29 30 func NewUnmarshaler() *Unmarshaler { 31 return &Unmarshaler{} 32 } 33 34 // UnmarshalRiskModel unmarshal a tradable instrument instead of a risk model since 35 // gRPC implementation of risk models can't be used with jsonpb.Unmarshaler. 36 func (u *Unmarshaler) UnmarshalRiskModel(r io.Reader) (*vegapb.TradableInstrument, error) { 37 proto := &vegapb.TradableInstrument{} 38 err := u.unmarshaler.Unmarshal(r, proto) 39 if err != nil { 40 return nil, err 41 } 42 return proto, nil 43 } 44 45 func (u *Unmarshaler) UnmarshalPriceMonitoring(r io.Reader) (*vegapb.PriceMonitoringSettings, error) { 46 proto := &vegapb.PriceMonitoringSettings{} 47 err := u.unmarshaler.Unmarshal(r, proto) 48 if err != nil { 49 return nil, err 50 } 51 return proto, nil 52 } 53 54 func (u *Unmarshaler) UnmarshalLiquiditySLAParams(r io.Reader) (*vegapb.LiquiditySLAParameters, error) { 55 proto := &vegapb.LiquiditySLAParameters{} 56 err := u.unmarshaler.Unmarshal(r, proto) 57 if err != nil { 58 return nil, err 59 } 60 return proto, nil 61 } 62 63 func (u *Unmarshaler) UnmarshalLiquidityMonitoring(r io.Reader) (*vegapb.LiquidityMonitoringParameters, error) { 64 proto := &vegapb.LiquidityMonitoringParameters{} 65 if err := u.unmarshaler.Unmarshal(r, proto); err != nil { 66 return nil, err 67 } 68 return proto, nil 69 } 70 71 func (u *Unmarshaler) UnmarshalPerpsDataSourceConfig(r io.Reader) (*vegapb.Perpetual, error) { 72 proto := &vegapb.Perpetual{} 73 err := u.unmarshaler.Unmarshal(r, proto) 74 if err != nil { 75 return nil, err 76 } 77 return proto, nil 78 } 79 80 // UnmarshalDataSourceConfig unmarshal a future as this is a common parent. 81 func (u *Unmarshaler) UnmarshalDataSourceConfig(r io.Reader) (*vegapb.Future, error) { 82 proto := &vegapb.Future{} 83 err := u.unmarshaler.Unmarshal(r, proto) 84 if err != nil { 85 return nil, err 86 } 87 return proto, nil 88 } 89 90 func (u *Unmarshaler) UnmarshalMarginCalculator(r io.Reader) (*vegapb.MarginCalculator, error) { 91 proto := &vegapb.MarginCalculator{} 92 err := u.unmarshaler.Unmarshal(r, proto) 93 if err != nil { 94 return nil, err 95 } 96 return proto, nil 97 } 98 99 func (u *Unmarshaler) UnmarshalFeesConfig(r io.Reader) (*vegapb.Fees, error) { 100 proto := &vegapb.Fees{} 101 err := u.unmarshaler.Unmarshal(r, proto) 102 if err != nil { 103 return nil, err 104 } 105 return proto, nil 106 } 107 108 func (u *Unmarshaler) UnmarshalLiquidationConfig(r io.Reader) (*vegapb.LiquidationStrategy, error) { 109 proto := &vegapb.LiquidationStrategy{} 110 if err := u.unmarshaler.Unmarshal(r, proto); err != nil { 111 return nil, err 112 } 113 return proto, nil 114 }