github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/sdk/python/sawtooth_sdk/consensus/engine.py (about) 1 # Copyright 2018 Intel Corporation 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # ----------------------------------------------------------------------------- 15 16 import abc 17 from collections import namedtuple 18 19 20 StartupState = namedtuple( 21 'StartupInfo', 22 ['chain_head', 'peers', 'local_peer_info']) 23 24 25 class Engine(metaclass=abc.ABCMeta): 26 @abc.abstractmethod 27 def start(self, updates, service, startup_state): 28 '''Called after the engine is initialized, when a connection to the 29 validator has been established. Notifications from the 30 validator are sent along UPDATES. SERVICE is used to send 31 requests to the validator. 32 33 Args: 34 updates (Queue) 35 service (Service) 36 startup (StartupInfo) 37 ''' 38 39 @abc.abstractmethod 40 def stop(self): 41 '''Called before the engine is dropped in order to give the engine a 42 chance to notify peers and clean up.''' 43 44 @abc.abstractproperty 45 def version(self): 46 '''Get the version of this engine. 47 48 Return: 49 str 50 ''' 51 52 @abc.abstractproperty 53 def name(self): 54 '''Get the name of the engine, typically the algorithm being 55 implemented. 56 57 Return: 58 str 59 '''