Esempio n. 1
0
    def save(self, *args, **kwargs):
        if not self.pk:
            first48 = "{}{}".format(uuid.uuid4(),
                                    uuid.uuid4()).replace("-", "")[:48]
            md5 = hashlib.md5()
            md5.update("{}{}".format(settings.SECRET_KEY, first48))
            reverse_track = reverse('betting_track',
                                    kwargs={
                                        'secret': md5.hexdigest(),
                                        'first48': first48
                                    })
            try:
                recv = receive.receive(
                    settings.BITCOIN_JACKPOT_ADDRESS,
                    '{}{}'.format(settings.BASE_DOMAIN, reverse_track))
            except Exception, e:
                LogUtils().error('bcjp.file', 'models',
                                 'BitcoinAddressSession', e)
                raise e

            LogUtils().info('bcjp.file', 'models', 'BitcoinAddressSession',
                            "{}".format(recv.callback_url))
            self.address = recv.input_address
            self.alias = random.choice(settings.ALIAS_WORDS).title()

            super(BitcoinAddressSession, self).save(*args, **kwargs)

            self.session = "{}-{}".format(self.pk, first48)
Esempio n. 2
0
def betting_track(request, secret=None, first48=None):
    """The callback url that is utilized for Blockchain.info API

    """
    confirmations = request.GET.get("confirmations", -1)

    try:
        confirmations = int(confirmations)
    except Exception, e:
        LogUtils().error('bcjp.warning_file', 'views', 'betting_track', e)
        LogUtils().info('bcjp.file', 'views', 'betting_track', "*not an integer*")
        return HttpResponse("*not an integer*")
Esempio n. 3
0
def betting_withdraw(request):
    if request.method == "POST":
        jsonRtn = {"success": True}

        try:
            bitcoin_address_session = BitcoinAddressSession.objects.get(pk=request.session["bas"])
            withdraw_address = request.POST.get('ig-address-text', None)
            withdraw_amount = request.POST.get('ig-amount-text', None)
            withdraw_lock = None

            if not withdraw_address or not withdraw_amount:
                raise ValueError("Please enter address and amount")
            if bitcoin_address_session.amount == 0:
                raise ValueError("Could not withdraw. Your current balance is 0 BTC.")

            withdraw_amount = float(withdraw_amount) * settings.SATOSHI_RATIO

            if withdraw_amount > bitcoin_address_session.amount:
                raise ValueError("You cannot withdraw more than your current balance.")

            if withdraw_amount < (0.0001 * settings.SATOSHI_RATIO):
                raise ValueError("Minimum withdrawal amount is 0.0001 BTC.")

            withdraw_lock = "{}{}".format(settings.REDIS_WITHDRAW_LOCK_PREFIX, bitcoin_address_session.id)

            while settings.REDIS_CLIENT.get(withdraw_lock):
                settings.REDIS_CLIENT.incrby(settings.REDIS_WITHDRAW_LOCK_COUNT, 1)

            settings.REDIS_CLIENT.set(withdraw_lock, 1)

            wallet = Wallet(settings.BITCOIN_PRIVATE_ADDRESS, None)
            wallet_withdraw = wallet.send(withdraw_address, withdraw_amount)

            withdraw_request = BitcoinWithdrawRequest()
            withdraw_request.bitcoin_address_session = bitcoin_address_session
            withdraw_request.amount = withdraw_amount
            withdraw_request.to_address = withdraw_address
            withdraw_request.transaction_hash = wallet_withdraw.tx_hash
            withdraw_request.save()

            bitcoin_address_session.amount -= withdraw_amount
            bitcoin_address_session.save()

            jsonRtn["message"] = wallet_withdraw.message
        except APIException, apie:
            LogUtils().info('bcjp.file', 'views', 'betting_withdraw', "APIException")
            jsonRtn["success"] = False
            jsonRtn["message"] = str(apie)
        except ValueError, ve:
            LogUtils().info('bcjp.file', 'views', 'betting_withdraw', "ValueError")
            jsonRtn["success"] = False
            jsonRtn["message"] = str(ve)
Esempio n. 4
0
 def save(self, *args, **kwargs):
     LogUtils().info(
         'bcjp.file', 'models', 'BitcoinWithdrawRequest',
         "Withdraw request made bitcoin_address_session.id {} amount {} to {}"
         .format(self.bitcoin_address_session.id, self.amount,
                 self.to_address))
     super(BitcoinWithdrawRequest, self).save(*args, **kwargs)
