code.vegaprotocol.io/vega@v0.79.0/datanode/entities/account_field.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 entities 17 18 import ( 19 "fmt" 20 21 v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2" 22 ) 23 24 // AccountField is an enumeration of the properties of an account 25 // which can be used for grouping and sorting. 26 type AccountField int64 27 28 const ( 29 AccountFieldUnspecified = iota 30 AccountFieldID 31 AccountFieldPartyID 32 AccountFieldAssetID 33 AccountFieldMarketID 34 AccountFieldType 35 ) 36 37 func (s AccountField) String() string { 38 switch s { 39 case AccountFieldID: 40 return "account_id" 41 case AccountFieldPartyID: 42 return "party_id" 43 case AccountFieldAssetID: 44 return "asset_id" 45 case AccountFieldMarketID: 46 return "market_id" 47 case AccountFieldType: 48 return "type" 49 } 50 return "unknown" 51 } 52 53 func AccountFieldFromProto(field v2.AccountField) (AccountField, error) { 54 switch field { 55 case v2.AccountField_ACCOUNT_FIELD_ID: 56 return AccountFieldID, nil 57 case v2.AccountField_ACCOUNT_FIELD_ASSET_ID: 58 return AccountFieldAssetID, nil 59 case v2.AccountField_ACCOUNT_FIELD_PARTY_ID: 60 return AccountFieldPartyID, nil 61 case v2.AccountField_ACCOUNT_FIELD_MARKET_ID: 62 return AccountFieldMarketID, nil 63 case v2.AccountField_ACCOUNT_FIELD_TYPE: 64 return AccountFieldType, nil 65 default: 66 return -1, fmt.Errorf("unknown account field %v", field) 67 } 68 }