예제 #1
0
 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")
예제 #2
0
 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"
     )
예제 #3
0
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')
예제 #4
0
    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")
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
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)
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
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)
예제 #11
0
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)
예제 #12
0
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)
예제 #13
0
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
예제 #14
0
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)
예제 #15
0
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)
예제 #16
0
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)
예제 #17
0
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
예제 #18
0
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
예제 #19
0
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
예제 #20
0
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)
예제 #21
0
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)
예제 #22
0
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)
예제 #23
0
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)
예제 #24
0
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
예제 #25
0
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)
예제 #26
0
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)
예제 #27
0
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)
예제 #28
0
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)
예제 #29
0
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
예제 #30
0
 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")