-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutxo.py
48 lines (40 loc) · 1.42 KB
/
utxo.py
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
from Crypto.Random.random import getrandbits
from utils import create_logger
logger = create_logger(__name__)
class TransactionInput:
def __init__(self, *args, **kwargs):
'''
previousOutputId: string
amount: int
'''
self.previousOutputId = kwargs['previousOutputId']
self.amount = kwargs['amount'] # maybe not needed
def serialize(self):
return {'previousOutputId': self.previousOutputId,
'amount': self.amount}
class TransactionOutput:
def __init__(self, *args, **kwargs):
'''
amount: int
transaction_id: int
address: bytes
id: int
'''
self.amount = kwargs['amount']
self.transaction_id = kwargs['transaction_id']
# id from transaction that this utxo came from
if kwargs.get('id', None) is not None:
# Got a JSON object
self.id = kwargs['id'] # maybe int() is needed
self.address = (kwargs['address']).encode()
else:
self.id = getrandbits(256) # some number ?? random
self.address = kwargs['address'] # to who this utxo is going ,
# if it's change: sender_address else: receiver_address
def serialize(self):
return{
'amount': self.amount,
'id': self.id,
'transaction_id': self.transaction_id,
'address': self.address.decode()
}