-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
42 lines (29 loc) · 1.09 KB
/
Main.py
File metadata and controls
42 lines (29 loc) · 1.09 KB
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
from BlockchainUtils import BlockchainUtils
from Wallet import Wallet
from TransactionPool import TransactionPool
from Blockchain import Blockchain
import pprint
if __name__ == '__main__':
sender = 'sender'
receiver = 'receiver'
amount = 1
type = 'TRANSFER'
wallet = Wallet()
pool = TransactionPool()
transaction = wallet.createTransaction(receiver, amount, type)
if not pool.transactionExists(transaction):
pool.addTransaction(transaction)
blockchain = Blockchain()
lastHash = BlockchainUtils.hash(
blockchain.blocks[-1].payload()
).hexdigest()
blockCount = blockchain.blocks[-1].blockCount + 1
block = wallet.createBlock(pool.transactions, lastHash, blockCount)
if not blockchain.lastBlockHashValid(block):
print('lastBlockHash is not valid')
if not blockchain.blockCountValid(block):
print('BlockCount is not valid')
if blockchain.lastBlockHashValid(block) and blockchain.blockCountValid(block):
blockchain.addBlock(block)
# blockchain.addBlock(block)
pprint.pprint(blockchain.toJson())