-
Notifications
You must be signed in to change notification settings - Fork 1
/
TxRecord.py
96 lines (75 loc) · 3.08 KB
/
TxRecord.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
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
93
94
95
96
# Bitclamp: a cryptocurrency-based publication tool
# Copyright (C) 2016 Joe Testa <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms version 3 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This class maintains information for an individual transaction, such as the
# TXID, redeem scripts, P2SH addresses, TXID and number of confirmations.
class TxRecord:
def __init__(self, redeem_scripts, p2sh_addresses, num_bytes):
self.redeem_scripts = redeem_scripts
self.p2sh_addresses = p2sh_addresses
self.num_bytes = num_bytes
self.txid = None
self.confirmations = 0
self.output_scripts = []
self.vout_nums = []
self.values = []
self.last_record = False
self.total_amount = -1.0
# Sets the TXID.
def set_txid(self, txid):
self.txid = txid
# Updates the number of confirmations. Note that this can decrease
# occasionally if blocks are rolled back.
def set_confirmations(self, confirmations):
self.confirmations = int(confirmations)
def add_output_script(self, output_script):
self.output_scripts.append(output_script)
def add_vout_num(self, vout_num):
self.vout_nums.append(vout_num)
def add_value(self, value):
self.values.append(value)
def get_txid(self):
return self.txid
def get_confirmations(self):
return self.confirmations
def get_output_scripts(self):
return self.output_scripts
def get_vout_nums(self):
return self.vout_nums
def get_values(self):
return self.values
def set_last_record(self):
self.last_record = True
def is_last_record(self):
return self.last_record
def get_total_amount(self):
return self.total_amount
def set_total_amount(self, amount):
self.total_amount = amount
# Returns a string representation of this TxRecord.
def __str__(self):
txid = self.txid
if txid is None:
txid = 'None'
vout_nums = ''
for vout_num in self.get_vout_nums():
vout_nums = vout_nums + "%d, " % vout_num
if len(vout_nums) > 2:
vout_nums = vout_nums[:-2]
values = ''
for value in self.get_values():
values = values + "%.8f, " % value
if len(values) > 2:
values = values[:-2]
return 'TxRecord: %s; Confirmations: %d; P2SH Addresses: %s; Output scripts: %s; vout nums: %s; Values: %s; Last Flag: %r' % (txid, self.confirmations, ', '.join(self.p2sh_addresses), ', '.join(self.output_scripts), vout_nums, values, self.last_record)