add amount option

This commit is contained in:
Galfour 2019-06-12 19:13:06 +00:00
parent a75c0ac061
commit fa5ac47d8f
5 changed files with 40 additions and 19 deletions

View File

@ -72,6 +72,14 @@ let syntax =
info ~docv ~doc ["syntax" ; "s"] in
value @@ opt string "pascaligo" info
let amount =
let open Arg in
let info =
let docv = "AMOUNT" in
let doc = "$(docv) is the amount the dry-run transaction will use." in
info ~docv ~doc ["amount"] in
value @@ opt string "0" info
let compile_file =
let f source entry_point syntax =
toplevel @@
@ -118,43 +126,43 @@ let compile_storage =
(term , Term.info ~docs cmdname)
let dry_run =
let f source entry_point storage input syntax =
let f source entry_point storage input amount syntax =
toplevel @@
let%bind output =
Ligo.Run.run_contract source entry_point storage input syntax in
Ligo.Run.run_contract ~amount source entry_point storage input syntax in
Format.printf "%a\n" Ast_simplified.PP.expression output ;
ok ()
in
let term =
Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ expression 3 $ syntax) in
Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ expression 3 $ amount $ syntax) in
let cmdname = "dry-run" in
let docs = "Subcommand: run a smart-contract with the given storage and input." in
(term , Term.info ~docs cmdname)
let run_function =
let f source entry_point parameter syntax =
let f source entry_point parameter amount syntax =
toplevel @@
let%bind output =
Ligo.Run.run_function source entry_point parameter syntax in
Ligo.Run.run_function ~amount source entry_point parameter syntax in
Format.printf "%a\n" Ast_simplified.PP.expression output ;
ok ()
in
let term =
Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ syntax) in
Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ amount $ syntax) in
let cmdname = "run-function" in
let docs = "Subcommand: run a function with the given parameter." in
(term , Term.info ~docs cmdname)
let evaluate_value =
let f source entry_point syntax =
let f source entry_point amount syntax =
toplevel @@
let%bind output =
Ligo.Run.evaluate_value source entry_point syntax in
Ligo.Run.evaluate_value ~amount source entry_point syntax in
Format.printf "%a\n" Ast_simplified.PP.expression output ;
ok ()
in
let term =
Term.(const f $ source 0 $ entry_point 1 $ syntax) in
Term.(const f $ source 0 $ entry_point 1 $ amount $ syntax) in
let cmdname = "evaluate-value" in
let docs = "Subcommand: evaluate a given definition." in
(term , Term.info ~docs cmdname)

View File

@ -0,0 +1 @@
let check = if Current.amount > 100tz then 42 else 0

View File

@ -17,8 +17,8 @@ let run_simplityped
let%bind annotated_result = Typer.untype_expression typed_result in
ok annotated_result
let evaluate_simplityped (program : Ast_typed.program) (entry : string)
let evaluate_simplityped ?options (program : Ast_typed.program) (entry : string)
: Ast_simplified.expression result =
let%bind typed_result = Run_typed.evaluate_typed entry program in
let%bind typed_result = Run_typed.evaluate_typed ?options entry program in
let%bind annotated_result = Typer.untype_expression typed_result in
ok annotated_result

View File

@ -217,23 +217,35 @@ let type_file ?(debug_simplify = false) ?(debug_typed = false)
)) ;
ok typed
let run_contract source entry_point storage input syntax =
let run_contract ?amount source entry_point storage input syntax =
let%bind typed =
type_file syntax source in
let%bind storage_simpl =
parsify_expression syntax storage in
let%bind input_simpl =
parsify_expression syntax input in
Run_simplified.run_simplityped typed entry_point (Ast_simplified.e_pair storage_simpl input_simpl)
let options =
let open Proto_alpha_utils.Memory_proto_alpha in
let amount = Option.bind (fun amount -> Alpha_context.Tez.of_string amount) amount in
(make_options ?amount ()) in
Run_simplified.run_simplityped ~options typed entry_point (Ast_simplified.e_pair storage_simpl input_simpl)
let run_function source entry_point parameter syntax =
let run_function ?amount source entry_point parameter syntax =
let%bind typed =
type_file syntax source in
let%bind parameter' =
parsify_expression syntax parameter in
Run_simplified.run_simplityped typed entry_point parameter'
let options =
let open Proto_alpha_utils.Memory_proto_alpha in
let amount = Option.bind (fun amount -> Alpha_context.Tez.of_string amount) amount in
(make_options ?amount ()) in
Run_simplified.run_simplityped ~options typed entry_point parameter'
let evaluate_value source entry_point syntax =
let evaluate_value ?amount source entry_point syntax =
let%bind typed =
type_file syntax source in
Run_simplified.evaluate_simplityped typed entry_point
let options =
let open Proto_alpha_utils.Memory_proto_alpha in
let amount = Option.bind (fun amount -> Alpha_context.Tez.of_string amount) amount in
(make_options ?amount ()) in
Run_simplified.evaluate_simplityped ~options typed entry_point

View File

@ -13,12 +13,12 @@ let transpile_value
let%bind r = Run_mini_c.run_entry f input in
ok r
let evaluate_typed (entry:string) (program:Ast_typed.program) : Ast_typed.annotated_expression result =
let evaluate_typed ?options (entry:string) (program:Ast_typed.program) : Ast_typed.annotated_expression result =
trace (simple_error "easy evaluate typed") @@
let%bind result =
let%bind mini_c_main =
Transpiler.translate_entry program entry in
Run_mini_c.run_entry mini_c_main (Mini_c.Combinators.d_unit) in
Run_mini_c.run_entry ?options mini_c_main (Mini_c.Combinators.d_unit) in
let%bind typed_result =
let%bind typed_main = Ast_typed.get_entry program entry in
Transpiler.untranspile result typed_main.type_annotation in