added fees to mining reward
This commit is contained in:
parent
ded8b0f1f7
commit
ed41cde4c2
@ -104,9 +104,11 @@ class Tx:
|
||||
self.add_reqd(reqd)
|
||||
self.sign(private_ser)
|
||||
|
||||
def createRewardTransaction(self, public_ser, private_ser, type):
|
||||
value = type == "MINE" and MINE_REWARD_VALUE or REGISTRATION_REWARD_VALUE
|
||||
self.add_output(public_ser, value)
|
||||
def createRewardTransaction(self, public_ser, private_ser, type, fee = 0):
|
||||
if type == "MINE":
|
||||
self.add_output(public_ser, MINE_REWARD_VALUE + fee)
|
||||
else:
|
||||
self.add_output(public_ser, REGISTRATION_REWARD_VALUE)
|
||||
self.type = REWARD
|
||||
self.sign(private_ser)
|
||||
|
||||
|
@ -132,9 +132,10 @@ def createBlock(self):
|
||||
fees[x] = transaction.inputs[0][1] - transaction.outputs[0][1]
|
||||
x+=1
|
||||
|
||||
print(fees)
|
||||
fees_list = list(fees.keys())
|
||||
selected_transactions = fees_list[-2:]
|
||||
available_transactions = fees_list[:-2]
|
||||
selected_transactions = fees_list[:2]
|
||||
available_transactions = fees_list[2:]
|
||||
|
||||
# print fees with values and keys if key is in available_transactions
|
||||
for key, value in fees.items():
|
||||
@ -261,8 +262,16 @@ def validateMinedBlock(self):
|
||||
|
||||
if new_block.metadata['true_validations'] >= 3:
|
||||
new_block.metadata['validated'] = True
|
||||
# get fees from transactions in block
|
||||
fees = 0
|
||||
for transaction in new_block.data:
|
||||
if transaction.type != 1:
|
||||
fees += transaction.inputs[0][1] - transaction.outputs[0][1]
|
||||
|
||||
new_reward = Tx()
|
||||
new_reward.createRewardTransaction(self.user.public_ser, self.user.private_ser, "MINE")
|
||||
new_reward.createRewardTransaction(self.user.public_ser, self.user.private_ser, "MINE", fees)
|
||||
utilityHelper.saveFile("../data/transaction_pool.dat", new_reward)
|
||||
|
||||
|
||||
try:
|
||||
del blocks[-1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user