-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamping-press.lll
82 lines (63 loc) · 3.04 KB
/
stamping-press.lll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;;;; ==========================================================================
;;;; @title Stamping press: creates pre-defined contracts, code for which is
;;;; contained in its own.
;;;; @notice This is a near-verbatim copy of `factory` from `lll-contracts`,
;;;; where this essentially started:
;;;; https://gitlab.com/veox/lll-contracts/blob/0d07d60e/contracts/factory.lll
;;;; @author Noel Maersk <veox>
(seq
(include "../common.lll.inc")
;; ==========================================================================
;; STORAGE LAYOUT
(def '*storloc-greeting* 0x1337)
;; ==========================================================================
;; CONSTANTS
(def '*initial-greeting* 42)
(def '*greet* 0xcfae3217) ; greet()
(def '*greeting* 0xef690cc0) ; greeting(): public storage in Solidity
(def '*set-greeting* 0xb2010978) ; setGreeting(string)
;; the most important product of any factory is compliant workers
(def '*stamp* 0xc85e07b9) ; stamp()
; TODO: find out if un/indexed args change the ID
(def '*event-stamped* ; stamped(address,address)
0x9f0f13e03835c7dcca2675cb51976e07bd186b2e351cefe0db24ec0fe62105ef)
;; ==========================================================================
;; INIT
; none!
;; ==========================================================================
;; CODE
(returnlll ; this factory will have code...
(seq
unpayable
mstore-function-selector
(def '*memloc-new-contract-at* 0x60)
(function *stamp*
(seq
(mstore ; save return value (created-at address) for event
*memloc-new-contract-at*
(create ; ...that creates greeters...
(seq
(sstore *storloc-greeting* *initial-greeting*)
(returnlll ; ...with the following code
(seq
unpayable
mstore-function-selector
;; change greeting value in storage
(def 'new-greeting (calldataload 0x04))
(function *set-greeting*
(seq
(sstore *storloc-greeting* new-greeting)
(stop)))
;; return greeting value from storage
(function *greet*
(return (sload *storloc-greeting*)))
;; for compatibility with Greeter.sol: "public storage variable"
(function *greeting*
(return (sload *storloc-greeting*)))
;; fallback
(revert 0 0))))))
;; event with one indexed chunk (address) and some data (address)
(emit1 *event-stamped* (caller) (mload *memloc-new-contract-at*) 0x20)
(return *memloc-new-contract-at* 0x20)))
;;
(revert 0 0))))