code.vegaprotocol.io/vega@v0.79.0/datanode/entities/protocol_upgrade_proposal.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 "encoding/json" 20 "fmt" 21 "time" 22 23 v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2" 24 eventspb "code.vegaprotocol.io/vega/protos/vega/events/v1" 25 ) 26 27 type ProtocolUpgradeProposal struct { 28 UpgradeBlockHeight uint64 29 VegaReleaseTag string 30 Approvers []string 31 Status ProtocolUpgradeProposalStatus 32 TxHash TxHash 33 VegaTime time.Time 34 } 35 36 func ProtocolUpgradeProposalFromProto(p *eventspb.ProtocolUpgradeEvent, txHash TxHash, vegaTime time.Time) ProtocolUpgradeProposal { 37 proposal := ProtocolUpgradeProposal{ 38 UpgradeBlockHeight: p.UpgradeBlockHeight, 39 VegaReleaseTag: p.VegaReleaseTag, 40 Approvers: p.Approvers, 41 Status: ProtocolUpgradeProposalStatus(p.Status), 42 TxHash: txHash, 43 VegaTime: vegaTime, 44 } 45 return proposal 46 } 47 48 func (p ProtocolUpgradeProposal) ToProto() *eventspb.ProtocolUpgradeEvent { 49 return &eventspb.ProtocolUpgradeEvent{ 50 UpgradeBlockHeight: p.UpgradeBlockHeight, 51 VegaReleaseTag: p.VegaReleaseTag, 52 Approvers: p.Approvers, 53 Status: eventspb.ProtocolUpgradeProposalStatus(p.Status), 54 } 55 } 56 57 func (p ProtocolUpgradeProposal) Cursor() *Cursor { 58 pc := ProtocolUpgradeProposalCursor{ 59 VegaTime: p.VegaTime, 60 UpgradeBlockHeight: p.UpgradeBlockHeight, 61 VegaReleaseTag: p.VegaReleaseTag, 62 } 63 return NewCursor(pc.String()) 64 } 65 66 func (p ProtocolUpgradeProposal) ToProtoEdge(_ ...any) (*v2.ProtocolUpgradeProposalEdge, error) { 67 return &v2.ProtocolUpgradeProposalEdge{ 68 Node: p.ToProto(), 69 Cursor: p.Cursor().Encode(), 70 }, nil 71 } 72 73 type ProtocolUpgradeProposalCursor struct { 74 VegaTime time.Time 75 UpgradeBlockHeight uint64 76 VegaReleaseTag string 77 } 78 79 func (pc ProtocolUpgradeProposalCursor) String() string { 80 bs, err := json.Marshal(pc) 81 if err != nil { 82 panic(fmt.Errorf("failed to marshal protocol upgrade proposal cursor: %w", err)) 83 } 84 return string(bs) 85 } 86 87 func (pc *ProtocolUpgradeProposalCursor) Parse(cursorString string) error { 88 if cursorString == "" { 89 return nil 90 } 91 return json.Unmarshal([]byte(cursorString), pc) 92 }