code.vegaprotocol.io/vega@v0.79.0/core/blockchain/server.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 blockchain
    17  
    18  import "code.vegaprotocol.io/vega/logging"
    19  
    20  type ChainServerImpl interface {
    21  	ReloadConf(cfg Config)
    22  	Stop() error
    23  	Start() error
    24  }
    25  
    26  // Server abstraction for the abci server.
    27  type Server struct {
    28  	*Config
    29  	log *logging.Logger
    30  	srv ChainServerImpl
    31  }
    32  
    33  // NewServer instantiate a new blockchain server.
    34  func NewServer(log *logging.Logger, srv ChainServerImpl) *Server {
    35  	return &Server{
    36  		log: log,
    37  		srv: srv,
    38  	}
    39  }
    40  
    41  func (s *Server) Start() error {
    42  	return s.srv.Start()
    43  }
    44  
    45  // Stop gracefully shutdowns down the blockchain provider's server.
    46  func (s *Server) Stop() error {
    47  	s.log.Info("Stopping blockchain server")
    48  
    49  	return s.srv.Stop()
    50  }
    51  
    52  func (s *Server) ReloadConf(cfg Config) {
    53  	s.srv.ReloadConf(cfg)
    54  }