diff --git a/duniterpy/api/bma/__init__.py b/duniterpy/api/bma/__init__.py index 6d4771f6336447e8c3b963fc046ab9e78d120f05..727c52b784cda73e4125b650aca550efc994295d 100644 --- a/duniterpy/api/bma/__init__.py +++ b/duniterpy/api/bma/__init__.py @@ -27,4 +27,4 @@ logger = logging.getLogger("duniter") from .api import API, ConnectionHandler, parse_error, parse_response, parse_text -from . import network, blockchain, tx, wot, node, ud, ws \ No newline at end of file +from . import network, blockchain, tx, wot, node, ud, ws diff --git a/duniterpy/api/bma/network.py b/duniterpy/api/bma/network.py index 1441d04c991491b128f9986fa5f79e7ba40cd920..e50ba81131d42d9840dc285fcc651f646b0ace63 100644 --- a/duniterpy/api/bma/network.py +++ b/duniterpy/api/bma/network.py @@ -144,20 +144,47 @@ async def peer(connection, entry=None, signature=None): r = await client.requests_post('/peering/peers', entry=entry, signature=signature) return r -# async def status(connection): -# """ -# NOT DOCUMENTED IN BMA API DOCUMENTATION -# POST a network status document to this node in order notify of its status -# -# :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance -# :param duniterpy.documents.peer.Peer entry: Peer document -# :param str signature: Signature of the document issuer -# :rtype: dict -# """ -# -# async def __post__(self, session, **kwargs): -# assert 'status' in kwargs -# assert 'signature' in kwargs -# -# r = await self.requests_post(session, '/status', **kwargs) -# return r +WS2P_HEADS_SCHEMA = { + "type": "object", + "properties": { + "heads": { + "type": "array", + "items": { + "type": "object", + "properties": { + "message": { + "type": "string" + }, + "sig": { + "type": "string", + }, + "messageV2": { + "type": "string" + }, + "sigV2": { + "type": "string", + }, + "step": { + "type": "number", + }, + }, + "required": ["messageV2", "sigV2", "step"] + } + } + }, + "required": ["heads"] + } + + +async def heads(connection): + """ + GET Certification data over a member + + :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance + :rtype: dict + """ + + client = API(connection, URL_PATH) + + r = await client.requests_get('/ws2p/heads') + return await parse_response(r, WS2P_HEADS_SCHEMA) diff --git a/duniterpy/api/bma/ws2p.py b/duniterpy/api/bma/ws2p.py deleted file mode 100644 index 13a0058a7477da6667f98c39b14a4fe7f2c8346c..0000000000000000000000000000000000000000 --- a/duniterpy/api/bma/ws2p.py +++ /dev/null @@ -1,50 +0,0 @@ -from duniterpy.api.bma import API, logging, parse_response - -logger = logging.getLogger("duniter/ws2p") - -URL_PATH = 'ws2p' - -WS2P_HEADS_SCHEMA = { - "type": "object", - "properties": { - "heads": { - "type": "array", - "items": { - "type": "object", - "properties": { - "message": { - "type": "string" - }, - "sig": { - "type": "string", - }, - "messageV2": { - "type": "string" - }, - "sigV2": { - "type": "string", - }, - "step": { - "type": "number", - }, - }, - "required": ["messageV2", "sigV2", "step"] - } - } - }, - "required": ["heads"] - } - - -async def heads(connection): - """ - GET Certification data over a member - - :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance - :rtype: dict - """ - - client = API(connection, URL_PATH) - - r = await client.requests_get('/heads') - return await parse_response(r, WS2P_HEADS_SCHEMA) diff --git a/duniterpy/documents/ws2p/heads.py b/duniterpy/documents/ws2p/heads.py index 92e4c0bd914063b4e003114081c2e0995b936adf..774745e4a54efb0f9ca483e05cc4846dec67272e 100644 --- a/duniterpy/documents/ws2p/heads.py +++ b/duniterpy/documents/ws2p/heads.py @@ -83,7 +83,7 @@ class HeadV0: api = API.from_inline(data.group(1)) head = Head.from_inline(data.group(2)) pubkey = data.group(3) - blockstamp = data.group(4) + blockstamp = BlockUID.from_str(data.group(4)) offload = data.group(5) return cls(signature, api, head, pubkey, blockstamp), offload @@ -133,6 +133,10 @@ class HeadV1: def signature(self): return self.v0.signature + @property + def blockstamp(self): + return self.v0.blockstamp + @attr.s class HeadV2: re_inline = re.compile("({free_member_room}):({free_mirror_room})(?::)?(.*)" @@ -162,4 +166,8 @@ class HeadV2: @property def signature(self): - return self.v1.signature \ No newline at end of file + return self.v1.signature + + @property + def blockstamp(self): + return self.v1.blockstamp \ No newline at end of file diff --git a/tests/api/bma/test_ws2p.py b/tests/api/bma/test_ws2p.py index 03c9a09c42e5a74824af9a5ee2542600580cfd87..408fcc1747bf3cd7d097043ae6d6960859255ebd 100644 --- a/tests/api/bma/test_ws2p.py +++ b/tests/api/bma/test_ws2p.py @@ -4,7 +4,7 @@ import jsonschema import json from duniterpy.documents import BMAEndpoint from tests.api.webserver import WebFunctionalSetupMixin, web, asyncio -from duniterpy.api.bma.ws2p import heads, WS2P_HEADS_SCHEMA +from duniterpy.api.bma.network import heads, WS2P_HEADS_SCHEMA from duniterpy.api.bma import parse_text