Exemple #1
0
def test_burn():
    global db, cursor
    unsigned_tx_hex = burn.create(source, quantity, test=True)
    assert unsigned_tx_hex == '0100000001c1d8c075936c3495f6d653c50f73d987f75448d97a750249b1eb83bee71b24ae0000000000ffffffff02de68f405000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac0000000000000000156a13544553540000003c50726f6f664f664275726e00000000'
    fee = quantity
    data = get_tx_data(unsigned_tx_hex)
    tx_insert(source, None, None, fee, data)
    cursor = blocks.parse_block(db, cursor, tx_index - 1)
Exemple #2
0
def test_overburn ():
    unsigned_tx_hex = burn.create(db, source_default, (1 * config.UNIT), test=True, overburn=True)  # Try to burn a whole 'nother BTC.

    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, burn.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #3
0
def test_burn ():
    unsigned_tx_hex = burn.create(db, source_default, int(.62 * quantity), 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, burn.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #4
0
def test_overburn():
    unsigned_tx_hex = burn.create(
        db, source_default, (1 * config.UNIT), test=True,
        overburn=True)  # Try to burn a whole 'nother BTC.

    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, burn.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #5
0
def test_burn():
    unsigned_tx_hex = burn.create(db,
                                  source_default,
                                  int(.62 * quantity),
                                  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, burn.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
        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':
        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':
Exemple #7
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)
Exemple #8
0
def test_overburn ():
    unsigned_tx_hex = burn.create(db, source_default, (1 * config.UNIT), overburn=True)  # Try to burn a whole 'nother BTC.

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
Exemple #9
0
def test_burn ():
    unsigned_tx_hex = burn.create(db, source_default, int(.62 * quantity))

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
                              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))
        json_print(bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'watch':
        while True:
            os.system('cls' if os.name=='nt' else 'clear')

            # Open orders.
            orders = api.get_orders(validity='Valid', show_expired=False, show_empty=False)
            table = PrettyTable(['Give', 'Get', 'Price', 'Fee', 'Time Left', 'Tx Hash'])
            for order in orders:
                order = format_order(order)
                table.add_row(order)
            print(colorama.Fore.WHITE + colorama.Style.BRIGHT + 'Open Orders' + colorama.Style.RESET_ALL)
            print(colorama.Fore.BLUE + str(table) + colorama.Style.RESET_ALL)
            print('\n')
Exemple #11
0
        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:
Exemple #12
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)