From ac7f4da1ab5ae968fa06db8e586fb34ec0550f3b Mon Sep 17 00:00:00 2001 From: Vincent Botbol Date: Fri, 3 Aug 2018 15:37:45 +0200 Subject: [PATCH] Alpha: add utility list conversion to operation application results --- .../lib_protocol/src/apply_results.ml | 19 +++++++++++++++++++ .../lib_protocol/src/apply_results.mli | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/proto_alpha/lib_protocol/src/apply_results.ml b/src/proto_alpha/lib_protocol/src/apply_results.ml index 3fd74ff84..d716dc81b 100644 --- a/src/proto_alpha/lib_protocol/src/apply_results.ml +++ b/src/proto_alpha/lib_protocol/src/apply_results.ml @@ -890,6 +890,25 @@ let rec unpack_contents_list : let ops, ress = unpack_contents_list rest in Cons (op, ops), Cons_result (res, ress) +let rec to_list = function + | Contents_result_list (Single_result o) -> [Contents_result o] + | Contents_result_list (Cons_result (o, os)) -> + Contents_result o :: to_list (Contents_result_list os) + +let rec of_list = function + | [] -> assert false + | [Contents_result o] -> Contents_result_list (Single_result o) + | (Contents_result o) :: os -> + let Contents_result_list os = of_list os in + match o, os with + | Manager_operation_result _, Single_result (Manager_operation_result _) -> + Contents_result_list (Cons_result (o, os)) + | Manager_operation_result _, Cons_result _ -> + Contents_result_list (Cons_result (o, os)) + | _ -> + Pervasives.failwith "Operation result list of length > 1 \ + should only contains manager operations result." + let operation_data_and_metadata_encoding = def "operation.alpha.operation_with_metadata" @@ union [ diff --git a/src/proto_alpha/lib_protocol/src/apply_results.mli b/src/proto_alpha/lib_protocol/src/apply_results.mli index 35d016658..6bedb396f 100644 --- a/src/proto_alpha/lib_protocol/src/apply_results.mli +++ b/src/proto_alpha/lib_protocol/src/apply_results.mli @@ -140,6 +140,12 @@ val unpack_contents_list : 'kind contents_and_result_list -> 'kind contents_list * 'kind contents_result_list +val to_list : + packed_contents_result_list -> packed_contents_result list + +val of_list : + packed_contents_result list -> packed_contents_result_list + type ('a, 'b) eq = Eq : ('a, 'a) eq val kind_equal_list : 'kind contents_list -> 'kind2 contents_result_list -> ('kind, 'kind2) eq option