-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathabi-json.ss
33 lines (25 loc) · 1.1 KB
/
abi-json.ss
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
;; Ethereum-standard JSON descriptors for the ABI
;; https://solidity.readthedocs.io/en/develop/abi-spec.html#json
(export #t)
(import
:clan/base
./types ./ethereum ./abi ./transaction)
;; : Type <- String
(def (Type<-simple-eth-type s)
(hash-get simple-eth-types s))
;; TODO: parse tuples and vector types, maybe even functions?
;; : Type <- String
(def (Type<-eth-type s)
(or (Type<-simple-eth-type s)
(error "ethereum type not supported" s)))
(def constructor<-contract-abi
(cut find (lambda (x) (equal? (hash-get x "type") "constructor")) <>))
(def inputs<-function-abi
(cut hash-get <> "inputs"))
(def (type<-variable-abi abi)
(Type<-eth-type (hash-get abi "type")))
(def constructor-input-types<-contract-abi
(compose (cut map type<-variable-abi <>) inputs<-function-abi constructor<-contract-abi))
;; If a JSON ABI descriptor is available, the types should be from constructor-input-types<-contract-abi
(def (create-ethabi-contract creator code types parameters value: (value 0) gas: (gas (void)))
(create-contract creator (ethabi-encode types parameters code) value: value gas: gas))