1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.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. *)(* *)(*****************************************************************************)typet=Bytes.tlistincludeCompare.Make(structtypenonrect=t(* Fitness comparison:
- shortest lists are smaller ;
- lexicographical order for lists of the same length. *)letcompare_bytesb1b2=letlen1=Bytes.lengthb1inletlen2=Bytes.lengthb2inletc=comparelen1len2inifc<>0thencelseletreccompare_byteb1b2poslen=ifpos=lenthen0elseletc=compare(Bytes.getb1pos)(Bytes.getb2pos)inifc<>0thencelsecompare_byteb1b2(pos+1)lenincompare_byteb1b20len1letcomparef1f2=letreccompare_recf1f2=match(f1,f2)with|[],[]->0|i1::f1,i2::f2->leti=compare_bytesi1i2inifi=0thencompare_recf1f2elsei|_,_->assertfalseinletlen=compare(List.lengthf1)(List.lengthf2)iniflen=0thencompare_recf1f2elselenend)letrecppfmt=function|[]->()|[f]->Format.fprintffmt"%a"Hex.pp(Hex.of_bytesf)|f1::f->Format.fprintffmt"%a::%a"Hex.pp(Hex.of_bytesf1)ppfletencoding=letopenData_encodingindef"fitness"~title:"Block fitness"~description:"The fitness, or score, of a block, that allow the Tezos to decide which \
chain is the best. A fitness value is a list of byte sequences. They \
are compared as follows: shortest lists are smaller; lists of the same \
length are compared according to the lexicographical order."@@splitted~json:(listbytes)~binary:(list(def"fitness.elem"bytes))letto_bytesv=Data_encoding.Binary.to_bytes_exnencodingvletof_bytesb=Data_encoding.Binary.of_bytes_optencodingb