Accept fake values for SENDER/SOURCE in dry-run
This commit is contained in:
parent
cbaac2d124
commit
e8afba9581
@ -6,7 +6,7 @@ let main =
|
|||||||
let term = Term.(const print_endline $ const "Ligo needs a command. Do ligo --help") in
|
let term = Term.(const print_endline $ const "Ligo needs a command. Do ligo --help") in
|
||||||
(term , Term.info "ligo")
|
(term , Term.info "ligo")
|
||||||
|
|
||||||
let source n =
|
let source_file n =
|
||||||
let open Arg in
|
let open Arg in
|
||||||
let info =
|
let info =
|
||||||
let docv = "SOURCE_FILE" in
|
let docv = "SOURCE_FILE" in
|
||||||
@ -53,6 +53,22 @@ let amount =
|
|||||||
info ~docv ~doc ["amount"] in
|
info ~docv ~doc ["amount"] in
|
||||||
value @@ opt string "0" info
|
value @@ opt string "0" info
|
||||||
|
|
||||||
|
let sender =
|
||||||
|
let open Arg in
|
||||||
|
let info =
|
||||||
|
let docv = "SENDER" in
|
||||||
|
let doc = "$(docv) is the sender the dry-run transaction will use." in
|
||||||
|
info ~docv ~doc ["sender"] in
|
||||||
|
value @@ opt (some string) None info
|
||||||
|
|
||||||
|
let source =
|
||||||
|
let open Arg in
|
||||||
|
let info =
|
||||||
|
let docv = "SOURCE" in
|
||||||
|
let doc = "$(docv) is the source the dry-run transaction will use." in
|
||||||
|
info ~docv ~doc ["source"] in
|
||||||
|
value @@ opt (some string) None info
|
||||||
|
|
||||||
let display_format =
|
let display_format =
|
||||||
let open Arg in
|
let open Arg in
|
||||||
let info =
|
let info =
|
||||||
@ -70,83 +86,90 @@ let michelson_code_format =
|
|||||||
value @@ opt string "michelson" info
|
value @@ opt string "michelson" info
|
||||||
|
|
||||||
let compile_file =
|
let compile_file =
|
||||||
let f source entry_point syntax display_format michelson_format =
|
let f source_file entry_point syntax display_format michelson_format =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
let%bind michelson_format = Main.Display.michelson_format_of_string michelson_format in
|
let%bind michelson_format = Main.Display.michelson_format_of_string michelson_format in
|
||||||
let%bind contract =
|
let%bind contract =
|
||||||
trace (simple_info "compiling contract to michelson") @@
|
trace (simple_info "compiling contract to michelson") @@
|
||||||
Ligo.Compile.Of_source.compile_file_contract_entry source entry_point (Syntax_name syntax) in
|
Ligo.Compile.Of_source.compile_file_contract_entry source_file entry_point (Syntax_name syntax) in
|
||||||
ok @@ Format.asprintf "%a\n" (Main.Display.michelson_pp michelson_format) contract
|
ok @@ Format.asprintf "%a\n" (Main.Display.michelson_pp michelson_format) contract
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ syntax $ display_format $ michelson_code_format) in
|
Term.(const f $ source_file 0 $ entry_point 1 $ syntax $ display_format $ michelson_code_format) in
|
||||||
let cmdname = "compile-contract" in
|
let cmdname = "compile-contract" in
|
||||||
let docs = "Subcommand: compile a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in
|
let docs = "Subcommand: compile a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let compile_parameter =
|
let compile_parameter =
|
||||||
let f source entry_point expression syntax display_format =
|
let f source_file entry_point expression syntax display_format =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
let%bind value =
|
let%bind value =
|
||||||
trace (simple_error "compile-input") @@
|
trace (simple_error "compile-input") @@
|
||||||
Ligo.Run.Of_source.compile_file_contract_parameter source entry_point expression (Syntax_name syntax) in
|
Ligo.Run.Of_source.compile_file_contract_parameter source_file entry_point expression (Syntax_name syntax) in
|
||||||
ok @@ Format.asprintf "%a\n" Tezos_utils.Michelson.pp value
|
ok @@ Format.asprintf "%a\n" Tezos_utils.Michelson.pp value
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ syntax $ display_format) in
|
Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ syntax $ display_format) in
|
||||||
let cmdname = "compile-parameter" in
|
let cmdname = "compile-parameter" in
|
||||||
let docs = "Subcommand: compile parameters to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which calls a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in
|
let docs = "Subcommand: compile parameters to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which calls a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let compile_storage =
|
let compile_storage =
|
||||||
let f source entry_point expression syntax display_format bigmap =
|
let f source_file entry_point expression syntax display_format bigmap =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
let%bind value =
|
let%bind value =
|
||||||
trace (simple_error "compile-storage") @@
|
trace (simple_error "compile-storage") @@
|
||||||
Ligo.Run.Of_source.compile_file_contract_storage ~value:bigmap source entry_point expression (Syntax_name syntax) in
|
Ligo.Run.Of_source.compile_file_contract_storage ~value:bigmap source_file entry_point expression (Syntax_name syntax) in
|
||||||
ok @@ Format.asprintf "%a\n" Tezos_utils.Michelson.pp value
|
ok @@ Format.asprintf "%a\n" Tezos_utils.Michelson.pp value
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ expression "STORAGE" 2 $ syntax $ display_format $ bigmap) in
|
Term.(const f $ source_file 0 $ entry_point 1 $ expression "STORAGE" 2 $ syntax $ display_format $ bigmap) in
|
||||||
let cmdname = "compile-storage" in
|
let cmdname = "compile-storage" in
|
||||||
let docs = "Subcommand: compile an initial storage in ligo syntax to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which originates a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in
|
let docs = "Subcommand: compile an initial storage in ligo syntax to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which originates a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let dry_run =
|
let dry_run =
|
||||||
let f source entry_point storage input amount syntax display_format bigmap =
|
let f source_file entry_point storage input amount sender source syntax display_format bigmap =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
let%bind output =
|
let%bind output =
|
||||||
Ligo.Run.Of_source.run_contract ~amount ~storage_value:bigmap source entry_point storage input (Syntax_name syntax) in
|
Ligo.Run.Of_source.run_contract
|
||||||
|
~options:{ amount ; sender ; source }
|
||||||
|
~storage_value:bigmap
|
||||||
|
source_file entry_point storage input (Syntax_name syntax) in
|
||||||
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression output
|
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression output
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ expression "STORAGE" 3 $ amount $ syntax $ display_format $ bigmap) in
|
Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ expression "STORAGE" 3 $ amount $ sender $ source $ syntax $ display_format $ bigmap) in
|
||||||
let cmdname = "dry-run" in
|
let cmdname = "dry-run" in
|
||||||
let docs = "Subcommand: run a smart-contract with the given storage and input." in
|
let docs = "Subcommand: run a smart-contract with the given storage and input." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let run_function =
|
let run_function =
|
||||||
let f source entry_point parameter amount syntax display_format =
|
let f source_file entry_point parameter amount sender source syntax display_format =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
let%bind output =
|
let%bind output =
|
||||||
Ligo.Run.Of_source.run_function_entry ~amount source entry_point parameter (Syntax_name syntax) in
|
Ligo.Run.Of_source.run_function_entry
|
||||||
|
~options:{ amount ; sender ; source }
|
||||||
|
source_file entry_point parameter (Syntax_name syntax) in
|
||||||
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression output
|
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression output
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ expression "PARAMETER" 2 $ amount $ syntax $ display_format) in
|
Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ amount $ sender $ source $ syntax $ display_format) in
|
||||||
let cmdname = "run-function" in
|
let cmdname = "run-function" in
|
||||||
let docs = "Subcommand: run a function with the given parameter." in
|
let docs = "Subcommand: run a function with the given parameter." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
|
||||||
let evaluate_value =
|
let evaluate_value =
|
||||||
let f source entry_point amount syntax display_format =
|
let f source_file entry_point amount sender source syntax display_format =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
let%bind output =
|
let%bind output =
|
||||||
Ligo.Run.Of_source.evaluate_entry ~amount source entry_point (Syntax_name syntax) in
|
Ligo.Run.Of_source.evaluate_entry
|
||||||
|
~options:{ amount ; sender ; source }
|
||||||
|
source_file entry_point (Syntax_name syntax) in
|
||||||
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression output
|
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression output
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
Term.(const f $ source 0 $ entry_point 1 $ amount $ syntax $ display_format) in
|
Term.(const f $ source_file 0 $ entry_point 1 $ amount $ sender $ source $ syntax $ display_format) in
|
||||||
let cmdname = "evaluate-value" in
|
let cmdname = "evaluate-value" in
|
||||||
let docs = "Subcommand: evaluate a given definition." in
|
let docs = "Subcommand: evaluate a given definition." in
|
||||||
(term , Term.info ~docs cmdname)
|
(term , Term.info ~docs cmdname)
|
||||||
|
@ -88,50 +88,61 @@ let compile_file_contract_args =
|
|||||||
let args = Ast_simplified.e_pair storage_simplified parameter_simplified in
|
let args = Ast_simplified.e_pair storage_simplified parameter_simplified in
|
||||||
Of_simplified.compile_expression ?value args ~env
|
Of_simplified.compile_expression ?value args ~env
|
||||||
|
|
||||||
|
type dry_run_options =
|
||||||
|
{ amount : string ;
|
||||||
|
sender : string option ;
|
||||||
|
source : string option }
|
||||||
|
|
||||||
let run_contract ?amount ?storage_value source_filename entry_point storage parameter syntax =
|
let make_dry_run_options (opts : dry_run_options) : Of_michelson.options result =
|
||||||
|
let open Proto_alpha_utils.Trace in
|
||||||
|
let open Proto_alpha_utils.Memory_proto_alpha in
|
||||||
|
let open Protocol.Alpha_context in
|
||||||
|
let%bind amount = match Tez.of_string opts.amount with
|
||||||
|
| None -> simple_fail "invalid amount"
|
||||||
|
| Some amount -> ok amount in
|
||||||
|
let%bind sender =
|
||||||
|
match opts.sender with
|
||||||
|
| None -> ok None
|
||||||
|
| Some sender ->
|
||||||
|
let%bind sender =
|
||||||
|
trace_alpha_tzresult
|
||||||
|
(simple_error "invalid address")
|
||||||
|
(Contract.of_b58check sender) in
|
||||||
|
ok (Some sender) in
|
||||||
|
let%bind source =
|
||||||
|
match opts.source with
|
||||||
|
| None -> ok None
|
||||||
|
| Some source ->
|
||||||
|
let%bind source =
|
||||||
|
trace_alpha_tzresult
|
||||||
|
(simple_error "invalid source address")
|
||||||
|
(Contract.of_b58check source) in
|
||||||
|
ok (Some source) in
|
||||||
|
ok @@ make_options ~amount ?source:sender ?payer:source ()
|
||||||
|
|
||||||
|
let run_contract ~options ?storage_value source_filename entry_point storage parameter syntax =
|
||||||
let%bind program = Compile.Of_source.type_file syntax source_filename in
|
let%bind program = Compile.Of_source.type_file syntax source_filename in
|
||||||
let%bind code = Compile.Of_typed.compile_function_entry program entry_point in
|
let%bind code = Compile.Of_typed.compile_function_entry program entry_point in
|
||||||
let%bind args = compile_file_contract_args ?value:storage_value source_filename entry_point storage parameter syntax in
|
let%bind args = compile_file_contract_args ?value:storage_value source_filename entry_point storage parameter syntax in
|
||||||
let%bind ex_value_ty =
|
let%bind options = make_dry_run_options options in
|
||||||
let options =
|
let%bind ex_value_ty = Of_michelson.run ~options code args in
|
||||||
let open Proto_alpha_utils.Memory_proto_alpha in
|
|
||||||
let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in
|
|
||||||
(make_options ?amount ())
|
|
||||||
in
|
|
||||||
Of_michelson.run ~options code args
|
|
||||||
in
|
|
||||||
Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry_point ex_value_ty
|
Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry_point ex_value_ty
|
||||||
|
|
||||||
let run_function_entry ?amount source_filename entry_point input syntax =
|
let run_function_entry ~options source_filename entry_point input syntax =
|
||||||
let%bind program = Compile.Of_source.type_file syntax source_filename in
|
let%bind program = Compile.Of_source.type_file syntax source_filename in
|
||||||
let%bind code = Compile.Of_typed.compile_function_entry program entry_point in
|
let%bind code = Compile.Of_typed.compile_function_entry program entry_point in
|
||||||
let%bind args = compile_file_expression source_filename entry_point input syntax in
|
let%bind args = compile_file_expression source_filename entry_point input syntax in
|
||||||
let%bind ex_value_ty =
|
let%bind options = make_dry_run_options options in
|
||||||
let options =
|
let%bind ex_value_ty = Of_michelson.run ~options code args in
|
||||||
let open Proto_alpha_utils.Memory_proto_alpha in
|
|
||||||
let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in
|
|
||||||
(make_options ?amount ())
|
|
||||||
in
|
|
||||||
Of_michelson.run ~options code args
|
|
||||||
in
|
|
||||||
Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry_point ex_value_ty
|
Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry_point ex_value_ty
|
||||||
|
|
||||||
let evaluate_entry ?amount source_filename entry_point syntax =
|
let evaluate_entry ~options source_filename entry_point syntax =
|
||||||
let%bind program = Compile.Of_source.type_file syntax source_filename in
|
let%bind program = Compile.Of_source.type_file syntax source_filename in
|
||||||
let%bind code = Compile.Of_typed.compile_expression_as_function_entry program entry_point in
|
let%bind code = Compile.Of_typed.compile_expression_as_function_entry program entry_point in
|
||||||
let%bind ex_value_ty =
|
let%bind options = make_dry_run_options options in
|
||||||
let options =
|
let%bind ex_value_ty = Of_michelson.evaluate ~options code in
|
||||||
let open Proto_alpha_utils.Memory_proto_alpha in
|
|
||||||
let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in
|
|
||||||
(make_options ?amount ())
|
|
||||||
in
|
|
||||||
Of_michelson.evaluate ~options code
|
|
||||||
in
|
|
||||||
Compile.Of_simplified.uncompile_typed_program_entry_expression_result program entry_point ex_value_ty
|
Compile.Of_simplified.uncompile_typed_program_entry_expression_result program entry_point ex_value_ty
|
||||||
|
|
||||||
let evaluate_michelson expression syntax =
|
let evaluate_michelson expression syntax =
|
||||||
let%bind code = Compile.Of_source.compile_expression_as_function expression syntax in
|
let%bind code = Compile.Of_source.compile_expression_as_function expression syntax in
|
||||||
Of_michelson.evaluate_michelson code
|
Of_michelson.evaluate_michelson code
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user