Skip to content

Commit

Permalink
Update for Gerbil 0.17.0-326-g494cedfd
Browse files Browse the repository at this point in the history
  • Loading branch information
fare committed Oct 3, 2023
1 parent e177c80 commit cb1545a
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cli.ss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(def keys (sort (hash-keys ethereum-networks) string<?))
(def (name<-key key) (.@ (hash-get ethereum-networks key) name))
(def keys-by-name (map (cut sort <> compare-strings-by-length-then-lexicographically<)
(grouping keys name<-key)))
(group-same keys key: name<-key)))
(def keys-strings (map (cut string-join <> " ") keys-by-name))
(def primary-keys (map car keys-by-name))
(def urls (map (lambda (key) (with-catch (lambda (_) "") (cut car (.@ (hash-get ethereum-networks key) rpc))))
Expand Down
24 changes: 16 additions & 8 deletions ethereum.ss
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
(export #t)

(import
:gerbil/gambit
:std/format :std/misc/number :std/misc/decimal :std/sugar
:clan/base :clan/maybe
:clan/crypto/keccak :clan/crypto/secp256k1
:clan/poo/object :clan/poo/io :clan/poo/brace
(only-in :clan/poo/mop sexp<-)
(only-in :clan/poo/type Sum define-sum-constructors)
./types ./hex ./rlp)
(only-in :gerbil/gambit object->serial-number)
(only-in :std/format format)
(only-in :std/misc/number integer-part)
(only-in :std/misc/decimal decimal->string)
(only-in :clan/base !> compose)
(only-in :clan/crypto/keccak keccak256<-bytes)
(only-in :clan/crypto/secp256k1 recover-signer-public-key make-message-signature PublicKey)
(only-in :clan/poo/object defmethod def-slots .mix .@)
(only-in :clan/poo/io bytes<- methods.marshal<-bytes)
(only-in :clan/poo/brace @method @@method)
(only-in :clan/poo/mop sexp<- define-type validate Type.)
(only-in :clan/poo/type Sum define-sum-constructors Maybe)
(only-in ./types Record Bytes Bytes4 Bytes20 Bytes32 UInt32 UInt63 UInt256
register-simple-eth-type ensure-zeroes)
(only-in ./hex address-bytes<-0x bytes<-0x 0x<-address-bytes)
(only-in ./rlp rlpbytes<-rlp rlp<-nat))

;; Types used by Ethereum APIs
(define-type Quantity UInt256)
Expand Down
2 changes: 1 addition & 1 deletion gerbil.pkg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; Gerbil Ethereum support
(package: mukn/ethereum
(package: clan/ethereum
depend: ("github.com/mighty-gerbils/gerbil-utils"
"github.com/mighty-gerbils/gerbil-crypto"
"github.com/mighty-gerbils/gerbil-poo"
Expand Down
9 changes: 6 additions & 3 deletions hex.ss
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
(export #t)

(import
:gerbil/gambit
:std/error :std/iter :std/misc/bytes :std/misc/number :std/srfi/13 :std/text/hex
:clan/crypto/keccak)
(only-in :std/error check-argument)
(only-in :std/iter for in-range)
(only-in :std/misc/bytes bytevector->uint big)
(only-in :std/misc/number half)
(only-in :std/text/hex hex-encode hex-decode)
(only-in :clan/crypto/keccak keccak256<-string))

;; Raise an error if the string doesn't strictly start with "0x"
;; : Unit <- 0xString
Expand Down
44 changes: 30 additions & 14 deletions known-addresses.ss
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
(export #t)

(import
:gerbil/gambit
:std/assert :std/format :std/iter
:std/misc/bytes :std/misc/list :std/misc/number
:std/sort
:std/srfi/13
:std/sugar
:std/text/hex
:clan/base :clan/json :clan/list :clan/ports
:clan/crypto/keccak
:clan/poo/io :clan/poo/brace :clan/poo/object :clan/poo/debug
:clan/crypto/secp256k1 :clan/crypto/secp256k1-ffi
./hex ./logger ./types ./ethereum)
(only-in :std/error check-argument)
(only-in :std/format format)
(only-in :std/iter for in-range in-naturals)
(only-in :std/misc/bytes u8vector->nat)
(only-in :std/misc/list push!)
(only-in :std/misc/number half)
(only-in :std/sort sort)
(only-in :std/srfi/13 string-ci= string-every)
(only-in :std/sugar while hash)
(only-in :std/text/hex unhex unhex*)
(only-in :clan/base ignore-errors nest)
(only-in :clan/json read-file-json write-json-ln)
(only-in :std/misc/ports with-output)
(only-in :clan/random random-nat)
(only-in :clan/crypto/keccak keccak256<-bytes)
(only-in :clan/poo/mop <-json json<- validate Type.)
(only-in :clan/poo/type Map)
(only-in :clan/poo/io bytes<-)
(only-in :clan/poo/brace @method)
(only-in :clan/poo/debug DDT)
(only-in :clan/crypto/secp256k1 secp256k1-order secp256k1-seckey PublicKey
import-secret-key/json export-secret-key/json secp256k1-seckey-data)
(only-in :clan/crypto/secp256k1-ffi secp256k1-pubkey<-seckey)
(only-in ./hex bytes<-0x)
(only-in ./logger eth-log)
(only-in ./types String define-type UInt256 Bytes32)
./ethereum)

(defstruct keypair (address public-key secret-key) equal: #t)

Expand All @@ -38,7 +53,8 @@
("pubkey" (json<- PublicKey (keypair-public-key kp)))
("seckey" (export-secret-key/json (keypair-secret-key kp)))))
(def (import-keypair/json j)
(assert! (equal? (sort (hash-keys j) string<?) '("address" "pubkey" "seckey")))
(check-argument (equal? (sort (hash-keys j) string<?) '("address" "pubkey" "seckey"))
"keypair json" j)
(keypair (<-json Address (hash-get j "address"))
(<-json PublicKey (hash-get j "pubkey"))
(import-secret-key/json (hash-get j "seckey"))))
Expand Down Expand Up @@ -84,7 +100,7 @@
(let/cc return)
(with ([score-function enough-score] scoring))
(let ((best-score-so-far -inf.0)
(seed (random-integer secp256k1-order))))
(seed (random-nat secp256k1-order))))
(while #t)
(let* ((seckey-data (bytes<- UInt256 seed))
(seckey (secp256k1-seckey seckey-data))
Expand Down
8 changes: 5 additions & 3 deletions logger.ss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(export #t)

(import :clan/logger)
(import
(only-in :clan/logger json-logger))

;;(def eth-log (json-logger "ethereum"))
(import :clan/json)(def eth-log (values write-json-ln))
(def eth-log (json-logger "ethereum"))

;;For debugging: (import :clan/json)(def eth-log (values write-json-ln))
16 changes: 8 additions & 8 deletions scripts/run-ethereum-test-net.ss
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
:clan/temporary-files
:clan/crypto/secp256k1
:clan/persist/db
:mukn/ethereum/hex
:mukn/ethereum/ethereum
:mukn/ethereum/known-addresses
:mukn/ethereum/json-rpc
:mukn/ethereum/testing
:mukn/ethereum/test-contracts)

(with-catch void (cut import-module ':mukn/ethereum/version #t #t))
:clan/ethereum/hex
:clan/ethereum/ethereum
:clan/ethereum/known-addresses
:clan/ethereum/json-rpc
:clan/ethereum/testing
:clan/ethereum/test-contracts)

(with-catch void (cut import-module ':clan/ethereum/version #t #t))

;; Let's share the configuration and data directories with the rest of the Glow ecosystem
(set! application-name (lambda () "glow"))
Expand Down
49 changes: 33 additions & 16 deletions types.ss
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
;; We are shadowing existing types. Should we monkey-patch them instead? Let's hope not.
(export #t)
(export (import: :clan/poo/mop) (import: :clan/poo/type) (import: :clan/poo/number))
(export (import: :clan/poo/mop)
(import: :clan/poo/number)
(import: :clan/poo/type))

;; For re-export
(import
(for-syntax :gerbil/gambit :std/iter :std/stxutil :clan/syntax)
:gerbil/gambit
:std/assert :std/format :std/iter
:std/misc/bytes :std/misc/completion :std/misc/hash :std/misc/list :std/misc/number
:std/sort
:std/srfi/1 :std/srfi/13 :std/srfi/43
:std/sugar
:std/text/json
:clan/base :clan/io :clan/json :clan/list
:clan/maybe :std/stxutil
:clan/poo/object :clan/poo/io :clan/poo/rationaldict
(except-in :clan/poo/mop Bool)
(prefix-in (only-in :clan/poo/mop Bool) poo.)
(except-in :clan/poo/number Nat UInt. UInt)
(except-in :clan/poo/type Maybe. BytesN. Symbol String Record Tuple. Enum.))

(import
(for-syntax (only-in :std/iter for/collect)
(only-in :std/stxutil symbolify))
(only-in :std/assert assert!)
(only-in :std/format format fprintf)
(only-in :std/iter for in-range)
(only-in :std/misc/bytes u8vector-uint-set! u8vector-uint-ref u8vector-sint-set! u8vector-sint-ref big)
(only-in :std/misc/hash hash-ensure-ref)
(only-in :std/misc/list-builder with-list-builder)
(only-in :std/misc/number ceiling-align normalize-nat)
(only-in :std/srfi/43 vector-every vector-fold vector-unfold)
(only-in :std/sugar defrule)
(only-in :std/text/json json-object->string)
(only-in :clan/base compose rcompose λ)
(only-in :clan/io marshal-uint16 unmarshal-uint16 marshal-sized16-u8vector unmarshal-sized16-u8vector)
(only-in :std/stxutil symbolify maybe-intern-symbol)
(only-in :clan/poo/object .def .@ .call .for-each! .mix)
(only-in :clan/poo/io methods.bytes<-marshal)
(only-in :clan/poo/rationaldict RationalSet)
(only-in :clan/poo/mop Type. Type define-type type-error validate json<-)
(prefix-in (only-in :clan/poo/mop Bool) poo.)
(prefix-in (only-in :clan/poo/number Nat UInt. UInt Int. Int) poo.)
(except-in :clan/poo/type Maybe. BytesN. Symbol String Record Tuple. Enum.)
(only-in :clan/poo/type methods.bytes)
(prefix-in (only-in :clan/poo/type Maybe. BytesN. Symbol String Record Tuple. Enum.) poo.)
:clan/poo/brace
./hex ./abi ./rlp)
(only-in :clan/poo/brace @method)
(only-in ./hex 0x<-bytes bytes<-0x 0x<-nat nat<-0x)
(only-in ./abi ethabi-display-types ethabi-head-length ethabi-tail-length
ethabi-encode-into ethabi-decode-from)
(only-in ./rlp <-rlp rlp<- rlp<-nat nat<-rlp))

(.def (Maybe. @ [poo.Maybe.] type)
.rlp<-: (lambda (x) (if (void? x) #u8() (rlp<- type x)))
Expand Down
4 changes: 2 additions & 2 deletions unit-tests.ss
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
(init-test-environment!)

;; Accept the command-line subcommands defined in the files below.
(import :mukn/ethereum/version :mukn/ethereum/testing :mukn/ethereum/cli
:mukn/ethereum/test-contracts)
(import :clan/ethereum/version :clan/ethereum/testing :clan/ethereum/cli
:clan/ethereum/test-contracts)

;; Define more commands
(import :std/misc/process
Expand Down

0 comments on commit cb1545a

Please sign in to comment.