Alpha,RPCs: run_code makes a dummy origination instead of taking a random contract from the wallet

This commit is contained in:
Benjamin Canou 2018-06-22 23:29:04 +02:00
parent 0b3606c017
commit 7de19f9cc0
4 changed files with 36 additions and 36 deletions

View File

@ -78,42 +78,31 @@ let print_trace_result (cctxt : #Client_context.printer) ~show_source ~parsed =
| Error errs -> | Error errs ->
print_errors cctxt errs ~show_source ~parsed print_errors cctxt errs ~show_source ~parsed
let get_contract cctxt ?(chain = `Main) block contract =
match contract with
| Some contract -> return contract
| None ->
(* TODO use local contract by default *)
Alpha_services.Contract.list cctxt (chain, block) >>|? List.hd
let run let run
(cctxt : #Proto_alpha.rpc_context) (cctxt : #Proto_alpha.rpc_context)
?(chain = `Main) ?(chain = `Main)
block block
?contract
?(amount = Tez.fifty_cents) ?(amount = Tez.fifty_cents)
~(program : Michelson_v1_parser.parsed) ~(program : Michelson_v1_parser.parsed)
~(storage : Michelson_v1_parser.parsed) ~(storage : Michelson_v1_parser.parsed)
~(input : Michelson_v1_parser.parsed) ~(input : Michelson_v1_parser.parsed)
() = () =
get_contract cctxt ~chain block contract >>=? fun contract ->
Alpha_services.Helpers.Scripts.run_code cctxt Alpha_services.Helpers.Scripts.run_code cctxt
(chain, block) (chain, block)
program.expanded (storage.expanded, input.expanded, amount, contract) program.expanded (storage.expanded, input.expanded, amount)
let trace let trace
(cctxt : #Proto_alpha.rpc_context) (cctxt : #Proto_alpha.rpc_context)
?(chain = `Main) ?(chain = `Main)
block block
?contract
?(amount = Tez.fifty_cents) ?(amount = Tez.fifty_cents)
~(program : Michelson_v1_parser.parsed) ~(program : Michelson_v1_parser.parsed)
~(storage : Michelson_v1_parser.parsed) ~(storage : Michelson_v1_parser.parsed)
~(input : Michelson_v1_parser.parsed) ~(input : Michelson_v1_parser.parsed)
() = () =
get_contract cctxt ~chain block contract >>=? fun contract ->
Alpha_services.Helpers.Scripts.trace_code cctxt Alpha_services.Helpers.Scripts.trace_code cctxt
(chain, block) (chain, block)
program.expanded (storage.expanded, input.expanded, amount, contract) program.expanded (storage.expanded, input.expanded, amount)
let typecheck_data let typecheck_data
cctxt cctxt

View File

@ -18,7 +18,6 @@ val run :
#Proto_alpha.rpc_context -> #Proto_alpha.rpc_context ->
?chain:Shell_services.chain -> ?chain:Shell_services.chain ->
Shell_services.block -> Shell_services.block ->
?contract:Contract.t ->
?amount:Tez.t -> ?amount:Tez.t ->
program:Michelson_v1_parser.parsed -> program:Michelson_v1_parser.parsed ->
storage:Michelson_v1_parser.parsed -> storage:Michelson_v1_parser.parsed ->
@ -32,7 +31,6 @@ val trace :
#Proto_alpha.rpc_context -> #Proto_alpha.rpc_context ->
?chain:Shell_services.chain -> ?chain:Shell_services.chain ->
Shell_services.block -> Shell_services.block ->
?contract:Contract.t ->
?amount:Tez.t -> ?amount:Tez.t ->
program:Michelson_v1_parser.parsed -> program:Michelson_v1_parser.parsed ->
storage:Michelson_v1_parser.parsed -> storage:Michelson_v1_parser.parsed ->

View File

@ -45,12 +45,11 @@ module Scripts = struct
let path = RPC_path.(path / "scripts") let path = RPC_path.(path / "scripts")
let run_code_input_encoding = let run_code_input_encoding =
(obj5 (obj4
(req "script" Script.expr_encoding) (req "script" Script.expr_encoding)
(req "storage" Script.expr_encoding) (req "storage" Script.expr_encoding)
(req "input" Script.expr_encoding) (req "input" Script.expr_encoding)
(req "amount" Tez.encoding) (req "amount" Tez.encoding))
(req "contract" Contract.encoding))
let run_code = let run_code =
RPC_service.post_service RPC_service.post_service
@ -140,32 +139,46 @@ module Scripts = struct
let register () = let register () =
let open Services_registration in let open Services_registration in
register0 S.run_code begin fun ctxt () let originate_dummy_contract ctxt script =
(code, storage, parameter, amount, contract) ->
Lwt.return (Gas.set_limit ctxt (Constants.hard_gas_limit_per_operation ctxt)) >>=? fun ctxt ->
let ctxt = Contract.init_origination_nonce ctxt Operation_hash.zero in let ctxt = Contract.init_origination_nonce ctxt Operation_hash.zero in
Contract.fresh_contract_from_current_nonce ctxt >>=? fun (ctxt, dummy_contract) ->
let balance = match Tez.of_mutez 4_000_000_000_000L with
| Some balance -> balance
| None -> assert false in
Contract.originate ctxt dummy_contract
~balance
~manager: Signature.Public_key_hash.zero
~delegate: None
~spendable: false
~delegatable: false
~script: (script, None) >>=? fun ctxt ->
return (ctxt, dummy_contract) in
register0 S.run_code begin fun ctxt ()
(code, storage, parameter, amount) ->
let storage = Script.lazy_expr storage in let storage = Script.lazy_expr storage in
let code = Script.lazy_expr code in let code = Script.lazy_expr code in
originate_dummy_contract ctxt { storage ; code } >>=? fun (ctxt, dummy_contract) ->
Lwt.return (Gas.set_limit ctxt (Constants.hard_gas_limit_per_operation ctxt)) >>=? fun ctxt ->
Script_interpreter.execute Script_interpreter.execute
ctxt Readable ctxt Readable
~source:contract (* transaction initiator *) ~source:dummy_contract
~payer:contract (* storage fees payer *) ~payer:dummy_contract
~self:(contract, { storage ; code }) (* script owner *) ~self:(dummy_contract, { storage ; code })
~amount ~parameter ~amount ~parameter
>>=? fun { Script_interpreter.storage ; operations ; big_map_diff ; _ } -> >>=? fun { Script_interpreter.storage ; operations ; big_map_diff ; _ } ->
return (storage, operations, big_map_diff) return (storage, operations, big_map_diff)
end ; end ;
register0 S.trace_code begin fun ctxt () register0 S.trace_code begin fun ctxt ()
(code, storage, parameter, amount, contract) -> (code, storage, parameter, amount) ->
Lwt.return (Gas.set_limit ctxt (Constants.hard_gas_limit_per_operation ctxt)) >>=? fun ctxt ->
let ctxt = Contract.init_origination_nonce ctxt Operation_hash.zero in
let storage = Script.lazy_expr storage in let storage = Script.lazy_expr storage in
let code = Script.lazy_expr code in let code = Script.lazy_expr code in
originate_dummy_contract ctxt { storage ; code } >>=? fun (ctxt, dummy_contract) ->
Lwt.return (Gas.set_limit ctxt (Constants.hard_gas_limit_per_operation ctxt)) >>=? fun ctxt ->
Script_interpreter.trace Script_interpreter.trace
ctxt Readable ctxt Readable
~source:contract (* transaction initiator *) ~source:dummy_contract
~payer:contract (* storage fees payer *) ~payer:dummy_contract
~self:(contract, { storage ; code }) (* script owner *) ~self:(dummy_contract, { storage ; code })
~amount ~parameter ~amount ~parameter
>>=? fun ({ Script_interpreter.storage ; operations ; big_map_diff ; _ }, trace) -> >>=? fun ({ Script_interpreter.storage ; operations ; big_map_diff ; _ }, trace) ->
return (storage, operations, trace, big_map_diff) return (storage, operations, trace, big_map_diff)
@ -249,13 +262,13 @@ module Scripts = struct
end end
let run_code ctxt block code (storage, input, amount, contract) = let run_code ctxt block code (storage, input, amount) =
RPC_context.make_call0 S.run_code ctxt RPC_context.make_call0 S.run_code ctxt
block () (code, storage, input, amount, contract) block () (code, storage, input, amount)
let trace_code ctxt block code (storage, input, amount, contract) = let trace_code ctxt block code (storage, input, amount) =
RPC_context.make_call0 S.trace_code ctxt RPC_context.make_call0 S.trace_code ctxt
block () (code, storage, input, amount, contract) block () (code, storage, input, amount)
let typecheck_code ctxt block = let typecheck_code ctxt block =
RPC_context.make_call0 S.typecheck_code ctxt block () RPC_context.make_call0 S.typecheck_code ctxt block ()

View File

@ -25,7 +25,7 @@ module Scripts : sig
val run_code: val run_code:
'a #RPC_context.simple -> 'a #RPC_context.simple ->
'a -> Script.expr -> (Script.expr * Script.expr * Tez.t * Contract.t) -> 'a -> Script.expr -> (Script.expr * Script.expr * Tez.t) ->
(Script.expr * (Script.expr *
packed_internal_operation list * packed_internal_operation list *
Contract.big_map_diff option) shell_tzresult Lwt.t Contract.big_map_diff option) shell_tzresult Lwt.t
@ -33,7 +33,7 @@ module Scripts : sig
val trace_code: val trace_code:
'a #RPC_context.simple -> 'a #RPC_context.simple ->
'a -> Script.expr -> 'a -> Script.expr ->
(Script.expr * Script.expr * Tez.t * Contract.t) -> (Script.expr * Script.expr * Tez.t) ->
(Script.expr * (Script.expr *
packed_internal_operation list * packed_internal_operation list *
Script_interpreter.execution_trace * Script_interpreter.execution_trace *