def test_reverse_url_complete(self): endpoint = BMAEndpoint("test.com", "124.2.2.1", "2001:0db8:0000:85a3:0000:0000:ac1f:8001 ", 9092) api = API(next(endpoint.conn_handler()), "any") self.assertEqual(api.reverse_url("http", "/test/url"), "http://test.com:9092/any/test/url")
def test_reverse_url_only_ipv6(self): endpoint = BMAEndpoint(None, None, "2001:0db8:0000:85a3:0000:0000:ac1f:8001", 9092) api = API(next(endpoint.conn_handler()), "any") self.assertEqual( api.reverse_url("http", "/test/url"), "http://[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:9092/any/test/url" )
def peer(connection): """ Connect to peer websocket :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :rtype: aiohttp.ClientWebSocketResponse """ client = API(connection, URL_PATH) return client.connect_ws('/peer')
def test_parse_error(self): api = API(None, "any") error = api.parse_error("""{ "ucode": 1005, "message": "Document has unkown fields or wrong line ending format" }""") self.assertEqual(error["ucode"], 1005) self.assertEqual( error["message"], "Document has unkown fields or wrong line ending format")
async def summary(connection): """ GET Certification data over a member :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :rtype: dict """ schema = { "type": "object", "properties": { "duniter": { "type": "object", "properties": { "software": { "type": "string" }, "version": { "type": "string", }, "forkWindowSize": { "type": "number" } }, "required": ["software", "version"] }, }, "required": ["duniter"] } client = API(connection, URL_PATH) r = await client.requests_get('/summary') return await parse_response(r, schema)
async def parameters(connection): """ GET the blockchain parameters used by this node :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/parameters') return await parse_response(r, PARAMETERS_SCHEMA)
async def ud(connection): """ GET, return block numbers containing universal dividend :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/with/ud') return await parse_response(r, BLOCK_NUMBERS_SCHEMA)
async def hardship(connection, pubkey): """ GET hardship level for given member's public key for writing next block :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str pubkey: Public key of the member :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/hardship/%s' % pubkey) return await parse_response(r, HARDSHIP_SCHEMA)
async def membership(connection, membership): """ POST a Membership document :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str membership: Membership signed raw document :rtype: aiohttp.ClientResponse """ client = API(connection, URL_PATH) return await client.requests_post('/membership', membership=membership)
async def members(connection): """ GET list of all current members of the Web of Trust :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/members') return await parse_response(r, MEMBERS_SCHEMA)
async def peering(connection): """ GET peering information about a peer :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/peering') return await parse_response(r, PEERING_SCHEMA)
async def memberships(connection, search): """ GET list of Membership documents for UID/Public key :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str search: UID/Public key :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/memberships/%s' % search) return await parse_response(r, MEMBERSHIPS_SCHEMA)
async def process(connection, transaction): """ POST a transaction :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param duniterpy.documents.Transaction transaction: Transaction document :rtype: aiohttp.ClientResponse """ client = API(connection, URL_PATH) r = await client.requests_post('/process', transaction=transaction) return r
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)
async def certified_by(connection, search): """ GET identities certified by UID/Public key :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str search: UID or public key :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/certified-by/%s' % search) return await parse_response(r, CERTIFICATIONS_SCHEMA)
async def lookup(connection, search): """ GET UID/Public key data :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str search: UID or public key :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/lookup/%s' % search) return await parse_response(r, LOOKUP_SCHEMA)
async def revoke(connection, revocation): """ POST revocation document :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param duniterpy.documents.certification.Revocation revocation: Certification document :rtype: aiohttp.ClientResponse """ client = API(connection, URL_PATH) r = await client.requests_post('/revoke', revocation=revocation) return r
async def certify(connection, cert): """ POST certification document :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param duniterpy.documents.certification.Certification cert: Certification document :rtype: aiohttp.ClientResponse """ client = API(connection, URL_PATH) r = await client.requests_post('/certify', cert=cert) return r
async def add(connection, identity): """ POST identity document :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param duniterpy.documents.certification.Identity identity: Identity document :rtype: aiohttp.ClientResponse """ client = API(connection, URL_PATH) r = await client.requests_post('/add', identity=identity) return r
async def sources(connection, pubkey): """ GET transaction sources :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str pubkey: Public key :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/sources/%s' % pubkey) return await parse_response(r, SOURCES_SCHEMA)
async def current(connection): """ GET, return last accepted block :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/current') return await parse_response(r, BLOCK_SCHEMA)
async def requirements(connection, search): """ GET list of requirements for a given UID/Public key :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str search: UID or public key :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/requirements/%s' % search) return await parse_response(r, REQUIREMENTS_SCHEMA)
async def history(connection, pubkey): """ Get transactions history of public key :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str pubkey: Public key :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/history/%s' % pubkey) return await parse_response(r, HISTORY_SCHEMA)
async def peer(connection, entry=None, signature=None): """ GET peering entries of every node inside the currency network :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 """ client = API(connection, URL_PATH) r = await client.requests_post('/peering/peers', entry=entry, signature=signature) return r
async def history(connection, pubkey): """ Get UD history of a member account :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str pubkey: Public key of the member :rtype: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/history/%s' % pubkey) return await parse_response(r, UD_SCHEMA)
async def times(connection, pubkey, start, end): """ GET public key transactions history between start and end timestamp :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param str pubkey: Public key :param int start: Start from timestamp :param int end: End to timestamp :return: dict """ client = API(connection, URL_PATH) r = await client.requests_get('/history/%s/times/%s/%s' % (pubkey, start, end)) return await parse_response(r, HISTORY_SCHEMA)
async def blocks(connection, count, start): """ GET list of blocks from the blockchain :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param int count: Number of blocks :param int start: First block number :rtype: list """ client = API(connection, URL_PATH) assert type(count) is int assert type(start) is int r = await client.requests_get('/blocks/%d/%d' % (count, start)) return await parse_response(r, BLOCKS_SCHEMA)
async def peers(connection, leaves=False, leaf=""): """ GET peering entries of every node inside the currency network :param bool leaves: True if leaves should be requested :param str leaf: True if leaf should be requested :rtype: dict """ client = API(connection, URL_PATH) # GET Peers if leaves: r = await client.requests_get('/peering/peers', leaves=leaves) else: r = await client.requests_get('/peering/peers', leaf=leaf) return await parse_response(r, PEERS_SCHEMA)
async def block(connection, number=0, block=None, signature=None): """ GET/POST a block from/to the blockchain :param duniterpy.api.bma.ConnectionHandler connection: Connection handler instance :param int number: Block number to get :param dict block: Block document to post :param str signature: Signature of the block document issuer :rtype: dict """ client = API(connection, URL_PATH) # POST block if block is not None and signature is not None: return await client.requests_post('/block', block=block, signature=signature) # GET block r = await client.requests_get('/block/%d' % number) data = await parse_response(r, BLOCK_SCHEMA) return data
def test_reverse_url_only_ipv4(self): endpoint = BMAEndpoint(None, "124.2.2.1", None, 9092) api = API(next(endpoint.conn_handler()), "any") self.assertEqual(api.reverse_url("http", "/test/url"), "http://124.2.2.1:9092/any/test/url")