Skip to content

Commit d73b92e

Browse files
committed
Generalizing liquidity client by separating Liquidity from Source
1 parent 66a3dfc commit d73b92e

14 files changed

+593
-334
lines changed

dune-network

Submodule dune-network updated from 7ddbe8c to 9ee1a98

tools/client/build.ocp2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ OCaml.library("ocplib-liquidity-client-functor",
88
"liquidClientSigs.ml";
99
"liquidClientRequest.ml";
1010
"liquidClientTypes.ml";
11+
"liquidTraceRepr.mli";
12+
"liquidTraceRepr.ml";
1113
"liquidClientErrors.ml";
1214
"liquidClientRPCs.ml";
1315
"liquidClient.ml";

tools/client/liquidClient.ml

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ open Lwt.Infix
99
open Dune_Network_Lib.Stdlib
1010
open Dune_Network_Lib.Crypto (* for crypto *)
1111

12-
module Liquidity = LiquidityLang
13-
14-
type liquidity_datatype = Liquidity.datatype Lazy_superposed.t
15-
type liquidity_const = Liquidity.const Lazy_superposed.t
16-
type liquidity_contract = Liquidity.contract Lazy_superposed.t
17-
18-
1912
module Make (L : LANG) = struct
20-
13+
2114
module L = L
2215
module RPC = LiquidClientRPCs.Make(L)
2316
module E = RPC.E
@@ -28,11 +21,17 @@ module Make (L : LANG) = struct
2821
open T
2922
open RPC
3023

24+
type source_datatype = Source.datatype Lazy_superposed.t
25+
type source_const = Source.const Lazy_superposed.t
26+
type source_contract = Source.contract Lazy_superposed.t
27+
3128
type target_datatype = Target.datatype Lazy_superposed.t
3229
type target_const = Target.const Lazy_superposed.t
3330
type target_contract = Target.contract Lazy_superposed.t
3431

35-
type liq_big_map_diff = (bm_id, Liquidity.const) Big_map_diff.t
32+
type liq_big_map_diff = (bm_id, Source.const) Big_map_diff.t
33+
34+
module SourceOperation = OperationMake (Source)
3635

3736
let get_private_key ?private_key () =
3837
match private_key, !LiquidOptions.private_key with
@@ -68,7 +67,7 @@ module Make (L : LANG) = struct
6867
| Some counter -> Lwt.return counter
6968

7069
let big_map_info storage storage_ty id =
71-
Liquidity.list_big_maps storage storage_ty
70+
Source.list_big_maps storage storage_ty
7271
|> List.find_opt (fun ((Bm_id i | Bm_name (i, _)), _, _) -> i = id)
7372

7473
let id_of_info id info = match info with
@@ -153,11 +152,14 @@ module Make (L : LANG) = struct
153152
| None -> get_head ()
154153

155154
let run_pre ?(debug=false) ?(amount = !LiquidOptions.amount)
156-
source_contract target_contract loc_table ?source entry_name input storage =
155+
source_contract
156+
target_contract
157+
loc_table
158+
?source entry_name input storage =
157159
let rpc = if debug then RPC.trace else RPC.run in
158-
let storage_ty = Liquidity.storage source_contract in
160+
let storage_ty = Source.storage source_contract in
159161
let input_ty =
160-
match List.assoc_opt entry_name (Liquidity.entries source_contract) with
162+
match List.assoc_opt entry_name (Source.entries source_contract) with
161163
| Some ty -> ty
162164
| None -> failwith ("Contract has no entry point " ^ entry_name) in
163165
let input = compile_const ~ty:input_ty input in
@@ -204,7 +206,7 @@ module Make (L : LANG) = struct
204206
let get_storage contract address =
205207
let _ = compile_contract contract in
206208
RPC.get_storage address >|= fun storage ->
207-
try decompile_const storage ~ty:(Liquidity.storage contract)
209+
try decompile_const storage ~ty:(Source.storage contract)
208210
with _ ->
209211
Format.eprintf "Could not convert constant to contract storage type.@.";
210212
decompile_const storage
@@ -248,13 +250,13 @@ module Make (L : LANG) = struct
248250

249251
let build_big_map_subst const const_ty big_map_diff =
250252
let open Big_map_diff in
251-
Liquidity.list_big_maps const const_ty |>
253+
Source.list_big_maps const const_ty |>
252254
List.map (fun ((Bm_id i | Bm_name (i, _)), _, _) ->
253255
i, big_map_elements i big_map_diff
254256
)
255257

256258
let replace_init_big_maps big_map_diff storage storage_ty =
257-
Liquidity.apply_big_map_subst
259+
Source.apply_big_map_subst
258260
(build_big_map_subst storage storage_ty big_map_diff)
259261
storage
260262

@@ -264,7 +266,7 @@ module Make (L : LANG) = struct
264266
try Some (get_source ?source ())
265267
with _ -> None in
266268
match comp_init, init_params with
267-
| Liquidity.No_init, [c]
269+
| Source.No_init, [c]
268270
| Init_constant c, [] -> Lwt.return c
269271

270272
| No_init, [] ->
@@ -281,9 +283,9 @@ module Make (L : LANG) = struct
281283
"init_storage: init storage needs %d arguments, but was given %d"
282284
l_req l_giv ;
283285
let param = match init_params with
284-
| [] -> Liquidity.unit
286+
| [] -> Source.unit
285287
| [x] -> x
286-
| _ -> Liquidity.tuple init_params
288+
| _ -> Source.tuple init_params
287289
in
288290
Lwt.return param
289291

@@ -295,13 +297,13 @@ module Make (L : LANG) = struct
295297
l_req l_giv;
296298
let eval_input_storage =
297299
try
298-
Liquidity.default_empty_const (Liquidity.storage contract)
300+
Source.default_empty_const (Source.storage contract)
299301
with Not_found -> failwith "could not construct dummy storage for eval"
300302
in
301303
let eval_input_parameter = match init_params with
302-
| [] -> Liquidity.unit
304+
| [] -> Source.unit
303305
| [x] -> x
304-
| _ -> Liquidity.tuple init_params
306+
| _ -> Source.tuple init_params
305307
in
306308

307309
let ct, _, loc_table = compile_contract c in
@@ -310,7 +312,7 @@ module Make (L : LANG) = struct
310312
>>= fun (_, eval_init_storage, big_map_diff, _) ->
311313
(* Add elements of big map *)
312314
let eval_init_storage =
313-
replace_init_big_maps big_map_diff eval_init_storage (Liquidity.storage contract) in
315+
replace_init_big_maps big_map_diff eval_init_storage (Source.storage contract) in
314316
Lwt.return eval_init_storage
315317

316318

@@ -320,11 +322,11 @@ module Make (L : LANG) = struct
320322
let ty = match comp_init with
321323
| Init_components args_tys ->
322324
(match args_tys with
323-
| [] -> Tunit
325+
| [] -> Source.tunit
324326
| [_, ty] -> ty
325-
| _ -> Ttuple (List.map snd args_tys)
327+
| _ -> Source.ttuple (List.map snd args_tys)
326328
)
327-
| _ -> Liquidity.storage contract in
329+
| _ -> Source.storage contract in
328330
compile_const ~ty init
329331

330332

@@ -571,7 +573,7 @@ module Make (L : LANG) = struct
571573
~loc_table address ?contract entry_name input =
572574
let input_ty = match contract with
573575
| None -> None
574-
| Some c -> match List.assoc_opt entry_name (Liquidity.entries c) with
576+
| Some c -> match List.assoc_opt entry_name (Source.entries c) with
575577
| None -> failwith ("Contract has no entry point " ^ entry_name)
576578
| ty -> ty in
577579
let input_t = compile_const ?ty:input_ty input in
@@ -687,11 +689,11 @@ module Make (L : LANG) = struct
687689
let open Big_map_diff in
688690
function
689691
| Big_map_add { id; key_hash; key; value } ->
690-
let key = Liquidity.const#ast key in
691-
let value = Liquidity.const#ast value in
692+
let key = Source.const#ast key in
693+
let value = Source.const#ast value in
692694
Big_map_add { id; key_hash; key; value }
693695
| Big_map_remove { id; key_hash; key } ->
694-
let key = Liquidity.const#ast key in
696+
let key = Source.const#ast key in
695697
Big_map_remove { id; key_hash; key }
696698
| Big_map_delete { id } ->
697699
Big_map_delete { id }
@@ -719,59 +721,59 @@ module Make (L : LANG) = struct
719721
type 'a t
720722
val init_storage :
721723
?source:string ->
722-
liquidity_contract ->
723-
liquidity_const list -> target_const t
724+
source_contract ->
725+
source_const list -> target_const t
724726
val run :
725727
?amount : LiquidNumber.tez ->
726-
liquidity_contract ->
728+
source_contract ->
727729
string ->
728-
liquidity_const ->
729-
liquidity_const ->
730-
(LiquidityOperation.internal list * liquidity_const *
731-
(bm_id, liquidity_const) Big_map_diff.item
730+
source_const ->
731+
source_const ->
732+
(SourceOperation.internal list * source_const *
733+
(bm_id, source_const) Big_map_diff.item
732734
list)
733735
t
734736
val run_debug :
735737
?amount : LiquidNumber.tez ->
736-
liquidity_contract ->
738+
source_contract ->
737739
string ->
738-
liquidity_const ->
739-
liquidity_const ->
740-
(LiquidityOperation.internal list * liquidity_const *
741-
(bm_id, liquidity_const) Big_map_diff.item
740+
source_const ->
741+
source_const ->
742+
(SourceOperation.internal list * source_const *
743+
(bm_id, source_const) Big_map_diff.item
742744
list *
743-
(Liquidity.location, liquidity_const) Trace.trace_item list)
745+
(Source.location, source_const) Trace.trace_item list)
744746
t
745747
val deploy :
746748
?balance : LiquidNumber.tez ->
747-
liquidity_contract ->
748-
liquidity_const list -> (string * string) t
749+
source_contract ->
750+
source_const list -> (string * string) t
749751
val get_storage :
750-
liquidity_contract -> string -> liquidity_const t
752+
source_contract -> string -> source_const t
751753
val get_big_map_value :
752-
bm_id * liquidity_datatype * liquidity_datatype ->
753-
liquidity_const -> liquidity_const option t
754+
bm_id * source_datatype * source_datatype ->
755+
source_const -> source_const option t
754756
val call :
755-
?contract:liquidity_contract ->
757+
?contract:source_contract ->
756758
?amount : LiquidNumber.tez ->
757-
address:string -> entry:string -> liquidity_const -> string t
759+
address:string -> entry:string -> source_const -> string t
758760
val activate : secret:string -> string t
759761
val inject : operation:bytes -> signature:string -> string t
760762
val pack :
761-
const:liquidity_const -> ty:liquidity_datatype -> bytes t
763+
const:source_const -> ty:source_datatype -> bytes t
762764
val forge_deploy :
763765
?head:Header.t ->
764766
?source:string ->
765767
?public_key:string ->
766768
?balance : LiquidNumber.tez ->
767-
liquidity_contract -> liquidity_const list -> bytes t
769+
source_contract -> source_const list -> bytes t
768770
val forge_call :
769771
?head:Header.t ->
770772
?source:string ->
771773
?public_key:string ->
772-
?contract:liquidity_contract ->
774+
?contract:source_contract ->
773775
?amount : LiquidNumber.tez ->
774-
address:string -> entry:string -> liquidity_const -> bytes t
776+
address:string -> entry:string -> source_const -> bytes t
775777
end
776778

777779
(* Withoud optional argument head *)
@@ -784,21 +786,25 @@ module Make (L : LANG) = struct
784786
>|= fun storage ->
785787
Target.const#ast storage
786788

787-
let run ?amount contract entry_name input storage =
789+
let run ?amount contract entry_name input storage :
790+
(SourceOperation.internal list * source_const *
791+
(LiquidClientUtils.bm_id, source_const)
792+
LiquidClientTypes.Big_map_diff.item list)
793+
Lwt.t =
788794
let contract = contract#ast in
789795
let input = input#ast in
790796
let storage = storage#ast in
791797
run ?amount contract entry_name input storage
792798
>|= fun (ops, storage, bm) ->
793-
(ops, Liquidity.const#ast storage, print_big_map_diff bm)
799+
(ops, Source.const#ast storage, print_big_map_diff bm)
794800

795801
let run_debug ?amount contract entry_name input storage =
796802
let contract = contract#ast in
797803
let input = input#ast in
798804
let storage = storage#ast in
799805
run_debug ?amount contract entry_name input storage
800806
>|= fun (ops, storage, bm, trace) ->
801-
(ops, Liquidity.const#ast storage, print_big_map_diff bm, print_trace trace)
807+
(ops, Source.const#ast storage, print_big_map_diff bm, print_trace trace)
802808

803809
let deploy ?balance contract args =
804810
let contract = contract#ast in
@@ -809,15 +815,15 @@ module Make (L : LANG) = struct
809815
let contract = contract#ast in
810816
get_storage contract address
811817
>|= fun storage ->
812-
Liquidity.const#ast storage
818+
Source.const#ast storage
813819

814820
let get_big_map_value (id, tk, tv) key =
815821
let id = id, tk#ast, tv#ast in
816822
let key = key#ast in
817823
get_big_map_value id key
818824
>|= function
819825
| None -> None
820-
| Some v -> Some (Liquidity.const#ast v)
826+
| Some v -> Some (Source.const#ast v)
821827

822828
let call ?contract ?amount ~address ~entry parameter =
823829
let contract = match contract with

0 commit comments

Comments
 (0)