Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ def get_tx_count(tx_list):
Input: List of transaction IDs (strings)
Output: Integer count
"""
return len(tx_list)


def filter_large_txids(tx_list, min_length):
"""
TODO: Return a list of txids with length greater than or equal to min_length.
Input: List of txids (strings), minimum length (int)
Output: Filtered list of strings
"""
return [txid for txid in tx_list if len(txid) >= min_length]


def process_txids(tx_list):
"""
Expand All @@ -19,6 +23,13 @@ def process_txids(tx_list):
Input: List of txids (strings)
Output: List of (int, string) tuples
"""
result = []
for i, txid in enumerate(tx_list):
if not txid.startswith('tx'):
continue
result.append((i, txid))
return result


def example_while_loop(limit):
"""
Expand All @@ -27,13 +38,25 @@ def example_while_loop(limit):
Input: Integer limit
Output: List of integers
"""
result = []
i = 0
while i < limit:
if i == 5:
break
result.append(i)
i += 1
return result


def unpack_tuple(block_header):
"""
TODO: Unpack the tuple representing a Bitcoin block header (height, previous hash, timestamp).
Input: Tuple (int, str, int)
Output: Unpacked tuple values
"""
height, prev_hash, timestamp = block_header
return height, prev_hash, timestamp


def dict_methods_example(block):
"""
Expand All @@ -42,13 +65,18 @@ def dict_methods_example(block):
Input: Dict
Output: Tuple of (list, list, list)
"""
return list(block.keys()), list(block.values()), list(block.items())


def multiple_assignment(a, b):
"""
TODO: Demonstrate multiple assignments and swapping two variables.
Input: two integers
Output: Tuple of two ints (swapped)
"""
a, b = b, a
return a, b


def set_example(addresses):
"""
Expand All @@ -57,46 +85,63 @@ def set_example(addresses):
Input: List of strings
Output: Set of strings
"""
return set(addresses)


class BitcoinTransaction:
def __init__(self, txid, amount):
"""
TODO: Initialize transaction with txid (string) and amount (float).
"""
self.txid = txid
self.amount = amount

def __str__(self):
"""
TODO: Return string representation: "Tx {txid} of {amount} BTC"
"""
return f"Tx {self.txid} of {self.amount} BTC"


class Wallet:
def __init__(self):
"""
TODO: Initialize an empty list to hold transactions.
"""
self.transactions = []

def add_tx(self, tx):
"""
TODO: Add a BitcoinTransaction to the wallet's transaction list.
"""
self.transactions.append(tx)

def total_balance(self):
"""
TODO: Calculate and return the sum of amounts of all transactions.
Output: Float
"""
return sum(tx.amount for tx in self.transactions)



def txid_generator(tx_list):
"""
TODO: Yield each txid from the list one by one.
Input: List of strings
"""
def txid_generator(tx_list):

for txid in tx_list:
yield txid


def filter_txids_gen(tx_list, prefix="tx"):
"""
TODO: Yield txids from list that start with given prefix.
Default prefix is 'tx'.
Input: List of strings, prefix string
"""
def filter_txids_gen(tx_list, prefix="tx"):

for txid in tx_list:
if txid.startswith(prefix):
yield txid