Example #1
0
def faircoin_history(request, resource_id):
    resource = get_object_or_404(EconomicResource, id=resource_id)
    agent = get_agent(request)
    wallet = faircoin_utils.is_connected()
    confirmed_balance = None
    unconfirmed_balance = None
    if wallet:
        if resource.is_wallet_address():
            exchange_service = ExchangeService.get()
            exchange_service.include_blockchain_tx_as_event(
                resource.owner(), resource)
            try:
                balances = faircoin_utils.get_address_balance(
                    resource.faircoin_address.address)
                confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR
                unconfirmed_balance = Decimal(balances[0] +
                                              balances[1]) / FAIRCOIN_DIVISOR
                unconfirmed_balance += resource.balance_in_tx_state_new()
            except:
                confirmed_balance = "Not accessible now"
                unconfirmed_balance = "Not accessible now"
        else:
            wallet = False
    event_list = resource.events.all()
    init = {
        "quantity": resource.quantity,
    }
    unit = resource.resource_type.unit

    paginator = Paginator(event_list, 25)

    page = request.GET.get('page')
    try:
        events = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        events = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        events = paginator.page(paginator.num_pages)
    if resource.owner() == agent or resource.owner() in agent.managed_projects(
    ) or agent.is_staff():
        return render(
            request, "faircoin/faircoin_history.html", {
                "resource": resource,
                "agent": agent,
                "confirmed_balance": confirmed_balance,
                "unconfirmed_balance": unconfirmed_balance,
                "unit": unit,
                "events": events,
                "wallet": wallet,
            })
    else:
        return render(request, 'work/no_permission.html')
Example #2
0
def faircoin_history(request, resource_id):
    resource = get_object_or_404(EconomicResource, id=resource_id)
    agent = get_agent(request)
    wallet = faircoin_utils.is_connected()
    confirmed_balance = None
    unconfirmed_balance = None
    if wallet:
        if resource.is_wallet_address():
            exchange_service = ExchangeService.get()
            exchange_service.include_blockchain_tx_as_event(resource.owner(), resource)
            try:
                balances = faircoin_utils.get_address_balance(resource.faircoin_address.address)
                confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR
                unconfirmed_balance =  Decimal(balances[0] + balances[1]) / FAIRCOIN_DIVISOR
                unconfirmed_balance += resource.balance_in_tx_state_new()
            except:
                confirmed_balance = "Not accessible now"
                unconfirmed_balance = "Not accessible now"
        else:
            wallet = False
    event_list = resource.events.all()
    init = {"quantity": resource.quantity,}
    unit = resource.resource_type.unit

    paginator = Paginator(event_list, 25)

    page = request.GET.get('page')
    try:
        events = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        events = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        events = paginator.page(paginator.num_pages)
    if resource.owner() == agent or resource.owner() in agent.managed_projects() or agent.is_staff():
        return render(request, "faircoin/faircoin_history.html", {
            "resource": resource,
            "agent": agent,
            "confirmed_balance": confirmed_balance,
            "unconfirmed_balance": unconfirmed_balance,
            "unit": unit,
            "events": events,
            "wallet": wallet,
        })
    else:
        return render(request, 'work/no_permission.html')
Example #3
0
 def balance(self):
     wallet = faircoin_utils.is_connected()
     if wallet:
         is_wallet_address = faircoin_utils.is_mine(self.address)
         if is_wallet_address:
             try:
                 balances = faircoin_utils.get_address_balance(self.address)
                 unconfirmed_balance =  Decimal(balances[1]) / FAIRCOIN_DIVISOR
                 unconfirmed_balance += self.resource.balance_in_tx_state_new()
                 confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR
                 if unconfirmed_balance < 0:
                     confirmed_balance += unconfirmed_balance
                 elif unconfirmed_balance == 0:
                     unconfirmed_balance = confirmed_balance
                 return confirmed_balance
             except:
                 pass
     return None
