-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
92 lines (79 loc) · 2.56 KB
/
main.py
File metadata and controls
92 lines (79 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from typing import Dict, Tuple, List, Generator, Set
def parse_txid(txid: str) -> tuple:
"""
Converts a hexadecimal txid string into a tuple of byte pairs.
Example: 'deadbeef' -> ('de', 'ad', 'be', 'ef')
"""
# TODO: Return a tuple of 2-character segments from txid
pass
def create_utxo(txid: str, vout: int, amount: int) -> dict:
"""
Creates a dictionary representing a UTXO with the given txid, vout, and amount.
"""
# TODO: Return a dict with keys 'txid', 'vout', and 'amount'
pass
def update_utxo(utxo: dict, new_amount: int) -> None:
"""
Updates the 'amount' field in a UTXO dictionary to a new value.
"""
# TODO: Use update to set new 'amount'
pass
def unpack_utxo(utxo: dict) -> str:
"""
Unpacks a UTXO dictionary and returns a formatted string representation.
"""
# TODO: Unpack the dictionary and return formatted string
pass
def swap_addresses(addr1: str, addr2: str) -> tuple:
"""
Swaps two Bitcoin addresses and returns them in reversed order.
"""
# TODO: Swap the values and return as tuple
pass
def unique_addresses(addresses: list) -> set:
"""
Returns a set of unique Bitcoin addresses from the provided list.
"""
# TODO: Convert the list to a set
pass
class BitcoinWallet:
def __init__(self):
"""
Initializes the wallet with an empty UTXO set.
"""
def add_utxo(self, utxo: Dict) -> None:
"""
Adds a UTXO to the wallet using a unique txid:vout key.
"""
# TODO: Create key from 'txid' and 'vout', store UTXO in self.utxos
pass
def get_balance(self) -> float:
"""
Returns the total balance of all UTXOs in the wallet.
"""
# TODO: Sum the 'amount' of all UTXOs
pass
class TransactionPool:
def __init__(self):
"""
Initializes an empty transaction pool.
"""
def add_transaction(self, txid: str) -> bool:
"""
Adds a txid to the transaction pool.
Returns True if it was not already present, False otherwise.
"""
# TODO: Check for presence and add if not present
pass
def get_pool_size(self) -> int:
"""
Returns the total number of unique transactions in the pool.
"""
# TODO: Return length of tx_pool
pass
def block_height_generator(start: int, end: int) -> Generator[int, None, None]:
"""
Yields block heights from start to end (exclusive).
"""
# TODO: Use a generator loop to yield block heights
pass