示例#1
0
def balance_tuples(balances):
    balances_new = []
    if balances!=None:
        cha_supply = util.cha_supply(db)
        for balance in balances:
            burns = util.get_burns(db, source = balance['address'], validity='valid')
            burned = sum([burn['burned'] for burn in burns])
            balances_new.append((balance['address'],util.devise(db, balance['amount'], 'CHA', 'output'),util.devise(db, burned, 'BTC', 'output'), balance['amount']/cha_supply*100))
    return balances_new
示例#2
0
def balance_tuples(balances):
    balances_new = []
    if balances != None:
        cha_supply = util.cha_supply(db)
        for balance in balances:
            burns = util.get_burns(db,
                                   source=balance['address'],
                                   validity='valid')
            burned = sum([burn['burned'] for burn in burns])
            balances_new.append(
                (balance['address'],
                 util.devise(db, balance['amount'], 'CHA', 'output'),
                 util.devise(db, burned, 'BTC',
                             'output'), balance['amount'] / cha_supply * 100))
    return balances_new
    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')
            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.
示例#4
0
def get_address (db, address, start_block=None, end_block=None):
    address_dict = {}
    address_dict['balances'] = util.get_balances(db, address=address)

    address_dict['debits'] = util.get_debits(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['credits'] = util.get_credits(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['burns'] = util.get_burns(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['sends'] = util.get_sends(db, source=address, destination=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block, filterop='or')
    #^ with filterop == 'or', we get all sends where this address was the source OR destination 

    address_dict['orders'] = util.get_orders(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['order_matches'] = util.get_order_matches(db, address=address,
        order_by='tx0_block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['btcpays'] = util.get_btcpays(db,
        filters=[{'field': 'source', 'op': '==', 'value': address}, {'field': 'destination', 'op': '==', 'value': address}],
        filterop='or', order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['issuances'] = util.get_issuances(db, issuer=address,
        order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['broadcasts'] = util.get_broadcasts(db, source=address,
        order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bets'] = util.get_bets(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bet_matches'] = util.get_bet_matches(db, address=address,
        order_by='tx0_block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['dividends'] = util.get_dividends(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['cancels'] = util.get_cancels(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['callbacks'] = util.get_callbacks(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bet_expirations'] = util.get_bet_expirations(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['order_expirations'] = util.get_order_expirations(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bet_match_expirations'] = util.get_bet_match_expirations(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['order_match_expirations'] = util.get_order_match_expirations(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    return address_dict
示例#5
0
    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')
            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.
示例#6
0
def get_address (db, address, start_block=None, end_block=None):
    address_dict = {}
    address_dict['balances'] = util.get_balances(db, address=address)

    address_dict['debits'] = util.get_debits(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['credits'] = util.get_credits(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['burns'] = util.get_burns(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['sends'] = util.get_sends(db, source=address, destination=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block, filterop='or')
    #^ with filterop == 'or', we get all sends where this address was the source OR destination 

    address_dict['orders'] = util.get_orders(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['order_matches'] = util.get_order_matches(db, address=address,
        order_by='tx0_block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['btcpays'] = util.get_btcpays(db,
        filters=[{'field': 'source', 'op': '==', 'value': address}, {'field': 'destination', 'op': '==', 'value': address}],
        filterop='or', order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['issuances'] = util.get_issuances(db, issuer=address,
        order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['broadcasts'] = util.get_broadcasts(db, source=address,
        order_by='block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bets'] = util.get_bets(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bet_matches'] = util.get_bet_matches(db, address=address,
        order_by='tx0_block_index', order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['dividends'] = util.get_dividends(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['cancels'] = util.get_cancels(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['callbacks'] = util.get_callbacks(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bet_expirations'] = util.get_bet_expirations(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['order_expirations'] = util.get_order_expirations(db, source=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['bet_match_expirations'] = util.get_bet_match_expirations(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    address_dict['order_match_expirations'] = util.get_order_match_expirations(db, address=address, order_by='block_index',
        order_dir='asc', start_block=start_block, end_block=end_block)

    return address_dict