コード例 #1
0
ファイル: test.py プロジェクト: becherovka/Counterparty
def test_order_buy_xcp():
    global db, cursor
    unsigned_tx_hex = order.create(source, 0, small, 1, small * 2, expiration, 0, fee_provided, test=True)
    assert unsigned_tx_hex == '0100000001c1d8c075936c3495f6d653c50f73d987f75448d97a750249b1eb83bee71b24ae0000000000ffffffff029e07db0b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac0000000000000000346a32544553540000000a000000000000000000000000004c4b4000000000000000010000000000989680000a000000000000000000000000'
    fee = config.MIN_FEE
    data = get_tx_data(unsigned_tx_hex)
    tx_insert(source, destination, config.DUST_SIZE, config.MIN_FEE, data)
    cursor = blocks.parse_block(db, cursor, tx_index - 1)
コード例 #2
0
ファイル: test_.py プロジェクト: CryptoEquity/counterpartyd
def test_order_to_be_cancelled ():
    unsigned_tx_hex = order.create(db, source_default, 'BBBB', small, 'XCP', small, expiration, 0, 0, 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, order.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
コード例 #3
0
ファイル: test_.py プロジェクト: CryptoEquity/counterpartyd
def test_order_sell_xcp ():
    unsigned_tx_hex = order.create(db, source_default, 'XCP', round(small * 2.1), 'BTC', small, expiration, fee_required, 0, 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, order.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
コード例 #4
0
def test_order_to_be_cancelled():
    unsigned_tx_hex = order.create(db,
                                   source_default,
                                   'BBBB',
                                   small,
                                   'XCP',
                                   small,
                                   expiration,
                                   0,
                                   0,
                                   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, order.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
コード例 #5
0
def test_order_sell_xcp():
    unsigned_tx_hex = order.create(db,
                                   source_default,
                                   'XCP',
                                   round(small * 2.1),
                                   'BTC',
                                   small,
                                   expiration,
                                   fee_required,
                                   0,
                                   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, order.parse)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
コード例 #6
0
        elif args.get_asset == 'BTC':
            fee_required = util.devise(db, args.fee_required, 'BTC', 'input')
            if args.fee_provided != config.MIN_FEE / config.UNIT:
                raise exceptions.FeeError('When buying BTC, do not specify a fee provided.')
            fee_provided = util.devise(db, args.fee_provided, 'BTC', 'input')
        else:
            fee_provided = util.devise(db, args.fee_provided, 'XCP', 'input')
            if fee_provided != config.MIN_FEE or args.fee_required != 0:
                raise exceptions.UselessError('No fee should be required or provided (explicitly) if not buying or selling BTC.')
            fee_required = 0
            fee_provided = config.MIN_FEE

        give_quantity = util.devise(db, args.give_quantity, args.give_asset, 'input')
        get_quantity = util.devise(db, args.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)
        json_print(bitcoin.transmit(unsigned_tx_hex, unsigned=args.unsigned))

    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))
コード例 #7
0
ファイル: server.py プロジェクト: chancecoin/chancecoin
 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)
コード例 #8
0
ファイル: test_.py プロジェクト: aQuant/counterpartyd
def test_order_to_be_cancelled ():
    unsigned_tx_hex = order.create(db, source_default, 'BBBBE', small, 'XCP', small, expiration, 0, config.MIN_FEE)

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
コード例 #9
0
ファイル: test_.py プロジェクト: aQuant/counterpartyd
def test_order_sell_xcp ():
    unsigned_tx_hex = order.create(db, source_default, 'XCP', round(small * 2.1), 'BTC', small, expiration, fee_required, config.MIN_FEE)

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
コード例 #10
0
ファイル: test_.py プロジェクト: aQuant/counterpartyd
def test_order_buy_xcp ():
    unsigned_tx_hex = order.create(db, source_default, 'BTC', small, 'XCP', small * 2, expiration, 0, fee_provided)

    parse_hex(unsigned_tx_hex)

    output_new[inspect.stack()[0][3]] = unsigned_tx_hex
コード例 #11
0
        # Fee argument is either fee_required or fee_provided, as necessary.
        fee = round(D(args.fee) * config.UNIT)
        if not give_id:
            fee_provided = fee
            assert fee_provided >= config.MIN_FEE
            fee_required = 0
        elif not get_id:
            fee_required = fee
            assert fee_required >= config.MIN_FEE
            fee_provided = config.MIN_FEE

        give_quantity = util.devise(args.give_quantity, give_id, 'input')
        get_quantity = util.devise(args.get_quantity, get_id, 'input')
        unsigned_tx_hex = order.create(args.source, give_id, round(give_quantity),
                                get_id, round(get_quantity),
                                args.expiration, fee_required, fee_provided)
        json_print(bitcoin.transmit(unsigned_tx_hex))

    elif args.action == 'btcpay':
        json_print(btcpay.create(args.order_match_id))

    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()
コード例 #12
0
ファイル: boottlexcp.py プロジェクト: bwknight/BoottleXCP
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)
コード例 #13
0
            fee_provided = config.MIN_FEE
            fee_required = util.devise(db, fee_required, 'fraction', 'input')
            fee_required = round(
                D(fee_required) * D(get_quantity) * D(config.UNIT))
        else:
            fee_required = 0
            fee_provided = config.MIN_FEE

        give_quantity = util.devise(db, give_quantity, args.give_asset,
                                    'input')
        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':
コード例 #14
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)