- Endpoints are declared by adding an
:entrypoint
metadata at the function declaration, which could further extended to adefentrypoint
macro. - Due to the typed nature of Michelson, the code must be typed to properly be translated to code:
- Type declarations should use the
type
function (or macro?) to declare types for namespace defined variables. - Extra type annotation could be done by using metadata.
- Need for a type checker, which I don't know how to implement (I don't know to how to build a backend also, but don't tell anyone).
- Michelson types need a correspondence for Clojure literals, while some are possible, conjunction and disjunction types are not available for Clojure.
- Type declarations should use the
- Some types have an extra challenge, like option and or, because Clojure doesn't have the proper idioms to deal with it, I should define a few patterns to describe how to interpret them, mainly option.
- To descrease the overhead for type inference, some literals are going to be used for natur
This file contains hidden or 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
FROM alpine | |
RUN apk add opam git musl-dev make m4 gcc bubblewrap bash coreutils pkgconfig openssl-libs-static openssl-dev | |
RUN opam init --disable-sandboxing | |
RUN opam install -y ocaml-base-compiler lambda-runtime dune | |
WORKDIR /app | |
COPY . . |
This file contains hidden or 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
(executable | |
(name server) | |
(libraries ssl piaf yojson ppx_deriving_yojson.runtime) | |
(preprocess (pps ppx_deriving_yojson))) |
This file contains hidden or 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
let valid_cpf cpf = | |
let aux size = | |
let sum = ref 0 in | |
for i = 0 to (size - 2) do | |
sum := !sum + cpf.(i) * (size - i); | |
done; | |
!sum * 10 mod 11 | |
in | |
(aux 10) == cpf.(9) && (aux 11) == cpf.(10) |
This file contains hidden or 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
AWS_ACCESS_KEYID= | |
AWS_SECRET_KEY= | |
BUCKET= |
This file contains hidden or 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
;; | |
;; Apesar de podermos fazer isso diretamente no `-main`, aqui | |
;; podemos separar a responsabilidade de interpretar as | |
;; opcoes e passar para os respectivos constructores dos | |
;; componentes. | |
;; | |
(defn system [& options] | |
(let [{:keys [database-url port]} options] | |
(component/system-map | |
:database (new-database database-url) |
This file contains hidden or 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
;; | |
;; Associa um valor `value` a um chave `key` no | |
;; primeiro argumento da funcao `f`. | |
;; | |
;; Espera-se que `f` seja um handler que possa | |
;; ser usado com o Ring. | |
;; | |
(defn wrap-assoc [f key value] | |
(fn [request] (f (assoc request key value)))) |
This file contains hidden or 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
;; | |
;; O web server pode seguir o mesmo protocolo | |
;; e principios que o banco de dados. | |
;; | |
(defrecord WebServer [port app] | |
component/Lifecycle | |
(start [component] | |
(assoc component | |
::jetty |
This file contains hidden or 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
;; | |
;; Todo o ciclo de vida do banco de dados | |
;; fica encapsulado em um componente. | |
;; | |
(defrecord Database [uri database connection] | |
component/Lifecycle | |
(start [component] | |
(let [{:keys [conn db]} (mg/connect-via-uri uri)] | |
(assoc component :database db |
This file contains hidden or 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
(defrecord Database [uri database connection]) | |
(defn create-database [uri] | |
(let [{:keys [db conn]} (mg/connect-via-uri uri)] | |
(map->Database {:uri uri | |
:database db | |
:connection conn}))) |