Exemple #1
0
    def send_anon_nhash(self, msg: str):
        res = send_hash_list(str(self.chat_id))
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            hash_list = res_map.hash
            map_by_hash = list(map(lambda t: t.check_hash, hash_list))
            print(map_by_hash, "SEND NHASH")

            if len(map_by_hash) == 0:
                return EMPTY_HASH_LIST
            else:
                res = get_used_private(str(self.chat_id))
                if res.state == SUCCESS_MESSAGE:
                    res_map = Map(res.data)
                    used_hash_list = res_map.added_hash
                    mapped_hash_list = list(
                        map(lambda t: t.used_hash, used_hash_list))
                    print(mapped_hash_list, "ALL HASH")

                    used_list = []
                    for i in map_by_hash:
                        print(i, "values")
                        if i not in mapped_hash_list:
                            if i not in self.non_p_activated:
                                used_list.append(i)
                                self.non_p_activated = list(
                                    filter(lambda t: t not in self.p_activated,
                                           used_list))

                    return NON_ACTIVATED_PRIVATE_HASH_ID
                else:
                    return ERROR_ID
        else:
            return ERROR_ID
Exemple #2
0
    def send_person_nhash(self, msg: str):
        res = get_all_hash(str(self.chat_id))
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            hash_list = res_map.hash
            map_by_hash = list(map(lambda t: t.check_hash, hash_list))
            print(map_by_hash, "HASH LIST")

            if len(map_by_hash) == 0:
                return EMPTY_HASH_LIST
            else:
                res = get_person_hash(str(self.chat_id))
                if res.state == SUCCESS_MESSAGE:
                    res_map = Map(res.data)
                    used_hash_list = res_map.added_hash
                    mapped_hash_list = list(
                        map(lambda t: t.used_hash, used_hash_list))
                    print(mapped_hash_list, "MAP LIST")

                    use_list = []
                    for i in map_by_hash:
                        print(i, "person n i")
                        if i not in mapped_hash_list:
                            if i not in self.non_activated:
                                use_list.append(i)
                                self.non_activated = list(
                                    filter(lambda t: t not in self.activated,
                                           use_list))
                                print(self.non_activated)
                    return NON_ACTIVATED_HASH_ID
                else:
                    return ERROR_ID
        else:
            return ERROR_ID
Exemple #3
0
    def send_anon_ahash(self, msg: str):
        res = send_hash_list(str(self.chat_id))
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            hash_list = res_map.hash
            map_by_hash = list(map(lambda t: t.check_hash, hash_list))
            print(map_by_hash, "HASH LIST ANON")

            if len(map_by_hash) == 0:
                return EMPTY_HASH_LIST
            else:
                res = get_used_private(str(self.chat_id))
                if res.state == SUCCESS_MESSAGE:
                    res_map = Map(res.data)
                    used_hash_list = res_map.added_hash
                    mapped_hash_list = list(
                        map(lambda t: t.used_hash, used_hash_list))
                    print(mapped_hash_list, "ALL HASH")

                    anon_used_list = []
                    for i in map_by_hash:
                        print(i, "i anon active")
                        if i in mapped_hash_list:
                            anon_used_list.append(i)
                            self.p_activated = anon_used_list
                            print(self.p_activated)

                    return ACTIVATED_PRIVATE_HASH_ID
                else:
                    return ERROR_ID
        else:
            return ERROR_ID
Exemple #4
0
    def get_preson_hash(self, msg: str):
        self.hash = msg
        res = get_all_hash(str(self.chat_id))
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            hash_list = res_map.hash
            print(hash_list)
            filter_by_hash = filter(lambda t: t.check_hash == self.hash,
                                    hash_list)
            filtered_hash_list = list(filter_by_hash)

            if len(filtered_hash_list) == 0:
                print("an impressive c**k")
                return INVALID_HASH_ID

            for i in filtered_hash_list:
                print(i, "meeh")
                values = list(i.values())

                check_data = values[4]
                receiver_data = values[3]
                print(receiver_data)
                res = get_person_hash(str(self.chat_id))
                if res.state == SUCCESS_MESSAGE:
                    hash_map = Map(res.data)
                    hash_in_db = hash_map.added_hash
                    final = list(map(lambda t: t.used_hash, hash_in_db))
                    print(final)

                    if self.hash not in final:
                        if self.bcs_address == receiver_data:
                            res = get_user(str(self.chat_id))
                            if res.state == SUCCESS_MESSAGE:
                                user_map = Map(res.data)
                                balance = user_map.users.balance

                                new_user_balance = update_user(
                                    str(self.chat_id), {
                                        "balance": balance + check_data,
                                        "bcs_address": self.bcs_address
                                    })
                                if new_user_balance.state == SUCCESS_MESSAGE:
                                    self.balance = balance + check_data
                                    res = put_person_hash(
                                        str(self.chat_id),
                                        {"used_hashes": self.hash})
                                    if res.state == SUCCESS_MESSAGE:
                                        return CORRECT_HASH_ID
                                else:
                                    return ERROR_ID
                            else:
                                return ERROR_ID
                        else:
                            return INVALID_USER_ID
                    else:
                        return INVALID_FLAG_ID
                else:
                    return ERROR_ID
        else:
            return ERROR_ID
Exemple #5
0
    def send_person_ahash(self, msg: str):
        # map, list, for loop  and other stuff
        res = get_all_hash(str(self.chat_id))
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            hash_list = res_map.hash
            map_by_hash = list(map(lambda t: t.check_hash, hash_list))
            print(map_by_hash, "HASH LIST")

            if len(map_by_hash) == 0:
                return EMPTY_HASH_LIST
            else:
                res = get_person_hash(str(self.chat_id))
                if res.state == SUCCESS_MESSAGE:
                    res_map = Map(res.data)
                    used_hash_list = res_map.added_hash
                    mapped_hash_list = list(
                        map(lambda t: t.used_hash, used_hash_list))
                    print(mapped_hash_list, "MAPPED LIST")

                    person_active_list = []
                    for i in map_by_hash:
                        print(i, "i values")
                        if i in mapped_hash_list:
                            person_active_list.append(i)
                    self.activated = person_active_list
                    print(self.activated)

                    return ACTIVATED_HASH_ID
                else:
                    return ERROR_ID
        else:
            return ERROR_ID
Exemple #6
0
    def send_to_contract(self, msg: str):
        self.payment = int(msg)
        res = get_user(str(self.chat_id))
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            balance = res_map.users.balance
            if self.payment > balance:
                return FORM_INVALID_BALANCE_ID
            else:
                new_user_balance = update_user(
                    str(self.chat_id), {
                        "balance": balance - self.payment,
                        "bcs_address": self.bcs_address
                    })
                if new_user_balance.state == SUCCESS_MESSAGE:
                    self.balance = balance - self.payment
                    if self.payment >= 1000:
                        send_message = send_email(
                            "*****@*****.**",
                            f"{self.chat_id} transaction request",
                            f"{self.payment} tokens from user {self.bcs_address}"
                        )
                        print(send_message)
                        return CONTRACT_RESPONSE_ID
                    else:
                        return ERROR_ID

                        # send_tokens = send_to_contract_request(self.bcs_address, self.payment,
                        #                                        self.address_contract)
                        # print(send_tokens)
                        # return CONTRACT_RESPONSE_ID
                else:
                    return ERROR_ID
        else:
            return ERROR_ID
Exemple #7
0
 def enter_anon_balance(self, msg: str):
     self.payment = int(msg)
     res = get_user(str(self.chat_id))
     if res.state == SUCCESS_MESSAGE:
         res_map = Map(res.data)
         balance = res_map.users.balance
         if self.payment > balance:
             return FORM_INVALID_BALANCE_ID
         else:
             new_user_balance = update_user(
                 str(self.chat_id), {
                     "balance": balance - self.payment,
                     "bcs_address": self.bcs_address
                 })
             if new_user_balance.state == SUCCESS_MESSAGE:
                 self.balance = balance - self.payment
                 send_hash = self.anon_hash()
                 print(send_hash)
                 if send_hash is not None:
                     self.sender_hash = send_hash
                 return FORM_CHECK_BALANCE_ID
             else:
                 return ERROR_ID
     else:
         return ERROR_ID
Exemple #8
0
    def handle_menu(self, msg: str):
        if msg == CB_DATA_BALANCE:
            res = get_user(str(self.chat_id))
            if res.state == SUCCESS_MESSAGE:
                res_map = Map(res.data)
                self.balance = res_map.users.balance
                return BALANCE_ID
            else:
                return ERROR_ID

        return SEND_NODE_ID if msg == CB_DATA_REPLENISH else \
            FORM_CHECK_SENDER_ID if msg == CB_DATA_CHECK else GET_CASH_ID if msg == CB_DATA_CASH \
                else SEND_TO_CONTRACT_ID if msg == CB_DATA_PAYLOAD \
                else STATISTICS_ID if msg == CB_DATA_STAT else None
Exemple #9
0
    def check_for_user(self, msg: str):
        if not re.match(r"B.{33}", msg):
            return INVALID_ID
        self.bcs_address = msg

        res = check_address_exists(msg)
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            if res_map.ok:
                return CORRECT_USER_ID
            else:
                return INVALID_USER_ID
        else:
            return ERROR_ID
Exemple #10
0
 def get_address_contract(self, msg: str):
     self.address_contract = msg
     res = get_address_contract()
     if res.state == SUCCESS_MESSAGE:
         res_map = Map(res.data)
         addreses = res_map.address
         relate = list(
             filter(lambda t: t.address_contract == self.address_contract,
                    addreses))
         if len(relate) == 0:
             return WRONG_CONTRACT_ID
         else:
             return ADDRESS_NODE_ID
     else:
         return ERROR_ID