Example #4
0
def manage_faircoin_account(request, resource_id):
    resource = get_object_or_404(EconomicResource, id=resource_id)
    user_agent = get_agent(request)
    if not user_agent or not (resource.owner() == user_agent
                              or resource.owner()
                              in user_agent.managed_projects()):
        raise Http404

    send_coins_form = None
    is_wallet_address = None
    limit = 0
    confirmed_balance = None
    unconfirmed_balance = None
    faircoin_account = False
    payment_due = False
    share_price = False
    number_of_shares = False
    can_pay = False
    candidate_membership = None
    wallet = faircoin_utils.is_connected()
    if wallet:
        is_wallet_address = faircoin_utils.is_mine(
            resource.faircoin_address.address)
        if is_wallet_address:
            send_coins_form = SendFairCoinsForm(agent=resource.owner())
            try:
                balances = faircoin_utils.get_address_balance(
                    resource.faircoin_address.address)
                unconfirmed_balance = Decimal(balances[1]) / FAIRCOIN_DIVISOR
                unconfirmed_balance += resource.balance_in_tx_state_new()
                confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR
                if unconfirmed_balance < 0:
                    confirmed_balance += unconfirmed_balance
                elif unconfirmed_balance == 0:
                    unconfirmed_balance = confirmed_balance
            except:
                confirmed_balance = "Not accessible now"
                unconfirmed_balance = "Not accessible now"
        else:
            #wallet = False
            if resource.is_address_requested(): is_wallet_address = True

    netfee = faircoin_utils.network_fee_fairs()
    project = jn_req = None
    pending_amount = 0
    for req in resource.owner().project_join_requests.all():
        #candidate_membership = resource.owner().candidate_membership(req.project.agent)
        if req.pending_shares() and req.project.agent.need_faircoins(
        ):  #candidate_membership:
            obj = req.payment_option()
            faircoin_account = resource.owner().faircoin_resource()
            shacct = req.project.shares_account_type()
            if faircoin_account and wallet and obj and obj[
                    'key'] == 'faircoin' and shacct:
                share = req.project.shares_type(
                )  #EconomicResourceType.objects.membership_share()
                #share_price = faircoin_utils.share_price_in_fairs(req)
                number_of_shares = req.pending_shares(
                )  #resource.owner().number_of_shares()
                share_price = Decimal(req.payment_pending_amount()
                                      )  #share_price * number_of_shares
                pending_amount = share_price
                project = req.project
                jn_req = req
                payment_due = True
                if resource.owner().owns_resource_of_type(
                        shacct) and share_price == 0:
                    payment_due = False
                if confirmed_balance and confirmed_balance != "Not accessible now":
                    can_pay = round(confirmed_balance, 8) >= round(
                        share_price, 8)
                    if not can_pay:
                        pending_amount = round(share_price - confirmed_balance,
                                               8)
                break
            elif request.user.is_superuser and req.project.agent.need_faircoins(
            ):
                logger.warning("(debug) pro:" + str(req.project.agent) +
                               " fair_account:" + str(faircoin_account) +
                               " wallet:" + str(wallet) + " obj:" + str(obj) +
                               " shares_account_type:" + str(shacct))
                messages.warning(
                    request, "(debug) pro:" + str(req.project.agent) +
                    " fair_account:" + str(faircoin_account) + " wallet:" +
                    str(wallet) + " obj:" + str(obj) +
                    " shares_account_type:" + str(shacct))

    return render(
        request, "faircoin/faircoin_account.html", {
            "resource": resource,
            "photo_size": (128, 128),
            "agent": resource.owner(),
            "wallet": wallet,
            "send_coins_form": send_coins_form,
            "is_wallet_address": is_wallet_address,
            "confirmed_balance": confirmed_balance,
            "unconfirmed_balance": unconfirmed_balance,
            "faircoin_account": faircoin_account,
            "candidate_membership": candidate_membership,
            "payment_due": payment_due,
            "share_price": round(share_price, 8),
            "pending_amount": round(pending_amount, 8),
            "number_of_shares": number_of_shares,
            "can_pay": can_pay,
            "project": project,
            "jn_req": jn_req,
            "help": get_help("faircoin account"),
        })
