@@ -76,9 +76,10 @@ def _graphql_request(self, query: str, variables: dict = {}):
7676 }
7777 self .logger .debug ("Sending a Query: {}" .format (payload ))
7878 response = requests .post (self .endpoint , json = payload , headers = headers )
79- if response .status_code == 200 :
79+ resp_json = response .json ()
80+ if response .status_code == 200 and "errors" not in resp_json :
8081 self .logger .debug ("Got a Response: {}" .format (response .json ()))
81- return response . json ()
82+ return resp_json
8283 else :
8384 print (response .text )
8485 raise Exception (
@@ -97,6 +98,7 @@ async def _graphql_subscription(self, query: str, variables: dict = {}, callback
9798 self .logger .info ("Listening to GraphQL Subscription..." )
9899
99100 uri = self .websocket_endpoint
101+ self .logger .info (uri )
100102 async with websockets .client .connect (uri , ping_timeout = None ) as websocket :
101103 # Set up Websocket Connection
102104 self .logger .debug ("WEBSOCKET -- Sending Hello Message: {}" .format (hello_message ))
@@ -464,15 +466,15 @@ async def listen_block_confirmations(self, callback):
464466 '''
465467 await self ._graphql_subscription (query , {}, callback )
466468
467- async def listen_new_blocks (self , pk : str , callback ):
468- """Creates a subscription for new blocks created by a proposer using a particular private key .
469+ async def listen_new_blocks (self , callback ):
470+ """Creates a subscription for new blocks, calls `callback` each time the subscription fires .
469471
470472 Arguments:
471- pk {PublicKey } -- The public key to use to filter blocks
473+ callback(block) {coroutine } -- This coroutine is executed with the new block as an argument each time the subscription fires
472474 """
473475 query = '''
474- subscription($pk:PublicKey ){
475- newBlock(publicKey:$pk ){
476+ subscription(){
477+ newBlock(){
476478 creator
477479 stateHash
478480 protocolState {
0 commit comments