Skip to content
Snippets Groups Projects
Select Git revision
  • 4f71771fb6e47aa071fdaa56d010082eba04ea24
  • master default protected
  • fix_picked_up_file_in_runtime_release
  • network/gtest-1000 protected
  • upgradable-multisig
  • runtime/gtest-1000
  • 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
  • gtest-1000-0.11.1 protected
  • gtest-1000-0.11.0 protected
  • gtest-1000 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
41 results

build-for-arm.md

Blame
    • Benjamin Gallois's avatar
      eb590e1c
      Fix #200 (!267) · eb590e1c
      Benjamin Gallois authored and Hugo Trentesaux's avatar Hugo Trentesaux committed
      * remove /ws from listen address
      
      * fix error when user already exist
      
      * change binary to duniter2
      
      * add rpc-cors
      
      * add config documentation
      
      * add reference in service files
      
      * use embedded distance oracle
      
      * optimize ci
      
      * use docker cache
      
      * add systemd timer
      
      * add documentation
      
      * fix base_path default
      
      * add duniter user
      
      * add services
      
      * update docs
      
      * add deb package to ci
      
      * add deb docker building
      eb590e1c
      History
      Fix #200 (!267)
      Benjamin Gallois authored and Hugo Trentesaux's avatar Hugo Trentesaux committed
      * remove /ws from listen address
      
      * fix error when user already exist
      
      * change binary to duniter2
      
      * add rpc-cors
      
      * add config documentation
      
      * add reference in service files
      
      * use embedded distance oracle
      
      * optimize ci
      
      * use docker cache
      
      * add systemd timer
      
      * add documentation
      
      * fix base_path default
      
      * add duniter user
      
      * add services
      
      * update docs
      
      * add deb package to ci
      
      * add deb docker building
    request_ws2p.py 5.19 KiB
    """
    Copyright  2014-2021 Vincent Texier <vit@free.fr>
    
    DuniterPy is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    DuniterPy is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    """
    
    import json
    import time
    import sys
    
    import jsonschema
    from jsonschema import ValidationError
    from typing import Any
    
    from duniterpy.tools import get_ws2p_challenge
    from duniterpy.key import SigningKey
    
    from duniterpy.helpers.ws2p import handshake, generate_ws2p_endpoint
    from duniterpy.api.ws2p import requests
    from duniterpy.api.client import Client, WSConnection
    
    # CONFIG #######################################
    
    # You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
    # or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
    # Here we use the WS2P API (WS2P [UUID] [DOMAIN] [PORT] [PATH])
    BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
    CURRENCY = "g1-test"
    
    
    ################################################
    
    
    def send(ws: WSConnection, request: str, request_id: str, schema: dict) -> Any:
        """
        Send a WS2P request
    
        :rtype: Any
        :param ws: WSConnection instance
        :param request: Request string to send
        :param request_id: Unique request id
        :param schema: Validation schema
        """
        # Send request
        ws.send_str(request)
    
        # Wait response with request id
        response = ws.receive_json()
        while "resId" not in response or (
            "resId" in response and response["resId"] != request_id
        ):
            response = ws.receive_json()
            time.sleep(1)
        try:
            # Check response format
            jsonschema.validate(response, schema)
            # If valid display response
        except ValidationError:
            # If invalid response...
            try:
                # Check error response format
                jsonschema.validate(response, requests.ERROR_RESPONSE_SCHEMA)
                # If valid, display error response
            except ValidationError as exception:
                # If invalid, display exception on response validation
                print(exception)
    
        return response
    
    
    def main():
        """
        Main code
        """
        # dummy credentials
        salt = password = "test"
    
        # You can connect with member credentials in case there is not much slots available on the endpoint
        #
        # # Prompt hidden user entry
        # import getpass
        # salt = getpass.getpass("Enter your passphrase (salt): ")
        #
        # # Prompt hidden user entry
        # password = getpass.getpass("Enter your password: ")
    
        # Init signing_key instance
        signing_key = SigningKey.from_credentials(salt, password)
    
        # Create Client from endpoint string in Duniter format
        try:
            ws2p_endpoint = generate_ws2p_endpoint(BMAS_ENDPOINT)
        except ValueError as e:
            print(e)
            return
        client = Client(ws2p_endpoint)
    
        try:
            # Create a Web Socket connection
            ws = client.connect_ws()
    
            print("Successfully connected to the web socket endpoint")
    
            # HANDSHAKE #######################################################
            try:
                handshake(ws, signing_key, CURRENCY)
            except ValidationError as exception:
                print(exception.message)
                print("HANDSHAKE FAILED !")
                sys.exit(1)
    
            # Send ws2p request
            print("Send getCurrent() request")
            request_id = get_ws2p_challenge()[:8]
            response = send(
                ws,
                requests.get_current(request_id),
                request_id,
                requests.BLOCK_RESPONSE_SCHEMA,
            )
            print("Response: " + json.dumps(response, indent=2))
    
            # Send ws2p request
            print("Send getBlock(30000) request")
            request_id = get_ws2p_challenge()[:8]
            response = send(
                ws,
                requests.get_block(request_id, 30000),
                request_id,
                requests.BLOCK_RESPONSE_SCHEMA,
            )
            print("Response: " + json.dumps(response, indent=2))
    
            # Send ws2p request
            print("Send getBlocks(30000, 2) request")
            request_id = get_ws2p_challenge()[:8]
            response = send(
                ws,
                requests.get_blocks(request_id, 30000, 2),
                request_id,
                requests.BLOCKS_RESPONSE_SCHEMA,
            )
            print("Response: " + json.dumps(response, indent=2))
    
            # Send ws2p request
            print("Send getRequirementsPending(3) request")
            request_id = get_ws2p_challenge()[:8]
            response = send(
                ws,
                requests.get_requirements_pending(request_id, 3),
                request_id,
                requests.REQUIREMENTS_RESPONSE_SCHEMA,
            )
            print("Response: " + json.dumps(response, indent=2))
    
        except jsonschema.ValidationError as e:
            print("{:}:{:}".format(str(e.__class__.__name__), str(e)))
    
    
    if __name__ == "__main__":
        main()