Merge branch 'dev' of https://gitlab.com/ligolang/ligo into api-docs/big_map

This commit is contained in:
Sander Spies 2020-03-09 18:25:49 +01:00
commit 5dc6980d46
85 changed files with 4433 additions and 1452 deletions

View File

@ -11,6 +11,7 @@ stages:
- build_and_package_binaries
- build_docker
- build_and_deploy
- ide-unit-test
- ide-build
- ide-e2e-test
- ide-deploy
@ -23,9 +24,8 @@ dont-merge-to-master:
only:
- master
.build_binary:
&build_binary # To run in sequence and save CPU usage, use stage: build_and_package_binaries
stage: test
.build_binary: &build_binary
stage: test # To run in sequence and save CPU usage, use stage: build_and_package_binaries
script:
- $build_binary_script "$target_os_family" "$target_os" "$target_os_version"
- $package_binary_script "$target_os_family" "$target_os" "$target_os_version"
@ -213,12 +213,17 @@ pages-attempt:
# WEBIDE jobs
run-webide-unit-tests:
stage: test
image: node:12-alpine
stage: ide-unit-test
dependencies:
- build-and-package-debian-10
image: node:12-buster
script:
- mv $(realpath dist/package/debian-10/*.deb) ligo_deb10.deb
- apt-get update && apt-get -y install libev-dev perl pkg-config libgmp-dev libhidapi-dev m4 libcap-dev bubblewrap rsync
- dpkg -i ligo_deb10.deb
- cd tools/webide/packages/server
- npm ci
- npm run test
- export LIGO_CMD=/bin/ligo && npm run test
rules:
- changes:
- tools/webide/**

View File

@ -2,7 +2,11 @@
## [Unreleased]
## [Add crypto reference page to docs](https://gitlab.com/ligolang/ligo/-/merge_requests/459)
## [Support for self] (https://gitlab.com/ligolang/ligo/-/merge_requests/453)
### Added
- support for `Tezos.self(%Entrypoint)`
## [Support for create_contract](https://gitlab.com/ligolang/ligo/-/merge_requests/459)
### Added
- support for `Tezos.create_contract` origination

View File

@ -310,7 +310,7 @@ let main (action, store: parameter * storage) : return =
```reasonligo group=c
let owner : address = ("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address);
let main = ((action, store) : (parameter, storage)) : storage => {
let main = ((action, store) : (parameter, storage)) : return => {
if (Tezos.source != owner) { (failwith ("Access denied.") : return); }
else { (([] : list (operation)), store); };
};
@ -478,4 +478,3 @@ let proxy = ((action, store): (parameter, storage)) : return => {
> *deprecated*.
</Syntax>

View File

@ -321,6 +321,37 @@ let main = (p : unit) : address => Tezos.self_address;
</Syntax>
## Self
Typecast the currently running contract with an entrypoint annotation.
If your are using entrypoints: use "%bar" for constructor Bar
If you are not using entrypoints: use "%default"
<Syntax syntax="pascaligo">
```pascaligo
function main (const p : unit) : contract(unit) is block {
const c : contract(unit) = Tezos.self("%Default") ;
} with c
```
</Syntax>
<Syntax syntax="cameligo">
```cameligo
let main (p : unit) : unit contract =
(Tezos.self("%Default") : unit contract)
```
</Syntax>
<Syntax syntax="reasonligo">
```reasonligo
let main = (p: unit) : contract(unit) =>
(Tezos.self("%Default") : contract(unit));
```
</Syntax>
## Implicit Account

View File

@ -134,7 +134,7 @@ let compile_file =
let f source_file entry_point syntax display_format michelson_format =
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed,_ = Compile.Of_simplified.compile simplified in
let%bind typed,_ = Compile.Of_simplified.compile (Contract entry_point) simplified in
let%bind mini_c = Compile.Of_typed.compile typed in
let%bind michelson = Compile.Of_mini_c.aggregate_and_compile_contract mini_c entry_point in
let%bind contract = Compile.Of_michelson.build_contract michelson in
@ -174,7 +174,7 @@ let print_typed_ast =
let f source_file syntax display_format = (
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed,_ = Compile.Of_simplified.compile simplified in
let%bind typed,_ = Compile.Of_simplified.compile Env simplified in
ok @@ Format.asprintf "%a\n" Compile.Of_typed.pretty_print typed
)
in
@ -187,7 +187,7 @@ let print_mini_c =
let f source_file syntax display_format = (
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed,_ = Compile.Of_simplified.compile simplified in
let%bind typed,_ = Compile.Of_simplified.compile Env simplified in
let%bind mini_c = Compile.Of_typed.compile typed in
ok @@ Format.asprintf "%a\n" Compile.Of_mini_c.pretty_print mini_c
)
@ -201,7 +201,7 @@ let measure_contract =
let f source_file entry_point syntax display_format =
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed,_ = Compile.Of_simplified.compile simplified in
let%bind typed,_ = Compile.Of_simplified.compile (Contract entry_point) simplified in
let%bind mini_c = Compile.Of_typed.compile typed in
let%bind michelson = Compile.Of_mini_c.aggregate_and_compile_contract mini_c entry_point in
let%bind contract = Compile.Of_michelson.build_contract michelson in
@ -218,7 +218,7 @@ let compile_parameter =
let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format =
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed_prg,state = Compile.Of_simplified.compile simplified in
let%bind typed_prg,state = Compile.Of_simplified.compile (Contract entry_point) simplified in
let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg entry_point in
let env = Ast_typed.program_environment typed_prg in
@ -249,7 +249,7 @@ let interpret =
let%bind (decl_list,state,env) = match init_file with
| Some init_file ->
let%bind simplified = Compile.Of_source.compile init_file (Syntax_name syntax) in
let%bind typed_prg,state = Compile.Of_simplified.compile simplified in
let%bind typed_prg,state = Compile.Of_simplified.compile Env simplified in
let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in
let env = Ast_typed.program_environment typed_prg in
ok (mini_c_prg,state,env)
@ -280,7 +280,7 @@ let temp_ligo_interpreter =
let f source_file syntax display_format =
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed,_ = Compile.Of_simplified.compile simplified in
let%bind typed,_ = Compile.Of_simplified.compile Env simplified in
let%bind res = Compile.Of_typed.some_interpret typed in
ok @@ Format.asprintf "%s\n" res
in
@ -294,7 +294,7 @@ let compile_storage =
let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format =
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed_prg,state = Compile.Of_simplified.compile simplified in
let%bind typed_prg,state = Compile.Of_simplified.compile (Contract entry_point) simplified in
let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg entry_point in
let env = Ast_typed.program_environment typed_prg in
@ -323,7 +323,7 @@ let dry_run =
let f source_file entry_point storage input amount balance sender source predecessor_timestamp syntax display_format =
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed_prg,state = Compile.Of_simplified.compile simplified in
let%bind typed_prg,state = Compile.Of_simplified.compile (Contract entry_point) simplified in
let env = Ast_typed.program_environment typed_prg in
let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg entry_point in
@ -359,7 +359,7 @@ let run_function =
toplevel ~display_format @@
let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in
let%bind simplified_prg = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed_prg,state = Compile.Of_simplified.compile simplified_prg in
let%bind typed_prg,state = Compile.Of_simplified.compile Env simplified_prg in
let env = Ast_typed.program_environment typed_prg in
let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in
@ -390,7 +390,7 @@ let evaluate_value =
let f source_file entry_point amount balance sender source predecessor_timestamp syntax display_format =
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed_prg,_ = Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Compile.Of_simplified.compile Env simplified in
let%bind mini_c = Compile.Of_typed.compile typed_prg in
let%bind (exp,_) = Mini_c.get_entry mini_c entry_point in
let%bind compiled = Compile.Of_mini_c.aggregate_and_compile_expression mini_c exp in

View File

@ -1218,3 +1218,117 @@ ligo: in file "create_contract_var.mligo", line 6, character 35 to line 10, char
DIP { DIP { DUP } ; SWAP ; CDR } ;
PAIR ;
DIP { DROP 2 } } } |}]
let%expect_test _ =
run_ligo_bad [ "compile-contract" ; bad_contract "self_type_annotation.ligo" ; "main" ] ;
[%expect {|
ligo: in file "self_type_annotation.ligo", line 8, characters 41-64. bad self type: expected (TO_Contract (int)) but got (TO_Contract (nat)) {"location":"in file \"self_type_annotation.ligo\", line 8, characters 41-64"}
If you're not sure how to fix this error, you can
do one of the following:
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
* Ask a question on our Discord: https://discord.gg/9rhYaEt
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
* Check the changelog by running 'ligo changelog' |}] ;
run_ligo_good [ "compile-contract" ; contract "self_type_annotation.ligo" ; "main" ] ;
[%expect {|
{ parameter nat ;
storage int ;
code { DUP ;
SELF %default ;
SWAP ;
CDR ;
NIL operation ;
PAIR ;
DIP { DROP 2 } } } |}]
let%expect_test _ =
run_ligo_bad [ "compile-contract" ; bad_contract "bad_contract.mligo" ; "main" ] ;
[%expect {|
ligo: in file "", line 0, characters 0-0. badly typed contract: unexpected entrypoint type {"location":"in file \"\", line 0, characters 0-0","entrypoint":"main","entrypoint_type":"( nat * int ) -> int"}
If you're not sure how to fix this error, you can
do one of the following:
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
* Ask a question on our Discord: https://discord.gg/9rhYaEt
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
* Check the changelog by running 'ligo changelog' |}] ;
run_ligo_bad [ "compile-contract" ; bad_contract "bad_contract2.mligo" ; "main" ] ;
[%expect {|
ligo: in file "", line 0, characters 0-0. bad return type: expected (TO_list(operation)), got string {"location":"in file \"\", line 0, characters 0-0","entrypoint":"main"}
If you're not sure how to fix this error, you can
do one of the following:
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
* Ask a question on our Discord: https://discord.gg/9rhYaEt
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
* Check the changelog by running 'ligo changelog' |}] ;
run_ligo_bad [ "compile-contract" ; bad_contract "bad_contract3.mligo" ; "main" ] ;
[%expect {|
ligo: in file "", line 0, characters 0-0. badly typed contract: expected {int} and {string} to be the same in the entrypoint type {"location":"in file \"\", line 0, characters 0-0","entrypoint":"main","entrypoint_type":"( nat * int ) -> ( (TO_list(operation)) * string )"}
If you're not sure how to fix this error, you can
do one of the following:
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
* Ask a question on our Discord: https://discord.gg/9rhYaEt
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
* Check the changelog by running 'ligo changelog' |}]
let%expect_test _ =
run_ligo_good [ "compile-contract" ; contract "self_with_entrypoint.ligo" ; "main" ] ;
[%expect {|
{ parameter (or (unit %default) (int %toto)) ;
storage nat ;
code { SELF %toto ;
DUP ;
PUSH mutez 300000000 ;
PUSH int 2 ;
TRANSFER_TOKENS ;
DUP ;
NIL operation ;
SWAP ;
CONS ;
DIP { DIP 2 { DUP } ; DIG 2 ; CDR } ;
PAIR ;
DIP { DROP 3 } } } |}] ;
run_ligo_good [ "compile-contract" ; contract "self_without_entrypoint.ligo" ; "main" ] ;
[%expect {|
{ parameter int ;
storage nat ;
code { SELF %default ;
DUP ;
PUSH mutez 300000000 ;
PUSH int 2 ;
TRANSFER_TOKENS ;
DUP ;
NIL operation ;
SWAP ;
CONS ;
DIP { DIP 2 { DUP } ; DIG 2 ; CDR } ;
PAIR ;
DIP { DROP 3 } } } |}] ;
run_ligo_bad [ "compile-contract" ; bad_contract "self_bad_entrypoint_format.ligo" ; "main" ] ;
[%expect {|
ligo: in file "self_bad_entrypoint_format.ligo", line 8, characters 52-58. bad entrypoint format: entrypoint "Toto" is badly formatted. We expect "%bar" for entrypoint Bar and "%default" when no entrypoint used {"location":"in file \"self_bad_entrypoint_format.ligo\", line 8, characters 52-58"}
If you're not sure how to fix this error, you can
do one of the following:
* Visit our documentation: https://ligolang.org/docs/intro/what-and-why/
* Ask a question on our Discord: https://discord.gg/9rhYaEt
* Open a gitlab issue: https://gitlab.com/ligolang/ligo/issues/new
* Check the changelog by running 'ligo changelog' |}]

View File

@ -9,6 +9,7 @@
interpreter
ast_simplified
self_ast_simplified
self_ast_typed
typer_new
typer
ast_typed

View File

@ -1,14 +1,23 @@
open Trace
let compile (program : Ast_simplified.program) : (Ast_typed.program * Typer.Solver.state) result =
type form =
| Contract of string
| Env
let compile (cform: form) (program : Ast_simplified.program) : (Ast_typed.program * Typer.Solver.state) result =
let%bind (prog_typed , state) = Typer.type_program program in
let () = Typer.Solver.discard_state state in
ok @@ (prog_typed, state)
let%bind prog_typed' = match cform with
| Contract entrypoint -> Self_ast_typed.all_contract entrypoint prog_typed
| Env -> ok prog_typed in
ok @@ (prog_typed', state)
let compile_expression ?(env = Ast_typed.Environment.full_empty) ~(state : Typer.Solver.state) (ae : Ast_simplified.expression)
: (Ast_typed.expression * Typer.Solver.state) result =
let%bind (ae_typed,state) = Typer.type_expression_subst env state ae in
let () = Typer.Solver.discard_state state in
Typer.type_expression_subst env state ae
let%bind ae_typed' = Self_ast_typed.all_expression ae_typed in
ok @@ (ae_typed',state)
let apply (entry_point : string) (param : Ast_simplified.expression) : Ast_simplified.expression result =
let name = Var.of_name entry_point in

View File

@ -1,12 +0,0 @@
open Trace
let source_to_typed syntax source_file =
let%bind simplified = Of_source.compile source_file syntax in
let%bind typed,state = Of_simplified.compile simplified in
let env = Ast_typed.program_environment typed in
ok (typed,state,env)
let source_to_typed_expression ~env ~state parameter syntax =
let%bind simplified = Of_source.compile_expression syntax parameter in
let%bind (typed,_) = Of_simplified.compile_expression ~env ~state simplified in
ok typed

View File

@ -558,9 +558,13 @@ fun_expr:
in raise (Error (WrongFunctionArguments e))
in
let binders = fun_args_to_pattern $1 in
let lhs_type = match $1 with
EAnnot {value = {inside = _ , _, t; _}; region = r} -> Some (r,t)
| _ -> None
in
let f = {kwd_fun;
binders;
lhs_type=None;
lhs_type;
arrow;
body
}

View File

@ -828,6 +828,18 @@ and simpl_declaration : Raw.declaration -> declaration Location.wrap list result
ok (Raw.EFun {region=Region.ghost ; value=fun_},List.fold_right' aux lhs_type' ty)
in
let%bind rhs' = simpl_expression let_rhs in
let%bind lhs_type = match lhs_type with
| None -> (match let_rhs with
| EFun {value={binders;lhs_type}} ->
let f_args = nseq_to_list (binders) in
let%bind lhs_type' = bind_map_option (fun x -> simpl_type_expression (snd x)) lhs_type in
let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in
let aux acc ty = Option.map (t_function (snd ty)) acc in
ok @@ (List.fold_right' aux lhs_type' ty)
| _ -> ok None
)
| Some t -> ok @@ Some t
in
ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type , inline, rhs'))]
)

View File

@ -0,0 +1,72 @@
open Ast_typed
open Trace
type contract_pass_data = {
contract_type : Helpers.contract_type ;
main_name : string ;
}
module Errors = struct
let bad_self_type expected got loc () =
let title = thunk "bad self type" in
let message () = Format.asprintf "expected %a but got %a" Ast_typed.PP.type_expression expected Ast_typed.PP.type_expression got in
let data = [
("location" , fun () -> Format.asprintf "%a" Location.pp loc)
] in
error ~data title message ()
let bad_format_entrypoint_ann ep loc () =
let title = thunk "bad entrypoint format" in
let message () = Format.asprintf "entrypoint \"%s\" is badly formatted. We expect \"%%bar\" for entrypoint Bar and \"%%default\" when no entrypoint used" ep in
let data = [
("location" , fun () -> Format.asprintf "%a" Location.pp loc) ;
] in
error ~data title message ()
let entrypoint_annotation_not_literal loc () =
let title = thunk "entrypoint annotation must be a string literal" in
let message () = Format.asprintf "" in
let data = [
("location" , fun () -> Format.asprintf "%a" Location.pp loc) ;
] in
error ~data title message ()
let unmatched_entrypoint loc () =
let title = thunk "No constructor matches the entrypoint annotation" in
let message () = Format.asprintf "" in
let data = [
("location" , fun () -> Format.asprintf "%a" Location.pp loc) ;
] in
error ~data title message ()
end
let check_entrypoint_annotation_format ep exp =
match String.split_on_char '%' ep with
| [ "" ; ep'] ->
let cap = String.capitalize_ascii ep' in
if String.equal cap ep' then fail @@ Errors.bad_format_entrypoint_ann ep exp.location
else ok cap
| _ -> fail @@ Errors.bad_format_entrypoint_ann ep exp.location
let self_typing : contract_pass_data -> expression -> (bool * contract_pass_data * expression) result = fun dat e ->
let bad_self_err () = Errors.bad_self_type
e.type_expression
{e.type_expression with type_content = T_operator (TC_contract dat.contract_type.parameter)}
e.location
in
match e.expression_content , e.type_expression with
| E_constant {cons_name=C_SELF ; arguments=[entrypoint_exp]}, {type_content = T_operator (TC_contract t) ; type_meta=_} ->
let%bind entrypoint = match entrypoint_exp.expression_content with
| E_literal (Literal_string ep) -> check_entrypoint_annotation_format ep entrypoint_exp
| _ -> fail @@ Errors.entrypoint_annotation_not_literal entrypoint_exp.location in
let%bind entrypoint_t = match dat.contract_type.parameter.type_content with
| T_sum cmap -> trace_option (Errors.unmatched_entrypoint entrypoint_exp.location)
@@ Stage_common.Types.CMap.find_opt (Constructor entrypoint) cmap
| t -> ok {dat.contract_type.parameter with type_content = t} in
let%bind () =
trace_strong (bad_self_err ()) @@
Ast_typed.assert_type_expression_eq (entrypoint_t , t) in
ok (true, dat, e)
| _ -> ok (true,dat,e)

View File

@ -0,0 +1,12 @@
(library
(name self_ast_typed)
(public_name ligo.self_ast_typed)
(libraries
simple-utils
ast_typed
)
(preprocess
(pps ppx_let bisect_ppx --conditional)
)
(flags (:standard -w +1..62-4-9-44-40-42-48-30@39@33 -open Simple_utils ))
)

View File

@ -0,0 +1,394 @@
open Ast_typed
open Trace
open Stage_common.Helpers
type 'a folder = 'a -> expression -> 'a result
let rec fold_expression : 'a folder -> 'a -> expression -> 'a result = fun f init e ->
let self = fold_expression f in
let%bind init' = f init e in
match e.expression_content with
| E_literal _ | E_variable _ -> ok init'
| E_list lst | E_set lst | E_constant {arguments=lst} -> (
let%bind res = bind_fold_list self init' lst in
ok res
)
| E_map lst | E_big_map lst -> (
let%bind res = bind_fold_list (bind_fold_pair self) init' lst in
ok res
)
| E_look_up ab ->
let%bind res = bind_fold_pair self init' ab in
ok res
| E_loop {condition;body} ->
let ab = (condition,body) in
let%bind res = bind_fold_pair self init' ab in
ok res
| E_application {expr1;expr2} -> (
let ab = (expr1,expr2) in
let%bind res = bind_fold_pair self init' ab in
ok res
)
| E_lambda { binder = _ ; result = e }
| E_constructor {element=e} -> (
let%bind res = self init' e in
ok res
)
| E_matching {matchee=e; cases} -> (
let%bind res = self init' e in
let%bind res = fold_cases f res cases in
ok res
)
| E_record m -> (
let aux init'' _ expr =
let%bind res = fold_expression self init'' expr in
ok res
in
let%bind res = bind_fold_lmap aux (ok init') m in
ok res
)
| E_record_update {record;update} -> (
let%bind res = self init' record in
let%bind res = fold_expression self res update in
ok res
)
| E_record_accessor {expr} -> (
let%bind res = self init' expr in
ok res
)
| E_let_in { let_binder = _ ; rhs ; let_result } -> (
let%bind res = self init' rhs in
let%bind res = self res let_result in
ok res
)
and fold_cases : 'a folder -> 'a -> matching_expr -> 'a result = fun f init m ->
match m with
| Match_bool { match_true ; match_false } -> (
let%bind res = fold_expression f init match_true in
let%bind res = fold_expression f res match_false in
ok res
)
| Match_list { match_nil ; match_cons = (_ , _ , cons, _) } -> (
let%bind res = fold_expression f init match_nil in
let%bind res = fold_expression f res cons in
ok res
)
| Match_option { match_none ; match_some = (_ , some, _) } -> (
let%bind res = fold_expression f init match_none in
let%bind res = fold_expression f res some in
ok res
)
| Match_tuple ((_ , e), _) -> (
let%bind res = fold_expression f init e in
ok res
)
| Match_variant (lst, _) -> (
let aux init' ((_ , _) , e) =
let%bind res' = fold_expression f init' e in
ok res' in
let%bind res = bind_fold_list aux init lst in
ok res
)
type mapper = expression -> expression result
let rec map_expression : mapper -> expression -> expression result = fun f e ->
let self = map_expression f in
let%bind e' = f e in
let return expression_content = ok { e' with expression_content } in
match e'.expression_content with
| E_list lst -> (
let%bind lst' = bind_map_list self lst in
return @@ E_list lst'
)
| E_set lst -> (
let%bind lst' = bind_map_list self lst in
return @@ E_set lst'
)
| E_map lst -> (
let%bind lst' = bind_map_list (bind_map_pair self) lst in
return @@ E_map lst'
)
| E_big_map lst -> (
let%bind lst' = bind_map_list (bind_map_pair self) lst in
return @@ E_big_map lst'
)
| E_look_up ab -> (
let%bind ab' = bind_map_pair self ab in
return @@ E_look_up ab'
)
| E_loop {condition;body} -> (
let ab = (condition,body) in
let%bind (a,b) = bind_map_pair self ab in
return @@ E_loop {condition = a; body = b}
)
| E_matching {matchee=e;cases} -> (
let%bind e' = self e in
let%bind cases' = map_cases f cases in
return @@ E_matching {matchee=e';cases=cases'}
)
| E_record_accessor acc -> (
let%bind e' = self acc.expr in
return @@ E_record_accessor {acc with expr = e'}
)
| E_record m -> (
let%bind m' = bind_map_lmap self m in
return @@ E_record m'
)
| E_record_update {record; path; update} -> (
let%bind record = self record in
let%bind update = self update in
return @@ E_record_update {record;path;update}
)
| E_constructor c -> (
let%bind e' = self c.element in
return @@ E_constructor {c with element = e'}
)
| E_application {expr1;expr2} -> (
let ab = (expr1,expr2) in
let%bind (a,b) = bind_map_pair self ab in
return @@ E_application {expr1=a;expr2=b}
)
| E_let_in { let_binder ; rhs ; let_result; inline } -> (
let%bind rhs = self rhs in
let%bind let_result = self let_result in
return @@ E_let_in { let_binder ; rhs ; let_result; inline }
)
| E_lambda { binder ; result } -> (
let%bind result = self result in
return @@ E_lambda { binder ; result }
)
| E_constant c -> (
let%bind args = bind_map_list self c.arguments in
return @@ E_constant {c with arguments=args}
)
| E_literal _ | E_variable _ as e' -> return e'
and map_cases : mapper -> matching_expr -> matching_expr result = fun f m ->
match m with
| Match_bool { match_true ; match_false } -> (
let%bind match_true = map_expression f match_true in
let%bind match_false = map_expression f match_false in
ok @@ Match_bool { match_true ; match_false }
)
| Match_list { match_nil ; match_cons = (hd , tl , cons, te) } -> (
let%bind match_nil = map_expression f match_nil in
let%bind cons = map_expression f cons in
ok @@ Match_list { match_nil ; match_cons = (hd , tl , cons, te) }
)
| Match_option { match_none ; match_some = (name , some, te) } -> (
let%bind match_none = map_expression f match_none in
let%bind some = map_expression f some in
ok @@ Match_option { match_none ; match_some = (name , some, te) }
)
| Match_tuple ((names , e), _) -> (
let%bind e' = map_expression f e in
ok @@ Match_tuple ((names , e'), [])
)
| Match_variant (lst, te) -> (
let aux ((a , b) , e) =
let%bind e' = map_expression f e in
ok ((a , b) , e')
in
let%bind lst' = bind_map_list aux lst in
ok @@ Match_variant (lst', te)
)
and map_program : mapper -> program -> program result = fun m p ->
let aux = fun (x : declaration) ->
match x with
| Declaration_constant (v , e , i, env) -> (
let%bind e' = map_expression m e in
ok (Declaration_constant (v , e' , i, env))
)
in
bind_map_list (bind_map_location aux) p
type 'a fold_mapper = 'a -> expression -> (bool * 'a * expression) result
let rec fold_map_expression : 'a fold_mapper -> 'a -> expression -> ('a * expression) result = fun f a e ->
let self = fold_map_expression f in
let%bind (continue, init',e') = f a e in
if (not continue) then ok(init',e')
else
let return expression_content = { e' with expression_content } in
match e'.expression_content with
| E_list lst -> (
let%bind (res, lst') = bind_fold_map_list self init' lst in
ok (res, return @@ E_list lst')
)
| E_set lst -> (
let%bind (res, lst') = bind_fold_map_list self init' lst in
ok (res, return @@ E_set lst')
)
| E_map lst -> (
let%bind (res, lst') = bind_fold_map_list (bind_fold_map_pair self) init' lst in
ok (res, return @@ E_map lst')
)
| E_big_map lst -> (
let%bind (res, lst') = bind_fold_map_list (bind_fold_map_pair self) init' lst in
ok (res, return @@ E_big_map lst')
)
| E_look_up ab -> (
let%bind (res, ab') = bind_fold_map_pair self init' ab in
ok (res, return @@ E_look_up ab')
)
| E_loop {condition;body} -> (
let ab = (condition,body) in
let%bind (res,(a,b)) = bind_fold_map_pair self init' ab in
ok (res, return @@ E_loop {condition = a; body = b})
)
| E_matching {matchee=e;cases} -> (
let%bind (res, e') = self init' e in
let%bind (res,cases') = fold_map_cases f res cases in
ok (res, return @@ E_matching {matchee=e';cases=cases'})
)
| E_record_accessor acc -> (
let%bind (res, e') = self init' acc.expr in
ok (res, return @@ E_record_accessor {acc with expr = e'})
)
| E_record m -> (
let%bind (res, lst') = bind_fold_map_list (fun res (k,e) -> let%bind (res,e) = self res e in ok (res,(k,e))) init' (LMap.to_kv_list m) in
let m' = LMap.of_list lst' in
ok (res, return @@ E_record m')
)
| E_record_update {record; path; update} -> (
let%bind (res, record) = self init' record in
let%bind (res, update) = self res update in
ok (res, return @@ E_record_update {record;path;update})
)
| E_constructor c -> (
let%bind (res,e') = self init' c.element in
ok (res, return @@ E_constructor {c with element = e'})
)
| E_application {expr1;expr2} -> (
let ab = (expr1,expr2) in
let%bind (res,(a,b)) = bind_fold_map_pair self init' ab in
ok (res, return @@ E_application {expr1=a;expr2=b})
)
| E_let_in { let_binder ; rhs ; let_result; inline } -> (
let%bind (res,rhs) = self init' rhs in
let%bind (res,let_result) = self res let_result in
ok (res, return @@ E_let_in { let_binder ; rhs ; let_result ; inline })
)
| E_lambda { binder ; result } -> (
let%bind (res,result) = self init' result in
ok ( res, return @@ E_lambda { binder ; result })
)
| E_constant c -> (
let%bind (res,args) = bind_fold_map_list self init' c.arguments in
ok (res, return @@ E_constant {c with arguments=args})
)
| E_literal _ | E_variable _ as e' -> ok (init', return e')
and fold_map_cases : 'a fold_mapper -> 'a -> matching_expr -> ('a * matching_expr) result = fun f init m ->
match m with
| Match_bool { match_true ; match_false } -> (
let%bind (init, match_true) = fold_map_expression f init match_true in
let%bind (init, match_false) = fold_map_expression f init match_false in
ok @@ (init, Match_bool { match_true ; match_false })
)
| Match_list { match_nil ; match_cons = (hd , tl , cons, te) } -> (
let%bind (init, match_nil) = fold_map_expression f init match_nil in
let%bind (init, cons) = fold_map_expression f init cons in
ok @@ (init, Match_list { match_nil ; match_cons = (hd , tl , cons, te) })
)
| Match_option { match_none ; match_some = (name , some, te) } -> (
let%bind (init, match_none) = fold_map_expression f init match_none in
let%bind (init, some) = fold_map_expression f init some in
ok @@ (init, Match_option { match_none ; match_some = (name , some, te) })
)
| Match_tuple ((names , e), _) -> (
let%bind (init, e') = fold_map_expression f init e in
ok @@ (init, Match_tuple ((names , e'), []))
)
| Match_variant (lst, te) -> (
let aux init ((a , b) , e) =
let%bind (init,e') = fold_map_expression f init e in
ok (init, ((a , b) , e'))
in
let%bind (init,lst') = bind_fold_map_list aux init lst in
ok @@ (init, Match_variant (lst', te))
)
and fold_map_program : 'a fold_mapper -> 'a -> program -> ('a * program) result = fun m init p ->
let aux = fun (acc,acc_prg) (x : declaration Location.wrap) ->
match Location.unwrap x with
| Declaration_constant (v , e , i, env) -> (
let%bind (acc',e') = fold_map_expression m acc e in
let wrap_content = Declaration_constant (v , e' , i, env) in
ok (acc', List.append acc_prg [{x with wrap_content}])
)
in
bind_fold_list aux (init,[]) p
module Errors = struct
let bad_contract_io entrypoint e () =
let title = thunk "badly typed contract" in
let message () = Format.asprintf "unexpected entrypoint type" in
let data = [
("location" , fun () -> Format.asprintf "%a" Location.pp e.location);
("entrypoint" , fun () -> entrypoint);
("entrypoint_type" , fun () -> Format.asprintf "%a" Ast_typed.PP.type_expression e.type_expression)
] in
error ~data title message ()
let expected_list_operation entrypoint got e () =
let title = thunk "bad return type" in
let message () = Format.asprintf "expected %a, got %a"
Ast_typed.PP.type_expression {got with type_content= T_operator (TC_list {got with type_content=T_constant TC_operation})}
Ast_typed.PP.type_expression got
in
let data = [
("location" , fun () -> Format.asprintf "%a" Location.pp e.location);
("entrypoint" , fun () -> entrypoint)
] in
error ~data title message ()
let expected_same entrypoint t1 t2 e () =
let title = thunk "badly typed contract" in
let message () = Format.asprintf "expected {%a} and {%a} to be the same in the entrypoint type"
Ast_typed.PP.type_expression t1
Ast_typed.PP.type_expression t2
in
let data = [
("location" , fun () -> Format.asprintf "%a" Location.pp e.location);
("entrypoint" , fun () -> entrypoint);
("entrypoint_type" , fun () -> Format.asprintf "%a" Ast_typed.PP.type_expression e.type_expression)
] in
error ~data title message ()
end
type contract_type = {
parameter : Ast_typed.type_expression ;
storage : Ast_typed.type_expression ;
}
let fetch_contract_type : string -> program -> contract_type result = fun main_fname program ->
let main_decl = List.rev @@ List.filter
(fun declt ->
let (Declaration_constant (v , _ , _ , _)) = Location.unwrap declt in
String.equal (Var.to_name v) main_fname
)
program
in
match main_decl with
| (hd::_) -> (
let (Declaration_constant (_,e,_,_)) = Location.unwrap hd in
match e.type_expression.type_content with
| T_arrow {type1 ; type2} -> (
match type1.type_content , type2.type_content with
| T_record tin , T_record tout when (is_tuple_lmap tin) && (is_tuple_lmap tout) ->
let%bind (parameter,storage) = Stage_common.Helpers.get_pair tin in
let%bind (listop,storage') = Stage_common.Helpers.get_pair tout in
let%bind () = trace_strong (Errors.expected_list_operation main_fname listop e) @@
Ast_typed.assert_t_list_operation listop in
let%bind () = trace_strong (Errors.expected_same main_fname storage storage' e) @@
Ast_typed.assert_type_expression_eq (storage,storage') in
(* TODO: on storage/parameter : assert_storable, assert_passable ? *)
ok { parameter ; storage }
| _ -> fail @@ Errors.bad_contract_io main_fname e
)
| _ -> fail @@ Errors.bad_contract_io main_fname e
)
| [] -> simple_fail ("Entrypoint '"^main_fname^"' does not exist")

View File

@ -0,0 +1,24 @@
open Trace
let all_passes = []
let contract_passes = [
Contract_passes.self_typing ;
]
let all_program =
let all_p = List.map Helpers.map_program all_passes in
bind_chain all_p
let all_expression =
let all_p = List.map Helpers.map_expression all_passes in
bind_chain all_p
let all_contract main_name prg =
let%bind contract_type = Helpers.fetch_contract_type main_name prg in
let data : Contract_passes.contract_pass_data = {
contract_type = contract_type ;
main_name = main_name ;
} in
let all_p = List.map (fun pass -> Helpers.fold_map_program pass data) contract_passes in
bind_chain_ignore_acc all_p prg

View File

@ -32,6 +32,20 @@ let rec get_operator : constant' -> type_value -> expression list -> predicate r
| Ok (x,_) -> ok x
| Error _ -> (
match s with
| C_SELF -> (
let%bind entrypoint_as_string = match lst with
| [{ content = E_literal (D_string s); type_value = _ }] -> (
match String.split_on_char '%' s with
| ["" ; s] -> ok @@ String.concat "" ["%" ; (String.uncapitalize_ascii s)]
| _ -> fail @@ corner_case ~loc:__LOC__ "mini_c . SELF"
)
| _ ->
fail @@ corner_case ~loc:__LOC__ "mini_c . SELF" in
ok @@ simple_unary @@ seq [
i_drop ;
prim ~annot:[entrypoint_as_string] I_SELF
]
)
| C_NONE -> (
let%bind ty' = Mini_c.get_t_option ty in
let%bind m_ty = Compiler_type.type_ ty' in

View File

@ -66,7 +66,6 @@ module Simplify = struct
module Pascaligo = struct
let constants = function
(* Tezos module (ex-Michelson) *)
| "Tezos.chain_id" -> ok C_CHAIN_ID
| "chain_id" -> ok C_CHAIN_ID (* Deprecated *)
| "get_chain_id" -> ok C_CHAIN_ID (* Deprecated *)
@ -80,6 +79,7 @@ module Simplify = struct
| "sender" -> ok C_SENDER (* Deprecated *)
| "Tezos.address" -> ok C_ADDRESS
| "address" -> ok C_ADDRESS (* Deprecated *)
| "Tezos.self" -> ok C_SELF
| "Tezos.self_address" -> ok C_SELF_ADDRESS
| "self_address" -> ok C_SELF_ADDRESS (* Deprecated *)
| "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT
@ -267,6 +267,7 @@ module Simplify = struct
| "sender" -> ok C_SENDER (* Deprecated *)
| "Tezos.address" -> ok C_ADDRESS
| "Current.address" -> ok C_ADDRESS (* Deprecated *)
| "Tezos.self" -> ok C_SELF
| "Tezos.self_address" -> ok C_SELF_ADDRESS
| "Current.self_address" -> ok C_SELF_ADDRESS (* Deprecated *)
| "Tezos.implicit_account" -> ok C_IMPLICIT_ACCOUNT
@ -791,6 +792,12 @@ module Typer = struct
let self_address = typer_0 "SELF_ADDRESS" @@ fun _ ->
ok @@ t_address ()
let self = typer_1_opt "SELF" @@ fun entrypoint_as_string tv_opt ->
let%bind () = assert_t_string entrypoint_as_string in
match tv_opt with
| None -> simple_fail "untyped SELF"
| Some t -> ok @@ t
let implicit_account = typer_1 "IMPLICIT_ACCOUNT" @@ fun key_hash ->
let%bind () = assert_t_key_hash key_hash in
ok @@ t_contract (t_unit () ) ()
@ -1228,6 +1235,7 @@ module Typer = struct
| C_SENDER -> ok @@ sender ;
| C_SOURCE -> ok @@ source ;
| C_ADDRESS -> ok @@ address ;
| C_SELF -> ok @@ self;
| C_SELF_ADDRESS -> ok @@ self_address;
| C_IMPLICIT_ACCOUNT -> ok @@ implicit_account;
| C_SET_DELEGATE -> ok @@ set_delegate ;

View File

@ -233,6 +233,10 @@ let assert_t_bytes = fun t ->
let%bind _ = get_t_bytes t in
ok ()
let assert_t_string = fun t ->
let%bind _ = get_t_string t in
ok ()
let assert_t_operation (t:type_expression) : unit result =
match t.type_content with
| T_constant (TC_operation) -> ok ()

View File

@ -91,6 +91,7 @@ val is_t_bytes : type_expression -> bool
val is_t_int : type_expression -> bool
val assert_t_bytes : type_expression -> unit result
val assert_t_string : type_expression -> unit result
(*
val assert_t_operation : type_expression -> unit result
*)

View File

@ -143,6 +143,7 @@ let constant ppf : constant' -> unit = function
| C_SOURCE -> fprintf ppf "SOURCE"
| C_SENDER -> fprintf ppf "SENDER"
| C_ADDRESS -> fprintf ppf "ADDRESS"
| C_SELF -> fprintf ppf "SELF"
| C_SELF_ADDRESS -> fprintf ppf "SELF_ADDRESS"
| C_IMPLICIT_ACCOUNT -> fprintf ppf "IMPLICIT_ACCOUNT"
| C_SET_DELEGATE -> fprintf ppf "SET_DELEGATE"

View File

@ -38,3 +38,9 @@ let label_range i j =
let is_tuple_lmap m =
List.for_all (fun i -> LMap.mem i m) @@ (label_range 0 (LMap.cardinal m))
let get_pair m =
let open Trace in
match (LMap.find_opt (Label "0") m , LMap.find_opt (Label "1") m) with
| Some e1, Some e2 -> ok (e1,e2)
| _ -> simple_fail "not a pair"

View File

@ -16,3 +16,6 @@ val bind_map_cmap :
'a Types.constructor_map ->
('b Types.constructor_map * 'c list, 'd) result
val is_tuple_lmap : 'a Types.label_map -> bool
val get_pair :
'a Types.label_map ->
(('a * 'a) * 'b list, unit -> Trace.error) result

View File

@ -285,6 +285,7 @@ and constant' =
| C_SOURCE
| C_SENDER
| C_ADDRESS
| C_SELF
| C_SELF_ADDRESS
| C_IMPLICIT_ACCOUNT
| C_SET_DELEGATE

View File

@ -237,6 +237,7 @@ and constant ppf : constant' -> unit = function
| C_SOURCE -> fprintf ppf "SOURCE"
| C_SENDER -> fprintf ppf "SENDER"
| C_ADDRESS -> fprintf ppf "ADDRESS"
| C_SELF -> fprintf ppf "SELF"
| C_SELF_ADDRESS -> fprintf ppf "SELF_ADDRESS"
| C_IMPLICIT_ACCOUNT -> fprintf ppf "IMPLICIT_ACCOUNT"
| C_SET_DELEGATE -> fprintf ppf "SET_DELEGATE"

View File

@ -5,7 +5,7 @@ open Test_helpers
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program =
@ -21,7 +21,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/coase.ligo" (Syntax_name "pascaligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -12,7 +12,7 @@ generated. unrecognized constant: {"constant":"BALANCE","location":"generated"}
type storage = tez;
let main2 = (p : unit, storage) =>
let main2 = (p : unit, s: storage) =>
([]: list (operation), Tezos.balance);
let main = (x : (unit, storage)) => main2 (x[0], x[1]);

View File

@ -0,0 +1,5 @@
type storage = int
type parameter = nat
let main (action, store : parameter * storage) : storage =
store + 1

View File

@ -0,0 +1,6 @@
type storage = int
type parameter = nat
type return = string * storage
let main (action, store : parameter * storage) : return =
("bad",store + 1)

View File

@ -0,0 +1,6 @@
type storage = int
type parameter = nat
type return = operation list * string
let main (action, store : parameter * storage) : return =
(([]: operation list),"bad")

View File

@ -0,0 +1,11 @@
type parameter is Default | Toto of int
type storage is nat
type return is list (operation) * storage
function main (const p : parameter; const s : storage) : return is
block {
const self_contract: contract(int) = Tezos.self("Toto") ;
const op : operation = Tezos.transaction (2, 300tz, self_contract) ;
}
with (list [op], s)

View File

@ -1,5 +1,5 @@
let foo (u : unit) : address = Tezos.self_address
let main (ps: unit * address): (operation list * address) =
let dummy = foo () in
([] : operation list), foo ()
let dummy = foo () in (* force not to inline foo *)
( ([] : operation list) , foo ())

View File

@ -0,0 +1,10 @@
type parameter is nat
type storage is int
type return is list (operation) * storage
function main (const p : parameter; const s : storage) : return is
block {
const self_contract: contract(int) = Tezos.self ("%default");
}
with ((nil: list(operation)), s)

View File

@ -0,0 +1,10 @@
type parameter is nat
type storage is int
type return is list (operation) * storage
function main (const p : parameter; const s : storage) : return is
block {
const self_contract: contract(parameter) = Tezos.self("%default") ;
}
with ((nil: list(operation)), s)

View File

@ -0,0 +1,12 @@
type parameter is Default | Toto of int
type storage is nat
type return is list (operation) * storage
function main (const p : parameter; const s : storage) : return is
block {
// const v : string = "%toto" ;
const self_contract: contract(int) = Tezos.self("%toto") ;
const op : operation = Tezos.transaction (2, 300tz, self_contract) ;
}
with (list [op], s)

View File

@ -0,0 +1,11 @@
type parameter is int
type storage is nat
type return is list (operation) * storage
function main (const p : parameter; const s : storage) : return is
block {
const self_contract: contract(int) = Tezos.self("%default") ;
const op : operation = Tezos.transaction (2, 300tz, self_contract) ;
}
with (list [op], s)

View File

@ -9,7 +9,7 @@ let add_op = (s: set (string)) : set (string) =>
let remove_op = (s: set (string)) : set (string) =>
Set.remove ("foobar", s);
let remove_deep = (s: (set (string), nat)): (set (string), nat) =>
let remove_deep = (s: (set (string), nat)): set (string) =>
Set.remove ("foobar", s[0]);
let mem_op = (s: set (string)) : bool =>

View File

@ -1,4 +1,4 @@
let main (_ : unit * unit) =
let main (ps : unit * unit) : operation list * unit =
if true
then failwith "This contract always fails"
else failwith "This contract still always fails"
then (failwith "This contract always fails" : operation list * unit)
else (failwith "This contract still always fails" : operation list * unit)

View File

@ -4,7 +4,7 @@ open Ast_simplified
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program =
@ -19,7 +19,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/hashlock.mligo" (Syntax_name "cameligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -5,7 +5,7 @@ open Ast_simplified
let mtype_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok (typed,state)
let get_program =
@ -20,7 +20,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/id.mligo" (Syntax_name "cameligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -5,18 +5,18 @@ open Ast_simplified.Combinators
let retype_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "reasonligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in
let () = Typer.Solver.discard_state state in
let () = Typer.Solver.discard_state state in
ok typed
let mtype_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in
let () = Typer.Solver.discard_state state in
ok typed
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in
let () = Typer.Solver.discard_state state in
ok typed

View File

@ -69,7 +69,7 @@ let compile_groups _filename grp_list =
trace (failed_to_compile_md_file _filename (s,grp,contents)) @@
let%bind v_syntax = Compile.Helpers.syntax_to_variant (Syntax_name s) None in
let%bind simplified = Compile.Of_source.compile_string contents v_syntax in
let%bind typed,_ = Compile.Of_simplified.compile simplified in
let%bind typed,_ = Compile.Of_simplified.compile Env simplified in
let%bind mini_c = Compile.Of_typed.compile typed in
bind_map_list
(fun ((_, _, exp),_) -> Compile.Of_mini_c.aggregate_and_compile_expression mini_c exp)

View File

@ -7,7 +7,7 @@ let refile = "./contracts/multisig.religo"
let type_file f s =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name s) in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program f st =

View File

@ -3,7 +3,7 @@ open Test_helpers
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program =
@ -18,7 +18,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/multisig-v2.ligo" (Syntax_name "pascaligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -5,7 +5,7 @@ open Ast_simplified
let retype_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "reasonligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in
ok (typed,state)
let get_program =
@ -20,7 +20,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/pledge.religo" (Syntax_name "reasonligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile Env simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -3,7 +3,7 @@ open Test_helpers
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program =
@ -18,7 +18,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/replaceable_id.ligo" (Syntax_name "pascaligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -4,7 +4,7 @@ open Ast_simplified
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program =
@ -19,7 +19,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/timelock_repeat.mligo" (Syntax_name "cameligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -3,7 +3,7 @@ open Test_helpers
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program =
@ -18,7 +18,7 @@ let get_program =
let compile_main () =
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/time-lock.ligo" (Syntax_name "pascaligo") in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
let%bind (_contract: Tezos_utils.Michelson.michelson) =

View File

@ -3,7 +3,7 @@ open Test_helpers
let type_file f =
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in
ok @@ (typed,state)
let get_program =

View File

@ -1,12 +1,23 @@
# Quick Start
Install `yarn`.
Run `yarn` to install dependencies.
1. Install `yarn`
1. Run `yarn` to install dependencies
1. Install Ligo compiler by following [Ligo installation instructions][install-ligo]
1. Go to `packages/server/` directory
1. Run `yarn start` to start the development server
1. Open http://localhost:8080
# Dependency on Examples
Examples that are displayed in the Web IDE are curated from `/src/test/examples` folder and packaged during the build of the client. To add a new example to the Web IDE, first add the example file to `/src/test/examples` folder; it may live under any level of subdirectories. Then, add the path to the example to the `CURATED_EXAMPLES` array in the `packages/client/package-examples.js` script. The path has to be relative to `/src/test/examples`.
## Server
See the README under the `packages/server/` for information about how to get started on the server development.
The server source code is located under `packages/server/`. Please see README under `packages/server/` for information about how to get started on the server development.
## Client
See the README under the `packages/client/` for information about how to get started on the client development.
The client source code is located under `packages/client/`. See the README under the `packages/client/` for information about how to get started on the client development.
[install-ligo]: https://ligolang.org/docs/intro/installation/

View File

@ -1,4 +1,15 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
# Quick Start
```sh
yarn start
open http://localhost:3000
```
Note: Some features such as compiler commands and examples will be unavailable. In order to have these features you have to start the server. See README under `../packages/server` for details.
# Dependency on Examples
Examples that are displayed in the Web IDE are curated from `/src/test/examples` folder and packaged during the build of the client. To add a new example to the Web IDE, first add the example file to `/src/test/examples` folder; it may live under any level of subdirectories. Then, add the path to the example to the `CURATED_EXAMPLES` array in the `packages/client/package-examples.js` script. The path has to be relative to `/src/test/examples`.
## Available Scripts

View File

@ -4,6 +4,12 @@ const join = require('path').join;
const fs = require('fs');
const YAML = require('yamljs');
const CURATED_EXAMPLES = [
'cameligo/arithmetic-contract.ligo',
'pascaligo/arithmetic-contract.ligo',
'reasonligo/arithmetic-contract.ligo'
];
function urlFriendlyHash(content) {
const hash = createHash('md5');
hash.update(content);
@ -103,12 +109,6 @@ async function main() {
// const EXAMPLES_GLOB = '**/*.ligo';
// const files = await findFiles(EXAMPLES_GLOB, EXAMPLES_DIR);
const CURATED_EXAMPLES = [
'cameligo/arithmetic-contract.ligo',
'pascaligo/arithmetic-contract.ligo',
'reasonligo/arithmetic-contract.ligo'
];
const EXAMPLES_DEST_DIR = join(process.cwd(), 'build', 'static', 'examples');
fs.mkdirSync(EXAMPLES_DEST_DIR, { recursive: true });

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,8 @@
"@fortawesome/fontawesome-svg-core": "^1.2.25",
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@fortawesome/react-fontawesome": "^0.1.6",
"@taquito/taquito": "^5.1.0-beta.1",
"@taquito/tezbridge-signer": "^5.1.0-beta.1",
"@taquito/taquito": "^6.1.0-beta.0",
"@taquito/tezbridge-signer": "^6.1.0-beta.0",
"@types/jest": "24.0.18",
"@types/node": "12.7.12",
"@types/react": "16.9.5",

View File

@ -2,7 +2,7 @@ import React from 'react';
import { Provider } from 'react-redux';
import styled from 'styled-components';
import { EditorComponent } from './components/editor';
import { EditorComponent } from './components/editor/editor';
import { Examples } from './components/examples';
import { FloatButtonComponent } from './components/float-button';
import { HeaderComponent } from './components/header';

View File

@ -4,7 +4,7 @@ import React, { useState } from 'react';
import OutsideClickHandler from 'react-outside-click-handler';
import styled, { css } from 'styled-components';
import { Command } from '../redux/types';
import { Command } from '../../redux/types';
const Container = styled.div`
flex: 2;

View File

@ -2,10 +2,10 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeEntrypointAction, ChangeMichelsonFormatAction, CompileState, MichelsonFormat } from '../redux/compile';
import { CheckboxComponent } from './checkbox';
import { Group, HGroup, Input, Label } from './inputs';
import { AppState } from '../../redux/app';
import { ChangeEntrypointAction, ChangeMichelsonFormatAction, CompileState, MichelsonFormat } from '../../redux/compile';
import { CheckboxComponent } from '../form/checkbox';
import { AccessFunctionLabel, Group, HGroup, Input, Label } from '../form/inputs';
const Container = styled.div``;
@ -26,7 +26,7 @@ export const CompilePaneComponent = () => {
return (
<Container>
<Group>
<Label htmlFor="entrypoint">Entrypoint</Label>
<AccessFunctionLabel htmlFor="entrypoint"></AccessFunctionLabel>
<Input
id="entrypoint"
value={entrypoint}

View File

@ -2,14 +2,14 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled, { css } from 'styled-components';
import { CompileAction } from '../redux/actions/compile';
import { DeployAction } from '../redux/actions/deploy';
import { DryRunAction } from '../redux/actions/dry-run';
import { EvaluateFunctionAction } from '../redux/actions/evaluate-function';
import { EvaluateValueAction } from '../redux/actions/evaluate-value';
import { AppState } from '../redux/app';
import { ChangeDispatchedAction, ChangeSelectedAction, CommandState } from '../redux/command';
import { Command } from '../redux/types';
import { CompileAction } from '../../redux/actions/compile';
import { DeployAction } from '../../redux/actions/deploy';
import { DryRunAction } from '../../redux/actions/dry-run';
import { EvaluateFunctionAction } from '../../redux/actions/evaluate-function';
import { EvaluateValueAction } from '../../redux/actions/evaluate-value';
import { AppState } from '../../redux/app';
import { ChangeDispatchedAction, ChangeSelectedAction, CommandState } from '../../redux/command';
import { Command } from '../../redux/types';
import { CommandSelectComponent } from './command-select';
import { CompilePaneComponent } from './compile-pane';
import { DeployPaneComponent } from './deploy-pane';

View File

@ -2,10 +2,10 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeEntrypointAction, ChangeStorageAction, DeployState, UseTezBridgeAction } from '../redux/deploy';
import { CheckboxComponent } from './checkbox';
import { Group, HGroup, Input, Label, Textarea } from './inputs';
import { AppState } from '../../redux/app';
import { ChangeEntrypointAction, ChangeStorageAction, DeployState, UseTezBridgeAction } from '../../redux/deploy';
import { CheckboxComponent } from '../form/checkbox';
import { AccessFunctionLabel, Group, HGroup, Input, Label, Textarea } from '../form/inputs';
const Container = styled.div``;
@ -33,7 +33,7 @@ export const DeployPaneComponent = () => {
return (
<Container>
<Group>
<Label htmlFor="entrypoint">Entrypoint</Label>
<AccessFunctionLabel htmlFor="entrypoint"></AccessFunctionLabel>
<Input
id="entrypoint"
value={entrypoint}

View File

@ -2,9 +2,9 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeEntrypointAction, ChangeParametersAction, ChangeStorageAction, DryRunState } from '../redux/dry-run';
import { Group, Input, Label, Textarea } from './inputs';
import { AppState } from '../../redux/app';
import { ChangeEntrypointAction, ChangeParametersAction, ChangeStorageAction, DryRunState } from '../../redux/dry-run';
import { AccessFunctionLabel, Group, Input, Label, Textarea } from '../form/inputs';
const Container = styled.div``;
@ -23,7 +23,7 @@ export const DryRunPaneComponent = () => {
return (
<Container>
<Group>
<Label htmlFor="entrypoint">Entrypoint</Label>
<AccessFunctionLabel htmlFor="entrypoint"></AccessFunctionLabel>
<Input
id="entrypoint"
value={entrypoint}

View File

@ -2,9 +2,9 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeEntrypointAction, ChangeParametersAction, EvaluateFunctionState } from '../redux/evaluate-function';
import { Group, Input, Label, Textarea } from './inputs';
import { AppState } from '../../redux/app';
import { ChangeEntrypointAction, ChangeParametersAction, EvaluateFunctionState } from '../../redux/evaluate-function';
import { Group, Input, Label, Textarea } from '../form/inputs';
const Container = styled.div``;
@ -20,7 +20,7 @@ export const EvaluateFunctionPaneComponent = () => {
return (
<Container>
<Group>
<Label htmlFor="entrypoint">Entrypoint</Label>
<Label htmlFor="entrypoint">Function name</Label>
<Input
id="entrypoint"
value={entrypoint}

View File

@ -2,9 +2,9 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeEntrypointAction, EvaluateValueState } from '../redux/evaluate-value';
import { Group, Input, Label } from './inputs';
import { AppState } from '../../redux/app';
import { ChangeEntrypointAction, EvaluateValueState } from '../../redux/evaluate-value';
import { Group, Input, Label } from '../form/inputs';
const Container = styled.div``;
@ -17,7 +17,7 @@ export const EvaluateValuePaneComponent = () => {
return (
<Container>
<Group>
<Label htmlFor="entrypoint">Entrypoint</Label>
<Label htmlFor="entrypoint">Expression</Label>
<Input
id="entrypoint"
value={entrypoint}

View File

@ -2,11 +2,11 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeTitleAction } from '../redux/editor';
import { AppState } from '../../redux/app';
import { ChangeTitleAction } from '../../redux/editor';
import { ShareComponent } from '../share';
import { EditableTitleComponent } from './editable-title';
import { MonacoComponent } from './monaco';
import { ShareComponent } from './share';
import { SyntaxSelectComponent } from './syntax-select';
const Container = styled.div`

View File

@ -3,9 +3,9 @@ import React, { useEffect, useRef } from 'react';
import { useDispatch, useStore } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeCodeAction, ChangeDirtyAction } from '../redux/editor';
import { ClearSelectedAction } from '../redux/examples';
import { AppState } from '../../redux/app';
import { ChangeCodeAction, ChangeDirtyAction } from '../../redux/editor';
import { ClearSelectedAction } from '../../redux/examples';
const Container = styled.div`
height: var(--content_height);

View File

@ -5,10 +5,10 @@ import OutsideClickHandler from 'react-outside-click-handler';
import { useDispatch, useSelector } from 'react-redux';
import styled, { css } from 'styled-components';
import { AppState } from '../redux/app';
import { ChangeLanguageAction, EditorState } from '../redux/editor';
import { Language } from '../redux/types';
import { Tooltip } from './tooltip';
import { AppState } from '../../redux/app';
import { ChangeLanguageAction, EditorState } from '../../redux/editor';
import { Language } from '../../redux/types';
import { Tooltip } from '../tooltip';
const Container = styled.div`
display: flex;

View File

@ -1,3 +1,4 @@
import React from 'react';
import styled from 'styled-components';
export const Group = styled.div`
@ -16,6 +17,21 @@ export const Label = styled.label`
user-select: none;
`;
export const Hint = styled.span`
font-style: italic;
font-size: 0.8em;
`;
export const AccessFunctionLabel = (props: any) => {
return (
<Label {...props}>
Access Function
<br />
<Hint>The function name from where your contract will start</Hint>
</Label>
);
};
export const Input = styled.input`
margin: 0.3em 0 0.7em 0;
background-color: var(--input_background);

View File

@ -1,194 +0,0 @@
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { PushSpinner } from 'react-spinners-kit';
import styled, { css } from 'styled-components';
import { AppState } from '../redux/app';
import { CommandState } from '../redux/command';
import { DoneLoadingAction, LoadingState } from '../redux/loading';
import { ResultState } from '../redux/result';
import { Command } from '../redux/types';
import { OutputToolbarComponent } from './output-toolbar';
const Container = styled.div<{ visible?: boolean }>`
position: absolute;
box-sizing: border-box;
width: 100%;
height: 100%;
font-family: Menlo, Monaco, 'Courier New', monospace;
display: flex;
flex-direction: column;
transform: translateX(100%);
transition: transform 0.2s ease-in;
${props =>
props.visible &&
css`
transform: translateX(0px);
`}
`;
const CancelButton = styled.div`
display: flex;
justify-content: center;
align-items: center;
color: white;
background-color: #fc683a;
cursor: pointer;
user-select: none;
margin: 1em;
padding: 0.5em 1em;
`;
const Output = styled.div`
flex: 1;
padding: 0.5em;
display: flex;
overflow: scroll;
/* This font size is used to calcuate spinner size */
font-size: 1em;
`;
const LoadingContainer = styled.div`
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`;
const LoadingMessage = styled.div`
padding: 1em 0;
`;
const Pre = styled.pre`
margin: 0;
`;
function copyOutput(el: HTMLElement | null) {
if (el) {
const range = document.createRange();
range.selectNodeContents(el);
const selection = window.getSelection();
if (selection) {
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
}
}
}
function downloadOutput(output: string) {
const anchor = document.createElement('a');
anchor.setAttribute(
'href',
`data:text/plain;charset=utf-8,${encodeURIComponent(output)}`
);
anchor.setAttribute('download', 'output.txt');
anchor.style.display = 'none';
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
}
export const OutputTabComponent = (props: {
selected?: boolean;
onCancel?: () => void;
}) => {
const output = useSelector<AppState, ResultState['output']>(
state => state.result.output
);
const contract = useSelector<AppState, ResultState['contract']>(
state => state.result.contract
);
const command = useSelector<AppState, ResultState['command']>(
state => state.result.command
);
const loading = useSelector<AppState, LoadingState>(state => state.loading);
const dispatchedAction = useSelector<
AppState,
CommandState['dispatchedAction']
>(state => state.command.dispatchedAction);
const dispatch = useDispatch();
const outputRef = useRef<HTMLDivElement>(null);
const preRef = useRef<HTMLPreElement>(null);
const [spinnerSize, setSpinnerSize] = useState(50);
useEffect(() => {
const outputEl = (outputRef.current as unknown) as HTMLElement;
const fontSize = window
.getComputedStyle(outputEl, null)
.getPropertyValue('font-size');
setSpinnerSize(parseFloat(fontSize) * 3);
}, [setSpinnerSize]);
return (
<Container visible={props.selected}>
{!(
loading.loading ||
output.length === 0 ||
command !== Command.Compile
) && (
<OutputToolbarComponent
onCopy={() => copyOutput(preRef.current)}
onDownload={() => downloadOutput(output)}
></OutputToolbarComponent>
)}
<Output id="output" ref={outputRef}>
{loading.loading && (
<LoadingContainer>
<PushSpinner size={spinnerSize} color="#fedace" />
<LoadingMessage>{loading.message}</LoadingMessage>
<CancelButton
onClick={() => {
if (dispatchedAction) {
dispatchedAction.cancel();
}
dispatch({ ...new DoneLoadingAction() });
if (props.onCancel) {
props.onCancel();
}
}}
>
Cancel
</CancelButton>
</LoadingContainer>
)}
{!loading.loading &&
((output.length !== 0 && <Pre ref={preRef}>{output}</Pre>) ||
(contract.length !== 0 && (
<span>
The contract was successfully deployed to the babylonnet test
network.
<br />
<br />
The address of your new contract is: <i>{contract}</i>
<br />
<br />
View your new contract using{' '}
<a
target="_blank"
rel="noopener noreferrer"
href={`https://better-call.dev/babylon/${contract}`}
>
Better Call Dev
</a>
!
</span>
)))}
</Output>
</Container>
);
};

View File

@ -0,0 +1,73 @@
import React, { useRef } from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../../redux/app';
import { ResultState } from '../../redux/result';
import { OutputToolbarComponent } from './output-toolbar';
const Container = styled.div<{ visible?: boolean }>`
display: flex;
flex-direction: column;
height: 100%;
`;
const Output = styled.div`
flex: 1;
padding: 0.5em;
display: flex;
overflow: scroll;
`;
const Pre = styled.pre`
margin: 0;
`;
function copyOutput(el: HTMLElement | null) {
if (el) {
const range = document.createRange();
range.selectNodeContents(el);
const selection = window.getSelection();
if (selection) {
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
}
}
}
function downloadOutput(output: string) {
const anchor = document.createElement('a');
anchor.setAttribute(
'href',
`data:text/plain;charset=utf-8,${encodeURIComponent(output)}`
);
anchor.setAttribute('download', 'output.txt');
anchor.style.display = 'none';
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
}
export const CompileOutputPane = () => {
const output = useSelector<AppState, ResultState['output']>(
state => state.result.output
);
const preRef = useRef<HTMLPreElement>(null);
return (
<Container>
<OutputToolbarComponent
onCopy={() => copyOutput(preRef.current)}
onDownload={() => downloadOutput(output)}
></OutputToolbarComponent>
<Output id="output">
<Pre ref={preRef}>{output}</Pre>
</Output>
</Container>
);
};

View File

@ -0,0 +1,67 @@
import React from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../../redux/app';
import { ResultState } from '../../redux/result';
const Container = styled.div<{ visible?: boolean }>`
display: flex;
flex-direction: column;
height: 100%;
`;
const Output = styled.div`
flex: 1;
padding: 0.5em 0.5em 0 0.5em;
display: flex;
flex-direction: column;
overflow: auto;
`;
const Pre = styled.pre`
padding: 0.5em;
margin: 0 -0.5em;
overflow: scroll;
height: 100%;
`;
export const DeployOutputPane = () => {
const output = useSelector<AppState, ResultState['output']>(
state => state.result.output
);
const contract = useSelector<AppState, ResultState['contract']>(
state => state.result.contract
);
return (
<Container>
<Output id="output">
{contract && (
<div>
The contract was successfully deployed to the carthage test network.
<br />
<br />
View your new contract using{' '}
<a
target="_blank"
rel="noopener noreferrer"
href={`https://better-call.dev/carthage/${contract}`}
>
Better Call Dev
</a>
!
<br />
<br />
<b>The address of your new contract is: </b>
<i>{contract}</i>
<br />
<br />
<b>The initial storage of your contract is: </b>
</div>
)}
{output && <Pre>{output}</Pre>}
</Output>
</Container>
);
};

View File

@ -0,0 +1,81 @@
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { PushSpinner } from 'react-spinners-kit';
import styled from 'styled-components';
import { AppState } from '../../redux/app';
import { CommandState } from '../../redux/command';
import { DoneLoadingAction, LoadingState } from '../../redux/loading';
const Container = styled.div`
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
/* This font size is used to calcuate spinner size */
font-size: 1em;
`;
const Cancel = styled.div`
display: flex;
justify-content: center;
align-items: center;
color: white;
background-color: #fc683a;
cursor: pointer;
user-select: none;
margin: 1em;
padding: 0.5em 1em;
`;
const Message = styled.div`
padding: 1em 0;
`;
export const Loading = (props: { onCancel?: () => void }) => {
const loading = useSelector<AppState, LoadingState>(state => state.loading);
const dispatchedAction = useSelector<
AppState,
CommandState['dispatchedAction']
>(state => state.command.dispatchedAction);
const dispatch = useDispatch();
const containerRef = useRef<HTMLDivElement>(null);
const [spinnerSize, setSpinnerSize] = useState(50);
useEffect(() => {
const el = (containerRef.current as unknown) as HTMLElement;
const fontSize = window
.getComputedStyle(el, null)
.getPropertyValue('font-size');
setSpinnerSize(parseFloat(fontSize) * 3);
}, [setSpinnerSize]);
return (
<Container ref={containerRef}>
<PushSpinner size={spinnerSize} color="#fedace" />
<Message>{loading.message}</Message>
<Cancel
onClick={() => {
if (dispatchedAction) {
dispatchedAction.cancel();
}
dispatch({ ...new DoneLoadingAction() });
if (props.onCancel) {
props.onCancel();
}
}}
>
Cancel
</Cancel>
</Container>
);
};

View File

@ -0,0 +1,37 @@
import React from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../../redux/app';
import { ResultState } from '../../redux/result';
const Container = styled.div<{ visible?: boolean }>`
display: flex;
flex-direction: column;
flex: 1;
`;
const Output = styled.div`
flex: 1;
padding: 0.5em;
display: flex;
overflow: scroll;
`;
const Pre = styled.pre`
margin: 0;
`;
export const OutputPane = () => {
const output = useSelector<AppState, ResultState['output']>(
state => state.result.output
);
return (
<Container>
<Output id="output">
<Pre>{output}</Pre>
</Output>
</Container>
);
};

View File

@ -0,0 +1,58 @@
import React from 'react';
import { useSelector } from 'react-redux';
import styled, { css } from 'styled-components';
import { AppState } from '../../redux/app';
import { LoadingState } from '../../redux/loading';
import { ResultState } from '../../redux/result';
import { Command } from '../../redux/types';
import { CompileOutputPane } from './compile-output-pane';
import { DeployOutputPane } from './deploy-output-pane';
import { Loading } from './loading';
import { OutputPane } from './output-pane';
const Container = styled.div<{ visible?: boolean }>`
position: absolute;
box-sizing: border-box;
width: 100%;
height: 100%;
font-family: Menlo, Monaco, 'Courier New', monospace;
display: flex;
flex-direction: column;
transform: translateX(100%);
transition: transform 0.2s ease-in;
${props =>
props.visible &&
css`
transform: translateX(0px);
`}
`;
export const OutputTab = (props: {
selected?: boolean;
onCancel?: () => void;
}) => {
const command = useSelector<AppState, ResultState['command']>(
state => state.result.command
);
const loading = useSelector<AppState, LoadingState['loading']>(
state => state.loading.loading
);
const renderResult = () => {
if (loading) {
return <Loading onCancel={props.onCancel}></Loading>;
} else if (command === Command.Compile) {
return <CompileOutputPane></CompileOutputPane>;
} else if (command === Command.Deploy) {
return <DeployOutputPane></DeployOutputPane>;
}
return <OutputPane></OutputPane>;
};
return <Container visible={props.selected}>{renderResult()}</Container>;
};

