Skip to content

Commit

Permalink
changed out unicode characters that were causing the windows terminal to
Browse files Browse the repository at this point in the history
choke (i.e. it can't deal with printing unicode output). this should fix
several windows display errors
  • Loading branch information
xnova committed Jan 7, 2014
1 parent d522746 commit e749729
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 56 deletions.
21 changes: 11 additions & 10 deletions counterpartyd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python3


import os
import argparse
import json
Expand Down Expand Up @@ -192,12 +193,12 @@ def format_feed (feed):


if __name__ == '__main__':
# Parse commandline arguments.
# Parse command-line arguments.
parser = argparse.ArgumentParser(prog='counterpartyd', description='the reference implementation of the Counterparty protocol')
parser.add_argument('-V', '--version', action='version', version="counterpartyd v%s" % config.VERSION)

parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='sets log level to DEBUG instead of WARNING')
parser.add_argument('--force', action='store_true', help='dont check whether Bitcoind is caught up')
parser.add_argument('--force', action='store_true', help='don\'t check whether Bitcoind is caught up')
parser.add_argument('--testnet', action='store_true', help='use Bitcoin testnet addresses and block numbers')
parser.add_argument('--testcoin', action='store_true', help='use the test Counterparty network on every blockchain')

Expand All @@ -206,10 +207,10 @@ def format_feed (feed):
parser.add_argument('--config-file', help='the location of the configuration file')
parser.add_argument('--log-file', help='the location of the log file')

parser.add_argument('--rpc-connect', help='the hostname of the Bitcoind JSONRPC server')
parser.add_argument('--rpc-port', type=int, help='the port used to communicate with Bitcoind over JSONRPC')
parser.add_argument('--rpc-user', help='the username used to communicate with Bitcoind over JSONRPC')
parser.add_argument('--rpc-password', help='the password used to communicate with Bitcoind over JSONRPC')
parser.add_argument('--rpc-connect', help='the hostname of the Bitcoind JSON-RPC server')
parser.add_argument('--rpc-port', type=int, help='the port used to communicate with Bitcoind over JSON-RPC')
parser.add_argument('--rpc-user', help='the username used to communicate with Bitcoind over JSON-RPC')
parser.add_argument('--rpc-password', help='the password used to communicate with Bitcoind over JSON-RPC')

subparsers = parser.add_subparsers(dest='action', help='the action to be taken')

Expand All @@ -228,8 +229,8 @@ def format_feed (feed):
parser_order.add_argument('--give-quantity', metavar='GIVE_QUANTITY', required=True, help='the quantity of GIVE_ASSET that you are willing to give')
parser_order.add_argument('--give-asset', metavar='GIVE_ASSET', required=True, help='the asset that you would like to buy')
parser_order.add_argument('--expiration', metavar='EXPIRATION', type=int, required=True, help='the number of blocks for which the order should be valid')
parser_order.add_argument('--fee_required', metavar='FEE_REQUIRED', default=0, help='the miners fee required to be paid by orders for them to match this one; in BTC; required iff buying BTC (may be zero, though)')
parser_order.add_argument('--fee_provided', metavar='FEE_PROVIDED', default=(config.MIN_FEE / config.UNIT), help='the miners fee provided; in BTC; required iff selling BTC (should not be lower than is required for acceptance in a block)')
parser_order.add_argument('--fee_required', metavar='FEE_REQUIRED', default=0, help='the miners\' fee required to be paid by orders for them to match this one; in BTC; required iff buying BTC (may be zero, though)')
parser_order.add_argument('--fee_provided', metavar='FEE_PROVIDED', default=(config.MIN_FEE / config.UNIT), help='the miners\' fee provided; in BTC; required iff selling BTC (should not be lower than is required for acceptance in a block)')

