Esempio n. 1
0
File: ws.py Progetto: kvrban/siliqua
    async def listen_for_msg(self):
        broadcast_keepalive = (self.keepalive_timestamp +
                               self.KEEPALIVE_INTERVAL_SECONDS < time.time())
        if broadcast_keepalive:
            await self.ws_conn.send_json({"event": "keepalive"})
            self.keepalive_timestamp = time.time()

        try:
            response = await self.ws_conn.receive_json(timeout=0.1)
        except asyncio.TimeoutError:
            return

        msg = response["data"]
        block_data = msg["block"]
        account_id = normalize_account_id(block_data["account"])
        amount = int(msg["amount"])

        if amount != 0:
            raw_block = get_raw_block_from_json(block_data)
            if raw_block.tx_type in ("send", "receive", "send/receive"):
                link_block = LinkBlock(block=raw_block, amount=amount)
                if link_block.recipient in self.subscribed_account_ids:
                    await self.process_pocketable_block_message(
                        block_data=block_data, amount=amount)

        if account_id in self.subscribed_account_ids:
            subtype = block_data["type"]
            if block_data["type"] == "state":
                if "is_send" in msg:
                    subtype = \
                        "send" if msg["is_send"] == "true" else "receive"

            await self.process_account_block_message(block_data=block_data,
                                                     account_id=account_id,
                                                     subtype=subtype)
Esempio n. 2
0
File: ws.py Progetto: kvrban/siliqua
    async def process_block_message(self, response):
        """
        Process a block and insert it into the account and/or pocketable
        queue
        """
        msg = response["message"]
        account_id = normalize_account_id(msg["account"])

        block_data = msg["block"]
        subtype = msg["block"]["subtype"]

        if account_id in self.account_sync_statuses:
            await self.process_account_block_message(
                block_data=block_data,
                account_id=account_id,
                subtype=subtype
            )

        amount = int(msg.get("amount", 0))

        if amount != 0:
            raw_block = get_raw_block_from_json(block_data)
            if raw_block.tx_type not in ("send", "receive", "send/receive"):
                return

            link_block = LinkBlock(
                block=raw_block,
                amount=amount
            )
            if link_block.recipient in self.account_sync_statuses:
                await self.process_pocketable_block_message(
                    block_data=block_data,
                    amount=int(msg["amount"])
                )
Esempio n. 3
0
 def set_account_id(self, account_id):
     self._account_id = normalize_account_id(
         validate_account_id(account_id))
Esempio n. 4
0
 def set_representative(self, representative):
     if representative:
         self._representative = normalize_account_id(
             validate_account_id(representative))
     else:
         self._representative = None