Esempio n. 5
0
def create_round_log(message=None,
                     rnd=None,
                     payment=None,
                     is_bet=False,
                     is_start=False,
                     is_end=False,
                     is_winner=False,
                     bet=None):
    if not message:
        LogUtils().info('bcjp.file', 'bcjp_utils', 'create_round_log',
                        "NO MESSAGE")
        return
    if not rnd:
        LogUtils().info('bcjp.file', 'bcjp_utils', 'create_round_log',
                        "NO rnd")
        return
    if not isinstance(rnd, Rounds):
        LogUtils().info('bcjp.file', 'bcjp_utils', 'create_round_log',
                        "NO Rounds")
        return
    if bet and not isinstance(bet, BitcoinBet):
        LogUtils().info('bcjp.file', 'bcjp_utils', 'create_round_log',
                        "NO BitcoinBet")
        return
    if payment and not isinstance(payment, BitcoinPaymentCompleted):
        LogUtils().info('bcjp.file', 'bcjp_utils', 'create_round_log',
                        "NO BitcoinPaymentCompleted")
        return

    rl = RoundLog()

    rl.round = rnd
    rl.payment = payment
    rl.message = message
    rl.is_bet = is_bet
    rl.is_start = is_start
    rl.is_end = is_end
    rl.is_winner = is_winner
    rl.bet = bet

    rl.save()

    if bet:
        settings.REDIS_CLIENT.incrby(settings.REDIS_ROUND_CURRENT_AMOUNT,
                                     long(bet.amount))

    return rl
Esempio n. 6
0
def round_progress(request):
    """
    Gets the round progress info
    """

    progress = settings.REDIS_CLIENT.get(settings.REDIS_ROUND_BETS)
    progress_sum = settings.REDIS_CLIENT.get(settings.REDIS_ROUND_CURRENT_AMOUNT)

    try:
        balance = BitcoinAddressSession.objects.get(pk=request.session["bas"]).amount
    except Exception, e:
        LogUtils().error('bcjp.warning_file', 'view', 'round_progress', e)
        balance = 0
Esempio n. 7
0
    def save(self, *args, **kwargs):
        if not self.pk:
            self.secret_hash = "{}{}".format(uuid.uuid4(),
                                             uuid.uuid4()).replace("-",
                                                                   "")[:48]
            self.winning_percent = (np.random.random_sample() * 100) + 1
            md5 = hashlib.md5()
            md5.update("{}-{}".format(self.secret_hash, self.winning_percent))
            self.round_hash = md5.hexdigest()
            LogUtils().info(
                'bcjp.file', 'models', 'Rounds',
                "Attempting to save Rounds with hash {}".format(
                    self.round_hash))

        super(Rounds, self).save(*args, **kwargs)
        return self
Esempio n. 8
0
def create_round_log_payment(bet=None, bas=None, rnd=None):
    if not bet:
        raise ValueError("")  # Needs to change
    if not isinstance(bet, BitcoinBet):
        raise ValueError("")  # Needs to change
    if not rnd: return
    if not isinstance(rnd, Rounds): return

    value = float(bet.amount) / settings.SATOSHI_RATIO

    try:
        bettor = bas.alias
    except Exception, e:
        LogUtils().error('bcjp.warning_file', 'bcjp_utils',
                         'create_round_log_payment', e)
        raise ValueError("")  # Needs to change
Esempio n. 9
0
def index_with_secret(request, secret_id=None):
    if not secret_id:
        return redirect('index')

    was_redirect = request.session.get('was_redirect', False)
    hide_how_it_works = request.session.get('hide_how_it_works', False)

    if was_redirect:
        del request.session['was_redirect']

    if request.session.get('last_log_id', False):
        del request.session['last_log_id']

    try:
        bas = BitcoinAddressSession.objects.get(session=secret_id)
        request.session["bas"] = bas.id
    except Exception, e:
        LogUtils().error('bcjp.warning_file', 'views', 'index_with_secret', e)
        return redirect('index')
Esempio n. 10
0
def betting_withdraw_address(request):
    if request.method != "POST":
        return redirect('index')
    if not request.POST.get('ig-withdraw_address-text', None):
        return redirect('index')
    if not request.session.get('bas', False):
        return redirect('index')

    withdraw_address = request.POST['ig-withdraw_address-text']

    if not re.search("^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$", withdraw_address):
        return redirect('index')        

    try:
        bas = BitcoinAddressSession.objects.get(pk=request.session['bas'])
        bas.withdraw_address = withdraw_address

        if settings.IS_EDUCATIONAL:
            bas.amount = settings.IS_EDUCATIONAL_AMOUNT * settings.SATOSHI_RATIO

        bas.save()
    except Exception, e:
        LogUtils().error('bcjp.warning_file', 'view', 'betting_withdraw_address', e)
