Exemple #1
0
 def post(self):
     db_updated = yield tornado.gen.Task(is_db_updated)
     bitcoin_updated = yield tornado.gen.Task(is_bitcoin_updated)
     version_updated = yield tornado.gen.Task(is_version_updated)
     block_count_db, block_count_bitcoin = yield tornado.gen.Task(get_status)
     info = None
     error = None
     bets = util.get_bets(db, order_by='tx_index', validity='valid')
     bets = bet_tuples(bets[:100])
     my_bets = []
     supply = util.devise(db, util.cha_supply(db), 'CHA', 'output')
     max_profit = float(supply)*config.MAX_PROFIT
     if self.get_argument("form")=="roll" and self.get_argument("source") and self.get_argument("bet") and self.get_argument("payout") and self.get_argument("chance"):
         source = self.get_argument("source")
         bet_amount = util.devise(db, self.get_argument("bet"), 'CHA', 'input')
         chance = util.devise(db, self.get_argument("chance"), 'value', 'input')
         payout = util.devise(db, self.get_argument("payout"), 'value', 'input')
         try:
             tx_hex = bet.create(db, source, bet_amount, chance, payout, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Thanks for betting!"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="my_bets" and self.get_argument("address"):
         try:
             my_bets = util.get_bets(db, source = self.get_argument("address"), order_by='tx_index', validity='valid')
             my_bets = bet_tuples(my_bets)
         except:
             my_bets = []
     self.render("casino.html", db_updated = db_updated, bitcoin_updated = bitcoin_updated, version_updated = version_updated, bets = bets, my_bets = my_bets, supply = supply, house_edge = config.HOUSE_EDGE, max_profit = max_profit, info = info, error = error, block_count_db = block_count_db, block_count_bitcoin = block_count_bitcoin)
Exemple #2
0
def test_bet_bearcfd_to_be_settled ():
    unsigned_tx_hex = bet.create(db, source_default, source_default, 1, 1388000100, small * 7, small * 3, 0.0, 5040, expiration, test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, config.MIN_FEE, data)
    parse_tx(tx_index - 1, data, bet.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #3
0
def test_bet_bullcfd_to_be_liquidated ():
    unsigned_tx_hex = bet.create(db, source_default, source_default, 0, 1388000100, small, round(small / 2), 0.0, 15120, expiration, test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, config.MIN_FEE, data)
    parse_tx(tx_index - 1, data, bet.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #4
0
def test_bet_notequal ():
    unsigned_tx_hex = bet.create(db, source_default, source_default, 3, 1388000200, small * 13, small * 15, 1, 5040, expiration, test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, config.MIN_FEE, data)
    parse_tx(tx_index - 1, data, bet.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #5
0
 def post(self):
     db_updated = yield tornado.gen.Task(is_db_updated)
     bitcoin_updated = yield tornado.gen.Task(is_bitcoin_updated)
     version_updated = yield tornado.gen.Task(is_version_updated)
     block_count_db, block_count_bitcoin = yield tornado.gen.Task(
         get_status)
     info = None
     error = None
     bets = util.get_bets(db, order_by='tx_index', validity='valid')
     bets = bet_tuples(bets[:100])
     my_bets = []
     supply = util.devise(db, util.cha_supply(db), 'CHA', 'output')
     max_profit = float(supply) * config.MAX_PROFIT
     if self.get_argument("form") == "roll" and self.get_argument(
             "source") and self.get_argument("bet") and self.get_argument(
                 "payout") and self.get_argument("chance"):
         source = self.get_argument("source")
         bet_amount = util.devise(db, self.get_argument("bet"), 'CHA',
                                  'input')
         chance = util.devise(db, self.get_argument("chance"), 'value',
                              'input')
         payout = util.devise(db, self.get_argument("payout"), 'value',
                              'input')
         try:
             tx_hex = bet.create(db,
                                 source,
                                 bet_amount,
                                 chance,
                                 payout,
                                 unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Thanks for betting!"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "my_bets" and self.get_argument(
             "address"):
         try:
             my_bets = util.get_bets(db,
                                     source=self.get_argument("address"),
                                     order_by='tx_index',
                                     validity='valid')
             my_bets = bet_tuples(my_bets)
         except:
             my_bets = []
     self.render("casino.html",
                 db_updated=db_updated,
                 bitcoin_updated=bitcoin_updated,
                 version_updated=version_updated,
                 bets=bets,
                 my_bets=my_bets,
                 supply=supply,
                 house_edge=config.HOUSE_EDGE,
                 max_profit=max_profit,
                 info=info,
                 error=error,
                 block_count_db=block_count_db,
                 block_count_bitcoin=block_count_bitcoin)
Exemple #6
0
def test_bet_notequal():
    unsigned_tx_hex = bet.create(db,
                                 source_default,
                                 source_default,
                                 3,
                                 1388000200,
                                 small * 13,
                                 small * 15,
                                 1,
                                 5040,
                                 expiration,
                                 test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, config.MIN_FEE, data)
    parse_tx(tx_index - 1, data, bet.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #7
0
def test_bet_bearcfd_to_be_settled():
    unsigned_tx_hex = bet.create(db,
                                 source_default,
                                 source_default,
                                 1,
                                 1388000100,
                                 small * 7,
                                 small * 3,
                                 0.0,
                                 5040,
                                 expiration,
                                 test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, config.MIN_FEE, data)
    parse_tx(tx_index - 1, data, bet.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #8
0
def test_bet_bullcfd_to_be_liquidated():
    unsigned_tx_hex = bet.create(db,
                                 source_default,
                                 source_default,
                                 0,
                                 1388000100,
                                 small,
                                 round(small / 2),
                                 0.0,
                                 15120,
                                 expiration,
                                 test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, config.MIN_FEE, data)
    parse_tx(tx_index - 1, data, bet.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #9
0
def test_bet_notequal ():
    unsigned_tx_hex = bet.create(db, source_default, source_default, 3, 1388000200, small * 13, small * 15, 1, 5040, expiration)

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #10
0
def test_bet_bearcfd_to_be_settled ():
    unsigned_tx_hex = bet.create(db, source_default, source_default, 1, 1388000100, small * 7, small * 3, 0.0, 5040, expiration)

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #11
0
def test_bet_bearcfd_to_be_liquidated ():
    unsigned_tx_hex = bet.create(db, source_default, source_default, 1, 1388000100, round(small / 2), round(small * .83), 0.0, 15120, expiration)

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #12
0
    elif args.action == 'broadcast':
        value = util.devise(db, args.value, 'value', 'input')
        unsigned_tx_hex = broadcast.create(db, args.source, int(time.time()),
                                           value, args.fee_multiplier,
                                           args.text)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'bet':
        deadline = round(datetime.timestamp(dateutil.parser.parse(args.deadline)))
        wager = util.devise(db, args.wager, 'XCP', 'input')
        counterwager = util.devise(db, args.counterwager, 'XCP', 'input')
        target_value = util.devise(db, args.target_value, 'value', 'input')
        leverage = util.devise(db, args.leverage, 'leverage', 'input')

        unsigned_tx_hex = bet.create(db, args.source, args.feed_address,
                                     util.BET_TYPE_ID[args.bet_type], deadline,
                                     wager, counterwager, target_value,
                                     leverage, args.expiration)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'dividend':
        quantity_per_share = util.devise(db, args.quantity_per_share, 'XCP', 'input')
        unsigned_tx_hex = dividend.create(db, args.source, quantity_per_share,
                                   args.share_asset)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'burn':
        quantity = util.devise(db, args.quantity, 'BTC', 'input')
        unsigned_tx_hex = burn.create(db, args.source, quantity)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'cancel':
        # Use a magic number to store the fee multplier as an integer.
        fee_multiplier = D(args.fee_multiplier) * D(1e8)
        if fee_multiplier > 4294967295:
            raise exceptions.OverflowError('Fee multiplier must be less than or equal to 42.94967295.')

        json_print(broadcast.create(args.source, int(time.time()), args.value,
                                    round(fee_multiplier), args.text))

    elif args.action == 'bet':
        bitcoin.bitcoind_check()

        deadline = datetime.timestamp(dateutil.parser.parse(args.deadline))

        json_print(bet.create(args.source, args.feed_address,
                              util.BET_TYPE_ID[args.bet_type], round(deadline),
                              round(D(args.wager) * config.UNIT),
                              round(D(args.counterwager) * config.UNIT),
                              float(args.threshold), args.leverage,
                              args.expiration))

    elif args.action == 'dividend':
        bitcoin.bitcoind_check()

        asset_id = util.get_asset_id(args.share_asset)
        quantity_per_share = D(args.quantity_per_share) * config.UNIT

        json_print(dividend.create(args.source, round(quantity_per_share),
                                   asset_id))

    elif args.action == 'burn':
        bitcoin.bitcoind_check()
        unsigned_tx_hex = burn.create(args.source, round(D(args.quantity) * config.UNIT))
Exemple #14
0
def counterparty_action():
    
    unsigned = True if request.forms.get('unsigned')!=None and request.forms.get('unsigned')=="1" else False
    print("unsigned:"+str(unsigned))
    try:
        action = request.forms.get('action')

        if action=='send':
            source = request.forms.get('source')
            destination = request.forms.get('destination')
            asset = request.forms.get('asset')  
            quantity = util.devise(db, request.forms.get('quantity'), asset, 'input')      
            unsigned_tx_hex = send.create(db, source, destination, quantity, asset, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}       

        elif action=='order':
            source = request.forms.get('source')
            give_asset = request.forms.get('give_asset')
            get_asset = request.forms.get('get_asset')
            give_quantity = util.devise(db, request.forms.get('give_quantity'), give_asset, 'input')
            get_quantity = util.devise(db, request.forms.get('get_quantity'), get_asset, 'input')
            expiration = int(request.forms.get('expiration')) 
            fee_required = 0
            fee_provided = config.MIN_FEE
            if give_asset == 'BTC':
                fee_required = 0
                fee_provided = util.devise(db, request.forms.get('fee_provided'), 'BTC', 'input')
            elif get_asset == 'BTC':
                fee_required = util.devise(db, request.forms.get('fee_required'), 'BTC', 'input')
                fee_provided = config.MIN_FEE
         
            unsigned_tx_hex = order.create(db, source, give_asset,
                                           give_quantity, get_asset,
                                           get_quantity, expiration,
                                           fee_required, fee_provided,
                                           unsigned=unsigned)

            result = {'success':True, 'message':str(unsigned_tx_hex)}       

        elif action=='btcpay':
            order_match_id = request.forms.get('order_match_id')         
            unsigned_tx_hex = btcpay.create(db, order_match_id, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}          

        elif action=='cancel':
            offer_hash = request.forms.get('offer_hash')           
            unsigned_tx_hex = cancel.create(db, offer_hash, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}

        elif action=='issuance':
            source = request.forms.get('source')
            destination = request.forms.get('destination')
            asset_name = request.forms.get('asset_name')
            divisible = True if request.forms.get('divisible')=="1" else False
            quantity = util.devise(db, request.forms.get('quantity'), None, 'input', divisible=divisible)

            callable_ = True if request.forms.get('callable')=="1" else False
            call_date = request.forms.get('call_date')
            call_price = request.forms.get('call_price')
            description = request.forms.get('description')
        
            if callable_:
                call_date = round(datetime.timestamp(dateutil.parser.parse(call_date)))
                call_price = float(call_price)
            else:
                call_date, call_price = 0, 0

            issuance.create(db, source, destination, asset_name, quantity, divisible, 
                            callable_, call_date, call_price, description, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}
        
        elif action=='dividend':
            source = request.forms.get('source')
            asset = request.forms.get('asset') 
            quantity_per_share = util.devise(db, request.forms.get('quantity_per_share'), 'XCP', 'input')
            unsigned_tx_hex = dividend.create(db, source, quantity_per_share, asset, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}

        elif action=='callback':
            source = request.forms.get('source')
            asset = request.forms.get('asset')
            fraction_per_share = float(request.forms.get('fraction_per_share'))
            unsigned_tx_hex = callback.create(db, source, fraction_per_share, asset, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}

        elif action=='broadcast':
            source = request.forms.get('source')
            text = request.forms.get('text')
            value = util.devise(db, request.forms.get('value'), 'value', 'input')
            fee_multiplier = request.forms.get('fee_multiplier')
            unsigned_tx_hex = broadcast.create(db, source, int(time.time()), value, fee_multiplier, text, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}

        elif action=='bet':
            source = request.forms.get('source')
            feed_address = request.forms.get('feed_address')
            bet_type = int(request.forms.get('bet_type'))
            deadline = calendar.timegm(dateutil.parser.parse(request.forms.get('deadline')).utctimetuple())
            wager = util.devise(db, request.forms.get('wager'), 'XCP', 'input')
            counterwager = util.devise(db, request.forms.get('counterwager'), 'XCP', 'input')
            target_value = util.devise(db, request.forms.get('target_value'), 'value', 'input')
            leverage = util.devise(db, request.forms.get('leverage'), 'leverage', 'input')

            expiration = request.forms.get('expiration')
            unsigned_tx_hex = bet.create(db, source, feed_address, bet_type, deadline,
                                        wager, counterwager, target_value,
                                        leverage, expiration, unsigned=unsigned)
            result = {'success':True, 'message':str(unsigned_tx_hex)}

        else:
            result = {'success':False, 'message':'Unknown action.'} 

        if result['success']==True and unsigned==False:
            tx_hash = bitcoin.transmit(unsigned_tx_hex, ask=False);
            result['message'] = "Transaction transmited: "+tx_hash

    except Exception as e:
        result = {'success':False, 'message':str(e)} 

    response.content_type = 'application/json'
    return json.dumps(result, cls=DecimalEncoder)
Exemple #15
0
    elif args.action == 'btcpay':
        unsigned_tx_hex = btcpay.create(db,
                                        args.order_match_id,
                                        unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(
            bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'bet':
        bet = util.devise(db, args.bet, 'CHA', 'input')
        chance = util.devise(db, args.chance, 'value', 'input')
        payout = util.devise(db, args.payout, 'value', 'input')

        unsigned_tx_hex = bet.create(db,
                                     args.source,
                                     bet,
                                     chance,
                                     payout,
                                     unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(
            bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'burn':
        quantity = util.devise(db, args.quantity, 'BTC', 'input')
        unsigned_tx_hex = burn.create(db,
                                      args.source,
                                      quantity,
                                      unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(
            bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'cancel':
    elif args.action == 'broadcast':
        value = util.devise(db, args.value, 'value', 'input')
        unsigned_tx_hex = broadcast.create(db, args.source, int(time.time()),
                                           value, args.fee_multiplier,
                                           args.text)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'bet':
        deadline = round(datetime.timestamp(dateutil.parser.parse(args.deadline)))
        wager = util.devise(db, args.wager, 'XCP', 'input')
        counterwager = util.devise(db, args.counterwager, 'XCP', 'input')
        target_value = util.devise(db, args.target_value, 'value', 'input')
        leverage = util.devise(db, args.leverage, 'leverage', 'input')

        unsigned_tx_hex = bet.create(db, args.source, args.feed_address,
                                     util.BET_TYPE_ID[args.bet_type], deadline,
                                     wager, counterwager, target_value,
                                     leverage, args.expiration)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'dividend':
        quantity_per_share = util.devise(db, args.quantity_per_share, 'XCP', 'input')
        unsigned_tx_hex = dividend.create(db, args.source, quantity_per_share,
                                   args.share_asset)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'burn':
        quantity = util.devise(db, args.quantity, 'BTC', 'input')
        unsigned_tx_hex = burn.create(db, args.source, quantity)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'cancel':
Exemple #17
0
        get_quantity = util.devise(db, get_quantity, args.get_asset, 'input')
        unsigned_tx_hex = order.create(db, args.source, args.give_asset, give_quantity,
                                args.get_asset, get_quantity,
                                args.expiration, fee_required, fee_provided, unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'btcpay':
        unsigned_tx_hex = btcpay.create(db, args.order_match_id, unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'bet':
        bet = util.devise(db, args.bet, 'CHA', 'input')
        chance = util.devise(db, args.chance, 'value', 'input')
        payout = util.devise(db, args.payout, 'value', 'input')

        unsigned_tx_hex = bet.create(db, args.source, bet, chance, payout, unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'burn':
        quantity = util.devise(db, args.quantity, 'BTC', 'input')
        unsigned_tx_hex = burn.create(db, args.source, quantity, unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'cancel':
        unsigned_tx_hex = cancel.create(db, args.offer_hash, unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'balances':
        try:
            bitcoin.base58_decode(args.address, config.ADDRESSVERSION)
        except Exception: