From 25ecd68b908a927d022b97b36fca4e17ccabff1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Mon, 16 Apr 2018 00:44:19 +0200 Subject: [PATCH] Alpha: use singular for `Sourced_operation` --- .../lib_client/client_proto_context.ml | 10 +++++----- src/proto_alpha/lib_client/injection.ml | 8 ++++---- .../lib_client/operation_result.ml | 12 +++++------ .../lib_protocol/src/alpha_context.mli | 4 ++-- src/proto_alpha/lib_protocol/src/apply.ml | 12 +++++------ .../lib_protocol/src/helpers_services.ml | 16 +++++++-------- .../lib_protocol/src/operation_repr.ml | 20 +++++++++---------- .../lib_protocol/src/operation_repr.mli | 4 ++-- .../test/helpers/helpers_operation.ml | 4 ++-- .../test/helpers/helpers_operation.mli | 6 +++--- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 801daa9d4..6df23ae8d 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -52,7 +52,7 @@ let transfer (cctxt : #Proto_alpha.full) let operations = [Transaction { amount ; parameters ; destination }] in append_reveal cctxt block ~source ~src_pk operations >>=? fun operations -> let contents = - Sourced_operations + Sourced_operation (Manager_operations { source ; fee ; counter ; gas_limit ; operations }) in Injection.inject_operation cctxt block ?confirmations @@ -72,7 +72,7 @@ let reveal cctxt | _ :: _ -> let gas_limit = Z.zero in let contents = - Sourced_operations + Sourced_operation (Manager_operations { source ; fee ; counter ; gas_limit ; operations }) in Injection.inject_operation cctxt block ?confirmations @@ -88,7 +88,7 @@ let originate append_reveal cctxt block ~source ~src_pk operations >>=? fun operations -> let contents = - Sourced_operations + Sourced_operation (Manager_operations { source ; fee ; counter ; gas_limit ; operations }) in Injection.inject_operation cctxt block ?confirmations @@ -127,7 +127,7 @@ let delegate_contract cctxt append_reveal cctxt block ~source ~src_pk operations >>=? fun operations -> let contents = - Sourced_operations + Sourced_operation (Manager_operations { source ; fee ; counter ; gas_limit = Z.zero ; operations }) in Injection.inject_operation cctxt block ?confirmations @@ -173,7 +173,7 @@ let get_manager return (src_name, src_pkh, src_pk, src_sk) let dictate rpc_config block ?confirmations command src_sk = - let contents = Sourced_operations (Dictator_operation command) in + let contents = Sourced_operation (Dictator_operation command) in Injection.inject_operation rpc_config block ?confirmations ~src_sk contents >>=? fun res -> diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 66405af3f..0716b58fb 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -35,7 +35,7 @@ let preapply ({ branch }, contents) in let watermark = match contents with - | Sourced_operations (Consensus_operation (Endorsements _)) -> + | Sourced_operation (Consensus_operation (Endorsements _)) -> Signature.Endorsement | _ -> Signature.Generic_operation in @@ -92,10 +92,10 @@ let may_patch_gas_limit ?src_sk contents = Alpha_services.Constants.hard_gas_limits cctxt block >>=? fun (_, gas_limit) -> match contents with - | Sourced_operations (Manager_operations c) + | Sourced_operation (Manager_operations c) when c.gas_limit < Z.zero || gas_limit < c.gas_limit -> let contents = - Sourced_operations (Manager_operations { c with gas_limit }) in + Sourced_operation (Manager_operations { c with gas_limit }) in preapply cctxt block ?branch ?src_sk contents >>=? fun (_, _, result) -> Lwt.return (estimated_gas result) >>=? fun gas -> begin @@ -108,7 +108,7 @@ let may_patch_gas_limit (Z.to_string gas) >>= fun () -> return (Z.add gas (Z.of_int 100)) end >>=? fun gas_limit -> - return (Sourced_operations (Manager_operations { c with gas_limit })) + return (Sourced_operation (Manager_operations { c with gas_limit })) | op -> return op let inject_operation diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 628a8ea88..858c25533 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -173,7 +173,7 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) = | _, _ -> invalid_arg "Apply_operation_result.pp" in Format.pp_print_list pp_anonymous_operation_result ppf ops_rs - | Sourced_operations + | Sourced_operation (Consensus_operation (Endorsements { block ; level ; slots })), Sourced_operation_result @@ -192,7 +192,7 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) = ~pp_sep:Format.pp_print_space Format.pp_print_int) slots - | Sourced_operations + | Sourced_operation (Amendment_operation { source ; operation = Proposals { period ; proposals } }), Sourced_operation_result Amendment_operation_result -> Format.fprintf ppf @@ -204,7 +204,7 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) = Signature.Public_key_hash.pp source Voting_period.pp period (Format.pp_print_list Protocol_hash.pp) proposals - | Sourced_operations + | Sourced_operation (Amendment_operation { source ; operation = Ballot { period ; proposal ; ballot } }), Sourced_operation_result Amendment_operation_result -> Format.fprintf ppf @@ -217,19 +217,19 @@ let pp_operation_result ppf ({ contents ; _ }, operation_result) = Voting_period.pp period Protocol_hash.pp proposal (match ballot with Yay -> "YAY" | Pass -> "PASS" | Nay -> "NAY") - | Sourced_operations (Dictator_operation (Activate protocol)), + | Sourced_operation (Dictator_operation (Activate protocol)), Sourced_operation_result Dictator_operation_result -> Format.fprintf ppf "@[Dictator protocol activation:@,\ Protocol: %a@]" Protocol_hash.pp protocol - | Sourced_operations (Dictator_operation (Activate_testchain protocol)), + | Sourced_operation (Dictator_operation (Activate_testchain protocol)), Sourced_operation_result Dictator_operation_result -> Format.fprintf ppf "@[Dictator test protocol activation:@,\ Protocol: %a@]" Protocol_hash.pp protocol - | Sourced_operations (Manager_operations { source ; fee ; counter ; operations ; gas_limit }), + | Sourced_operation (Manager_operations { source ; fee ; counter ; operations ; gas_limit }), Sourced_operation_result (Manager_operations_result { balance_updates ; operation_results }) -> let pp_result ppf result = Format.fprintf ppf "@," ; diff --git a/src/proto_alpha/lib_protocol/src/alpha_context.mli b/src/proto_alpha/lib_protocol/src/alpha_context.mli index fcc17186b..37f40e0a1 100644 --- a/src/proto_alpha/lib_protocol/src/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/src/alpha_context.mli @@ -717,7 +717,7 @@ type operation = { and proto_operation = | Anonymous_operations of anonymous_operation list - | Sourced_operations of sourced_operations + | Sourced_operation of sourced_operation and anonymous_operation = | Seed_nonce_revelation of { @@ -737,7 +737,7 @@ and anonymous_operation = secret: Blinded_public_key_hash.secret ; } -and sourced_operations = +and sourced_operation = | Consensus_operation of consensus_operation | Amendment_operation of { source: Signature.Public_key_hash.t ; diff --git a/src/proto_alpha/lib_protocol/src/apply.ml b/src/proto_alpha/lib_protocol/src/apply.ml index a067bfda2..7bed69042 100644 --- a/src/proto_alpha/lib_protocol/src/apply.ml +++ b/src/proto_alpha/lib_protocol/src/apply.ml @@ -608,8 +608,8 @@ let apply_anonymous_operation ctxt _delegate kind = return (ctxt, Seed_nonce_revelation_result [(* FIXME *)]) | Double_endorsement_evidence { op1 ; op2 } -> begin match op1.contents, op2.contents with - | Sourced_operations (Consensus_operation (Endorsements e1)), - Sourced_operations (Consensus_operation (Endorsements e2)) + | Sourced_operation (Consensus_operation (Endorsements e1)), + Sourced_operation (Consensus_operation (Endorsements e2)) when Raw_level.(e1.level = e2.level) && not (Block_hash.equal e1.block e2.block) -> let level = Level.from_raw ctxt e1.level in @@ -709,7 +709,7 @@ let apply_operation (ctxt, []) ops >>=? fun (ctxt, results) -> return (ctxt, Anonymous_operations_result (List.rev results)) - | Sourced_operations ops -> + | Sourced_operation ops -> apply_sourced_operation ctxt pred_block block_prio operation ops >>=? fun (ctxt, result) -> return (ctxt, Sourced_operation_result result) @@ -800,9 +800,9 @@ let finalize_application ctxt protocol_data delegate = let compare_operations op1 op2 = match op1.contents, op2.contents with | Anonymous_operations _, Anonymous_operations _ -> 0 - | Anonymous_operations _, Sourced_operations _ -> -1 - | Sourced_operations _, Anonymous_operations _ -> 1 - | Sourced_operations op1, Sourced_operations op2 -> + | Anonymous_operations _, Sourced_operation _ -> -1 + | Sourced_operation _, Anonymous_operations _ -> 1 + | Sourced_operation op1, Sourced_operation op2 -> match op1, op2 with | Consensus_operation _, (Amendment_operation _ | Manager_operations _ | Dictator_operation _) -> -1 | (Amendment_operation _ | Manager_operations _ | Dictator_operation _), Consensus_operation _ -> 1 diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.ml b/src/proto_alpha/lib_protocol/src/helpers_services.ml index aa05123ef..d3c85b583 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.ml +++ b/src/proto_alpha/lib_protocol/src/helpers_services.ml @@ -320,7 +320,7 @@ module Forge = struct Manager_operations { source ; counter ; operations ; fee ; gas_limit } in (RPC_context.make_call0 S.operations ctxt block - () ({ branch }, Sourced_operations ops)) + () ({ branch }, Sourced_operation ops)) let reveal ctxt block ~branch ~source ~sourcePubKey ~counter ~fee ()= @@ -364,7 +364,7 @@ module Forge = struct block ~branch operation = let ops = Consensus_operation operation in (RPC_context.make_call0 S.operations ctxt block - () ({ branch }, Sourced_operations ops)) + () ({ branch }, Sourced_operation ops)) let endorsement ctxt b ~branch ~block ~level ~slots () = @@ -380,7 +380,7 @@ module Forge = struct block ~branch ~source operation = let ops = Amendment_operation { source ; operation } in (RPC_context.make_call0 S.operations ctxt block - () ({ branch }, Sourced_operations ops)) + () ({ branch }, Sourced_operation ops)) let proposals ctxt b ~branch ~source ~period ~proposals () = @@ -400,7 +400,7 @@ module Forge = struct block ~branch operation = let op = Dictator_operation operation in (RPC_context.make_call0 S.operations ctxt block - () ({ branch }, Sourced_operations op)) + () ({ branch }, Sourced_operation op)) let activate ctxt b ~branch hash = @@ -472,7 +472,7 @@ module Parse = struct let check_signature ctxt signature shell contents = match contents with | Anonymous_operations _ -> return () - | Sourced_operations (Manager_operations op) -> + | Sourced_operation (Manager_operations op) -> let public_key = List.fold_left (fun acc op -> match op with @@ -487,16 +487,16 @@ module Parse = struct end >>=? fun public_key -> Operation.check_signature public_key { signature ; shell ; contents } - | Sourced_operations (Consensus_operation (Endorsements { level ; slots ; _ })) -> + | Sourced_operation (Consensus_operation (Endorsements { level ; slots ; _ })) -> let level = Level.from_raw ctxt level in Baking.check_endorsements_rights ctxt level slots >>=? fun public_key -> Operation.check_signature public_key { signature ; shell ; contents } - | Sourced_operations (Amendment_operation { source ; _ }) -> + | Sourced_operation (Amendment_operation { source ; _ }) -> Roll.delegate_pubkey ctxt source >>=? fun source -> Operation.check_signature source { signature ; shell ; contents } - | Sourced_operations (Dictator_operation _) -> + | Sourced_operation (Dictator_operation _) -> let key = Constants.dictator_pubkey ctxt in Operation.check_signature key { signature ; shell ; contents } diff --git a/src/proto_alpha/lib_protocol/src/operation_repr.ml b/src/proto_alpha/lib_protocol/src/operation_repr.ml index 263bcc29c..6aed575cf 100644 --- a/src/proto_alpha/lib_protocol/src/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/src/operation_repr.ml @@ -24,7 +24,7 @@ type operation = { and proto_operation = | Anonymous_operations of anonymous_operation list - | Sourced_operations of sourced_operations + | Sourced_operation of sourced_operation and anonymous_operation = | Seed_nonce_revelation of { @@ -44,7 +44,7 @@ and anonymous_operation = secret: Blinded_public_key_hash.secret ; } -and sourced_operations = +and sourced_operation = | Consensus_operation of consensus_operation | Amendment_operation of { source: Signature.Public_key_hash.t ; @@ -317,8 +317,8 @@ module Encoding = struct manager_kind_case (Tag 2) ; dictator_kind_case (Tag 3) ; ]) - (function Sourced_operations ops -> Some ops | _ -> None) - (fun ops -> Sourced_operations ops) + (function Sourced_operation op -> Some op | _ -> None) + (fun op -> Sourced_operation op) let seed_nonce_revelation_encoding = (obj3 @@ -469,10 +469,10 @@ let parse (op: Operation.t) = let acceptable_passes op = match op.contents with - | Sourced_operations (Consensus_operation _) -> [0] - | Sourced_operations (Amendment_operation _ | Dictator_operation _) -> [1] + | Sourced_operation (Consensus_operation _) -> [0] + | Sourced_operation (Amendment_operation _ | Dictator_operation _) -> [1] | Anonymous_operations _ -> [2] - | Sourced_operations (Manager_operations _) -> [3] + | Sourced_operation (Manager_operations _) -> [3] type error += Invalid_signature (* `Permanent *) type error += Missing_signature (* `Permanent *) @@ -508,9 +508,9 @@ let forge shell proto = let check_signature key { shell ; contents ; signature } = match contents, signature with | Anonymous_operations _, _ -> return () - | Sourced_operations _, None -> + | Sourced_operation _, None -> fail Missing_signature - | Sourced_operations (Consensus_operation _), Some signature -> + | Sourced_operation (Consensus_operation _), Some signature -> (* Safe for baking *) let unsigned_operation = forge shell contents in if Signature.check @@ -519,7 +519,7 @@ let check_signature key { shell ; contents ; signature } = return () else fail Invalid_signature - | Sourced_operations _, Some signature -> + | Sourced_operation _, Some signature -> (* Unsafe for baking *) let unsigned_operation = forge shell contents in if Signature.check diff --git a/src/proto_alpha/lib_protocol/src/operation_repr.mli b/src/proto_alpha/lib_protocol/src/operation_repr.mli index 9364c972a..fac1715cb 100644 --- a/src/proto_alpha/lib_protocol/src/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/src/operation_repr.mli @@ -24,7 +24,7 @@ type operation = { and proto_operation = | Anonymous_operations of anonymous_operation list - | Sourced_operations of sourced_operations + | Sourced_operation of sourced_operation and anonymous_operation = | Seed_nonce_revelation of { @@ -44,7 +44,7 @@ and anonymous_operation = secret: Blinded_public_key_hash.secret ; } -and sourced_operations = +and sourced_operation = | Consensus_operation of consensus_operation | Amendment_operation of { source: Signature.Public_key_hash.t ; diff --git a/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.ml b/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.ml index 822730c0c..657139900 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.ml @@ -11,7 +11,7 @@ open Proto_alpha open Error_monad open Alpha_context -let sourced ops = Sourced_operations ops +let sourced ops = Sourced_operation ops let manager (src : Helpers_account.t) ?(fee = Tez.zero) operations context gas_limit = Alpha_context.prepare @@ -101,7 +101,7 @@ let sign src oph protop = let watermark = match protop with | Proto_alpha.Alpha_context.Anonymous_operations _ -> None - | Proto_alpha.Alpha_context.Sourced_operations + | Proto_alpha.Alpha_context.Sourced_operation (Proto_alpha.Alpha_context.Consensus_operation (Endorsements _)) -> Some Signature.Endorsement | _ -> diff --git a/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.mli b/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.mli index e394263f9..4d06a02b9 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/helpers_operation.mli @@ -12,11 +12,11 @@ open Alpha_context (** Functions building operations *) -val sourced : sourced_operations -> proto_operation +val sourced : sourced_operation -> proto_operation val manager : Helpers_account.t -> ?fee:Tez.tez -> manager_operation list -> - Alpha_environment.Context.t -> Z.t -> sourced_operations proto_tzresult Lwt.t + Alpha_environment.Context.t -> Z.t -> sourced_operation proto_tzresult Lwt.t val manager_full : Helpers_account.t -> ?fee:Tez.tez -> manager_operation list -> @@ -50,7 +50,7 @@ val transaction_full : Alpha_environment.Context.t -> proto_operation proto_tzresult Lwt.t val amendment_operation : - Helpers_account.t -> amendment_operation -> sourced_operations + Helpers_account.t -> amendment_operation -> sourced_operation val endorsements : ?slot:int -> Block_hash.t -> Raw_level.t -> consensus_operation