def __init__(self, logger): # Global config self.config = util.load_config_from_file() if UNIT_TESTING: if logger: logger.warn("UNIT_TESTING is enabled. Kill process immediately if not in test environment!") else: print("UNIT_TESTING is enabled. Kill process immediately if not in test environment!") self.rpc_interface = rpc_interface.RPCInterface() self.logger = logger self.enode = None self.name = None self.eth_node_id = None # useful statistics on RPC responsiveness # will at least tell us if it's connected to a test harness! self.total_rpc_calls = 0 self.total_rpc_delay = 0 self.gas_price = None self.synced = False self.blocks_behind = 0 self.balance = 0 self.peers = [] self.latest_block = None self._admin_node_info() self.update()
def create_smart_contract(self): encoded_data = encode_abi( ('uint256', 'string', 'string'), (self.initial_supply, self.token_name, self.token_symbol)) hex_encoded_data = encoded_data.hex() object_data = '0x' + self.erc20bin["object"] + hex_encoded_data rpc = rpc_interface.RPCInterface() result = rpc.eth_send_transaction(config["account"], object_data) return result
async def startup(self) -> None: #The startup sequence is quite complex, with all kinds of #inter-dependencies between subsystems. #The first thing we can do is create the plugin interface #(based on the stdio streams), and perform its startup sequence. #This will give us the values of various (commandline) parameters #passed to lightningd. stdin, stdout = await stdio( ) #type: Tuple[asyncio.StreamReader, asyncio.streams.StreamWriter] self.pluginInterface = plugin_interface.PluginInterface( self, stdin, stdout) #type: plugin_interface.PluginInterface await self.pluginInterface.startup() #Guarantees that init is called #The log filename is a commandline parameter. #Now that we know it, we can start logging to it: logging.basicConfig( filename=self.pluginInterface.logFile, format='%(asctime)s %(levelname)s: %(message)s', level=logging.INFO, ) logging.info('\n\n\n\nOpened the log file') #The plugin interface start-up also informed us about the lightningd #RPC path. #Using this, we can create the RPC interface and start it up. #This will give us our Lightning node ID. reader, writer = await asyncio.open_unix_connection( path=self.pluginInterface.RPCPath ) #type: ignore #mypy bug: it doesn't know open_unix_connection self.rpcInterface = rpc_interface.RPCInterface( self, reader, writer) #type: rpc_interface.RPCInterface await self.rpcInterface.startupRPC() #We can create the BL4P interface, but we cannot start it yet. #Creating it doesn't really do anything and doesn't depend on anything. self.bl4pInterface = bl4p_interface.BL4PInterface( self) #type: bl4p_interface.BL4PInterface #We can inform the backend about certain information. self.backend.setLNAddress(self.rpcInterface.nodeID) #TODO (bug 16): get address from BL4P self.backend.setBL4PAddress('BL4Pdummy') #The DB file is a commandline parameter. #Now that we know it and we passed the other information to the backend, #we can start up the backend. #This will load data from the DB file (like the configuration), #and start certain tasks. self.backend.startup(self.pluginInterface.DBFile) #The subsystems that have been started can be added as message handlers. self.messageRouter.addHandler(self.backend) self.messageRouter.addHandler(self.pluginInterface) self.messageRouter.addHandler(self.rpcInterface) #We can now start up the BL4P interface. #This depends on configuration data from the backend. await self.startupBL4PInterface() #Only start messaging at the very end logging.info('Startup has finished; we can now start messaging.') self.messageRouter.startMessaging()
def setUp(self): self.client = Mock() self.input = DummyReader() self.output = DummyWriter() self.rpc = rpc_interface.RPCInterface(self.client, self.input, self.output)