parser_btcpay= subparsers.add_parser('btcpay', help='create and broadcast a *BTCpay* message, to settle an Order Match for which you owe BTC')
parser_btcpay.add_argument('--order-match-id', metavar='ORDER_MATCH_ID', required=True, help='the concatenation of the hashes of the two transactions which compose the order match')
Expand All @@ -238,7 +239,7 @@ def format_feed (feed):
parser_issuance.add_argument('--from', metavar='SOURCE', dest='source', required=True, help='the source address')
parser_issuance.add_argument('--transfer-asset-to', metavar='TRANSFER_DESTINATION', dest='transfer_destination', help='for transfer of ownership of asset issuance rights')
parser_issuance.add_argument('--quantity', metavar='QUANTITY', required=True, help='the quantity of ASSET to be issued')
parser_issuance.add_argument('--asset', metavar='ASSET', required=True, help='the name of the asset to be issued (if its available)')
parser_issuance.add_argument('--asset', metavar='ASSET', required=True, help='the name of the asset to be issued (if it\'s available)')
parser_issuance.add_argument('--divisible', action='store_true', help='whether or not the asset is divisible (must agree with previous issuances, if there are any)')

parser_broadcast = subparsers.add_parser('broadcast', help='broadcast textual and numerical information to the network')
Expand Down Expand Up @@ -278,7 +279,7 @@ def format_feed (feed):

parser_wallet = subparsers.add_parser('wallet', help='list the addresses in your Bitcoind wallet along with their balances in all Counterparty assets')

parser_market = subparsers.add_parser('market', help='fill the screen with an always up‐to‐date summary of the Counterparty market')
parser_market = subparsers.add_parser('market', help='fill the screen with an always up-to-date summary of the Counterparty market')
parser_market.add_argument('--give-asset', metavar='GIVE_ASSET', help='only show orders offering to sell GIVE_ASSET')
parser_market.add_argument('--get-asset', metavar='GET_ASSET', help='only show orders offering to buy GET_ASSET')

