123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduletypeTEMP_ID=sigtypetvalequal:t->t->boolvalinit:tvalnext:t->tendmoduletypeID=sigtypetvalcompare:t->t->intvalencoding:tData_encoding.tvalrpc_arg:tRPC_arg.argvalinit:t(** In the protocol, to be used in parse_data only *)valparse_z:Z.t->t(** In the protocol, to be used in unparse_data only *)valunparse_to_z:t->Z.tvalnext:t->tvalis_temp:t->boolvalof_legacy_USE_ONLY_IN_Legacy_big_map_diff:Z.t->tvalto_legacy_USE_ONLY_IN_Legacy_big_map_diff:t->Z.tincludePath_encoding.Swithtypet:=tendmoduletypeTitle=sigvaltitle:stringendmoduletypeTitleWithId=sigvaltitle:stringmoduleId:IDmoduleTemp_id:TEMP_IDwithtypet=privateId.tmoduleIdSet:Set.Swithtypeelt=Id.tendmoduleMakeId(Title:Title):TitleWithId=structlettitle=Title.titlelettitle_words=String.map(function'_'->' '|c->c)titleletrpc_arg_error=Format.sprintf"Cannot parse %s id"title_wordsletdescription=Format.sprintf"A %s identifier"title_wordsletname=title^"_id"letencoding_title=String.capitalize_asciititle_words^" identifier"moduleId=structtypet=Z.tletcompare=Z.compareletencoding=Data_encoding.defname~title:encoding_title~descriptionData_encoding.zletrpc_arg=letconstruct=Z.to_stringinletdestructhash=Result.catch_f(fun()->Z.of_stringhash)(fun_->rpc_arg_error)inRPC_arg.make~descr:description~name~construct~destruct()letinit=Z.zeroletparse_z(z:Z.t):t=zletunparse_to_z(z:t):Z.t=zletnext=Z.succletof_legacy_USE_ONLY_IN_Legacy_big_map_diff(z:Z.t):t=zletto_legacy_USE_ONLY_IN_Legacy_big_map_diff(z:t):Z.t=zletis_tempz=Compare.Z.(z<Z.zero)letpath_length=1letto_pathzl=Z.to_stringz::lletof_path=function|[]|_::_::_->None|[z]->Some(Z.of_stringz)endmoduleTemp_id=structtypet=Id.tletequal=Z.equalletinit=Z.of_int~-1letnextz=Z.subzZ.oneendmoduleIdSet=Set.Make(Id)endmoduleBig_map=structincludeMakeId(structlettitle="big_map"end)typealloc={key_type:Script_repr.expr;value_type:Script_repr.expr}typeupdate={key:Script_repr.expr;(** The key is ignored by [apply_update] but is shown in the receipt,
as specified in [print_big_map_diff]. *)key_hash:Script_expr_hash.t;value:Script_repr.exproption;}typeupdates=updatelistletalloc_encoding=letopenData_encodinginconv(fun{key_type;value_type}->(key_type,value_type))(fun(key_type,value_type)->{key_type;value_type})(obj2(req"key_type"Script_repr.expr_encoding)(req"value_type"Script_repr.expr_encoding))letupdate_encoding=letopenData_encodinginconv(fun{key_hash;key;value}->(key_hash,key,value))(fun(key_hash,key,value)->{key_hash;key;value})(obj3(req"key_hash"Script_expr_hash.encoding)(req"key"Script_repr.expr_encoding)(opt"value"Script_repr.expr_encoding))letupdates_encoding=Data_encoding.listupdate_encodingendmoduleSapling_state=structincludeMakeId(structlettitle="sapling_state"end)typealloc={memo_size:Sapling_repr.Memo_size.t}typeupdates=Sapling_repr.diffletalloc_encoding=letopenData_encodinginconv(fun{memo_size}->memo_size)(funmemo_size->{memo_size})(obj1(req"memo_size"Sapling_repr.Memo_size.encoding))letupdates_encoding=Sapling_repr.diff_encodingend(*
When adding cases to this type, grep for [new lazy storage kind] in the code
for locations to update.
It must be:
- the value [all] right below,
- modules [Temp_ids], [IdSet] below,
- the rest should be guided by type errors.
*)type('id,'alloc,'updates)t=|Big_map:(Big_map.Id.t,Big_map.alloc,Big_map.updates)t|Sapling_state:(Sapling_state.Id.t,Sapling_state.alloc,Sapling_state.updates)ttypeex=Ex_Kind:(_,_,_)t->ex(* /!\ Don't forget to add new lazy storage kinds here. /!\ *)letall=[(0,Ex_KindBig_map);(1,Ex_KindSapling_state)]type(_,_)cmp=Eq:('a,'a)cmp|Neqletequal:typei1a1u1i2a2u2.(i1,a1,u1)t->(i2,a2,u2)t->(i1*a1*u1,i2*a2*u2)cmp=funk1k2->match(k1,k2)with|(Big_map,Big_map)->Eq|(Sapling_state,Sapling_state)->Eq|(Big_map,_)->Neq|(_,Big_map)->Neqtype('i,'a,'u)kind=('i,'a,'u)tmoduleTemp_ids=structtypet={big_map:Big_map.Temp_id.t;sapling_state:Sapling_state.Temp_id.t;}letinit={big_map=Big_map.Temp_id.init;sapling_state=Sapling_state.Temp_id.init}letfresh:typeiau.(i,a,u)kind->t->t*i=funkindtemp_ids->matchkindwith|Big_map->letbig_map=Big_map.Temp_id.nexttemp_ids.big_mapin({temp_idswithbig_map},(temp_ids.big_map:>Big_map.Id.t))|Sapling_state->letsapling_state=Sapling_state.Temp_id.nexttemp_ids.sapling_statein({temp_idswithsapling_state},(temp_ids.sapling_state:>Sapling_state.Id.t))[@@coq_axiom_with_reason"gadt"]letfold_s:typeiau.(i,a,u)kind->('acc->i->'accLwt.t)->t->'acc->'accLwt.t=funkindftemp_idsacc->lethelper(typej)(moduleTemp_id:TEMP_IDwithtypet=j)~lastf=letrecauxaccid=ifTemp_id.equalidlastthenLwt.returnaccelsefaccid>>=funacc->auxacc(Temp_id.nextid)inauxaccTemp_id.initinmatchkindwith|Big_map->helper(moduleBig_map.Temp_id)~last:temp_ids.big_map(funacctemp_id->facc(temp_id:>i))|Sapling_state->helper(moduleSapling_state.Temp_id)~last:temp_ids.sapling_state(funacctemp_id->facc(temp_id:>i))[@@coq_axiom_with_reason"gadt"]endmoduleIdSet=structtypet={big_map:Big_map.IdSet.t;sapling_state:Sapling_state.IdSet.t}type'accfold_f={f:'i'a'u.('i,'a,'u)kind->'i->'acc->'acc}letempty={big_map=Big_map.IdSet.empty;sapling_state=Sapling_state.IdSet.empty}letmem(typeiau)(kind:(i,a,u)kind)(id:i)set=match(kind,set)with|(Big_map,{big_map;_})->Big_map.IdSet.memidbig_map|(Sapling_state,{sapling_state;_})->Sapling_state.IdSet.memidsapling_state[@@coq_axiom_with_reason"gadt"]letadd(typeiau)(kind:(i,a,u)kind)(id:i)set=match(kind,set)with|(Big_map,{big_map;_})->letbig_map=Big_map.IdSet.addidbig_mapin{setwithbig_map}|(Sapling_state,{sapling_state;_})->letsapling_state=Sapling_state.IdSet.addidsapling_statein{setwithsapling_state}[@@coq_axiom_with_reason"gadt"]letdiffset1set2=letbig_map=Big_map.IdSet.diffset1.big_mapset2.big_mapinletsapling_state=Sapling_state.IdSet.diffset1.sapling_stateset2.sapling_statein{big_map;sapling_state}[@@coq_axiom_with_reason"gadt"]letfold(typeiau)(kind:(i,a,u)kind)(f:i->'acc->'acc)set(acc:'acc)=match(kind,set)with|(Big_map,{big_map;_})->Big_map.IdSet.foldfbig_mapacc|(Sapling_state,{sapling_state;_})->Sapling_state.IdSet.foldfsapling_stateacc[@@coq_axiom_with_reason"gadt"]letfold_allfsetacc=List.fold_left(funacc(_,Ex_Kindkind)->foldkind(f.fkind)setacc)accall[@@coq_axiom_with_reason"gadt"]end