Skip to content

Commit

Permalink
Use margin=90
Browse files Browse the repository at this point in the history
  • Loading branch information
vaivaswatha committed Jan 16, 2020
1 parent 959ad36 commit b61f33e
Show file tree
Hide file tree
Showing 77 changed files with 971 additions and 2,201 deletions.
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
margin=90
6 changes: 2 additions & 4 deletions src/base/AssocDictionary.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ let lookup k d =
let rec update k v d =
match d with
| [] -> []
| (kd, vd) :: rest ->
if k = kd then (k, v) :: rest else (kd, vd) :: update k v rest
| (kd, vd) :: rest -> if k = kd then (k, v) :: rest else (kd, vd) :: update k v rest

let rec update_all k v d =
match d with
| [] -> []
| (kd, vd) :: rest ->
if k = kd then (k, v) :: update_all k v rest
else (kd, vd) :: update_all k v rest
if k = kd then (k, v) :: update_all k v rest else (kd, vd) :: update_all k v rest

let insert_unique k v d =
let d' = remove_all k d in
Expand Down
25 changes: 7 additions & 18 deletions src/base/Bech32.ml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ let decode_bech32_addr ~prefix ~addr:str =
(* Create a buffer of bits for the result (20-byte raw address). *)
let bitacc = Buffer.create () in
let chk, err, (have_lower, have_upper), _ =
List.fold
(String.to_list addr_chk_str)
List.fold (String.to_list addr_chk_str)
~init:(chk, false, (false, false), 0)
~f:(fun (chk, err, (have_lower, have_upper), index) c ->
(* do nothing if we've already seen an error. *)
Expand All @@ -144,17 +143,11 @@ let decode_bech32_addr ~prefix ~addr:str =

(* Accumulate the lower 5 bits of c' into our bit buffer *)
( if index < bech32_payload_len then
let shifted_5_bits =
Bytes.make 1 (char_of_ascii (c' lsl (8 - 5)))
in
let shifted_5_bits = Bytes.make 1 (char_of_ascii (c' lsl (8 - 5))) in
Buffer.add_bits bitacc shifted_5_bits 5 );

let have_lower' =
c' >= ascii_of_char 'a' && c' <= ascii_of_char 'z'
in
let have_upper' =
c' >= ascii_of_char 'A' && c' <= ascii_of_char 'Z'
in
let have_lower' = c' >= ascii_of_char 'a' && c' <= ascii_of_char 'z' in
let have_upper' = c' >= ascii_of_char 'A' && c' <= ascii_of_char 'Z' in
(chk', err, (have_lower', have_upper'), index + 1))
in
if err || (have_lower && have_upper) then None
Expand All @@ -163,8 +156,7 @@ let decode_bech32_addr ~prefix ~addr:str =

(* Check if a bech32 address string is valid, based on the specification in
* https://github.com/Zilliqa/Zilliqa/wiki/Address-Standard#specification *)
let is_valid_bech32 ~prefix ~addr =
Option.is_some (decode_bech32_addr ~prefix ~addr)
let is_valid_bech32 ~prefix ~addr = Option.is_some (decode_bech32_addr ~prefix ~addr)

(* Encodes a 20-byte string into the bech32 address format.
* Signature: prefix -> bystr20 address -> bech32_addr. *)
Expand All @@ -174,8 +166,7 @@ let encode_bech32_addr ~prefix ~addr:bys =
else
(* 2. Scan the prefix for errors. *)
let chk, err =
List.fold (String.to_list prefix) ~init:(1, false)
~f:(fun (chk, err) ch ->
List.fold (String.to_list prefix) ~init:(1, false) ~f:(fun (chk, err) ch ->
if
err
|| ascii_of_char ch < 33
Expand Down Expand Up @@ -225,9 +216,7 @@ let encode_bech32_addr ~prefix ~addr:bys =
if err then None
else
(* 7. We are left with building up the last 6 / checksum characters. *)
let chk =
int_fold ~init:chk ~f:(fun chkacc _ -> bech32_polymod_step chkacc) 6
in
let chk = int_fold ~init:chk ~f:(fun chkacc _ -> bech32_polymod_step chkacc) 6 in
let chk = chk lxor 1 in
let chkstr =
int_fold 6 ~init:"" ~f:(fun acc i ->
Expand Down
Loading

0 comments on commit b61f33e

Please sign in to comment.