示例#1
0
 def __str__(self):
     dict_to_str = {
         'attr1': self.attr1,
         'attr2': self.attr2,
         'attr3': self.attr3
     }
     return json_dumps(dict_to_str)
示例#2
0
    def add(self, account_id, token_type, contract_addr, to, amount,
            dids) -> str:
        """

        :param account_id:
        :param token_type:
        :param contract_addr:
        :param to:
        :param amount:
        :param dids:
        :return:
        """
        # get need data
        last_tx_id = self._last_pending_tx_id_db.get() + 1

        pending_tx_id_list_as_str = self._pending_tx_id_list_db.get()
        if pending_tx_id_list_as_str == "":
            pending_tx_id_list_as_str = json_dumps([])

        pending_tx_id_list = json_loads(pending_tx_id_list_as_str)

        # create pending tx
        pending_tx = {
            "id": last_tx_id,
            "tokenType": token_type,
            "contractAddr": contract_addr,
            "from": account_id,
            "to": to,
            "amount": amount,
            "dids": dids
        }

        # update db
        pending_tx_as_str = json_dumps(pending_tx)
        self._pending_tx_list[last_tx_id] = pending_tx_as_str
        self._last_pending_tx_id_db.set(last_tx_id)
        pending_tx_id_list.append(last_tx_id)
        self._pending_tx_id_list_db.set(json_dumps(pending_tx_id_list))
        return pending_tx_as_str
示例#3
0
 def to_str(self):
     dict_to_str = {
         'attr1': self.attr1,
         'attr2': self.attr2,
     }
     return json_dumps(dict_to_str)
示例#4
0
 def update(self, pending_tx: dict):
     self._pending_tx_list[pending_tx["id"]] = json_dumps(pending_tx)
示例#5
0
 def remove(self, tx_id: int):
     del self._pending_tx_list[tx_id]
     pending_tx_id_list = json_loads(
         self._pending_tx_id_list_db.get())  # type: List
     pending_tx_id_list.remove(tx_id)
     self._pending_tx_id_list_db.set(json_dumps(pending_tx_id_list))