Exemple #1
0
    def test_utility_function(self):
        with self.assertRaises(ValueError) as context:
            encode_base62(-100)
        self.assertIn("cannot encode negative numbers", str(context.exception))

        self.assertEqual('0', encode_base62(0))

        self.assertEqual('w1R', encode_base62(123123))
Exemple #2
0
    def __init__(self, protocol):
        self.protocol = protocol
        #: payloads.NetworkAddress: Address of the remote endpoint.
        self.address = payloads.NetworkAddress(
            state=payloads.AddressState.DEAD)
        self.nodeid: int = id(self)  #: int: Unique identifier.
        self.nodeid_human: str = encode_base62(
            self.nodeid)  #: str: Human readable id.
        self.version = None
        self.tasks = []
        self.nodeweight = nodeweight.NodeWeight(self.nodeid)
        self.best_height: int = 0  #: int: Best block height of node.
        self.best_height_last_update = datetime.utcnow().timestamp()

        self._read_task = None  # type: asyncio.Task
        #: bool: Whether the node is in the process of disconnecting and shutting down its tasks.
        self.disconnecting: bool = False

        #: Dict[message.MessageType, Callable[[message.Message], None]]: A table matching message types to handler
        #: functions.
        self.dispatch_table: Dict[message.MessageType, Callable[
            [message.Message], None]] = {
                message.MessageType.ADDR: self.handler_addr,
                message.MessageType.BLOCK: self.handler_block,
                message.MessageType.CONSENSUS: self.handler_consensus,
                message.MessageType.INV: self.handler_inv,
                message.MessageType.FILTERADD: self.handler_filteradd,
                message.MessageType.FILTERCLEAR: self.handler_filterclear,
                message.MessageType.FILTERLOAD: self.handler_filterload,
                message.MessageType.GETADDR: self.handler_getaddr,
                message.MessageType.GETBLOCKS: self.handler_getblocks,
                message.MessageType.GETBLOCKDATA: self.handler_getblockdata,
                message.MessageType.GETDATA: self.handler_getdata,
                message.MessageType.GETHEADERS: self.handler_getheaders,
                message.MessageType.HEADERS: self.handler_headers,
                message.MessageType.MEMPOOL: self.handler_mempool,
                message.MessageType.MERKLEBLOCK: self.handler_merkleblock,
                message.MessageType.PING: self.handler_ping,
                message.MessageType.PONG: self.handler_pong,
                message.MessageType.TRANSACTION: self.handler_transaction
            }