Skip to content

Commit

Permalink
Merge branch 'main' into experimental-arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
fergalwalsh committed Jul 8, 2024
2 parents 26d1e95 + df4b013 commit d744197
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/stdlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,17 @@ All builtin Tealish functions are Capitalized to distinguish them from the AVM f
const TINYMAN = Address("RIKLQ5HEVXAOAWYSW2LGQFYGWVO4J6LIAQQ72ZRULHZ4KS5NRPCCKYPCUU")
.. function:: ARC28Event(signature, bytes, ...,) -> bytes

Generates an `ARC28 <https://arc.algorand.foundation/ARCs/arc-0028>`_ compliant byte string for logging event messages.
The message is prefixed with the first 4 bytes of the SHA512_256 hash of the signature.

.. code-block::
log(ARC28Event("set_manager(address)", new_manager))
# The above line generates the following Teal:
pushbytes 0xba87e7f4 // SHA512_256("set_manager(address)")[:4]
load 4 // new_manager
concat
log
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ packages = ["tealish"]

[project]
name = "tealish"
version = "0.0.3"
version = "0.0.4"
authors = [
{ name="Tinyman", email="[email protected]" },
]
Expand All @@ -24,7 +24,8 @@ dependencies = [
'textX >= 3.0.0',
'click >= 8.1.3',
'requests >= 2.0.0',
'py-algorand-sdk >= 1.20.0'
'py-algorand-sdk >= 1.20.0',
'pycryptodomex >= 3.15.0'
]

[project.urls]
Expand Down
20 changes: 20 additions & 0 deletions tealish/stdlib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional, Union
from Cryptodome.Hash import SHA512
from tealish import TealWriter
from tealish.base import BaseNode
from tealish.errors import CompileError, warning
Expand Down Expand Up @@ -487,6 +488,24 @@ def write_teal(self, writer: "TealWriter") -> None:
writer.write(self, f"addr {value}")


class ARC28Event(FunctionCall):
name = "ARC28Event"

def process(self) -> None:
self.signature = self.args[0].value
self.prefix = SHA512.new(self.signature.encode(), truncate="256").hexdigest()[:8] # 4 bytes, 8 chars of hex
for arg in self.args[1:]:
arg.process()
self.type = BytesType()

def write_teal(self, writer: "TealWriter") -> None:
writer.write(self, f"pushbytes 0x{self.prefix} // SHA512_256(\"{self.signature}\")[:4]")
for arg in self.args[1:]:
writer.write(self, arg)
for _ in range(len(self.args[1:])):
writer.write(self, "concat")


functions = {
f.name: f
for f in [
Expand All @@ -502,6 +521,7 @@ def write_teal(self, writer: "TealWriter") -> None:
Lpad,
Concat,
Address,
ARC28Event,
]
}

Expand Down

0 comments on commit d744197

Please sign in to comment.