Last active
January 17, 2018 08:24
-
-
Save zigguratt/ea41e2af324ac35ce657d435fd538b21 to your computer and use it in GitHub Desktop.
A contract that illustrates LLL contract structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; -------------------------------------------------------------------------- | |
;;;; @title A contract that illustrates LLL contract structure. | |
;;;; @author Daniel Ellison <[email protected]> | |
(seq | |
;; Define the macros for this contract. | |
(include "macros.lll") | |
;;; ------------------------------------------------------------------------- | |
;;; INIT | |
;; Our constructor is marked as 'payable: false' in its ABI specification, | |
;; so we abort if any ETH was passed in during the deployment process. | |
(when (callvalue) | |
(panic)) | |
;; Store the single constructor argument. | |
(codecopy *scratch* (bytecodesize) 32) | |
(sstore *parameter* (mload *scratch*)) | |
;;; ------------------------------------------------------------------------- | |
;;; CODE | |
(returnlll | |
(seq | |
;; Since the requested function ID could be used many times in a more | |
;; complex contract, we retrieve and save it for future use. This | |
;; technique is courtesy of Ben Edgington. See macros.lll for its | |
;; definition. | |
get-function-id | |
;; ---------------------------------------------------------------------- | |
;; @notice Returns the value passed into the constructor. | |
;; @dev Signature: getConstructorParameter() | |
;; @return The value passed into the constructor. | |
(function *get-constructor-parameter* | |
(seq unpayable | |
;; This takes the constructor parameter and stores it in memory at | |
;; *scratch*, which resolves to 0x00. | |
(mstore *scratch* (sload *parameter*)) | |
;; The 'return' operator takes a memory location and a length and | |
;; returns the data at that memory location of the specified length. | |
(return *scratch* 32))) | |
;; ---------------------------------------------------------------------- | |
;; @notice Fallback: No functions matched the function ID provided. | |
(panic)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment