forked from hyperledger/indy-plenum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.py
81 lines (66 loc) · 2.1 KB
/
state.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from abc import abstractmethod
from typing import Optional
class State:
@abstractmethod
def set(self, key: bytes, value: bytes):
raise NotImplementedError
@abstractmethod
def get(self, key: bytes, isCommitted: bool=True) -> Optional[bytes]:
# If `isCommitted` is True then get value corresponding to the
# committed state else get the latest value
raise NotImplementedError
@abstractmethod
def get_for_root_hash(self, root_hash, key: bytes) -> Optional[bytes]:
'''
Gets a value corresponded to the key for a given root_hash
:param root_hash: a hash of the root get the value for
:param key: a key in the trie corresponded to the root
:return: a value (in bytes) or None
'''
raise NotImplementedError
@abstractmethod
def remove(self, key: bytes):
raise NotImplementedError
@abstractmethod
def commit(self, rootHash=None, rootNode=None):
raise NotImplementedError
@abstractmethod
def revertToHead(self, headHash=None):
# Revert to the given head
raise NotImplementedError
@abstractmethod
def close(self):
raise NotImplementedError
@property
@abstractmethod
def head(self):
# The current head of the state, if the state is a merkle tree then
# head is the root
raise NotImplementedError
@property
@abstractmethod
def committedHead(self):
# The committed head of the state, if the state is a merkle tree then
# head is the root
raise NotImplementedError
@property
@abstractmethod
def headHash(self):
"""
The hash of the current head of the state, if the state is a merkle
tree then hash of the root
:return:
"""
raise NotImplementedError
@property
@abstractmethod
def committedHeadHash(self):
raise NotImplementedError
@property
@abstractmethod
def closed(self):
raise NotImplementedError
@property
@abstractmethod
def isEmpty(self):
raise NotImplementedError