Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Apply dummy last key to VarDB
Browse files Browse the repository at this point in the history
* Add DUMMY to KeyType class
  • Loading branch information
goldworm committed Nov 11, 2020
1 parent bd5da74 commit 196847a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion iconservice/iconscore/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class KeyType(Enum):
SUB = auto()

ARRAY_SIZE = auto()
DUMMY = auto()
LAST = auto()


Expand Down Expand Up @@ -170,7 +171,8 @@ def _get_container_final_key_with_pipe(self, last_key: Key) -> List[bytes]:
keys.append(self._tag.value)
keys.append(key.value)

keys.append(last_key.value)
if last_key.type != KeyType.DUMMY:
keys.append(last_key.value)

return keys

Expand Down
10 changes: 7 additions & 3 deletions iconservice/iconscore/icon_container_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class VarDB(object):
:K: [int, str, Address, bytes]
:V: [int, str, Address, bytes, bool]
"""
_DUMMY_LAST_KEY = Key(b"", KeyType.DUMMY)

def __init__(self, var_key: K, db: 'IconScoreDatabase', value_type: type) -> None:
# Use var_key as a db prefix in the case of VarDB
Expand All @@ -297,21 +298,24 @@ def set(self, value: V) -> None:
:param value: a value to be set
"""
byte_value = ContainerUtil.encode_value(value)
self._db.put(b"", byte_value)
self._db.put(self._DUMMY_LAST_KEY, byte_value)

def get(self) -> Optional[V]:
"""
Gets the value
:return: value of the var db
"""
return ContainerUtil.decode_object(self._db.get(b""), self.__value_type)
return ContainerUtil.decode_object(
self._db.get(self._DUMMY_LAST_KEY),
self.__value_type
)

def remove(self) -> None:
"""
Deletes the value
"""
self._db.delete(b"")
self._db.delete(self._DUMMY_LAST_KEY)


def get_default_value(value_type: type) -> Any:
Expand Down

0 comments on commit 196847a

Please sign in to comment.