Skip to content
Snippets Groups Projects
Commit 9174b01a authored by inso's avatar inso
Browse files

Move ws2p heads to network api

parent cc5ae9e0
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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)
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)
......@@ -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})(?::)?(.*)"
......@@ -163,3 +167,7 @@ class HeadV2:
@property
def signature(self):
return self.v1.signature
@property
def blockstamp(self):
return self.v1.blockstamp
\ No newline at end of file
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment