Exemplo n.º 1
0
    def get_object(self):
        project = super().get_object()

        if project.addr_donate == None:
            address_new = instruct_wallet("getnewaddress",
                                          [str(project.title)])["result"]
            project.addr_donate = address_new
            project.save()
            print("This is title: {} and this is address: {} ".format(
                project.title, address_new))

        balance = instruct_wallet("getbalance", [str(project.title)])["result"]
        needed = project.amount_goal - balance
        progress = int(balance / project.amount_goal * 100)

        if balance >= project.amount_goal:
            #Set True on completed and save
            project.completed = True
            project.save()

            send_tx = instruct_wallet(
                "sendfrom", [str(project.title),
                             str(project.addr_shop), 1])  #Cambiar ammount
            print(send_tx)
            return project

        else:
            # Record the last accessed date
            progress_finish = str(progress) + "%"
            project.amount_needed = needed
            project.amount_donate = balance
            project.progress = progress_finish
            project.save()
            return project
Exemplo n.º 2
0
    def get_success_url(self):

        faucet, created = Faucet.objects.get_or_create(
            username=str(self.request.user))

        now = datetime.datetime.now()
        now = pytz.utc.localize(now)
        faucet_date_completed = faucet.updated + datetime.timedelta(1, 0)

        if now > faucet_date_completed:
            faucet.completed = False

        if faucet.completed == True:
            return reverse_lazy('faucet_completed')

        else:
            faucet.completed = True
            faucet.username = str(self.request.user)
            faucet.ip_user = str(self.request.META["REMOTE_ADDR"])
            faucet.save()

            user_faucet = faucet.username + "-faucet"
            print(user_faucet)
            tx = instruct_wallet("move",
                                 ["Faucet-CRW", user_faucet, 0.001])["result"]
            balance = instruct_wallet("getbalance", [user_faucet])["result"]
            if balance >= 1:
                tx_move = instruct_wallet(
                    "move", [user_faucet, faucet.username, 1])["result"]

            return reverse_lazy('profile') + '?created'
Exemplo n.º 3
0
    def get_success_url(self):

        faucet, created = Faucet.objects.get_or_create(
            username=str(self.request.user))

        faucet_date = datetime.datetime.now()
        faucet_date_completed = faucet.updated - datetime.timedelta(1, 0)
        print(faucet_date_completed)
        print(faucet_date)
        if faucet_date == faucet_date_completed:
            completed = False

        if faucet.completed == True:
            print("Ya lo hiciste hoy, vuelve mañana")
            return reverse_lazy('faucet_completed')

        else:
            faucet.completed = True
            faucet.username = str(self.request.user)
            faucet.ip_user = str(self.request.META["REMOTE_ADDR"])
            faucet.save()

            user_faucet = faucet.username + "-faucet"
            print(user_faucet)
            tx = instruct_wallet("move",
                                 ["Faucet-CRW", user_faucet, 0.001])["result"]
            balance = instruct_wallet("getbalance", [user_faucet])["result"]
            if balance >= 1:
                tx_move = instruct_wallet(
                    "move", [user_faucet, faucet.username, 1])["result"]

            return reverse_lazy('profile') + '?created'
Exemplo n.º 4
0
 def get_object(self):
     # recuperar el objeto que se va editar
     profile, created = Profile.objects.get_or_create(
         user=self.request.user)
     x = profile.user
     faucet_user = str(x) + "-faucet"
     balance_faucet = instruct_wallet('getbalance',
                                      [str(faucet_user)])["result"]
     balance = instruct_wallet('getbalance', [str(x)])["result"]
     profile.balance = balance
     profile.balance_faucet = balance_faucet
     profile.save()
     return profile
Exemplo n.º 5
0
def history_user(username):
    #Take all txs
    txs = instruct_wallet("listtransactions", [str(username)])["result"]
    txs_list = []

    for tx in txs:
        timestamping = tx["time"]
        date = datetime.fromtimestamp(timestamping)

        try:
            address = tx["address"]
            tx_id = tx["txid"]
        except:
            address = tx["otheraccount"]

        if address == "FeeWallet":
            pass

        else:

            tx_ready = dict(address=address,
                            amount=tx["amount"],
                            date=date,
                            category=tx["category"],
                            tx_id=tx_id)
            txs_list.append(tx_ready)

    return txs_list
Exemplo n.º 6
0
def ensure_profile_exists(sender, instance, **kwargs):
    if kwargs.get("created", False):
        Profile.objects.get_or_create(user=instance)
        address = instruct_wallet("getnewaddress", [str(instance)])["result"]
        profile_address = Profile.objects.get(user=instance)
        profile_address.addr_base = address
        profile_address.save()
        print("Se acaba de crear un perfil")