Elaborating on the print_transactions() function

We define the print_transaction() function on line 81. We've made a few alterations to the function, starting on line 88 where we added an entry to log the current execution phase. Take a look at the following function:

081 def print_transactions(account):
082 """
083 The print_transaction function is responsible for presenting
084 transaction details to end user.
085 :param account: The JSON decoded account and transaction data
086 :return: Nothing
087 """
088 logging.info(
089 'Printing account and transaction data to console.')
090 print_header(account)
091 print('Transactions')
092 for i, tx in enumerate(account['txs']):
093 print('Transaction #{}'.format(i))
094 print('Transaction Hash:', tx['hash'])
095 print('Transaction Date: {}'.format(
096 unix.unix_converter(tx['time'])))

For the conditional statement starting on line 99, we add different cases using if, elif, and else statements to handle when the number of input values is greater than, equal to, or other than one. While rare, the first ever Bitcoin transaction, for example, had no input address. When an input address is absent, it's ideal to write a warning in the log that there are no detected inputs and print this information for the user, as follows:

097         for output in tx['out']:
098 inputs = get_inputs(tx)
099 if len(inputs) > 1:
100 print('{} --> {} ({:.8f} BTC)'.format(
101 ' & '.join(inputs), output['addr'],
102 output['value'] * 10**-8))
103 elif len(inputs) == 1:
104 print('{} --> {} ({:.8f} BTC)'.format(
105 ''.join(inputs), output['addr'],
106 output['value'] * 10**-8))
107 else:
108 logging.warn(
109 'Detected 0 inputs for transaction {}').format(
110 tx['hash'])
111 print('Detected 0 inputs for transaction.')
112
113 print('{:=^22}\n'.format(''))