Esempio n. 11
0
    for i, paths in enumerate(image_paths):
        print("[INFO] Computing folder " + str(i))
        #Divide the image set into chunks for each core
        image_chunks = chunk_it(paths, n_cores)

        for i, chunk in enumerate(image_chunks):
            p = multiprocessing.Process(target=compute_images,
                                        args=(chunk, return_hashes))
            print("[INFO] Processing " + str(len(chunk)) +
                  " images in CPU No. " + str(i))
            jobs.append(p)
            p.start()

        for proc in jobs:
            proc.join()

    #Check if we need to export logs
    if args['log']:
        print("[INFO] Creating log!")
        LogUtils(return_hashes).export(args['log'])

    if args['merge']:
        print("[INFO] Merging folders!")
        MergeUtils(return_hashes).merge(args['merge'])

    #Check for missing images
    for (h, image_paths) in return_hashes.items():
        if len(image_paths) <= 1:
            print("[WARNING] Image integrity check failed! for " +
                  image_paths[0])
Esempio n. 12
0
import os
import torch
import torch.backends.cudnn as cudnn
import torch.nn.init as init
import torch.optim as optim
import torch.utils.data as data
from torch.autograd import Variable

from data import VOCroot, VOC_300, VOC_512, COCO_300, COCO_512, COCO_mobile_300, AnnotationTransform, \
    COCODetection, VOCDetection, detection_collate, BaseTransform, preproc,COCOroot
from layers.functions import Detect, PriorBox
from layers.modules import MultiBoxLoss
from utils.nms_wrapper import nms
from utils.timer import Timer
from log_utils import LogUtils
lop_util=LogUtils()


def str2bool(v):
    return v.lower() in ("yes", "true", "t", "1")


parser = argparse.ArgumentParser(
    description='Receptive Field Block Net Training')
parser.add_argument('-v', '--version', default='RFB_vgg',
                    help='RFB_vgg ,RFB_E_vgg RFB_mobile SSD_vgg version.')
parser.add_argument('-s', '--size', default='300',
                    help='300 or 512 input size.')
parser.add_argument('-d', '--dataset', default='VOC',
                    help='VOC or COCO dataset')
parser.add_argument(
Esempio n. 13
0
 def save(self, *args, **kwargs):
     LogUtils().info(
         'bcjp.file', 'models', 'BitcoinBet',
         "Attempting to save BitcoinBet with bitcoin_address_session.id {} for amount {}"
         .format(self.bitcoin_address_session.pk, self.amount))
     super(BitcoinBet, self).save(*args, **kwargs)
Esempio n. 14
0
 def save(self, *args, **kwargs):
     LogUtils().info(
         'bcjp.file', 'models', 'BitcoinPaymentCompleted',
         "Attempting to save payment with {} confirmations and hash {}".
         format(self.confirmations, self.transaction_hash))
     super(BitcoinPaymentCompleted, self).save(*args, **kwargs)
Esempio n. 15
0
    rnd = None

    try:
        rnd = Rounds.objects.get(
            pk=settings.REDIS_CLIENT.get(settings.REDIS_ROUND_CURRENT_ID))
    except Rounds.DoesNotExist, e:
        # THIS IS VERY SHITTY
        raise e

    try:
        bas.amount -= bet.amount
        bas.save()

        create_round_log_payment(bet, bas, rnd)
    except Exception, e:
        LogUtils().error('bcjp.warning_file', 'bcjp_utils',
                         'process_round_bet', e)
        return

    current_count = settings.REDIS_CLIENT.incrby(settings.REDIS_ROUND_BETS, 1)

    if current_count < 25:
        return

    # Set round lock
    settings.REDIS_CLIENT.set(settings.REDIS_ROUND_LOCK, 1)

    try:
        # Post secret and winning percentage logs
        create_round_log_winning_percent(rnd=rnd)
        create_round_log_secret(rnd=rnd)
Esempio n. 16
0
def betting_track(request, secret=None, first48=None):
    """The callback url that is utilized for Blockchain.info API

    """
    confirmations = request.GET.get("confirmations", -1)

    try:
        confirmations = int(confirmations)
    except Exception, e:
        LogUtils().error('bcjp.warning_file', 'views', 'betting_track', e)
        LogUtils().info('bcjp.file', 'views', 'betting_track', "*not an integer*")
        return HttpResponse("*not an integer*")

    if confirmations < 0 or not secret or not first48:
        LogUtils().info('bcjp.file', 'views', 'betting_track', "*invalid params*")
        return HttpResponse("*invalid params*")
    elif confirmations < 6:
        payment = BitcoinPaymentPending()
    else:
        payment = BitcoinPaymentCompleted()

    md5 = hashlib.md5()
    md5.update("{}{}".format(settings.SECRET_KEY, first48))

    if md5.hexdigest() != secret:
        LogUtils().info('bcjp.file', 'views', 'betting_track', "*invalid secret*")
        return HttpResponse("*invalid secret*")

    payment.value = request.GET.get('value', 0)
    payment.input_address = request.GET.get('input_address', 0)