def rejections(request): if request.POST: try: node = Peer.objects.get(domain=request.POST['domain']) except Peer.DoesNotExist: return HttpResponseBadRequest("Unregistered peer") try: ValidatedRejection.validate_rejection_from_peer( peer, request.POST['txid'], request.POST['signature'] ) except Exception as exc: return HttpResponseBadRequest("Invalid Rejection: %s" % exc.display()) else: # rendering the rejections page if 'epoch' in request.GET: epoch = int(request.GET['epoch']) else: epoch = get_epoch_number() epoch_start, epoch_end = get_epoch_range(epoch) rejected = ValidatedTransaction.objects.filter( validatedrejection__isnull=False, timestamp__gt=epoch_start, timestamp__lt=epoch_end ).distinct() if 'json' in request.GET: return JsonResponse({'rejections': [ (tx.txid, tx.rejected_reputation_percent()) for tx in rejected ]}) return render(request, "rejections.html", locals())
def filter_for_epoch(epoch=None, prefix=''): if not epoch: epoch = get_epoch_number() epoch_start, epoch_end = get_epoch_range(epoch) return { '%stimestamp__lte' % prefix: epoch_end, '%stimestamp__gte' % prefix: epoch_start, }
def ledger(address, timestamp): try: entry = LedgerEntry.objects.get(address=address) except LegderEntry.DoesNotExist: raise Exception("%s does not exist" % address) last_updated = entry.last_updated current_balance = entry.amount adjusted = ValidatedMovement.adjusted_balance(address, get_epoch_number(timestamp)) #spend_this_epoch = ValidatedTransaction.last_spend(address) return (current_balance + adjusted) #, spend_this_epoch or last_updated
def handle(self, *args, **options): if options['rank']: rank = options['rank'] node = Peer.get_by_rank(rank) else: node = Peer.my_node() # close last epoch that just ended epoch = get_epoch_number() - 1 es = EpochSummary.close_epoch(epoch) for domain, mini_hashes in es.consensus_pushes().items(): push = EpochHashPush.make(epoch, node.domain, domain, node.private_key, mini_hashes) propagate_to_peers([domain], push, "epoch hash")
def prop_domains(cls, epoch=None): """ Returns the list of domains that you propagate you based on the shuffled node matrix and your node's current ranking. """ if not epoch: epoch = get_epoch_number() - 1 cache = caches['default'] key = "prop-domains" domains = cache.get(key) if not domains: try: es = EpochSummary.objects.get(epoch=epoch) except EpochSummary.DoesNotExist: es = EpochSummary.objects.latest() domains = [ x.domain for x in es.consensus_nodes()['minihash1_push_to'] ] cache.set(key, domains) return domains
def ledger(request): if "sync_start" in request.GET: start = dateutil.parser.parse(request.GET['sync_start']) ledgers = LedgerEntry.objects.filter(last_updated__gt=start).order_by('-last_updated') return JsonResponse({ 'data': [ [x.address, "%.8f" % x.amount, x.last_updated.isoformat()] for x in ledgers[:500] ] }) elif 'address' in request.GET: address = request.GET['address'] try: balance = LedgerEntry.objects.get(address=address).amount except LedgerEntry.DoesNotExist: balance = 0 adjusted_balance = ( balance + ValidatedMovement.adjusted_balance( address, epoch=get_epoch_number() ) ) return HttpResponse(str(adjusted_balance))
def network_summary(request): peers = Peer.objects.order_by('-reputation') total_issued = LedgerEntry.total_issued() epoch = get_epoch_number() return render(request, "staeon_summary.html", locals())
def epoch(self): return get_epoch_number(self.timestamp)