6565 UpdateOp ,
6666)
6767
68- CONTENT_TYPE_DEFAULT = "application/octet-stream"
69- EXPIRES_IN_DEFAULT = (
70- 1000 # Default blocks to live for created entities (~30 mins with 2s blocks)
71- )
72-
7368logger = logging .getLogger (__name__ )
7469
7570
71+ def to_seconds (
72+ seconds : int = 0 , minutes : int = 0 , hours : int = 0 , days : int = 0
73+ ) -> int :
74+ """
75+ Convert a time duration to number of seconds.
76+
77+ Useful for calculating expires_in parameters based on
78+ desired entity lifetime.
79+
80+ Args:
81+ seconds: Number of seconds
82+ minutes: Number of minutes
83+ hours: Number of hours
84+ days: Number of days
85+
86+ Returns:
87+ Number of seconds corresponding to the time duration
88+ """
89+ total_seconds = seconds + minutes * 60 + hours * 3600 + days * 86400
90+ return total_seconds
91+
92+
93+ def to_blocks (seconds : int = 0 , minutes : int = 0 , hours : int = 0 , days : int = 0 ) -> int :
94+ """
95+ Convert a time duration to number of blocks.
96+
97+ Args:
98+ seconds: Number of seconds
99+ minutes: Number of minutes
100+ hours: Number of hours
101+ days: Number of days
102+
103+ Returns:
104+ Number of blocks corresponding to the time duration
105+ """
106+ # Import here to avoid circular dependency
107+ from arkiv .module_base import ArkivModuleBase
108+
109+ total_seconds = ArkivModuleBase .to_seconds (
110+ seconds = seconds , minutes = minutes , hours = hours , days = days
111+ )
112+ return total_seconds // ArkivModuleBase .BLOCK_TIME_SECONDS
113+
114+
76115def to_entity_key (entity_key_int : int ) -> EntityKey :
77116 hex_value = Web3 .to_hex (entity_key_int )
78117 # ensure lenth is 66 (0x + 64 hex)
@@ -129,11 +168,17 @@ def check_and_set_entity_op_defaults(
129168) -> tuple [bytes , str , Attributes , int ]:
130169 """Check and set defaults for entity management arguments."""
131170 if expires_in is None :
132- expires_in = EXPIRES_IN_DEFAULT
171+ # Import here to avoid circular dependency
172+ from arkiv .module_base import ArkivModuleBase
173+
174+ expires_in = ArkivModuleBase .EXPIRES_IN_DEFAULT
133175 if not payload :
134176 payload = b""
135177 if not content_type :
136- content_type = CONTENT_TYPE_DEFAULT
178+ # Import here to avoid circular dependency
179+ from arkiv .module_base import ArkivModuleBase
180+
181+ content_type = ArkivModuleBase .CONTENT_TYPE_DEFAULT
137182 if not attributes :
138183 attributes = Attributes ({})
139184
@@ -710,7 +755,7 @@ def rlp_encode_transaction(tx: Operations) -> bytes:
710755 # Create
711756 [
712757 [
713- element .expires_in ,
758+ to_blocks ( seconds = element .expires_in ) ,
714759 element .content_type ,
715760 element .payload ,
716761 * split_attributes (element .attributes ),
@@ -722,7 +767,7 @@ def rlp_encode_transaction(tx: Operations) -> bytes:
722767 [
723768 entity_key_to_bytes (element .key ),
724769 element .content_type ,
725- element .expires_in ,
770+ to_blocks ( seconds = element .expires_in ) ,
726771 element .payload ,
727772 * split_attributes (element .attributes ),
728773 ]
0 commit comments