forked from nickspanos/riverhead
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslide_short3
More file actions
37 lines (32 loc) · 1.19 KB
/
slide_short3
File metadata and controls
37 lines (32 loc) · 1.19 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
import hashlib
import json
import time
from typing import Dict, List, Optional, Tuple
# Assuming you have access to the shorthash function and the required library has been imported
from slidechain import shorthash
class Block:
def __init__(
self, index: int, timestamp: int, data: str, previous_hash: str, nonce: int
):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
self.nonce = nonce
self.payload_hash = self.compute_payload_hash()
def compute_payload_hash(self) -> str:
payload_string = json.dumps(self.data, sort_keys=True)
return shorthash(payload_string.encode()) # Use the shorthash function for payload hashing
def hash(self) -> str:
block_string = json.dumps(
{
"index": self.index,
"timestamp": self.timestamp,
"payload_hash": self.payload_hash,
"previous_hash": self.previous_hash,
"nonce": self.nonce,
},
sort_keys=True,
)
return hashlib.sha256(block_string.encode()).hexdigest()
# Rest of the code remains the same.