Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/mininode.py
Show First 20 Lines • Show All 400 Lines • ▼ Show 20 Lines | def deserialize(self, f): | ||||
self.nLockTime = struct.unpack("<I", f.read(4))[0] | self.nLockTime = struct.unpack("<I", f.read(4))[0] | ||||
self.sha256 = None | self.sha256 = None | ||||
self.hash = None | self.hash = None | ||||
def billable_size(self): | def billable_size(self): | ||||
""" | """ | ||||
Returns the size used for billing the against the transaction | Returns the size used for billing the against the transaction | ||||
""" | """ | ||||
return len(self.serialize()) | # We need a heuristic for unsigned transactions as they do not yet | ||||
# include the pubkey hash, or the signature. | |||||
tx_size = 10 # base transaction overhead | |||||
for vin in self.vin: | |||||
# Max of sig + p2kh, or the actual size if it's more. | |||||
tx_size += max(len(ToHex(vin))//2, 147) | |||||
for vout in self.vout: | |||||
# Include the sizes for the outputs. | |||||
tx_size += len(ToHex(vout))//2 | |||||
tx_size += (len(self.vout) - len(self.vin))*1790 | |||||
return max(tx_size, 10 + 34 * len(self.vout)) | |||||
def serialize(self): | def serialize(self): | ||||
r = b"" | r = b"" | ||||
r += struct.pack("<i", self.nVersion) | r += struct.pack("<i", self.nVersion) | ||||
r += ser_vector(self.vin) | r += ser_vector(self.vin) | ||||
r += ser_vector(self.vout) | r += ser_vector(self.vout) | ||||
r += struct.pack("<I", self.nLockTime) | r += struct.pack("<I", self.nLockTime) | ||||
return r | return r | ||||
▲ Show 20 Lines • Show All 1,356 Lines • Show Last 20 Lines |