Skip to content

Commit

Permalink
fix tag
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Sep 24, 2023
1 parent 60fc842 commit 0255f04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions cashu/core/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ def __init__(self, tags: Optional[List[List[str]]] = None, **kwargs):
super().__init__(**kwargs)
self.__root__ = tags or []

def __setitem__(self, key: str, value: str) -> None:
if self.get_tag(key) is None:
def __setitem__(self, key: str, value: Union[str, List[str]]) -> None:
if isinstance(value, str):
self.__root__.append([key, value])
else:
for tag in self.__root__:
if tag[0] == key:
tag.append(value)
elif isinstance(value, list):
self.__root__.append([key, *value])

def __getitem__(self, key: str) -> Union[str, None]:
return self.get_tag(key)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_wallet_p2pk.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ def test_tags():
# set multiple values of the same key
tags["key3"] = "value3"
assert tags.get_tag_all("key3") == ["value3"]
tags["key3"] = "value4"
assert tags.get_tag_all("key3") == ["value3", "value4"]
tags["key4"] = ["value4", "value4_2"]
assert tags.get_tag_all("key4") == ["value4", "value4_2"]


@pytest.mark.asyncio
Expand Down

0 comments on commit 0255f04

Please sign in to comment.