Example #5
0
def faircoin_history(request, resource_id):
    resource = get_object_or_404(EconomicResource, id=resource_id)
    agent = get_agent(request)
    owner = resource.owner()
    wallet = faircoin_utils.is_connected()
    confirmed_balance = None
    unconfirmed_balance = None
    if wallet:
        if resource.is_wallet_address():
            exchange_service = ExchangeService.get()
            exchange_service.include_blockchain_tx_as_event(owner, resource)
            try:
                balances = faircoin_utils.get_address_balance(
                    resource.faircoin_address.address)
                confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR
                unconfirmed_balance = Decimal(balances[0] +
                                              balances[1]) / FAIRCOIN_DIVISOR
                unconfirmed_balance += resource.balance_in_tx_state_new()
            except:
                confirmed_balance = "Not accessible now"
                unconfirmed_balance = "Not accessible now"
        else:
            wallet = False
    event_list = EconomicEvent.objects.filter(
        Q(resource=resource)
        | Q(faircoin_transaction__to_address=resource.faircoin_address.address)
    ).annotate(numev=Count("transfer__events")).exclude(
        numev__gt=1, event_type__name="Receive")
    #event_list = resource.events.all()
    for ev in event_list:
        if ev.exchange:
            if ev.to_agent == owner.parent() and not ev.from_agent == owner:
                print "-- change exchange agent to parent? ev:" + str(
                    ev.id) + " ca:" + str(
                        ev.exchange.context_agent) + " from:" + str(
                            ev.from_agent) + " ex:" + str(
                                ev.exchange.id) + " et:" + str(
                                    ev.exchange.exchange_type)
                logger.debug("-- change exchange agent to parent? ev:" +
                             str(ev.id) + " ca:" +
                             str(ev.exchange.context_agent) + " from:" +
                             str(ev.from_agent) + " ex:" +
                             str(ev.exchange.id) + " et:" +
                             str(ev.exchange.exchange_type))
            if ev.from_agent == owner.parent() and not ev.to_agent == owner:
                print "-- change exchange agent from parent? ev:" + str(
                    ev.id) + " ca:" + str(
                        ev.exchange.context_agent) + " to:" + str(
                            ev.to_agent) + " ex:" + str(
                                ev.exchange.id) + " et:" + str(
                                    ev.exchange.exchange_type)
                logger.debug("-- change exchange agent from parent? ev:" +
                             str(ev.id) + " ca:" +
                             str(ev.exchange.context_agent) + " to:" +
                             str(ev.to_agent) + " ex:" + str(ev.exchange.id) +
                             " et:" + str(ev.exchange.exchange_type))

        ev.list_name = ev.show_name(resource.owner()).split(' ')[0]
    init = {
        "quantity": resource.quantity,
    }
    unit = resource.resource_type.unit

    paginator = Paginator(event_list, 25)

    page = request.GET.get('page')
    try:
        events = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        events = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        events = paginator.page(paginator.num_pages)
    if resource.owner() == agent or resource.owner() in agent.managed_projects(
    ) or agent.is_staff():
        return render(
            request, "faircoin/faircoin_history.html", {
                "resource": resource,
                "agent": agent,
                "confirmed_balance": confirmed_balance,
                "unconfirmed_balance": unconfirmed_balance,
                "unit": unit,
                "events": events,
                "wallet": wallet,
            })
    else:
        return render(request, 'work/no_permission.html')
