Created
November 3, 2021 21:39
-
-
Save smondet/006fa072e8d7afb32ba1adec106b09d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* In the tezos codebase: Use ["dune utop src/lib_base figure_out_kt1.ml"] *) | |
open Tezos_crypto | |
let enc = | |
(* src/proto_alpha/lib_protocol/contract_repr.ml *) | |
let open Data_encoding in | |
obj2 (req "operation" Operation_hash.encoding) (dft "index" int32 0l) | |
(* src/proto_alpha/lib_protocol/contract_hash.ml *) | |
let contract_hash = "\002\090\121" (* KT1(36) *) | |
module H = | |
Blake2B.Make | |
(Base58) | |
(struct | |
let name = "Contract_hash" | |
let title = "A contract ID" | |
let b58check_prefix = contract_hash | |
let size = Some 20 | |
end) | |
let input = | |
[ | |
("ooLC2QykF5NGiugdTyXJwsn2MEPMdRYJ4TeUoPMx8s38NzFximC", 0l); | |
(* let expected = "KT1B94zMXzBr5nLuGXxx1GF7r6uSK6Sfz7pn" *) | |
("opCCqC2xtPgXHdoYynQF4WajE3BvAJwr2uJN4jS54ziweKCiUgw", 0l); | |
("opCCqC2xtPgXHdoYynQF4WajE3BvAJwr2uJN4jS54ziweKCiUgw", 1l); | |
("opCCqC2xtPgXHdoYynQF4WajE3BvAJwr2uJN4jS54ziweKCiUgw", 1023l); | |
("opCCqC2xtPgXHdoYynQF4WajE3BvAJwr2uJN4jS54ziweKCiUgw", 0xdeadbeefl); | |
] | |
let op op58 = Operation_hash.of_b58check_exn op58 | |
let data op index = Data_encoding.Binary.to_bytes_exn enc (op, index) | |
let () = | |
Fmt.pr "[\n" ; | |
ListLabels.iter input ~f:(fun (op58, index) -> | |
let kt1 = H.hash_bytes [data (op op58) index] |> H.to_b58check in | |
Fmt.pr " (%S, 0x%lxl, %S);\n" op58 index kt1) ; | |
Fmt.pr "]\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment