code.vegaprotocol.io/vega@v0.79.0/datanode/entities/party_vesting_balances.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 "time" 20 21 "code.vegaprotocol.io/vega/libs/num" 22 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 23 ) 24 25 type ( 26 PartyLockedBalance struct { 27 PartyID PartyID 28 AssetID AssetID 29 AtEpoch uint64 30 UntilEpoch uint64 31 Balance num.Decimal 32 VegaTime time.Time 33 } 34 35 PartyVestingBalance struct { 36 PartyID PartyID 37 AssetID AssetID 38 AtEpoch uint64 39 Balance num.Decimal 40 VegaTime time.Time 41 } 42 ) 43 44 func PartyVestingBalanceFromProto( 45 partyID string, 46 atEpoch uint64, 47 pvb *eventspb.PartyVestingBalance, 48 t time.Time, 49 ) (*PartyVestingBalance, error) { 50 balance, err := num.DecimalFromString(pvb.Balance) 51 if err != nil { 52 return nil, err 53 } 54 55 return &PartyVestingBalance{ 56 PartyID: PartyID(partyID), 57 AssetID: AssetID(pvb.Asset), 58 AtEpoch: atEpoch, 59 Balance: balance, 60 VegaTime: t, 61 }, nil 62 } 63 64 func PartyLockedBalanceFromProto( 65 partyID string, 66 atEpoch uint64, 67 pvb *eventspb.PartyLockedBalance, 68 t time.Time, 69 ) (*PartyLockedBalance, error) { 70 balance, err := num.DecimalFromString(pvb.Balance) 71 if err != nil { 72 return nil, err 73 } 74 75 return &PartyLockedBalance{ 76 PartyID: PartyID(partyID), 77 AssetID: AssetID(pvb.Asset), 78 AtEpoch: atEpoch, 79 UntilEpoch: pvb.UntilEpoch, 80 Balance: balance, 81 VegaTime: t, 82 }, nil 83 }