Skip to content

Commit

Permalink
Create data_provenance.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jun 1, 2024
1 parent 189010d commit f06e12e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions blockchain/data_provenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import hashlib
from blockchain import Blockchain

class DataProvenance(object):
def __init__(self, blockchain):
self.blockchain = blockchain

def add_data(self, data):
data_hash = hashlib.sha256(data.encode()).hexdigest()
new_block = self.blockchain.create_block(1, self.blockchain.chain[-1]["hash"])
new_block["data"] = data_hash
self.blockchain.chain.append(new_block)
return new_block

def get_data_provenance(self, data_hash):
for block in self.blockchain.chain:
if block["data"] == data_hash:
return block
return None

0 comments on commit f06e12e

Please sign in to comment.