Exemple #11
0
 def anon_hash(self):
     print('Creating hash..')
     new_user_hash = add_anon_hash(
         str(self.chat_id), {
             "flag": False,
             "check_hash": form_hash_key("itsbondagegaywebsite"),
             "sender": self.bcs_address,
             "value": self.payment
         })
     if new_user_hash.state == SUCCESS_MESSAGE:
         res = get_anon_hash(str(self.chat_id))
         if res.state == SUCCESS_MESSAGE:
             res_map = Map(res.data)
             print(res_map)
             user_hash = res_map.hash.check_hash
             return user_hash
         else:
             return None
     else:
         return ERROR_ID
Exemple #12
0
    def enter_balance(self, msg: str):
        self.payment = int(msg)
        res = get_user(str(self.chat_id))

        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            balance = res_map.users.balance
            if self.payment > balance:
                return ERROR_ID
            else:
                new_user_balance = update_user(
                    str(self.chat_id), {
                        "balance": balance - self.payment,
                        "bcs_address": self.bcs_address
                    })
                if new_user_balance.state == SUCCESS_MESSAGE:
                    self.balance = balance - self.payment
                    return BALANCE_ID
                else:
                    return ERROR_ID
        else:
            return ERROR_ID
Exemple #13
0
    def check_transaction(self, msg: str):
        global balance_sum
        if msg == CB_DATA_BACK:
            return BLOCKCHAIN_NODE_ID
        res = get_transactions(self.bcs_address, self.address_contract)
        if res.state == SUCCESS_MESSAGE:
            res_map = Map(res.data)
            transactions = res_map.transactions

            users_transactions = filter(lambda t: t.sender == self.bcs_address,
                                        transactions)
            users_transactions_list = list(users_transactions)
            if len(users_transactions_list) == 0:
                return FORM_WRONG_ID

            user_transaction_ids = map(lambda t: t.transactionId,
                                       users_transactions_list)
            user_transaction_ids_list = list(user_transaction_ids)
            print(user_transaction_ids_list)

            for i in user_transaction_ids_list:
                if i is not None:
                    print("add transactions")
                    new_transactions = add_user_transaction(
                        str(self.chat_id), {
                            "transaction_id": i,
                            "sender": "Bot",
                            "receiver": self.bcs_address,
                        })
                    print(new_transactions.data)

                    if new_transactions.state == SUCCESS_MESSAGE:
                        print("new transaction ----------------------------")
                    else:
                        return FORM_WRONG_ID
                else:
                    tx_id = get_user_transaction(str(self.chat_id))
                    if tx_id.state == SUCCESS_MESSAGE:
                        tx_id_map = Map(tx_id.data)

                        used_tx = tx_id_map.transaction_id
                        if used_tx == i:
                            return FORM_WRONG_ID
                    else:
                        return ERROR_ID

            user_transaction_balance = map(lambda t: t.evmLogs[-1],
                                           users_transactions_list)
            user_transaction_balance_list = list(user_transaction_balance)

            sum_list = []
            for i in user_transaction_balance_list:
                values = list(i.values())
                print(values)
                user_data = values[3]
                print(user_data, "raw user data")
                if len(user_data) != 0:
                    converted_data = int(user_data, 16)
                    print(converted_data, "uncut data")
                    str_data = str(converted_data)
                    print(len(str_data))
                    decimal_data = str_data[0:-6]
                    int_dec_data = int(decimal_data)
                    print(int_dec_data, "cut data")

                    if int_dec_data is not None:
                        sum_list.append(int_dec_data)
                        print(sum_list)
                        balance_sum = sum(sum_list)
                        print(balance_sum)

            if not is_unique(user_transaction_ids_list):
                return FORM_WRONG_ID

            found_transaction = next(
                (t
                 for t in users_transactions_list if transaction_condition(t)),
                None)

            is_valid = found_transaction is not None

            if is_valid:
                print(self.bcs_address, "ADDRESS")
                res = get_user(str(self.chat_id))
                if res.state == SUCCESS_MESSAGE:
                    res_map = Map(res.data)
                    self.balance = res_map.users.balance
                else:
                    return ERROR_ID

                res = update_user(
                    str(self.chat_id), {
                        "balance": balance_sum + self.balance,
                        "bcs_address": self.bcs_address
                    })
                if res.state == SUCCESS_MESSAGE:
                    return FORM_CHECK_ID
                else:
                    return ERROR_ID
            else:
                return FORM_WRONG_ID
        else:
            return ERROR_ID
    "kurwa": [0, 1, 2, 3, 4, 5],
    "oh_kurwa": {
        "kek": "suka",
        "c_kaifom": {
            "ahahahah": True,
            "meh": {
                "loop": {},
                "poop": {
                    "heh": [3, 5]
                }
            }
        }
    }
}

data_map = Map(data)


class MyTestCase(unittest.TestCase):
    def test_shallow(self):
        self.assertEqual(data_map.kurwa[2], 2)
        self.assertEqual(data_map.oh_kurwa, data["oh_kurwa"])

    def test_deep(self):
        self.assertEqual(data_map.oh_kurwa.kek, "suka")
        self.assertEqual(data_map.oh_kurwa.c_kaifom.ahahahah, True)
        self.assertEqual(data_map.oh_kurwa.c_kaifom.meh.poop.heh[0], 3)

    def test_invalid_key(self):
        self.assertEqual(data_map.invalid, None)