def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() self.driver = ContractDriver(driver=InMemDriver()) self.client = ContractingClient(driver=self.driver) self.client.flush() asyncio.set_event_loop(self.loop)
def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() self.driver = ContractDriver(driver=InMemDriver()) asyncio.set_event_loop(self.loop) self.authenticator = authentication.SocketAuthenticator( client=ContractingClient(driver=self.driver), ctx=self.ctx)
def __init__(self, host, port, *, filter_hostname=None, filter_pid=None, filter_run_engine_id=None, loop=None): if loop is None: loop = zmq.asyncio.ZMQEventLoop() self._loop = loop asyncio.set_event_loop(self._loop) self._host = host self._port = int(port) self._context = zmq.asyncio.Context() self._socket = self._context.socket(zmq.SUB) url = "tcp://%s:%d" % (self.host, self.port) self._socket.connect(url) self._socket.setsockopt_string(zmq.SUBSCRIBE, "") self._task = None def is_our_message(hostname, pid, RE_id): # Close over filters and decide if this message applies to this # RemoteDispatcher. return ((filter_hostname is None or filter_hostname == hostname) and (filter_pid is None or filter_pid == pid) and (filter_run_engine_id is None or filter_run_engine_id == RE_id)) self._is_our_message = is_our_message super().__init__()
def setUp(self): self.ctx = zmq.asyncio.Context() self.ctx.max_sockets = 50_000 self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) ContractingClient().flush() MasterStorage().drop_collections()
def setUp(self): self.wallet = Wallet() # Wallets for VKs self.test_wallet_1 = Wallet() self.test_wallet_2 = Wallet() self.peer_table = { self.test_wallet_1.verifying_key().hex(): 'ipc:///tmp/n1', self.test_wallet_2.verifying_key().hex(): 'ipc:///tmp/n2', } self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() self.contacts = MockContacts( masters=[self.test_wallet_1.verifying_key().hex()], delegates=[self.test_wallet_2.verifying_key().hex()]) self.paramaters = Parameters(socket_base='tcp://127.0.0.1', wallet=self.wallet, ctx=self.ctx, contacts=self.contacts) self.authenticator = SocketAuthenticator(wallet=self.wallet, contacts=self.contacts, ctx=self.ctx) asyncio.set_event_loop(self.loop)
def setUp(self): self.sk = '06391888e37a48cef1ded85a375490df4f9b2c74f7723e88c954a055f3d2685a' self.vk = '82540bb5a9c84162214c5540d6e43be49bbfe19cf49685660cab608998a65144' self.private_key = 'f0ca3d349e56e419e72f11c1fd734ae929a483f9490907d2ded554d9f794f361' self.public_key = '73619fa1464ce16802b480a0fd7868ffcce0f7285050a927a07ef1ffdd34c162' self.curve_public_key = b'B77YmmOI=O0<)GJ@DJ2Q+&5jzp/absPNMCh?88@S' self.ironhouse = Ironhouse(self.sk, wipe_certs=True, auth_validate=auth_validate) self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop)
def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) self.authenticator = authentication.SocketAuthenticator( client=ContractingClient(), ctx=self.ctx) self.b = masternode.BlockService(blocks=storage.BlockStorage(), driver=ContractDriver()) self.r = router.Router(socket_id='tcp://127.0.0.1:18001', ctx=self.ctx) self.r.add_service(base.BLOCK_SERVICE, self.b)
def main_loop(self): # set the context for zmq # we want to be able to use the zmq polls rpcloop = zmq.asyncio.ZMQEventLoop() asyncio.set_event_loop(rpcloop) # setup tasks tasks=[ self.worker_loop(), self.rpc_loop() ] # now start the zmq message loop rpcloop.run_until_complete(asyncio.wait(tasks))
def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) self.blocks = storage.BlockStorage() self.driver = ContractDriver(driver=InMemDriver()) self.b = masternode.BlockService(blocks=self.blocks, driver=self.driver) self.blocks.drop_collections() self.driver.flush() self.authenticator = authentication.SocketAuthenticator( client=ContractingClient(), ctx=self.ctx)
def __init__(self): self.common = Common() self.logger = get_log() self.http = MarketHttpClient() self.market_token = self.http.get_market_token( self.http.get_login_token(phone=login_phone, pwd=login_pwd, device_id=login_device_id)) self.new_loop = self.common.getNewLoop() asyncio.set_event_loop(self.new_loop) self.api = SubscribeApi(union_ws_url, self.new_loop) asyncio.get_event_loop().run_until_complete( future=self.api.client.ws_connect()) asyncio.get_event_loop().run_until_complete(future=self.api.LoginReq( token=self.market_token)) asyncio.run_coroutine_threadsafe(self.api.hearbeat_job(), self.new_loop)
def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop)
import sys import binascii import zmq.asyncio import asyncio loop = zmq.asyncio.ZMQEventLoop() asyncio.set_event_loop(loop) import libbitcoin context = libbitcoin.Context() async def main(): client = context.Client("tcp://gateway.unsystem.net:9091") idx = "77cb1e9d44f1b8e8341e6e6848bf34ea6cb7a88bdaad0126ac1254093480f13f" idx = bytes.fromhex(idx) ec, tx_data = await client.transaction(idx) if ec: print("Couldn't fetch transaction:", ec, file=sys.stderr) context.stop_all() return # Should be 257 bytes. print("tx size is %s bytes" % len(tx_data)) ec, height, index = await client.transaction_index(idx) if ec: print("Couldn't fetch transaction_index:", ec, file=sys.stderr) context.stop_all()
def test_refresh_remove_old_nodes(self): constitution = self.get_vkbook_args() sync.submit_from_genesis_json_file(cilantro_ee.contracts.__path__[0] + '/genesis.json', client=self.client) sync.submit_node_election_contracts( initial_masternodes=constitution['masternodes'], boot_mns=constitution['masternode_min_quorum'], initial_delegates=constitution['delegates'], boot_dels=constitution['delegate_min_quorum'], client=self.client) PhoneBook = VKBook(client=self.client) w1 = Wallet() p1 = Network(wallet=w1, ctx=self.ctx, socket_base='tcp://127.0.0.1') peeps = { 'stu': 'tcp://127.0.0.1', 'raghu': 'tcp://127.0.0.8', 'tejas': 'tcp://127.0.2.1', 'steve': 'tcp://127.0.54.6' } p1.peer_service.table = peeps ctx2 = zmq.asyncio.Context() masternodes = Parameters(socket_base='tcp://127.0.0.1', wallet=w1, contacts=MockContacts(['stu', 'raghu'], ['tejas', 'steve']), ctx=ctx2) self.assertDictEqual(masternodes.sockets, {}) async def late_refresh(): await asyncio.sleep(0.3) await masternodes.refresh() async def stop(): await asyncio.sleep(0.5) p1.stop() tasks = asyncio.gather(p1.start(discover=False), late_refresh(), stop()) self.loop.run_until_complete(tasks) expected = {'stu': 'tcp://127.0.0.1', 'raghu': 'tcp://127.0.0.8'} self.assertDictEqual(masternodes.sockets, expected) self.ctx.destroy() self.loop.close() self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) w1 = Wallet() p1 = Network(wallet=w1, ctx=self.ctx, socket_base='tcp://127.0.0.1') peeps = { 'stu': 'tcp://127.0.2.1', 'raghu': 'tcp://127.0.0.8', 'tejas': 'tcp://127.0.2.1', 'steve': 'tcp://127.0.54.6' } p1.peer_service.table.peers = peeps vkbook_args = self.get_vkbook_args(mns=['stu', 'tejas']) sync.submit_vkbook(vkbook_args, overwrite=True) async def late_refresh(): await asyncio.sleep(0.3) await masternodes.refresh() async def stop(): await asyncio.sleep(1) p1.stop() tasks = asyncio.gather(p1.start(discover=False), late_refresh(), stop()) self.loop.run_until_complete(tasks) expected = { 'stu': 'tcp://127.0.2.1', 'tejas': 'tcp://127.0.2.1', } self.assertDictEqual(masternodes.sockets, expected)
def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() ContractingClient().flush() asyncio.set_event_loop(self.loop)
def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop)
import sys import binascii import zmq.asyncio import asyncio loop = zmq.asyncio.ZMQEventLoop() asyncio.set_event_loop(loop) import libbitcoin context = libbitcoin.Context() async def main(): client = context.Client("tcp://gateway.unsystem.net:9091") address = "13ejSKUxLT9yByyr1bsLNseLbx9H9tNj2d" ec, history = await client.history(address) if ec: print("Couldn't fetch history:", ec, file=sys.stderr) context.stop_all() return for output, spend in history: print("OUTPUT point=%s, height=%s, value=%s" % (output[0], output[1], output[2])) if spend is not None: print("-> SPEND point=%s, height=%s" % (spend[0], spend[1])) print() # Calculate the balance of a Bitcoin address from its history. balance = sum(output[2] for output, spend in history if spend is None) print("Address balance:", balance)
def test_refresh_remove_old_nodes(self): vkbook_args = self.get_vkbook_args() sync.submit_vkbook(vkbook_args, overwrite=True) PhoneBook = VKBook() w1 = Wallet() p1 = Network(wallet=w1, ctx=self.ctx, socket_base='tcp://127.0.0.1') peeps = { 'stu': 'tcp://127.0.0.1', 'raghu': 'tcp://127.0.0.8', 'tejas': 'tcp://127.0.2.1', 'steve': 'tcp://127.0.54.6' } p1.peer_service.table.peers = peeps ctx2 = zmq.asyncio.Context() masternodes = SocketBook( socket_base='tcp://127.0.0.1', service_type=ServiceType.EVENT, ctx=ctx2, phonebook_function=PhoneBook.contract.get_masternodes) self.assertDictEqual(masternodes.sockets, {}) async def late_refresh(): await asyncio.sleep(0.3) await masternodes.refresh() async def stop(): await asyncio.sleep(0.5) p1.stop() tasks = asyncio.gather(p1.start(discover=False), late_refresh(), stop()) self.loop.run_until_complete(tasks) expected = { 'stu': _socket('tcp://127.0.0.1:{}'.format(EVENT_PORT)), 'raghu': _socket('tcp://127.0.0.8:{}'.format(EVENT_PORT)) } self.assertDictEqual(masternodes.sockets, expected) self.ctx.destroy() self.loop.close() self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) w1 = Wallet() p1 = Network(wallet=w1, ctx=self.ctx, socket_base='tcp://127.0.0.1') peeps = { 'stu': 'tcp://127.0.2.1', 'raghu': 'tcp://127.0.0.8', 'tejas': 'tcp://127.0.2.1', 'steve': 'tcp://127.0.54.6' } p1.peer_service.table.peers = peeps vkbook_args = self.get_vkbook_args(mns=['stu', 'tejas']) sync.submit_vkbook(vkbook_args, overwrite=True) async def late_refresh(): await asyncio.sleep(0.3) await masternodes.refresh() async def stop(): await asyncio.sleep(1) p1.stop() tasks = asyncio.gather(p1.start(discover=False), late_refresh(), stop()) self.loop.run_until_complete(tasks) expected = { 'stu': _socket('tcp://127.0.2.1:{}'.format(EVENT_PORT)), 'tejas': _socket('tcp://127.0.2.1:{}'.format(EVENT_PORT)), } self.assertDictEqual(masternodes.sockets, expected)
def setUp(self): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) self.t = BlockchainDriver() self.ctx = zmq.asyncio.Context()