Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The `main` function demonstrates how to create, extend, and query entities:

- Subscribes to log events from the network (create, update, delete, extend).

- Creates an entity with data `"hello"`, TTL of `60`, and an annotation of `("foo", "bar")`.
- Creates an entity with data `"hello"`, BTL of `60`, and an annotation of `("foo", "bar")`.

- Prints various metadata and state:

Expand Down
2 changes: 1 addition & 1 deletion example/nix/packages/golem-base-sdk-example.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let

pythonSet =
(pkgs.callPackage inputs.pyproject-nix.build.packages {
python = pkgs.python312;
python = pkgs.python310;
}).overrideScope
(
lib.composeManyExtensions [
Expand Down
2 changes: 1 addition & 1 deletion example/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
]
version = "0.0.1"
license = "GPL-3.0-only"
requires-python = ">=3.12"
requires-python = ">=3.10"
dynamic = ["description"]
classifiers = ["Private :: Do Not Upload"]

Expand Down
1,189 changes: 915 additions & 274 deletions example/uv.lock

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions golem_base_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,9 @@ async def _send_gb_transaction(
await self.http_client().eth.call(txData)
except Web3RPCError as e:
if e.rpc_response:
error = e.rpc_response["error"]["message"]
raise Exception(
f"Error while processing transaction: {
e.rpc_response['error']['message']
}"
f"Error while processing transaction: {error}"
) from e
else:
raise e
Expand Down
19 changes: 13 additions & 6 deletions golem_base_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from dataclasses import dataclass
from typing import (
Any,
Generic,
NewType,
override,
TypeVar,
)

from eth_typing import ChecksumAddress, HexStr
Expand All @@ -27,8 +28,9 @@ def as_address(self) -> ChecksumAddress:
"""Convert this instance to a `eth_typing.ChecksumAddress`."""
return AsyncWeb3.to_checksum_address(self.as_hex_string())

@override
# @override
def __repr__(self) -> str:
"""Encode bytes as a string."""
return f"{type(self).__name__}({self.as_hex_string()})"

@staticmethod
Expand All @@ -44,15 +46,20 @@ def from_hex_string(hexstr: str) -> "GenericBytes":
Address = NewType("Address", GenericBytes)


# TODO: use new generic syntax once we can bump to python 3.12 or higher
V = TypeVar("V")


@dataclass(frozen=True)
class Annotation[V]:
class Annotation(Generic[V]):
"""Class to represent generic annotations."""

key: str
value: V

@override
# @override
def __repr__(self) -> str:
"""Encode annotation as a string."""
return f"{type(self).__name__}({self.key} -> {self.value})"


Expand All @@ -61,7 +68,7 @@ class GolemBaseCreate:
"""Class to represent a create operation in Golem Base."""

data: bytes
ttl: int
btl: int
string_annotations: Sequence[Annotation[str]]
numeric_annotations: Sequence[Annotation[int]]

Expand All @@ -72,7 +79,7 @@ class GolemBaseUpdate:

entity_key: EntityKey
data: bytes
ttl: int
btl: int
string_annotations: Sequence[Annotation[str]]
numeric_annotations: Sequence[Annotation[int]]

Expand Down
9 changes: 6 additions & 3 deletions golem_base_sdk/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utility methods."""

import logging
from typing import TypeVar

import rlp

Expand All @@ -15,8 +16,10 @@

def rlp_encode_transaction(tx: GolemBaseTransaction) -> bytes:
"""Encode a Golem Base transaction in RLP."""
# TODO: use new generic syntax once we can bump to python 3.12 or higher
T = TypeVar("T")

def format_annotation[T](annotation: Annotation[T]) -> tuple[str, T]:
def format_annotation(annotation: Annotation[T]) -> tuple[str, T]:
return (annotation.key, annotation.value)

# Turn the transaction into a simple list of basic types that can be
Expand All @@ -26,7 +29,7 @@ def format_annotation[T](annotation: Annotation[T]) -> tuple[str, T]:
list(
map(
lambda el: [
el.ttl,
el.btl,
el.data,
list(map(format_annotation, el.string_annotations)),
list(map(format_annotation, el.numeric_annotations)),
Expand All @@ -39,7 +42,7 @@ def format_annotation[T](annotation: Annotation[T]) -> tuple[str, T]:
map(
lambda el: [
el.entity_key.generic_bytes,
el.ttl,
el.btl,
el.data,
list(map(format_annotation, el.string_annotations)),
list(map(format_annotation, el.numeric_annotations)),
Expand Down
Loading
Loading