Expand Down
10 changes: 5 additions & 5 deletions lib/bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def create (db, source, feed_address, bet_type, deadline, wager_amount,
# Look at feed to be bet on.
broadcasts = util.get_broadcasts(db, validity='Valid', source=feed_address)
if not broadcasts:
raise exceptions.FeedError('That feed doesnt exist.')
raise exceptions.FeedError('That feed doesn\'t exist.')
elif not broadcasts[-1]['text']:
raise exceptions.FeedError('That feed is locked.')
elif broadcasts[-1]['timestamp'] >= deadline:
raise exceptions.FeedError('Deadline is in that feeds past.')
raise exceptions.FeedError('Deadline is in that feed\'s past.')

# Check for sufficient funds.
fee_multiplier = get_fee_multiplier(db, feed_address)
balances = util.get_balances(db, address=source, asset='XCP')
if not balances or balances[0]['amount'] < wager_amount * (1 + fee_multiplier / 1e8):
raise exceptions.BalanceError('Insufficient funds to both make wager and pay feed fee (in XCP). (Check that the database is up‐to‐date.)')
raise exceptions.BalanceError('Insufficient funds to both make wager and pay feed fee (in XCP). (Check that the database is up-to-date.)')

# Valid leverage level?
if leverage != 5040 and bet_type in (2,3): # Equal, NotEqual
Expand Down Expand Up @@ -88,7 +88,7 @@ def parse (db, tx, message):
elif not broadcasts[-1]['text']:
validity = 'Invalid: locked feed'
elif broadcasts[-1]['timestamp'] >= deadline:
validity = 'Invalid: deadline is in that feeds past'
validity = 'Invalid: deadline is in that feed\'s past'

# Leverage < 5040 is allowed.

Expand All @@ -112,7 +112,7 @@ def parse (db, tx, message):
else:
odds = 0

# Add parsed transaction to messagetype–specific table.
# Add parsed transaction to message-type–specific table.
bet_parse_cursor.execute('''INSERT INTO bets(
tx_index,
tx_hash,
Expand Down
4 changes: 2 additions & 2 deletions lib/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def get_inputs (source, total_btc_out, test=False):
return inputs, total_btc_in
return None, None

# Replace test flag with fake bitcoind JSONRPC server.
# Replace test flag with fake bitcoind JSON-RPC server.
def transaction (source, destination, btc_amount, fee, data, test=False):
# Validate addresses.
for address in (source, destination):
Expand All @@ -212,7 +212,7 @@ def transaction (source, destination, btc_amount, fee, data, test=False):
if not rpc('validateaddress', [source])['ismine']:
raise exceptions.InvalidAddressError('Not one of your Bitcoin addresses:', source)

# Check that the destination output isnt a dust output.
# Check that the destination output isn't a dust output.
if destination:
if not btc_amount >= config.DUST_SIZE:
raise exceptions.TXConstructionError('Destination output is below the dust target value.')
Expand Down
6 changes: 3 additions & 3 deletions lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def parse_block (db, block_index):
"""This is a separate function from follow() so that changing the parsing
rules doesnt require a full database rebuild. If parsing rules are changed
rules doesn't require a full database rebuild. If parsing rules are changed
(but not data identification), then just restart `counterparty.py follow`.
"""
Expand Down Expand Up @@ -311,7 +311,7 @@ def get_tx_info (tx):
vin_tx = bitcoin.rpc('getrawtransaction', [vin['txid'], 1]) # Get the full transaction data for this input transaction.
vout = vin_tx['vout'][vin['vout']]
fee += D(vout['value']) * config.UNIT
source_list.append(vout['scriptPubKey']['addresses'][0]) # Assume that the output was not not multisig.
source_list.append(vout['scriptPubKey']['addresses'][0]) # Assume that the output was not not multi-sig.
# Require that all possible source addresses be the same.
if all(x == source_list[0] for x in source_list): source = source_list[0]
else: source = None
Expand Down Expand Up @@ -375,7 +375,7 @@ def reorg (db):
reorg_cursor.execute('''DELETE FROM blocks WHERE block_index>=?''', (block_index,))
reorg_cursor.execute('''DELETE FROM transactions WHERE block_index>=?''', (block_index,))

# Reparse all transactions that are still there.
# Re-parse all transactions that are still there.
purge(db, quiet=True)

reorg_cursor.close()
Expand Down
22 changes: 11 additions & 11 deletions lib/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"""
Broadcast a message, with or without a price.
Multiple messages per block are allowed. Bets are be made on the timestamp
Multiple messages per block are allowed. Bets are be made on the 'timestamp'
field, and not the block index.
An address is a feed of broadcasts. Feeds (addresses) may be locked with a
broadcast containing a blank text field. Bets on a feed reference the address
broadcast containing a blank 'text' field. Bets on a feed reference the address
that is the source of the feed in an output which includes the (latest)
required fee.
Broadcasts without a price may not be used for betting. Broadcasts about events
with a small number of possible outcomes (e.g. sports games), should be
written, for example, such that a price of 1 XCP means one outcome, 2 XCP means
another, etc., which schema should be described in the text field.
another, etc., which schema should be described in the 'text' field.
fee_multipilier: .05 XCP means 5%. It may be greater than 1, however; but
because it is stored as a fourbyte integer, it may not be greater than about
because it is stored as a four-byte integer, it may not be greater than about
42.
"""

Expand Down Expand Up @@ -72,7 +72,7 @@ def parse (db, tx, message):
elif not timestamp > last_broadcast['timestamp']:
validity = 'Invalid: feed timestamps must be monotonically increasing'

# Add parsed transaction to messagetype–specific table.
# Add parsed transaction to message-type–specific table.
broadcast_parse_cursor.execute('''INSERT INTO broadcasts(
tx_index,
tx_hash,
Expand All @@ -99,8 +99,8 @@ def parse (db, tx, message):
if not text:
logging.info('Broadcast: {} locked his feed.'.format(tx['source'], util.short(tx['tx_hash'])))
else:
if not value: infix = '‘' + text + ''
else: infix = '‘' + text + '' + ' = ' + str(value)
if not value: infix = '\'' + text + '\''
else: infix = '\'' + text + '\'' + ' = ' + str(value)
suffix = ' from ' + tx['source'] + ' at ' + util.isodt(timestamp) + ' with a fee multiplier of {}'.format(util.devise(db, fee_multiplier, 'fee_multiplier', 'output')) + ' (' + util.short(tx['tx_hash']) + ')'
logging.info('Broadcast: {}'.format(infix + suffix))

Expand Down Expand Up @@ -159,17 +159,17 @@ def parse (db, tx, message):
bull_credit = total_escrow
bear_credit = 0
util.credit(db, bull_address, 'XCP', bull_credit)
validity = 'ForceLiquidated Bear'
validity = 'Force-Liquidated Bear'
elif bull_credit <= 0:
bull_credit = 0
bear_credit = total_escrow
util.credit(db, bear_address, 'XCP', bear_credit)
validity = 'ForceLiquidated Bull'
validity = 'Force-Liquidated Bull'

# Pay fee to feed.
util.credit(db, bet_match['feed_address'], 'XCP', fee)

logging.info('Contract ForceLiquidated: {} XCP credited to the bull, {} XCP credited to the bear, and {} XCP credited to the feed address ({})'.format(util.devise(db, bull_credit, 'XCP', 'output'), util.devise(db, bear_credit, 'XCP', 'output'), util.devise(db, fee, 'XCP', 'output'), util.short(bet_match_id)))
logging.info('Contract Force-Liquidated: {} XCP credited to the bull, {} XCP credited to the bear, and {} XCP credited to the feed address ({})'.format(util.devise(db, bull_credit, 'XCP', 'output'), util.devise(db, bear_credit, 'XCP', 'output'), util.devise(db, fee, 'XCP', 'output'), util.short(bet_match_id)))

# Settle.
if validity == 'Valid' and timestamp >= bet_match['deadline']:
Expand Down Expand Up @@ -208,7 +208,7 @@ def parse (db, tx, message):

logging.info('Contract Settled: {} won the pot of {} XCP; {} XCP credited to the feed address ({})'.format(winner, util.devise(db, total_escrow, 'XCP', 'output'), util.devise(db, fee, 'XCP', 'output'), util.short(bet_match_id)))

# Update the bet matchs status.
# Update the bet match's status.
broadcast_bet_match_cursor.execute('''UPDATE bet_matches \
SET validity=? \
WHERE (tx0_hash=? and tx1_hash=?)''',
Expand Down
6 changes: 3 additions & 3 deletions lib/btcpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LENGTH = 32 + 32

def create (db, order_match_id, test=False):
tx0_hash, tx1_hash = order_match_id[:64], order_match_id[64:] # UTF8 encoding means that the indices are doubled.
tx0_hash, tx1_hash = order_match_id[:64], order_match_id[64:] # UTF-8 encoding means that the indices are doubled.
tx0_hash_bytes, tx1_hash_bytes = binascii.unhexlify(bytes(tx0_hash, 'utf-8')), binascii.unhexlify(bytes(tx1_hash, 'utf-8'))
data = config.PREFIX + struct.pack(config.TXTYPE_FORMAT, ID)
data += struct.pack(FORMAT, tx0_hash_bytes, tx1_hash_bytes)
Expand Down Expand Up @@ -60,7 +60,7 @@ def parse (db, tx, message):

if validity == 'Valid':
# Credit source address for the currency that he bought with the bitcoins.
# BTC must be paid all at once and come from the correct address.
# BTC must be paid all at once and come from the 'correct' address.
if order_match['tx0_address'] == tx['source'] and tx['btc_amount'] >= order_match['forward_amount']:
btcpay_parse_cursor.execute('''UPDATE order_matches SET validity=? WHERE (tx0_hash=? AND tx1_hash=?)''', ('Valid', tx0_hash, tx1_hash))
if order_match['backward_asset'] != 'BTC':
Expand All @@ -73,7 +73,7 @@ def parse (db, tx, message):
validity = 'Paid'
logging.info('BTC Payment for Order Match: {} ({})'.format(util.short(order_match_id), util.short(tx['tx_hash'])))

# Add parsed transaction to messagetype–specific table.
# Add parsed transaction to message-type–specific table.
btcpay_parse_cursor.execute('''INSERT INTO btcpays(
tx_index,
tx_hash,
Expand Down
8 changes: 4 additions & 4 deletions lib/burn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
LENGTH = 11

def create (db, source, quantity, test=False, overburn=False):
# Try to make sure that the burned funds wont go to waste.
# Try to make sure that the burned funds won't go to waste.
block_count = bitcoin.rpc('getblockcount', [])
if block_count < config.BURN_START:
raise exceptions.UselessError('The proof‐of‐burn period has not yet begun.')
raise exceptions.UselessError('The proof-of-burn period has not yet begun.')
elif block_count > config.BURN_END:
raise exceptions.UselessError('The proof‐of‐burn period has already ended.')
raise exceptions.UselessError('The proof-of-burn period has already ended.')

# Check that a maximum of 1 BTC total is burned per address.
burns = util.get_burns(db, address=source, validity='Valid')
Expand Down Expand Up @@ -66,7 +66,7 @@ def parse (db, tx, message=None):
if validity == 'Valid':
util.credit(db, tx['source'], 'XCP', earned)

# Add parsed transaction to messagetype–specific table.
# Add parsed transaction to message-type–specific table.
# TODO: store sent in table
burn_parse_cursor.execute('''INSERT INTO burns(
tx_index,
Expand Down
2 changes: 1 addition & 1 deletion lib/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse (db, tx, message):

logging.info('Cancel: {} ({})'.format(util.short(offer_hash), util.short(tx['tx_hash'])))

# Add parsed transaction to messagetype–specific table.
# Add parsed transaction to message-type–specific table.
cancel_parse_cursor.execute('''INSERT INTO cancels(
tx_index,
tx_hash,
Expand Down
4 changes: 2 additions & 2 deletions lib/dividend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create (db, source, amount_per_share, asset, test=False):
balances = util.get_balances(db, address=source, asset='XCP')
if not balances or balances[0]['amount'] < amount:
print(balances[0]['amount'], amount)
raise exceptions.BalanceError('Insufficient funds. (Check that the database is up‐to‐date.)')
raise exceptions.BalanceError('Insufficient funds. (Check that the database is up-to-date.)')
if not issuances:
raise exceptions.DividendError('No such asset: {}.'.format(asset))
if not amount_per_share:
Expand Down Expand Up @@ -75,7 +75,7 @@ def parse (db, tx, message):
amount = address_amount * amount_per_share
util.credit(db, address, 'XCP', amount)

# Add parsed transaction to messagetype–specific table.
# Add parsed transaction to message-type–specific table.
dividend_parse_cursor.execute('''INSERT INTO dividends(
tx_index,
tx_hash,
Expand Down
6 changes: 3 additions & 3 deletions lib/issuance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create (db, source, destination, asset, amount, divisible, test=False):
if not util.valid_asset_name(asset):
raise exceptions.AssetError('Bad asset name.')

# Valid reissuance?
# Valid re-issuance?
issuances = util.get_issuances(db, validity='Valid', asset=asset)
if issuances:
last_issuance = issuances[-1]
Expand Down Expand Up @@ -52,7 +52,7 @@ def parse (db, tx, message):
if validity == 'Valid' and not util.valid_asset_name(asset):
validity = 'Invalid: bad asset name'

# Valid reissuance?
# Valid re-issuance?
if validity == 'Valid':
issuances = util.get_issuances(db, validity='Valid', asset=asset)
if issuances:
Expand Down Expand Up @@ -80,7 +80,7 @@ def parse (db, tx, message):
issuer = tx['source']
transfer = False

# Add parsed transaction to messagetype–specific table.
# Add parsed transaction to message-type–specific table.
issuance_parse_cursor.execute('''INSERT INTO issuances(
tx_index,
tx_hash,
Expand Down
Loading

0 comments on commit e749729

Please sign in to comment.