Ejemplo n.º 1
0
def test_broadcast_equal ():
    unsigned_tx_hex = broadcast.create(db, source_default, 1388000201, 2, fee_multiplier_default, 'Unit Test', 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, broadcast.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Ejemplo n.º 2
0
def test_broadcast_equal():
    unsigned_tx_hex = broadcast.create(db,
                                       source_default,
                                       1388000201,
                                       2,
                                       fee_multiplier_default,
                                       'Unit Test',
                                       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, broadcast.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Ejemplo n.º 3
0
    elif args.action == 'btcpay':
        unsigned_tx_hex = btcpay.create(db, args.order_match_id)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'issuance':
        quantity = util.devise(db, args.quantity, None, 'input',
                               divisible=args.divisible)
        unsigned_tx_hex = issuance.create(db, args.source,
                                          args.transfer_destination,
                                          args.asset, quantity, args.divisible)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    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))
Ejemplo n.º 4
0
def test_broadcast_equal ():
    unsigned_tx_hex = broadcast.create(db, source_default, 1388000201, 2, fee_multiplier_default, 'Unit Test')

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Ejemplo n.º 5
0
def test_broadcast_liquidate ():
    unsigned_tx_hex = broadcast.create(db, source_default, 1388000050, round(100 - (.415/3) - .00001, 5), fee_multiplier_default, 'Unit Test')

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Ejemplo n.º 6
0
    elif args.action == 'issuance':
        bitcoin.bitcoind_check()

        quantity = util.devise(args.quantity, asset_id, 'input')
        json_print(issuance.create(args.source, args.asset_id, round(quantity),
                                args.divisible))

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

        # 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()
Ejemplo n.º 7
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)
            if not args.call_price:
                parser.error('must specify call price of callable asset')
            call_date = calendar.timegm(dateutil.parser.parse(args.call_date).utctimetuple())
            call_price = float(args.call_price)
        else:
            call_date, call_price = 0, 0

        unsigned_tx_hex = issuance.create(db, args.source,
                                          args.transfer_destination,
                                          args.asset, quantity, args.divisible, args.callable_, call_date, call_price, args.description, unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(bitcoin.transmit(unsigned_tx_hex))

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

    elif args.action == 'bet':
        deadline = calendar.timegm(dateutil.parser.parse(args.deadline).utctimetuple())
        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, unsigned=args.unsigned)
        print(unsigned_tx_hex) if args.unsigned else json_print(bitcoin.transmit(unsigned_tx_hex))
Ejemplo n.º 9
0
    elif args.action == 'btcpay':
        unsigned_tx_hex = btcpay.create(db, args.order_match_id)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'issuance':
        quantity = util.devise(db, args.quantity, None, 'input',
                               divisible=args.divisible)
        unsigned_tx_hex = issuance.create(db, args.source,
                                          args.transfer_destination,
                                          args.asset, quantity, args.divisible)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    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))