Skip to content
Snippets Groups Projects
Select Git revision
  • 079fa58f2ac5df7b38e74a989bcf76b279e50eb5
  • master default protected
  • network/gdev-800 protected
  • cgeek/issue-297-cpu
  • gdev-800-tests
  • update-docker-compose-rpc-squid-names
  • fix-252
  • 1000i100-test
  • hugo/tmp-0.9.1
  • network/gdev-803 protected
  • hugo/endpoint-gossip
  • network/gdev-802 protected
  • hugo/distance-precompute
  • network/gdev-900 protected
  • tuxmain/anonymous-tx
  • debug/podman
  • hugo/195-doc
  • hugo/195-graphql-schema
  • hugo-tmp-dockerfile-cache
  • release/client-800.2 protected
  • release/runtime-800 protected
  • gdev-900-0.10.1 protected
  • gdev-900-0.10.0 protected
  • gdev-900-0.9.2 protected
  • gdev-800-0.8.0 protected
  • gdev-900-0.9.1 protected
  • gdev-900-0.9.0 protected
  • gdev-803 protected
  • gdev-802 protected
  • runtime-801 protected
  • gdev-800 protected
  • runtime-800-bis protected
  • runtime-800 protected
  • runtime-800-backup protected
  • runtime-701 protected
  • runtime-700 protected
  • runtime-600 protected
  • runtime-500 protected
  • v0.4.1 protected
  • runtime-401 protected
  • v0.4.0 protected
41 results

runtime-calls.md

Blame
    • Hugo Trentesaux's avatar
      b793b455
      implement quotas and refund transaction fees (!183) · b793b455
      Hugo Trentesaux authored
      * implement quotas
      
      implement weights "à l'arrache"
      
      benchmarks duniter-account "à l'arrache"
      
      implement benchmark logic (not proper benchmarks)
      
      fix live tests :man_facepalming:
      
      and clippy :man_facepalming::man_facepalming:
      
      replace quotas by quota everywhere
      
      comment unused sections of template
      
      remove quota treasury dependency
      
      give treasury address as argument
      
      typo
      
      review tuxmain
      
      doc readme
      
      rename error DistanceKO to DistanceNotOK
      
      merge new owner key and revocation signature
      
      merge signature error types
      
      rename NewOwnerKeyPayload
      
      fix comment
      
      make eligibility more explicit
      
      implement quotas
      
      implement weights "à l'arrache"
      
      benchmarks duniter-account "à l'arrache"
      
      implement benchmark logic (not proper benchmarks)
      
      fix live tests :man_facepalming:
      
      and clippy :man_facepalming::man_facepalming:
      
      replace quotas by quota everywhere
      
      comment unused sections of template
      
      remove quota treasury dependency
      
      give treasury address as argument
      
      typo
      
      review tuxmain
      
      doc readme
      
      rename error DistanceKO to DistanceNotOK
      
      merge new owner key and revocation signature
      
      merge signature error types
      
      rename NewOwnerKeyPayload
      
      fix comment
      
      make eligibility more explicit
      
      update metadata
      
      fix
      
      fix fee multiplier update
      
      prevent network discovery + connecting other nodes
      b793b455
      History
      implement quotas and refund transaction fees (!183)
      Hugo Trentesaux authored
      * implement quotas
      
      implement weights "à l'arrache"
      
      benchmarks duniter-account "à l'arrache"
      
      implement benchmark logic (not proper benchmarks)
      
      fix live tests :man_facepalming:
      
      and clippy :man_facepalming::man_facepalming:
      
      replace quotas by quota everywhere
      
      comment unused sections of template
      
      remove quota treasury dependency
      
      give treasury address as argument
      
      typo
      
      review tuxmain
      
      doc readme
      
      rename error DistanceKO to DistanceNotOK
      
      merge new owner key and revocation signature
      
      merge signature error types
      
      rename NewOwnerKeyPayload
      
      fix comment
      
      make eligibility more explicit
      
      implement quotas
      
      implement weights "à l'arrache"
      
      benchmarks duniter-account "à l'arrache"
      
      implement benchmark logic (not proper benchmarks)
      
      fix live tests :man_facepalming:
      
      and clippy :man_facepalming::man_facepalming:
      
      replace quotas by quota everywhere
      
      comment unused sections of template
      
      remove quota treasury dependency
      
      give treasury address as argument
      
      typo
      
      review tuxmain
      
      doc readme
      
      rename error DistanceKO to DistanceNotOK
      
      merge new owner key and revocation signature
      
      merge signature error types
      
      rename NewOwnerKeyPayload
      
      fix comment
      
      make eligibility more explicit
      
      update metadata
      
      fix
      
      fix fee multiplier update
      
      prevent network discovery + connecting other nodes
    request_ws2p.py 6.85 KiB
    import asyncio
    import json
    import time
    
    from _socket import gaierror
    
    import aiohttp
    import jsonschema
    from jsonschema import ValidationError
    
    from duniterpy.key import SigningKey
    
    from duniterpy.helpers.ws2p import handshake, get_ws2p_challenge
    from duniterpy.api.ws2p import requests
    from duniterpy.api.client import Client
    
    # CONFIG #######################################
    
    # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
    # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
    # Here we use the WS2P API (WS2P)
    WS2P_ENDPOINT = "WS2P 2f731dcd 127.0.0.1 20900"
    CURRENCY = "g1-test"
    
    
    ################################################
    
    
    async def main():
        """
        Main code
        """
    
        # # Prompt hidden user entry
        # salt = getpass.getpass("Enter your passphrase (salt): ")
        #
        # # Prompt hidden user entry
        # password = getpass.getpass("Enter your password: ")
        salt = password = "toto"
    
        # Init signing_key instance
        signing_key = SigningKey.from_credentials(salt, password)
    
        # Create Client from endpoint string in Duniter format
        client = Client(WS2P_ENDPOINT)
    
        try:
            # Create a Web Socket connection
            ws = await client.connect_ws()
    
            print("Connected successfully to web socket endpoint")
    
            # HANDSHAKE #######################################################
            try:
                await handshake(ws, signing_key, CURRENCY, True)
            except ValidationError as exception:
                print(exception.message)
                print("HANDSHAKE FAILED !")
                exit(1)
    
            # Send ws2p request
            print("Send getCurrent() request")
            request_id = get_ws2p_challenge()[:8]
            await ws.send_str(requests.get_current(request_id))
    
            # Wait response with request id
            response = await ws.receive_json()
            while "resId" not in response or (
                "resId" in response and response["resId"] != request_id
            ):
                response = await ws.receive_json()
                time.sleep(1)
            try:
                # Check response format
                jsonschema.validate(response, requests.BLOCK_RESPONSE_SCHEMA)
                # If valid display response
                print("Response: " + json.dumps(response, indent=2))
            except ValidationError:
                # If invalid response...
                try:
                    # Check error response format
                    jsonschema.validate(response, requests.ERROR_RESPONSE_SCHEMA)
                    # If valid, display error response
                    print("Error response: " + json.dumps(response, indent=2))
                except ValidationError as exception:
                    # If invalid, display exception on response validation
                    print(exception)
    
            # Send ws2p request
            print("Send getBlock(360000) request")
            request_id = get_ws2p_challenge()[:8]
            await ws.send_str(requests.get_block(request_id, 360000))
    
            # Wait response with request id
            response = await ws.receive_json()
            while "resId" not in response or (
                "resId" in response and response["resId"] != request_id
            ):
                response = await ws.receive_json()
                time.sleep(1)
            try:
                # Check response format
                jsonschema.validate(response, requests.BLOCK_RESPONSE_SCHEMA)
                # If valid display response
                print("Response: " + json.dumps(response, indent=2))
            except ValidationError:
                # If invalid response...
                try:
                    # Check error response format
                    jsonschema.validate(response, requests.ERROR_RESPONSE_SCHEMA)
                    # If valid, display error response
                    print("Error response: " + json.dumps(response, indent=2))
                except ValidationError as exception:
                    # If invalid, display exception on response validation
                    print(exception)
    
            # Send ws2p request
            print("Send getBlocks(360000, 2) request")
            request_id = get_ws2p_challenge()[:8]
            await ws.send_str(requests.get_blocks(request_id, 360000, 2))
    
            # Wait response with request id
            response = await ws.receive_json()
            while "resId" not in response or (
                "resId" in response and response["resId"] != request_id
            ):
                response = await ws.receive_json()
                time.sleep(1)
            try:
                # Check response format
                jsonschema.validate(response, requests.BLOCKS_RESPONSE_SCHEMA)
                # If valid display response
                print("Response: " + json.dumps(response, indent=2))
            except ValidationError:
                # If invalid response...
                try:
                    # Check error response format
                    jsonschema.validate(response, requests.ERROR_RESPONSE_SCHEMA)
                    # If valid, display error response
                    print("Error response: " + json.dumps(response, indent=2))
                except ValidationError as exception:
                    # If invalid, display exception on response validation
                    print(exception)
    
            # Send ws2p request
            print("Send getRequirementsPending(3) request")
            request_id = get_ws2p_challenge()[:8]
            await ws.send_str(requests.get_requirements_pending(request_id, 3))
            # Wait response with request id
            response = await ws.receive_json()
            while "resId" not in response or (
                "resId" in response and response["resId"] != request_id
            ):
                response = await ws.receive_json()
                time.sleep(1)
            try:
                # Check response format
                jsonschema.validate(response, requests.REQUIREMENTS_RESPONSE_SCHEMA)
                # If valid display response
                print("Response: " + json.dumps(response, indent=2))
            except ValidationError:
                # If invalid response...
                try:
                    # Check error response format
                    jsonschema.validate(response, requests.ERROR_RESPONSE_SCHEMA)
                    # If valid, display error response
                    print("Error response: " + json.dumps(response, indent=2))
                except ValidationError as exception:
                    # If invalid, display exception on response validation
                    print(exception)
    
            # Close session
            await client.close()
    
        except (aiohttp.WSServerHandshakeError, ValueError) as e:
            print("Websocket handshake {0} : {1}".format(type(e).__name__, str(e)))
        except (aiohttp.ClientError, gaierror, TimeoutError) as e:
            print("{0} : {1}".format(str(e), WS2P_ENDPOINT))
        except jsonschema.ValidationError as e:
            print("{:}:{:}".format(str(e.__class__.__name__), str(e)))
    
    
    # Latest duniter-python-api is asynchronous and you have to use asyncio, an asyncio loop and a "as" on the data.
    # ( https://docs.python.org/3/library/asyncio.html )
    asyncio.get_event_loop().run_until_complete(main())