From 025187da2f9b5fcbb283e2b9366778c141659e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Wed, 16 May 2018 15:07:15 +0800 Subject: [PATCH] Data_encoding/Json: use strings for all int64 See Issue #190 --- scripts/protocol_parameters.json | 4 ++-- src/bin_client/test/protocol_parameters.json | 4 ++-- src/bin_client/tezos-init-sandboxed-client.sh | 2 +- src/lib_data_encoding/json.ml | 22 +++++++------------ .../lib_baking/test/proto_alpha_helpers.ml | 8 +++---- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/scripts/protocol_parameters.json b/scripts/protocol_parameters.json index 6a72296f4..96cfca723 100644 --- a/scripts/protocol_parameters.json +++ b/scripts/protocol_parameters.json @@ -7,10 +7,10 @@ ], "dictator_pubkey": "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", - "time_between_blocks" : [ 1, 0 ], + "time_between_blocks" : [ "1", "0" ], "blocks_per_roll_snapshot" : 4, "blocks_per_cycle" : 8, "preserved_cycles" : 2, "first_free_baking_slot" : 4, - "proof_of_work_threshold": -1 + "proof_of_work_threshold": "-1" } diff --git a/src/bin_client/test/protocol_parameters.json b/src/bin_client/test/protocol_parameters.json index 76ce28711..600f6ae5c 100644 --- a/src/bin_client/test/protocol_parameters.json +++ b/src/bin_client/test/protocol_parameters.json @@ -20,10 +20,10 @@ ], "dictator_pubkey": "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", - "time_between_blocks" : [ 1, 0 ], + "time_between_blocks" : [ "1", "0" ], "blocks_per_cycle" : 128, "blocks_per_roll_snapshot" : 32, "preserved_cycles" : 1, "first_free_baking_slot" : 4, - "proof_of_work_threshold": -1 + "proof_of_work_threshold": "-1" } diff --git a/src/bin_client/tezos-init-sandboxed-client.sh b/src/bin_client/tezos-init-sandboxed-client.sh index c1dae2942..1aed24352 100755 --- a/src/bin_client/tezos-init-sandboxed-client.sh +++ b/src/bin_client/tezos-init-sandboxed-client.sh @@ -37,7 +37,7 @@ init_sandboxed_client() { ], "dictator_pubkey": "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", - "time_between_blocks" : [ 1, 0 ], + "time_between_blocks" : [ "1", "0" ], "blocks_per_roll_snapshot" : 4, "blocks_per_cycle" : 8, "preserved_cycles" : 2, diff --git a/src/lib_data_encoding/json.ml b/src/lib_data_encoding/json.ml index a39b5425c..23ce1fb31 100644 --- a/src/lib_data_encoding/json.ml +++ b/src/lib_data_encoding/json.ml @@ -31,18 +31,13 @@ let wrap_error f = let int64_encoding = let open Json_encoding in - union [ - case - int32 - (fun i -> - let j = Int64.to_int32 i in - if Int64.equal (Int64.of_int32 j) i then Some j else None) - Int64.of_int32 ; - case - string - (fun i -> Some (Int64.to_string i)) - Int64.of_string - ] + def "int64" + ~title: "64 bit integers" + ~description: "Decimal representation of 64 bit integers" @@ + conv + Int64.to_string + (wrap_error Int64.of_string) + string let n_encoding = let open Json_encoding in @@ -51,8 +46,7 @@ let n_encoding = ~description: "Decimal representation of a positive big number" @@ conv (fun z -> - if Z.sign z < 0 then - raise (Json_encoding.Cannot_destruct ([], Failure "negative natural")) ; + if Z.sign z < 0 then invalid_arg "negative natural" ; Z.to_string z) (fun s -> let n = Z.of_string s in diff --git a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml index 25b8d407b..ca39a2a93 100644 --- a/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml +++ b/src/proto_alpha/lib_baking/test/proto_alpha_helpers.ml @@ -76,12 +76,12 @@ let protocol_parameters = [ "btz1Q1N2ePwhVw5ED3aaRVek6EBzYs1GDkSVD", "3569618927693" ], [ "btz1VFFVsVMYHd5WfaDTAt92BeQYGK8Ri4eLy", "9034781424478" ] ], - "time_between_blocks" : [ 1, 0 ], + "time_between_blocks" : [ "1", "0" ], "blocks_per_cycle" : 4, "blocks_per_roll_snapshot" : 2, "preserved_cycles" : 1, "first_free_baking_slot" : 4, - "proof_of_work_threshold": -1 + "proof_of_work_threshold": "-1" } |json} in match json_result with @@ -99,13 +99,13 @@ let vote_protocol_parameters = [ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ], [ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ] ], - "time_between_blocks" : [ 1, 0 ], + "time_between_blocks" : [ "1", "0" ], "blocks_per_cycle" : 4, "blocks_per_roll_snapshot" : 2, "preserved_cycles" : 1, "first_free_baking_slot" : 4, "blocks_per_voting_period": 2, - "proof_of_work_threshold": -1 + "proof_of_work_threshold": "-1" } |json} in match json_result with