Skip to content
Snippets Groups Projects
Commit f7f01678 authored by Moul's avatar Moul Committed by Vincent Texier
Browse files

[enh] #58: WS2P examples improvements:

- Request blocks around 30.000 as 360.000 does not already exists in Ğ1
- Move dummy credential before getpass in order to be overwriten
- Add ability to pass member credentials to listen_ws2p
- Add getpass import
- Close WS2P clients in three examples in case of a raised exception
- Use sys.exit() because pylint complains
parent 4ad9109e
No related branches found
No related tags found
2 merge requests!94Merge dev into master for release 0.56.0,!84#58: WS2P support
Pipeline #7734 passed
import asyncio
import json
import sys
from _socket import gaierror
......@@ -31,6 +32,15 @@ async def main():
# Arbitrary credentials to create the node key pair to sign ws2p documents
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)
......@@ -56,7 +66,7 @@ async def main():
except ValidationError as exception:
print(exception.message)
print("HANDSHAKE FAILED !")
exit(1)
sys.exit(1)
print("Handshake ok")
......@@ -78,6 +88,7 @@ async def main():
print("{0} : {1}".format(str(e), ws2p_endpoint.inline()))
except jsonschema.ValidationError as e:
print("{:}:{:}".format(str(e.__class__.__name__), str(e)))
await client.close()
# Latest duniter-python-api is asynchronous and you have to use asyncio, an asyncio loop and a "as" on the data.
......
......@@ -51,6 +51,7 @@ async def main():
print("{0} : {1}".format(str(e), BMAS_ENDPOINT))
except jsonschema.ValidationError as e:
print("{:}:{:}".format(str(e.__class__.__name__), str(e)))
await client.close()
# Latest duniter-python-api is asynchronous and you have to use asyncio, an asyncio loop and a "as" on the data.
......
import asyncio
import json
import time
import sys
from _socket import gaierror
......@@ -69,17 +70,18 @@ async 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: ")
# dummy credentials
salt = password = "test"
# Init signing_key instance
signing_key = SigningKey.from_credentials(salt, password)
......@@ -103,7 +105,7 @@ async def main():
except ValidationError as exception:
print(exception.message)
print("HANDSHAKE FAILED !")
exit(1)
sys.exit(1)
# Send ws2p request
print("Send getCurrent() request")
......@@ -117,22 +119,22 @@ async def main():
print("Response: " + json.dumps(response, indent=2))
# Send ws2p request
print("Send getBlock(360000) request")
print("Send getBlock(30000) request")
request_id = get_ws2p_challenge()[:8]
response = await send(
ws,
requests.get_block(request_id, 360000),
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(360000, 2) request")
print("Send getBlocks(30000, 2) request")
request_id = get_ws2p_challenge()[:8]
response = await send(
ws,
requests.get_blocks(request_id, 360000, 2),
requests.get_blocks(request_id, 30000, 2),
request_id,
requests.BLOCKS_RESPONSE_SCHEMA,
)
......@@ -158,6 +160,7 @@ async def main():
print("{0} : {1}".format(str(e), ws2p_endpoint.inline()))
except jsonschema.ValidationError as e:
print("{:}:{:}".format(str(e.__class__.__name__), str(e)))
await client.close()
# Latest duniter-python-api is asynchronous and you have to use asyncio, an asyncio loop and a "as" on the data.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment