コード例 #1
0
def compose (db, source, quantity_per_unit, asset, dividend_asset):

    dividend_total, outputs, problems, fee = validate(db, source, quantity_per_unit, asset, dividend_asset, util.last_block(db)['block_index'])
    if problems: raise exceptions.ComposeError(problems)
    logging.info('Total quantity to be distributed in dividends: {} {}'.format(util.devise(db, dividend_total, dividend_asset, 'output'), dividend_asset))

    if dividend_asset == config.BTC:
        return (source, [(output['address'], output['dividend_quantity']) for output in outputs], None)

    asset_id = util.get_asset_id(asset, util.last_block(db)['block_index'])
    dividend_asset_id = util.get_asset_id(dividend_asset, util.last_block(db)['block_index'])
    data = struct.pack(config.TXTYPE_FORMAT, ID)
    data += struct.pack(FORMAT_2, quantity_per_unit, asset_id, dividend_asset_id)
    return (source, [], data)
コード例 #2
0
def compose (db, source, quantity_per_unit, asset, dividend_asset):

    dividend_total, outputs, problems, fee = validate(db, source, quantity_per_unit, asset, dividend_asset, util.last_block(db)['block_index'])
    if problems: raise exceptions.ComposeError(problems)
    logging.info('Total quantity to be distributed in dividends: {} {}'.format(util.devise(db, dividend_total, dividend_asset, 'output'), dividend_asset))

    if dividend_asset == config.BTC:
        return (source, [(output['address'], output['dividend_quantity']) for output in outputs], None)

    asset_id = util.get_asset_id(db, asset, util.last_block(db)['block_index'])
    dividend_asset_id = util.get_asset_id(db, dividend_asset, util.last_block(db)['block_index'])
    data = struct.pack(config.TXTYPE_FORMAT, ID)
    data += struct.pack(FORMAT_2, quantity_per_unit, asset_id, dividend_asset_id)
    return (source, [], data)
コード例 #3
0
def compose (db, source, fraction, asset):
    call_price, callback_total, outputs, problems = validate(db, source, fraction, asset, util.last_block(db)['block_time'], util.last_block(db)['block_index'], parse=False)
    if problems: raise exceptions.ComposeError(problems)
    logging.info('Total quantity to be called back: {} {}'.format(util.devise(db, callback_total, asset, 'output'), asset))

    asset_id = util.get_asset_id(asset, util.last_block(db)['block_index'])
    data = struct.pack(config.TXTYPE_FORMAT, ID)
    data += struct.pack(FORMAT, fraction, asset_id)
    return (source, [], data)
コード例 #4
0
ファイル: callback.py プロジェクト: ivanaszuber/counterpartyd
def compose (db, source, fraction, asset):
    call_price, callback_total, outputs, problems = validate(db, source, fraction, asset, util.last_block(db)['block_time'], util.last_block(db)['block_index'], parse=False)
    if problems: raise exceptions.ComposeError(problems)
    logging.info('Total quantity to be called back: {} {}'.format(util.devise(db, callback_total, asset, 'output'), asset))

    asset_id = util.get_asset_id(db, asset, util.last_block(db)['block_index'])
    data = struct.pack(config.TXTYPE_FORMAT, ID)
    data += struct.pack(FORMAT, fraction, asset_id)
    return (source, [], data)
コード例 #5
0
ファイル: order.py プロジェクト: evanwagner1/counterpartyd
def compose (db, source, give_asset, give_quantity, get_asset, get_quantity, expiration, fee_required):
    cursor = db.cursor()

    # Check balance.
    if give_asset != config.BTC:
        balances = list(cursor.execute('''SELECT * FROM balances WHERE (address = ? AND asset = ?)''', (source, give_asset)))
        if (not balances or balances[0]['quantity'] < give_quantity):
            raise exceptions.ComposeError('insufficient funds')

    problems = validate(db, source, give_asset, give_quantity, get_asset, get_quantity, expiration, fee_required, util.last_block(db)['block_index'])
    if problems: raise exceptions.ComposeError(problems)

    give_id = util.get_asset_id(db, give_asset, util.last_block(db)['block_index'])
    get_id = util.get_asset_id(db, get_asset, util.last_block(db)['block_index'])
    data = struct.pack(config.TXTYPE_FORMAT, ID)
    data += struct.pack(FORMAT, give_id, give_quantity, get_id, get_quantity,
                        expiration, fee_required)
    cursor.close()
    return (source, [], data)
コード例 #6
0
def compose (db, source, transfer_destination, asset, quantity, divisible, callable_, call_date, call_price, description):
    call_date, call_price, problems, fee, description, divisible = validate(db, source, transfer_destination, asset, quantity, divisible, callable_, call_date, call_price, description, util.last_block(db)['block_index'])
    if problems: raise exceptions.ComposeError(problems)

    asset_id = util.get_asset_id(asset, util.last_block(db)['block_index'])
    data = struct.pack(config.TXTYPE_FORMAT, ID)
    if len(description) <= 42:
        curr_format = FORMAT_2 + '{}p'.format(len(description) + 1)
    else:
        curr_format = FORMAT_2 + '{}s'.format(len(description))
    data += struct.pack(curr_format, asset_id, quantity, 1 if divisible else 0, 1 if callable_ else 0,
        call_date or 0, call_price or 0.0, description.encode('utf-8'))
    if transfer_destination:
        destination_outputs = [(transfer_destination, None)]
    else:
        destination_outputs = []
    return (source, destination_outputs, data)
コード例 #7
0
            total = util.devise(db, total, args.asset, 'output')
            divisible = True
            issuer = None
        elif args.asset == 'BTC':
            total = None
            divisible = True
            issuer = None
        else:
            issuances = util.get_issuances(db, validity='Valid', asset=args.asset)
            total = sum([issuance['amount'] for issuance in issuances])
            total = util.devise(db, total, args.asset, 'output')
            divisible = bool(issuances[-1]['divisible'])
            issuer = issuances[-1]['issuer'] # Issuer of last issuance.

        print('Asset Name:', args.asset)
        print('Asset ID:', util.get_asset_id(args.asset))
        print('Total Issued:', total)
        print('Divisible:', divisible)
        print('Issuer:', issuer)

    elif args.action == 'wallet':
        total_table = PrettyTable(['Asset', 'Balance'])
        totals = {}

        print()
        for group in bitcoin.rpc('listaddressgroupings', []):
            for bunch in group:
                address, btc_balance = bunch[:2]
                get_address = util.get_address(db, address=address)
                balances = get_address['balances']
                table = PrettyTable(['Asset', 'Balance'])
コード例 #8
0
                                'fraction', 'input'), args.asset],
           args.unsigned)


    # VIEWING (temporary)
    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':
        results = util.api('get_asset_info', ([args.asset],))[0]    # HACK
        asset_id = util.get_asset_id(args.asset)
        divisible = results['divisible']
        total_issued = util.devise(db, results['total_issued'], args.asset, dest='output')
        call_date = util.isodt(results['call_date']) if results['call_date'] else results['call_date']
        call_price = str(results['call_price']) + ' XCP' if results['call_price'] else results['call_price']

        print('Asset Name:', args.asset)
        print('Asset ID:', asset_id)
        print('Divisible:', divisible)
        print('Total Issued:', total_issued)
        print('Issuer:', results['issuer'])
        print('Callable:', results['callable'])
        print('Call Date:', call_date)
        print('Call Price:', call_price)
        print('Description:', '‘' + results['description'] + '’')
コード例 #9
0
            args.source,
            util.devise(db, args.fraction, 'fraction', 'input'), args.asset
        ], args.unsigned)

    # VIEWING (temporary)
    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':
        results = util.api('get_asset_info', [args.asset])
        asset_id = util.get_asset_id(args.asset)
        divisible = results['divisible']
        total_issued = util.devise(db,
                                   results['total_issued'],
                                   args.asset,
                                   dest='output')
        call_date = util.isodt(
            results['call_date']
        ) if results['call_date'] else results['call_date']
        call_price = str(results['call_price']) + ' XCP' if results[
            'call_price'] else results['call_price']

        print('Asset Name:', args.asset)
        print('Asset ID:', asset_id)
        print('Divisible:', divisible)
        print('Total Issued:', total_issued)
コード例 #10
0
    if not args.log_file: config.LOG = config.data_dir + '/counterparty.log'

    logging.basicConfig(filename=config.LOG, level=logging.INFO,
                        format='%(asctime)s %(message)s',
                        datefmt='%m-%d-%YT%I:%M:%S%z')
    requests_log = logging.getLogger("requests")
    requests_log.setLevel(logging.WARNING)

    # Do something.
    if args.version:
        print('This is Version 0.01 of counterparty.')

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

        asset_id = util.get_asset_id(args.asset)
        quantity = util.devise(args.quantity, asset_id, 'input')

        unsigned_tx_hex = send.create(args.source, args.destination,
                                      round(quantity), asset_id)
        json_print(bitcoin.transmit(unsigned_tx_hex))

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

        give_id = util.get_asset_id(args.give_asset)
        get_id = util.get_asset_id(args.get_asset)

        # Fee argument is either fee_required or fee_provided, as necessary.
        fee = round(D(args.fee) * config.UNIT)
        if not give_id:
コード例 #11
0
            total = util.devise(db, total, args.asset, 'output')
            divisible = True
            issuer = None
        elif args.asset == 'BTC':
            total = None
            divisible = True
            issuer = None
        else:
            issuances = util.get_issuances(db, validity='Valid', asset=args.asset)
            total = sum([issuance['amount'] for issuance in issuances])
            total = util.devise(db, total, args.asset, 'output')
            divisible = bool(issuances[-1]['divisible'])
            issuer = issuances[-1]['issuer'] # Issuer of last issuance.

        print('Asset Name:', args.asset)
        print('Asset ID:', util.get_asset_id(args.asset))
        print('Total Issued:', total)
        print('Divisible:', divisible)
        print('Issuer:', issuer)

    elif args.action == 'wallet':
        total_table = PrettyTable(['Asset', 'Balance'])
        totals = {}

        print()
        for group in bitcoin.rpc('listaddressgroupings', []):
            for bunch in group:
                address, btc_balance = bunch[:2]
                get_address = util.get_address(db, address=address)
                balances = get_address['balances']
                table = PrettyTable(['Asset', 'Balance'])