Skip to content

Instantly share code, notes, and snippets.

@charles-cooper
Created October 25, 2021 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charles-cooper/241430cd5c4a0b65ac7d0c6f6dfd8c60 to your computer and use it in GitHub Desktop.
Save charles-cooper/241430cd5c4a0b65ac7d0c6f6dfd8c60 to your computer and use it in GitHub Desktop.
demonstrate LLL features used by vyper
# example contract demonstrating LLL features
x: public(uint256)
y: public(Bytes[32])
z: public(int128)
w: public(bool)
@external
def __init__(x: uint256, y: Bytes[32], z: int128, w: bool):
self.x = x
self.y = y
self.z = z
self.w = w
@internal
def _branch(x: uint256, y: Bytes[32], z: bool) -> uint256:
if z:
self.y = slice(y, 0, x)
return 1
else:
return 0
@internal
def _loop(x: uint256):
for i in range(3):
self.x += i
@external
def branch(x: uint256, y: Bytes[32], z: bool) -> uint256:
if z:
self.y = slice(y, 0, x)
return 1
else:
return 0
@external
def do_stuff():
self._loop(self._branch(self.x, self.y, self.z >= 0))
@external
def external_no_args_no_return():
pass
@external
def external_kwargs(x: uint256 = 7):
pass
@external
def external_int_marshalling(x: uint256) -> uint256:
return x
@external
@nonreentrant("key")
def external_nonreentrant():
pass
@external
def external_bytes_marshalling(x: Bytes[33]) -> Bytes[33]:
return x
@internal
def internal_no_args_no_return():
pass
@internal
def internal_kwargs(x: uint256 = 7):
pass
@internal
def internal_int_marshalling(x: uint256) -> uint256:
return x
@internal
def internal_nonreentrant():
pass
@internal
def internal_bytes_marshalling(x: Bytes[33]) -> Bytes[33]:
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment