code.vegaprotocol.io/vega@v0.79.0/core/validators/erc20multisig/erc20multisig.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 erc20multisig 17 18 import ( 19 "context" 20 "fmt" 21 22 "code.vegaprotocol.io/vega/core/broker" 23 "code.vegaprotocol.io/vega/core/netparams" 24 "code.vegaprotocol.io/vega/core/types" 25 "code.vegaprotocol.io/vega/logging" 26 ) 27 28 func NewERC20MultisigTopology( 29 config Config, 30 log *logging.Logger, 31 witness Witness, 32 33 broker broker.Interface, 34 ethClient EthereumClient, 35 ethConfirmation EthConfirmations, 36 netp *netparams.Store, 37 scope string, 38 ) *Topology { 39 ocv := NewOnChainVerifier(config, log, ethClient, ethConfirmation) 40 top := NewTopology(config, log, witness, ocv, broker, scope) 41 42 if scope == "primary" { 43 _ = netp.Watch(netparams.WatchParam{ 44 Param: netparams.BlockchainsPrimaryEthereumConfig, 45 Watcher: func(_ context.Context, cfg interface{}) error { 46 ethCfg, err := types.EthereumConfigFromUntypedProto(cfg) 47 if err != nil { 48 return fmt.Errorf("ERC20 multisig didn't receive a valid Ethereum configuration: %w", err) 49 } 50 ocv.UpdateMultiSigAddress(ethCfg.MultiSigControl().Address(), ethCfg.ChainID()) 51 top.SetChainID(ethCfg.ChainID()) 52 return nil 53 }, 54 }) 55 } else { 56 _ = netp.Watch(netparams.WatchParam{ 57 Param: netparams.BlockchainsEVMBridgeConfigs, 58 Watcher: func(_ context.Context, cfg interface{}) error { 59 cfgs, err := types.EVMChainConfigFromUntypedProto(cfg) 60 if err != nil { 61 return fmt.Errorf("ERC20 multisig didn't receive a valid Ethereum configuration: %w", err) 62 } 63 ethCfg := cfgs.Configs[0] 64 ocv.UpdateMultiSigAddress(ethCfg.MultiSigControl().Address(), ethCfg.ChainID()) 65 top.SetChainID(ethCfg.ChainID()) 66 return nil 67 }, 68 }) 69 } 70 71 return top 72 }