View File

@ -4,10 +4,10 @@ import React from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { AppState } from '../redux/app';
import { ResultState } from '../redux/result';
import { Item, Toolbar } from './toolbar';
import { Tooltip } from './tooltip';
import { AppState } from '../../redux/app';
import { ResultState } from '../../redux/result';
import { Item, Toolbar } from '../toolbar';
import { Tooltip } from '../tooltip';
const Divider = styled.div`
display: block;

View File

@ -1,8 +1,8 @@
import React, { useState } from 'react';
import styled, { css } from 'styled-components';
import { ConfigureTabComponent } from './configure-tab';
import { OutputTabComponent } from './output-tab';
import { ConfigureTabComponent } from './configure/configure-tab';
import { OutputTab } from './output/output-tab';
const Container = styled.div`
flex: 1;
@ -86,12 +86,12 @@ export const TabsPanelComponent = () => {
selectTab(TABS[1]);
}}
></ConfigureTabComponent>
<OutputTabComponent
<OutputTab
selected={selectedTab.index === 1}
onCancel={() => {
selectTab(TABS[0]);
}}
></OutputTabComponent>
></OutputTab>
</Content>
</Container>
);

View File

@ -11,7 +11,7 @@ import { Command } from '../types';
import { CancellableAction } from './cancellable';
Tezos.setProvider({
rpc: 'https://api.tez.ie/rpc/babylonnet',
rpc: 'https://api.tez.ie/rpc/carthagenet',
signer: new TezBridgeSigner()
});
@ -56,12 +56,19 @@ export class DeployAction extends CancellableAction {
return;
}
dispatch({ ...new UpdateLoadingAction('Deploying to babylon network...') });
return await op.contract();
dispatch({
...new UpdateLoadingAction('Deploying to carthage network...')
});
return {
address: (await op.contract()).address,
storage: michelsonStorage
};
}
async deployOnServerSide(dispatch: Dispatch, getState: () => AppState) {
dispatch({ ...new UpdateLoadingAction('Deploying to babylon network...') });
dispatch({
...new UpdateLoadingAction('Deploying to carthage network...')
});
const { editor: editorState, deploy: deployState } = getState();
@ -89,10 +96,16 @@ export class DeployAction extends CancellableAction {
dispatch({
...new ChangeContractAction(contract.address, Command.Deploy)
});
dispatch({
...new ChangeOutputAction(contract.storage, Command.Deploy)
});
} catch (ex) {
if (this.isCancelled()) {
return;
}
dispatch({
...new ChangeContractAction('', Command.Deploy)
});
dispatch({
...new ChangeOutputAction(
`Error: ${getErrorMessage(ex)}`,

View File

@ -18,7 +18,7 @@ describe('Deploy contract', () => {
beforeEach(async () => await page.goto(API_HOST));
it('should deploy', async done => {
expect(await deploy()).toContain('The contract was successfully deployed to the babylonnet test network.');
expect(await deploy()).toContain('The contract was successfully deployed to the carthage test network.');
done();
});

View File

@ -11,7 +11,7 @@ In the project directory, you can run:
## `yarn start`
Runs the server in development mode. This will also start the client.
Runs the server in development mode. This will also build and server the client.
## `yarn test`

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
"prestart": "cd ../client && npm run build",
"start": "nodemon -r @ts-tools/node/r -r tsconfig-paths/register ./src/index.ts",
"build": "tsc",
"test": "jest"
"test": "export DATA_DIR=/tmp && jest"
},
"devDependencies": {
"@ts-tools/node": "^1.0.0",
@ -31,7 +31,7 @@
"dependencies": {
"@google-cloud/storage": "^4.0.0",
"@hapi/joi": "^16.1.7",
"@taquito/taquito": "^5.1.0-beta.1",
"@taquito/taquito": "^6.1.0-beta.0",
"@types/node-fetch": "^2.5.4",
"body-parser": "^1.19.0",
"escape-html": "^1.0.3",

View File

@ -13,7 +13,7 @@ interface DeployBody {
storage: string;
}
Tezos.setProvider({ rpc: 'https://api.tez.ie/rpc/babylonnet' });
Tezos.setProvider({ rpc: 'https://api.tez.ie/rpc/carthagenet' });
const validateRequest = (body: any): { value: DeployBody; error: any } => {
return joi
@ -57,13 +57,13 @@ export async function deployHandler(req: Request, res: Response) {
const contract = await op.contract();
res.send({ ...contract });
res.send({ address: contract.address, storage: michelsonStorage });
} catch (ex) {
if (ex instanceof CompilerError) {
res.status(400).json({ error: ex.message });
} else {
logger.error(ex);
res.sendStatus(500);
res.status(500).json({ error: ex.message });
}
}
}

View File

@ -1,12 +1,12 @@
import fetch from 'node-fetch';
const URL = 'https://api.tez.ie/keys/babylonnet/';
const URL = 'https://api.tez.ie/keys/carthagenet/';
const AUTHORIZATION_HEADER = 'Bearer ligo-ide';
export async function fetchRandomPrivateKey(): Promise<string> {
const response = await fetch(URL, {
method: 'POST',
headers: { 'Authorization': AUTHORIZATION_HEADER }
headers: { Authorization: AUTHORIZATION_HEADER }
});
return response.text();

View File

@ -1343,44 +1343,37 @@
"@svgr/plugin-svgo" "^4.3.1"
loader-utils "^1.2.3"
"@taquito/http-utils@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/http-utils/-/http-utils-5.1.0-beta.1.tgz#283b89eeae13c78c54657bccef15f1b3242326a0"
integrity sha512-/UvE61t9j5CR94vy8Dtb+/6oJERE0P9LmHBbkESKUxNC9SAlETCEntSNiHha+vuwgCoOj0pXsHkBtAZkWAaEeg==
"@taquito/http-utils@^6.1.0-beta.0":
version "6.1.0-beta.0"
resolved "https://registry.yarnpkg.com/@taquito/http-utils/-/http-utils-6.1.0-beta.0.tgz#9d7eb1e41962e3d6aefbb89840e496753407fef6"
integrity sha512-qQg/siOh3Vrj4lYbRGuHXKLgd8Or/5upJ2LgP8Y+i6X0n/uBsE6lnwGD8JCHWt644tvhEuf53j7DJI13blLaKg==
dependencies:
xhr2-cookies "^1.1.0"
"@taquito/indexer@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/indexer/-/indexer-5.1.0-beta.1.tgz#62595d2b4758ad541dc54906896131ddf8ee9c59"
integrity sha512-NDWK7XQGgUP0YkEWhJklF9uhKHZDWtRaAPSsSfxSDYiQzol4iAUn7ru7+TQPNqfsXq0NjpvzGHBysQ8HTeb0Gg==
"@taquito/michelson-encoder@^6.1.0-beta.0":
version "6.1.0-beta.0"
resolved "https://registry.yarnpkg.com/@taquito/michelson-encoder/-/michelson-encoder-6.1.0-beta.0.tgz#8f8d143a69814723550776dfe9c024a2196cbb57"
integrity sha512-02CHk0Ag7pBLCDIJnAKXPp4Owcl3qLkIKB8pQa5uOT1fxefaT2EadMnxQEpbXPiFp4tcBRJq16Bd4JtogO+/CQ==
dependencies:
"@taquito/http-utils" "^5.1.0-beta.1"
"@taquito/utils" "^6.1.0-beta.0"
bignumber.js "^9.0.0"
fast-json-stable-stringify "^2.1.0"
"@taquito/michelson-encoder@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/michelson-encoder/-/michelson-encoder-5.1.0-beta.1.tgz#38620820d377f908ea6fc6d4136fa08247702656"
integrity sha512-kBpHDfsvsxzsIXbM4dOZs0nklY7CjCunSJ2sABUdBu4SmXDM06F5NDzg0166q7VBhFZgOhq/NNM9g7hcgn5qJg==
"@taquito/rpc@^6.1.0-beta.0":
version "6.1.0-beta.0"
resolved "https://registry.yarnpkg.com/@taquito/rpc/-/rpc-6.1.0-beta.0.tgz#e3247607a578f778f5168a356567dc86c0a3b809"
integrity sha512-umpiFpasPIVNuRUkrlOi2Z3tOHQ1p6MU0AI3xRUdoUf2Hhn7tWN1CsFzQzm87LekVz1kW7Dogkwc5hD4gsIPZg==
dependencies:
"@taquito/utils" "^5.1.0-beta.1"
bignumber.js "^9.0.0"
"@taquito/rpc@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/rpc/-/rpc-5.1.0-beta.1.tgz#6e6aa3ca57a9e5d5811f7bb16ce3a1e9fd8a87e3"
integrity sha512-ZbqpJVZw1ljAS92Xs9t/1BAgPEMzOv3qk7ubWU7AGZOKDLREjOqI4EAZQfq4gL9hP2KIgqgLubTvPF3GsmTADg==
dependencies:
"@taquito/http-utils" "^5.1.0-beta.1"
"@taquito/http-utils" "^6.1.0-beta.0"
bignumber.js "^9.0.0"
lodash "^4.17.15"
"@taquito/signer@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/signer/-/signer-5.1.0-beta.1.tgz#b5aadd782df0cc7330501c01f5d4ffd5c537ebd7"
integrity sha512-N7ZteHnXv2kS+CCxbmQ+Br21aIf8cwP/WGAjwOh0uMUcXg2qsmKE/0XnRYnLhftVaJolNo85oBckYnA6U48uCg==
"@taquito/signer@^6.1.0-beta.0":
version "6.1.0-beta.0"
resolved "https://registry.yarnpkg.com/@taquito/signer/-/signer-6.1.0-beta.0.tgz#05d3994347de460f0f1722a99ac0bdc95528d3cf"
integrity sha512-/N5X+e029r5xJ8/LCdRqzBMh3or0n3BL2m15CRsZdhH21n8I1SHRh7vqXG/jDHLqB7i47lWW6rb5V2Pql2q0og==
dependencies:
"@taquito/utils" "^5.1.0-beta.1"
"@taquito/utils" "^6.1.0-beta.0"
bignumber.js "^9.0.0"
bip39 "^3.0.2"
elliptic "^6.5.1"
@ -1388,31 +1381,30 @@
pbkdf2 "^3.0.17"
typedarray-to-buffer "^3.1.5"
"@taquito/taquito@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/taquito/-/taquito-5.1.0-beta.1.tgz#32ab600a3a08214463e961085205e25c87fea122"
integrity sha512-hLV7vZiraMlx+Not3dRdELNSwxd0ZLndRGGDBh+uexpo1aH7xX5IQbIgQBREaR1F7fqHswxBBCKcBbrGhP5EWQ==
"@taquito/taquito@^6.1.0-beta.0":
version "6.1.0-beta.0"
resolved "https://registry.yarnpkg.com/@taquito/taquito/-/taquito-6.1.0-beta.0.tgz#f7497979170019f888b32f290012ce1005cd0c7a"
integrity sha512-gln8L2w4jYPj5PY2sCld5J8b5i+so7qUnGbVtoWIvqURfLSxIzLhhGDCMoSqJaJnjWWDQcsE88398TbCLjZJxQ==
dependencies:
"@taquito/indexer" "^5.1.0-beta.1"
"@taquito/michelson-encoder" "^5.1.0-beta.1"
"@taquito/rpc" "^5.1.0-beta.1"
"@taquito/signer" "^5.1.0-beta.1"
"@taquito/utils" "^5.1.0-beta.1"
"@taquito/michelson-encoder" "^6.1.0-beta.0"
"@taquito/rpc" "^6.1.0-beta.0"
"@taquito/signer" "^6.1.0-beta.0"
"@taquito/utils" "^6.1.0-beta.0"
bignumber.js "^9.0.0"
rxjs "^6.5.3"
"@taquito/tezbridge-signer@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/tezbridge-signer/-/tezbridge-signer-5.1.0-beta.1.tgz#8e88cc3c47a802dade294336d9afa53f8d53bc21"
integrity sha512-Q/bjRjMgYjIcrdW4h2JUAajYuck0wxxb27k7ElINVEtV3qdP3g+0Ubls1YXPMnb5MG4NlDJ4H3xGWiy1dnfrdQ==
"@taquito/tezbridge-signer@^6.1.0-beta.0":
version "6.1.0-beta.0"
resolved "https://registry.yarnpkg.com/@taquito/tezbridge-signer/-/tezbridge-signer-6.1.0-beta.0.tgz#adaad917091e946d6284ce4fd74f314b9c52c8d3"
integrity sha512-diVlbdJTqrw23xZ86E3NqfKDLrJSdg6sNQ1tZkQUvinEwYUGCUTTu7+kDM9vOM/loEH0vfyUUBE+cf27uJ7j1w==
dependencies:
"@taquito/utils" "^5.1.0-beta.1"
"@taquito/utils" "^6.1.0-beta.0"
typedarray-to-buffer "^3.1.5"
"@taquito/utils@^5.1.0-beta.1":
version "5.1.0-beta.1"
resolved "https://registry.yarnpkg.com/@taquito/utils/-/utils-5.1.0-beta.1.tgz#6ab4f344abd0e3e7d40828182f461cccb9b94b24"
integrity sha512-3Qk+RLYKNYUW3jj1HYH0KymQQjWXdMcsp08eG+Cc0LKDvwzC5ewd4tfeUwq/jfHsd1fQ9LsG5FJ3NZg93W0H6w==
"@taquito/utils@^6.1.0-beta.0":
version "6.1.0-beta.0"
resolved "https://registry.yarnpkg.com/@taquito/utils/-/utils-6.1.0-beta.0.tgz#11e8887379738cae10d7a696c7b6cc0cec9eeab0"
integrity sha512-RaqVw1F7tR9RV71wuDs2Qn1DSH5qwcVVQc/JZMwQS92YUGyFGM5Sp3d+TivBaMhcjgESJNPUNijKj2xNCLd1aQ==
dependencies:
blakejs "^1.1.0"
bs58check "^2.1.2"
@ -4900,6 +4892,11 @@ fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0:
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I=
fast-json-stable-stringify@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==
fast-levenshtein@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"

View File

@ -699,6 +699,16 @@ let rec bind_chain : ('a -> 'a result) list -> 'a -> 'a result = fun fs x ->
bind aux (ok x)
)
let rec bind_chain_ignore_acc : ('a -> ('b * 'a) result) list -> 'a -> 'a result = fun fs x ->
match fs with
| [] -> ok x
| hd :: tl -> (
let aux : 'a -> 'a result = fun x ->
hd x >>? fun (_,aa) ->
bind (bind_chain_ignore_acc tl) (ok aa) in
bind aux (ok x)
)
(**
Wraps a call that might trigger an exception in a result.
*)