Example #6
0
def manage_faircoin_account(request, resource_id):
    resource = get_object_or_404(EconomicResource, id=resource_id)
    user_agent = get_agent(request)
    if not user_agent or not (resource.owner() == user_agent
                              or resource.owner()
                              in user_agent.managed_projects()):
        raise Http404

    send_coins_form = None
    is_wallet_address = None
    limit = 0
    confirmed_balance = None
    unconfirmed_balance = None
    faircoin_account = False
    payment_due = False
    share_price = False
    number_of_shares = False
    can_pay = False

    wallet = faircoin_utils.is_connected()
    if wallet:
        is_wallet_address = faircoin_utils.is_mine(
            resource.faircoin_address.address)
        if not is_wallet_address:
            if resource.is_address_requested(): is_wallet_address = True
        if is_wallet_address:
            send_coins_form = SendFairCoinsForm(agent=resource.owner())
            try:
                balances = faircoin_utils.get_address_balance(
                    resource.faircoin_address.address)
                confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR
                unconfirmed_balance = Decimal(balances[0] +
                                              balances[1]) / FAIRCOIN_DIVISOR
                unconfirmed_balance += resource.balance_in_tx_state_new()
                fee = Decimal(faircoin_utils.network_fee()) / FAIRCOIN_DIVISOR
                limit = min(confirmed_balance, unconfirmed_balance) - fee
            except:
                confirmed_balance = "Not accessible now"
                unconfirmed_balance = "Not accessible now"
                limit = Decimal("0.0")
        else:
            wallet = False

    candidate_membership = resource.owner().candidate_membership()
    if candidate_membership:
        faircoin_account = resource.owner().faircoin_resource()
        if faircoin_account and wallet:
            share = EconomicResourceType.objects.membership_share()
            share_price = share.price_per_unit
            number_of_shares = resource.owner().number_of_shares()
            share_price = share_price * number_of_shares
            payment_due = True
            if resource.owner().owns_resource_of_type(share):
                payment_due = False
            if confirmed_balance and confirmed_balance != "Not accessible now":
                can_pay = confirmed_balance >= share_price

    return render(
        request, "faircoin/faircoin_account.html", {
            "resource": resource,
            "photo_size": (128, 128),
            "agent": resource.owner(),
            "wallet": wallet,
            "send_coins_form": send_coins_form,
            "is_wallet_address": is_wallet_address,
            "confirmed_balance": confirmed_balance,
            "unconfirmed_balance": unconfirmed_balance,
            "limit": limit,
            "faircoin_account": faircoin_account,
            "candidate_membership": candidate_membership,
            "payment_due": payment_due,
            "share_price": share_price,
            "number_of_shares": number_of_shares,
            "can_pay": can_pay,
            "help": get_help("faircoin account"),
        })
Example #7
0
def manage_faircoin_account(request, resource_id):
    resource = get_object_or_404(EconomicResource, id=resource_id)
    user_agent = get_agent(request)
    if not user_agent or not (resource.owner() == user_agent or resource.owner() in user_agent.managed_projects()):
        raise Http404

    send_coins_form = None
    is_wallet_address = None
    limit = 0
    confirmed_balance = None
    unconfirmed_balance = None
    faircoin_account = False
    payment_due = False
    share_price = False
    number_of_shares = False
    can_pay = False
    wallet = faircoin_utils.is_connected()
    if wallet:
        is_wallet_address = faircoin_utils.is_mine(resource.faircoin_address.address)
        if is_wallet_address:
            send_coins_form = SendFairCoinsForm(agent=resource.owner())
            try:
                balances = faircoin_utils.get_address_balance(resource.faircoin_address.address)
                unconfirmed_balance =  Decimal(balances[1]) / FAIRCOIN_DIVISOR
                unconfirmed_balance += resource.balance_in_tx_state_new()
                confirmed_balance = Decimal(balances[0]) / FAIRCOIN_DIVISOR
                if unconfirmed_balance < 0:
                    confirmed_balance += unconfirmed_balance
                elif unconfirmed_balance == 0:
                    unconfirmed_balance = confirmed_balance
            except:
                confirmed_balance = "Not accessible now"
                unconfirmed_balance = "Not accessible now"
        else:
            wallet = False
            if resource.is_address_requested(): is_wallet_address = True

    candidate_membership = resource.owner().candidate_membership()
    if candidate_membership:
        faircoin_account = resource.owner().faircoin_resource()
        if faircoin_account and wallet:
            share = EconomicResourceType.objects.membership_share()
            share_price = share.price_per_unit
            number_of_shares = resource.owner().number_of_shares()
            share_price = share_price * number_of_shares
            payment_due = True
            if resource.owner().owns_resource_of_type(share):
                payment_due = False
            if confirmed_balance and confirmed_balance != "Not accessible now":
                can_pay = confirmed_balance >= share_price

    return render(request, "faircoin/faircoin_account.html", {
        "resource": resource,
        "photo_size": (128, 128),
        "agent": resource.owner(),
        "wallet": wallet,
        "send_coins_form": send_coins_form,
        "is_wallet_address": is_wallet_address,
        "confirmed_balance": confirmed_balance,
        "unconfirmed_balance": unconfirmed_balance,
        "faircoin_account": faircoin_account,
        "candidate_membership": candidate_membership,
        "payment_due": payment_due,
        "share_price": share_price,
        "number_of_shares": number_of_shares,
        "can_pay": can_pay,
        "help": get_help("faircoin account"),
    })