| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import sys
- import hashlib
- # Constants
- GENESIS_STR = 'This is the genesis hash'
- # Specify buffer size
- BUF_SIZE = 65536 # 64kB chunks!
- # Init objects
- sha256 = hashlib.sha256()
- def hashfile(filename):
- with open(filename, 'rb') as f:
- while True:
- data = f.read(BUF_SIZE)
- if not data:
- break
- sha256.update(data)
- return sha256.hexdigest
- def hashdata(data):
- sha256 = hashlib.sha256(data.encode())
- return sha1.hexdigest
- # Constant!
- GENESIS_HASH = hashdata(GENESIS_STR)
- # sample txstring
- txstring = '[13e36dd45bc4115a7ddab608d9ca26fdb951d0ff74631c554f2c3653b58e8a31, datetime, 1, 3, 40304.50]'
- def gen_txhash(txstring):
- # Generates a transaction hash from
- # transaction data
- # Return new transaction hash
- return hashdata(txstring)
- def append_tx(txhash, pbhash):
- # Takes transaction hash and
- # appends to previous block hash
- inputs = f'[{pbhash}, {txhash}]'
- # Return new block hash
- return hashdata(inputs)
|