TODO fix isvalid function

This commit is contained in:
Ryan Bakkes 2023-11-08 13:43:02 +01:00
parent bdad62d2e2
commit 1f492c8a29

View File

@ -4,6 +4,7 @@ NORMAL = 0
REWARD = 1 REWARD = 1
from helpers import SignatureHelper as Signature from helpers import SignatureHelper as Signature
from helpers import UtilityHelper as utilityHelper
class Tx: class Tx:
def __init__(self, type = NORMAL): def __init__(self, type = NORMAL):
@ -24,18 +25,19 @@ class Tx:
self.reqd.append(addr) self.reqd.append(addr)
def sign(self, private): def sign(self, private):
ser = Signature.privateBytesToKey(private)
message = self.__gather() message = self.__gather()
newsig = Signature.sign(message, private) newsig = Signature.sign(message, ser)
self.sigs.append(newsig) self.sigs.append(newsig)
def is_valid(self): def is_valid(self):
# if self.type == REWARD: if self.type == REWARD:
# if len(self.inputs)!=0 and len(self.outputs)!=1: if len(self.inputs)!=0 and len(self.outputs)!=1:
# return False return False
# return True return True
# else: else:
# total_in = 0 # total_in = 0
# total_out = 0 # total_out = 0
# message = self.__gather() # message = self.__gather()
@ -94,17 +96,17 @@ class Tx:
return repr_str return repr_str
def createTransaction(self, public_key, private_key, amount, fee, recipient, reqd = None, type = NORMAL): def createTransaction(self, public_ser, private_ser, amount, fee, recipient, reqd = None, type = NORMAL):
self.add_input(public_key, amount + fee) self.add_input(public_ser, amount + fee)
self.add_output(recipient, amount) self.add_output(recipient, amount)
self.type = type self.type = type
if reqd != None: if reqd != None:
self.add_reqd(reqd) self.add_reqd(reqd)
self.sign(private_key) self.sign(private_ser)
def createRewardTransaction(self, public_key, private_key, type): def createRewardTransaction(self, public_ser, private_ser, type):
value = type == "mine" and MINE_REWARD_VALUE or REGISTRATION_REWARD_VALUE value = type == "MINE" and MINE_REWARD_VALUE or REGISTRATION_REWARD_VALUE
self.add_output(public_key, value) self.add_output(public_ser, value)
self.type = REWARD self.type = REWARD
self.sign(private_key) self.sign(private_ser)