Skip to content

Commit ab7a58b

Browse files
author
SharmaMohit
committed
Basic Pruning + Adding README
1 parent c8144d9 commit ab7a58b

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

BlockChain.py

+5-14
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,33 @@ def getCurrentBlock(self):
2323
currentBlock = self.chain[-1]
2424
return currentBlock
2525

26-
# def addNewBlock(self, sender, receiver, amount):
27-
# currentBlock = self.getCurrentBlock()
28-
# currTime = str(datetime.now())
29-
# newTransaction = Transaction(sender, receiver, amount, currTime)
30-
# newBlock = Block(currTime, newTransaction, currentBlock.currentHash)
31-
# newBlock.mineBlock(BlockChain.difficulty)
32-
# self.chain.append(newBlock)
33-
3426
def minePendingTransactions(self, minerRewardAddress):
3527
currTime = str(datetime.now())
3628
newBlock = Block(currTime, self.pendingTransactions)
3729
newBlock.mineBlock(BlockChain.difficulty)
3830
self.chain.append(newBlock)
39-
self.pendingTransactions = [Transaction(None, minerRewardAddress, self.miningReward)]
31+
self.pendingTransactions = [Transaction(
32+
None, minerRewardAddress, self.miningReward)]
4033

4134
def addTransaction(self, newTransaction):
4235
self.pendingTransactions.append(newTransaction)
43-
4436

4537
def getBalanceMiner(self, minerAddress):
46-
balance = 0;
38+
balance = 0
4739
for block in self.chain:
4840
for trans in block.transactions:
4941
if trans.getSenderAddress() == minerAddress:
5042
balance -= trans.amount
5143
if trans.getReceiverAddress() == minerAddress:
5244
balance += trans.amount
5345
return balance
54-
46+
5547
def getAllTransaction(self):
5648
for trans in self.pendingTransactions:
5749
print(trans.getSenderAddress())
5850
print(trans.getReceiverAddress())
59-
print(trans.getAmount(), "\n")
51+
print(trans.getAmount(), "\n")
6052

61-
6253
def verifyIntegity(self):
6354
for i in range(1, len(self.chain)):
6455
prevBlock = self.chain[i-1]

HashGenerator.py

-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@
88
def HashGenerator(input):
99
result = hashlib.sha256(input.encode())
1010
return result.hexdigest()
11-
12-

Main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
bc.minePendingTransactions("Mohit")
1010
print(bc.getBalanceMiner("Mohit"))
1111
bc.minePendingTransactions("Mohit")
12-
print(bc.getBalanceMiner("Mohit"))
12+
print(bc.getBalanceMiner("Mohit"))

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h1> Basic Implementation of Blockchain</h1>
2+
<h3> Still in progress </h3>
3+
4+
<ol>
5+
<li> Transaction Format (Done) </li>
6+
<li> Hash Generaton (Done) </li>
7+
<li> Block struture + slockchain Structure implementation </li>
8+
<li> Key Generator (Incomplete).
9+
<ul>
10+
<li> Code to implement generation of public key and private key. </li>
11+
<li> Code to sign a transaction with user's private key. </li>
12+
<li> Code to validate the sign with public key. <li>
13+
</ul>
14+
</li>
15+
</ol>

Transaction.py

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ def __init__(self, senderAddress, receiverAddress, amount):
1515
def createHash(self):
1616
return HashGenerator(self.senderAdress + self.receiverAddress + self.amount + self.txnDateTime)
1717

18-
# def signTransaction(self, signingKey):
19-
# hashTxn = self.createHash()
20-
# sign = signingKey.sign()
21-
2218
def getSenderAddress(self):
2319
return self.senderAdress
2420

0 commit comments

Comments
 (0)