示例#1
0
def test_cancel ():
    unsigned_tx_hex = cancel.create(db, 'ab897fbdedfa502b2d839b6a56100887dccdc507555c282e59589e06300a62e2', test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, fee_provided, data)

    parse_tx(tx_index - 1, data, cancel.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
示例#2
0
def test_cancel():
    unsigned_tx_hex = cancel.create(
        db,
        'ab897fbdedfa502b2d839b6a56100887dccdc507555c282e59589e06300a62e2',
        test=True)

    destination, btc_amount, data = get_tx_data(unsigned_tx_hex)
    tx_insert(source_default, destination, btc_amount, fee_provided, data)

    parse_tx(tx_index - 1, data, cancel.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
                                     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':
        unsigned_tx_hex = cancel.create(db, args.offer_hash)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    elif args.action == 'address':
        try:
            bitcoin.base58_decode(args.address, config.ADDRESSVERSION)
        except Exception:
            raise exceptions.InvalidAddressError('Invalid Bitcoin address:',
                                                  args.address)
        address(args.address)

    elif args.action == 'asset':
        if args.asset == 'XCP':
            burns = util.get_burns(db, validity='Valid', address=None)
            total = sum([burn['earned'] for burn in burns])
            total = util.devise(db, total, args.asset, 'output')
示例#4
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
     orders_sell = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, filters=[{'field': 'give_asset', 'op': '==', 'value': 'CHA'},{'field': 'get_asset', 'op': '==', 'value': 'BTC'}])
     orders_buy = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, filters=[{'field': 'get_asset', 'op': '==', 'value': 'CHA'},{'field': 'give_asset', 'op': '==', 'value': 'BTC'}])
     orders_sell = sorted(order_tuples(orders_sell), key=lambda tup: tup[1], reverse=True)
     orders_buy = sorted(order_tuples(orders_buy), key=lambda tup: tup[1], reverse=True)
     my_orders = None
     my_order_matches = None
     balance = None
     if self.get_argument("form")=="balance":
         address = self.get_argument("address")
         try:
             wallet = util.get_address(db, address = address)
         except:
             wallet = None
         balance = None
         if wallet != None:
             for balance in wallet['balances']:
                 if balance['asset']=='CHA':
                     balance = util.devise(db, balance['amount'], 'CHA', 'output')
     elif self.get_argument("form")=="my_orders":
         address = self.get_argument("address")
         try:
             my_orders = util.get_orders(db, validity='valid', show_empty=False, show_expired=False, source=address)
             my_orders = order_tuples(my_orders)
             my_order_matches = util.get_order_matches(db, validity='pending', is_mine=True, address=address)
             my_order_matches = order_match_tuples(my_order_matches)
         except:
             my_orders = None
             my_order_matches = None
     elif self.get_argument("form")=="btcpay":
         order_match_id = self.get_argument("order_match_id")
         try:
             tx_hex = btcpay.create(db, order_match_id, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "BTC payment successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="cancel":
         tx_hash = self.get_argument("tx_hash")
         try:
             tx_hex = cancel.create(db, tx_hash, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Cancel successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="send":
         source = self.get_argument("source")
         destination = self.get_argument("destination")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         try:
             tx_hex = send.create(db, source, destination, quantity, 'CHA', unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Send successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="burn":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         try:
             tx_hex = burn.create(db, source, quantity, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Burn successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="buy":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         price = util.devise(db, self.get_argument("price"), 'value', 'input')
         pricetimesquantity = float(self.get_argument("quantity"))*float(self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity*config.UNIT)
         expiration = 6 * 24 #24 hour order
         try:
             tx_hex = order.create(db, source, 'BTC', pricetimesquantity, 'CHA', quantity,
                                        expiration, 0, config.MIN_FEE, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Buy order successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form")=="sell":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA', 'input')
         price = util.devise(db, self.get_argument("price"), 'value', 'input')
         pricetimesquantity = float(self.get_argument("quantity"))*float(self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity*config.UNIT)
         expiration = 6 * 24 #24 hour order
         try:
             tx_hex = order.create(db, source, 'CHA', quantity, 'BTC', pricetimesquantity,
                                            expiration, 0, config.MIN_FEE, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Sell order successful"
         except:
             error = sys.exc_info()[1]
     self.render("wallet.html", db_updated = db_updated, bitcoin_updated = bitcoin_updated, version_updated = version_updated, orders_buy = orders_buy, orders_sell = orders_sell, info = info, error = error, block_count_db = block_count_db, block_count_bitcoin = block_count_bitcoin, balance = balance, my_orders = my_orders, my_order_matches = my_order_matches)
示例#5
0
def test_cancel ():
    unsigned_tx_hex = cancel.create(db, 'ab897fbdedfa502b2d839b6a56100887dccdc507555c282e59589e06300a62e2')

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
示例#6
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)
示例#7
0
                                     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:
            raise exceptions.InvalidAddressError('Invalid Bitcoin address:',
                                                 args.address)
        balances(args.address)

    elif args.action == 'asset':
        # TODO: Use API
        if args.asset == 'CHA':
示例#8
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
     orders_sell = util.get_orders(db,
                                   validity='valid',
                                   show_empty=False,
                                   show_expired=False,
                                   filters=[{
                                       'field': 'give_asset',
                                       'op': '==',
                                       'value': 'CHA'
                                   }, {
                                       'field': 'get_asset',
                                       'op': '==',
                                       'value': 'BTC'
                                   }])
     orders_buy = util.get_orders(db,
                                  validity='valid',
                                  show_empty=False,
                                  show_expired=False,
                                  filters=[{
                                      'field': 'get_asset',
                                      'op': '==',
                                      'value': 'CHA'
                                  }, {
                                      'field': 'give_asset',
                                      'op': '==',
                                      'value': 'BTC'
                                  }])
     orders_sell = sorted(order_tuples(orders_sell),
                          key=lambda tup: tup[1],
                          reverse=True)
     orders_buy = sorted(order_tuples(orders_buy),
                         key=lambda tup: tup[1],
                         reverse=True)
     my_orders = None
     my_order_matches = None
     balance = None
     if self.get_argument("form") == "balance":
         address = self.get_argument("address")
         try:
             wallet = util.get_address(db, address=address)
         except:
             wallet = None
         balance = None
         if wallet != None:
             for balance in wallet['balances']:
                 if balance['asset'] == 'CHA':
                     balance = util.devise(db, balance['amount'], 'CHA',
                                           'output')
     elif self.get_argument("form") == "my_orders":
         address = self.get_argument("address")
         try:
             my_orders = util.get_orders(db,
                                         validity='valid',
                                         show_empty=False,
                                         show_expired=False,
                                         source=address)
             my_orders = order_tuples(my_orders)
             my_order_matches = util.get_order_matches(db,
                                                       validity='pending',
                                                       is_mine=True,
                                                       address=address)
             my_order_matches = order_match_tuples(my_order_matches)
         except:
             my_orders = None
             my_order_matches = None
     elif self.get_argument("form") == "btcpay":
         order_match_id = self.get_argument("order_match_id")
         try:
             tx_hex = btcpay.create(db, order_match_id, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "BTC payment successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "cancel":
         tx_hash = self.get_argument("tx_hash")
         try:
             tx_hex = cancel.create(db, tx_hash, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Cancel successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "send":
         source = self.get_argument("source")
         destination = self.get_argument("destination")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         try:
             tx_hex = send.create(db,
                                  source,
                                  destination,
                                  quantity,
                                  'CHA',
                                  unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Send successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "burn":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         try:
             tx_hex = burn.create(db, source, quantity, unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Burn successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "buy":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         price = util.devise(db, self.get_argument("price"), 'value',
                             'input')
         pricetimesquantity = float(self.get_argument("quantity")) * float(
             self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity * config.UNIT)
         expiration = 6 * 24  #24 hour order
         try:
             tx_hex = order.create(db,
                                   source,
                                   'BTC',
                                   pricetimesquantity,
                                   'CHA',
                                   quantity,
                                   expiration,
                                   0,
                                   config.MIN_FEE,
                                   unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Buy order successful"
         except:
             error = sys.exc_info()[1]
     elif self.get_argument("form") == "sell":
         source = self.get_argument("source")
         quantity = util.devise(db, self.get_argument("quantity"), 'CHA',
                                'input')
         price = util.devise(db, self.get_argument("price"), 'value',
                             'input')
         pricetimesquantity = float(self.get_argument("quantity")) * float(
             self.get_argument("price"))
         pricetimesquantity = int(pricetimesquantity * config.UNIT)
         expiration = 6 * 24  #24 hour order
         try:
             tx_hex = order.create(db,
                                   source,
                                   'CHA',
                                   quantity,
                                   'BTC',
                                   pricetimesquantity,
                                   expiration,
                                   0,
                                   config.MIN_FEE,
                                   unsigned=False)
             bitcoin.transmit(tx_hex, ask=False)
             info = "Sell order successful"
         except:
             error = sys.exc_info()[1]
     self.render("wallet.html",
                 db_updated=db_updated,
                 bitcoin_updated=bitcoin_updated,
                 version_updated=version_updated,
                 orders_buy=orders_buy,
                 orders_sell=orders_sell,
                 info=info,
                 error=error,
                 block_count_db=block_count_db,
                 block_count_bitcoin=block_count_bitcoin,
                 balance=balance,
                 my_orders=my_orders,
                 my_order_matches=my_order_matches)