def start(self): log = self.app.log args = self.app.pargs abci_app = ABCIServer(app=EzoABCI()) abci_app.run()
def start(): logger.info(BANNER) from abci import ABCIServer app = ABCIServer(app=App()) app.run()
def start(): # Exchange object for event stream api logger.info('Starting BigchainDB') exchange = Exchange() # start the web api app_server = server.create_server(settings=bigchaindb.config['server'], log_config=bigchaindb.config['log'], bigchaindb_factory=BigchainDB) p_webapi = Process(name='bigchaindb_webapi', target=app_server.run, daemon=True) p_webapi.start() # start message logger.info(BANNER.format(bigchaindb.config['server']['bind'])) # start websocket server p_websocket_server = Process(name='bigchaindb_ws', target=websocket_server.start, daemon=True, args=(exchange.get_subscriber_queue( EventTypes.BLOCK_VALID), )) p_websocket_server.start() # connect to tendermint event stream p_websocket_client = Process(name='bigchaindb_ws_to_tendermint', target=event_stream.start, daemon=True, args=(exchange.get_publisher_queue(), )) p_websocket_client.start() p_exchange = Process(name='bigchaindb_exchange', target=exchange.run, daemon=True) p_exchange.start() # We need to import this after spawning the web server # because import ABCIServer will monkeypatch all sockets # for gevent. from abci import ABCIServer setproctitle.setproctitle('bigchaindb') # Start the ABCIServer app = ABCIServer(app=App()) app.run()
def abci_server(): from abci import ABCIServer from bigchaindb.tendermint.core import App from bigchaindb.utils import Process app = ABCIServer(app=App()) abci_proxy = Process(name='ABCI', target=app.run) yield abci_proxy.start() abci_proxy.terminate()
def start(): # Exchange object for event stream api logger.info('Starting BigchainDB') exchange = Exchange() # start the web api app_server = server.create_server( settings=bigchaindb.config['server'], log_config=bigchaindb.config['log'], bigchaindb_factory=BigchainDB) p_webapi = Process(name='bigchaindb_webapi', target=app_server.run, daemon=True) p_webapi.start() # start message logger.info(BANNER.format(bigchaindb.config['server']['bind'])) # start websocket server p_websocket_server = Process(name='bigchaindb_ws', target=websocket_server.start, daemon=True, args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),)) p_websocket_server.start() # connect to tendermint event stream p_websocket_client = Process(name='bigchaindb_ws_to_tendermint', target=event_stream.start, daemon=True, args=(exchange.get_publisher_queue(),)) p_websocket_client.start() p_exchange = Process(name='bigchaindb_exchange', target=exchange.run, daemon=True) p_exchange.start() # We need to import this after spawning the web server # because import ABCIServer will monkeypatch all sockets # for gevent. from abci import ABCIServer setproctitle.setproctitle('bigchaindb') # Start the ABCIServer app = ABCIServer(app=App()) app.run()
def start(args): # Exchange object for event stream api logger.info('Starting BigchainDB') exchange = Exchange() # start the web api app_server = server.create_server(settings=bigchaindb.config['server'], log_config=bigchaindb.config['log'], bigchaindb_factory=BigchainDB) p_webapi = Process(name='bigchaindb_webapi', target=app_server.run, daemon=True) p_webapi.start() logger.info(BANNER.format(bigchaindb.config['server']['bind'])) # start websocket server p_websocket_server = Process(name='bigchaindb_ws', target=websocket_server.start, daemon=True, args=(exchange.get_subscriber_queue( EventTypes.BLOCK_VALID), )) p_websocket_server.start() p_exchange = Process(name='bigchaindb_exchange', target=exchange.run, daemon=True) p_exchange.start() # We need to import this after spawning the web server # because import ABCIServer will monkeypatch all sockets # for gevent. from abci import ABCIServer setproctitle.setproctitle('bigchaindb') # Start the ABCIServer if args.experimental_parallel_validation: app = ABCIServer(app=ParallelValidationApp( events_queue=exchange.get_publisher_queue())) else: app = ABCIServer(app=App(events_queue=exchange.get_publisher_queue())) app.run()
logger.info("Transaction delivered succesfully") return ResponseDeliverTx(code=CodeTypeOk) def check_tx(self, tx): return ResponseCheckTx(code=CodeTypeOk) def commit(self): byte_length = max(ceil(self.state.size.bit_length() / 8), 1) app_hash = self.state.size.to_bytes(byte_length, byteorder='big') self.state.app_hash = app_hash self.state.height += 1 self.state.save() return ResponseCommit(data=app_hash) def query(self, req): if req.prove: value = self.state.db.get(prefix_key(req.data)) # todo: make Proof return index return ResponseQuery(code=CodeTypeOk, value=value) else: value = self.state.db.get(prefix_key(req.data)) return ResponseQuery(code=CodeTypeOk, value=value) if __name__ == '__main__': logger.info("Initalisation is complete. KV Store Application is ready") app = ABCIServer(app=KVStoreApplication()) app.run()
if not self.__valid_input(tx): return Result.error(log='bad count') self.txCount += 1 return Result.ok() def end_block(self, height): """Called at the end of processing. If this is a stateful application you can use the height from here to record the last_block_height""" self.last_block_height = height return ResponseEndBlock() def query(self, reqQuery): """Return the last tx count""" v = encode_number(self.txCount) rq = ResponseQuery(code=0, key=b'count', value=v, height=self.last_block_height) return rq def commit(self): """Return the current encode state value to tendermint""" h = struct.pack('>Q', self.txCount) return Result.ok(data=h) if __name__ == '__main__': app = ABCIServer(app=SimpleCounter()) app.run()
return ResponseCheckTx(code=1) return ResponseCheckTx(code=CodeTypeOk) def deliver_tx(self, tx) -> ResponseDeliverTx: """Simply increment the state""" self.txCount += 1 return ResponseDeliverTx(code=CodeTypeOk) def query(self, req) -> ResponseQuery: """Return the last tx count""" v = encode_number(self.txCount) return ResponseQuery(code=CodeTypeOk, value=v, height=self.last_block_height) def commit(self) -> ResponseCommit: """Return the current encode state value to tendermint""" hash = struct.pack('>Q', self.txCount) return ResponseCommit(data=hash) if __name__ == '__main__': # Define argparse argument for changing proxy app port parser = argparse.ArgumentParser() parser.add_argument('-p', type=int, help='Proxy app port') args = parser.parse_args() # Create the app if args.p is None: app = ABCIServer(app=SimpleCounter()) # defaults to default port if -p not provided else: app = ABCIServer(app=SimpleCounter(), port=args.p) # Run it app.run()
return rq def begin_block(self, reqBeginBlock): """Called to process a block""" self.new_block_txs = [] return ResponseBeginBlock() def end_block(self, height): """Called at the end of processing. If this is a stateful application you can use the height from here to record the last_block_height""" self.db.set_block_height(increment=True) if self.new_block_txs: # Change app hash only if there any new txns self.db.set_block_app_hash( utils.get_merkle_root(self.new_block_txs)) return ResponseEndBlock() def commit(self): """Return the current encode state value to tendermint""" h = self.db.get_block_app_hash().encode() return ResponseCommit(data=h) if __name__ == '__main__': app = ABCIServer(app=SimpleCoin(), port=26658) app.run()
def run(self): """ Run the app in the py-abci server """ server = ABCIServer(app=self) server.run()
# def reset_chains(self): # """ # reset the state of the application. # """ # self.bdomainschain = Blockchain() # self.bobjectschain = Blockchain() # self.bdomainstree = MerkleTools(hash_type="md5") # self.bobjectstree = MerkleTools(hash_type="md5") # self.db0domains = DB0() # self.db0objects = DB0() # self.users = {} # self.groups = {} # self.acls = {} # self.acis = {} # def restore_state(self): # """ # Apply the transactions from the chains the achieve the application state. # """ # for tx in self.bdomainschain: # self.handle_tx(tx) # for tx in self.bobjectschain: # self.handle_tx(tx) if __name__ == '__main__': app = ABCIServer(app=SimpleRC()) app.run()
def deliver_tx(self, tx: bytes) -> ResponseDeliverTx: message = decode(tx) self.state, resp = self.handlers[type(message.data)].deliver_tx(self.state, message) return resp def query(self, req) -> ResponseQuery: message = sign_message(RawMessage(self.public_key, self.state, self.sequence), self.private_key) res = encode_for_wire(message) self.sequence += 1 return ResponseQuery(code=CodeTypeOk, value=res, height=self.state.last_block_height) def end_block(self, req) -> ResponseEndBlock: self.state, resp = self.end_block_handler.end_block(self.state, req) return resp def commit(self) -> ResponseCommit: return ResponseCommit(data=state_hash(self.state)) if __name__ == '__main__': tp = TenderPotato( [ NewPlayerHandler(), TossPotatoHandler(), ], FixedBlowUp(100), ) app = ABCIServer(app=tp) app.run()
self.state.app_hash = app_hash self.state.height += 1 self.state.save() return ResponseCommit(data=app_hash) def query(self, req): output = dict() param = req.data.split(b',') varId = param[0].split(b':')[1] varSpk = param[1].split(b':')[1] varRpk = param[2].split(b':')[1] srchStr = "id:" + varId.decode('ascii') + "," srchStr = srchStr + "senderpk:" + (varSpk.decode('ascii'), ".*")[varSpk == b''] + "," srchStr = srchStr + "receiverpk:" + (varRpk.decode('ascii'), ".*")[varRpk == b''] for key, val in self.state.db.snapshot().items(): x = re.search(srchStr, key.decode('ascii')) if not x is None: value = self.state.db.get(key) output[key] = value return ResponseQuery(code=CodeTypeOk, value=str(output).encode('ascii')) if __name__ == '__main__': logger.info("Initalisation is complete. KV Store Application is ready") app = ABCIServer(app=KVStoreApplication(), port=46658) app.run()
help='Path to dataset') parser.add_argument('-device', type=str, default="CPU", help='Device') parser.add_argument('-config', type=str, default=None, help='config') args = parser.parse_args() if args.config is None: exit("No config.ini found.") con = Configer(args.config) os.environ["DATASET"] = con.trainer.get_dataset() # newsender = sender(log, url_="http://node0:26657") newsender = sender(log, url_=con.bcfl.get_sender()) # newdb = moddb("ipfs") newdb = moddb(con.bcfl.get_db()) newagg = aggregator(log, con, newdb, newsender) # newtrain = trainer(log, args.dataset, newdb, newsender, devices=args.device) newtrain = trainer(log, con, newdb, newsender) newcontroller = State_controller(log, newtrain, newagg, con.agg.get_threshold()) # Create the app # app = ABCIServer(app=SimpleBCFL(newcontroller), port=args.p) app = ABCIServer(app=SimpleBCFL(newcontroller), port=con.bcfl.get_app_port()) # Run it app.run()
try: self.f1 = open(path1, 'a') self.f2 = open(path2, 'a') except: path1 = './time.txt' path2 = './num.txt' self.f1 = open(path1, 'a') self.f2 = open(path2, 'a') print("change path to current directory") self.f1.write(format(int(time.time()*1000))) self.f1.write('\n') self.f1.flush() self.f2.write(format(self.txIndex)) self.f2.write('\n') self.f2.flush() #ret = [self.txIndex] self.txIndex = 0 return ResponseCommit()#data=bytes(ret)) if __name__ == '__main__': if len(sys.argv) == 2: port = sys.argv[1]#26658 else: port = 26658 if len(sys.argv) == 2: port = int(sys.argv[1]) app = ABCIServer(port=port, app=PlasmaCash()) app.run()
) return rq def begin_block(self, reqBeginBlock): """Called to process a block""" self.new_block_txs = [] return ResponseBeginBlock() def end_block(self, height): """Called at the end of processing. If this is a stateful application you can use the height from here to record the last_block_height""" self.db.set_block_height(increment=True) if self.new_block_txs: # Change app hash only if there any new txns self.db.set_block_app_hash(utils.get_merkle_root(self.new_block_txs)) return ResponseEndBlock() def commit(self): """Return the current encode state value to tendermint""" h = self.db.get_block_app_hash().encode() return Result.ok(data=h) if __name__ == '__main__': app = ABCIServer(app=SimpleCoin()) app.run()