code.vegaprotocol.io/vega@v0.79.0/commands/ethereum_key_rotate_submission.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 commands 17 18 import ( 19 "code.vegaprotocol.io/vega/libs/crypto" 20 commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1" 21 ) 22 23 func CheckEthereumKeyRotateSubmission(cmd *commandspb.EthereumKeyRotateSubmission) error { 24 return checkEthereumKeyRotateSubmission(cmd).ErrorOrNil() 25 } 26 27 func checkEthereumKeyRotateSubmission(cmd *commandspb.EthereumKeyRotateSubmission) Errors { 28 errs := NewErrors() 29 30 if cmd == nil { 31 return errs.FinalAddForProperty("ethereum_key_rotate_submission", ErrIsRequired) 32 } 33 34 if len(cmd.NewAddress) <= 0 { 35 errs.AddForProperty("ethereum_key_rotate_submission.new_address", ErrIsRequired) 36 } else if !crypto.EthereumIsValidAddress(cmd.NewAddress) { 37 errs.AddForProperty("ethereum_key_rotate_submission.new_address", ErrIsNotValidEthereumAddress) 38 } 39 40 if len(cmd.CurrentAddress) <= 0 { 41 errs.AddForProperty("ethereum_key_rotate_submission.current_address", ErrIsRequired) 42 } else if !crypto.EthereumIsValidAddress(cmd.CurrentAddress) { 43 errs.AddForProperty("ethereum_key_rotate_submission.current_address", ErrIsNotValidEthereumAddress) 44 } 45 46 if cmd.TargetBlock == 0 { 47 errs.AddForProperty("ethereum_key_rotate_submission.target_block", ErrIsRequired) 48 } 49 50 if cmd.EthereumSignature == nil { 51 errs.AddForProperty("ethereum_key_rotate_submission.signature", ErrIsRequired) 52 } 53 54 if len(cmd.SubmitterAddress) != 0 && !crypto.EthereumIsValidAddress(cmd.SubmitterAddress) { 55 errs.AddForProperty("ethereum_key_rotate_submission.submitter_address", ErrIsNotValidEthereumAddress) 56 } 57 58 return errs 59 }