Verified Commit 82fc0334 authored by Grégoire Henry's avatar Grégoire Henry Committed by Marco Stronati

Alpha/Contracts: uniform indexation for both implicit and originated contracts

This patch change the way contracts are indexed internally, using the
same database paths for implicit contracts, delegate accounts,
scripted and non scripted contracts.

It simplifies future updates, for instance to add new account types.
parent b9408be7
......@@ -172,39 +172,39 @@ let rpc_arg =
()
module Index = struct
type t = contract
let path_length =
assert Compare.Int.(Signature.Public_key_hash.path_length =
1 + Contract_hash.path_length) ;
Signature.Public_key_hash.path_length
let path_length = 6
let to_path c l =
match c with
| Implicit k ->
Signature.Public_key_hash.to_path k l
| Originated h ->
"originated" :: Contract_hash.to_path h l
let raw_key = Data_encoding.Binary.to_bytes_exn encoding c in
let `Hex key = MBytes.to_hex raw_key in
let `Hex index_key = MBytes.to_hex (Raw_hashes.blake2b raw_key) in
String.sub index_key 0 2 ::
String.sub index_key 2 2 ::
String.sub index_key 4 2 ::
String.sub index_key 6 2 ::
String.sub index_key 8 2 ::
key ::
l
let of_path = function
| "originated" :: key -> begin
match Contract_hash.of_path key with
| None -> None
| Some h -> Some (Originated h)
end
| key -> begin
match Signature.Public_key_hash.of_path key with
| None -> None
| Some h -> Some (Implicit h)
end
let contract_prefix s =
"originated" :: Contract_hash.prefix_path s
let pkh_prefix_ed25519 s =
Ed25519.Public_key_hash.prefix_path s
let pkh_prefix_secp256k1 s =
Secp256k1.Public_key_hash.prefix_path s
let pkh_prefix_p256 s =
P256.Public_key_hash.prefix_path s
| [] | [_] | [_;_] | [_;_;_] | [_;_;_;_] | [_;_;_;_;_]
| _::_::_::_::_::_::_::_ ->
None
| [ index1 ; index2 ; index3 ; index4 ; index5 ; key ] ->
let raw_key = MBytes.of_hex (`Hex key) in
let `Hex index_key = MBytes.to_hex (Raw_hashes.blake2b raw_key) in
assert Compare.String.(String.sub index_key 0 2 = index1) ;
assert Compare.String.(String.sub index_key 2 2 = index2) ;
assert Compare.String.(String.sub index_key 4 2 = index3) ;
assert Compare.String.(String.sub index_key 6 2 = index4) ;
assert Compare.String.(String.sub index_key 8 2 = index5) ;
Data_encoding.Binary.of_bytes encoding raw_key
let rpc_arg = rpc_arg
let encoding = encoding
let compare = compare
end
......@@ -76,10 +76,4 @@ val origination_nonce_encoding : origination_nonce Data_encoding.t
val rpc_arg : contract RPC_arg.arg
module Index : sig
include Storage_description.INDEX with type t = t
val contract_prefix: string -> string list
val pkh_prefix_ed25519: string -> string list
val pkh_prefix_secp256k1: string -> string list
val pkh_prefix_p256: string -> string list
end
module Index : Storage_description.INDEX with type t = t
......@@ -607,50 +607,3 @@ module Ramp_up = struct
end)
end
(** Resolver *)
let () =
Raw_context.register_resolvers
Contract_hash.b58check_encoding
(fun ctxt p ->
let p = Contract_repr.Index.contract_prefix p in
Contract.Indexed_context.resolve ctxt p >|= fun l ->
List.map
(function
| Contract_repr.Implicit _ -> assert false
| Contract_repr.Originated s -> s)
l) ;
Raw_context.register_resolvers
Ed25519.Public_key_hash.b58check_encoding
(fun ctxt p ->
let p = Contract_repr.Index.pkh_prefix_ed25519 p in
Contract.Indexed_context.resolve ctxt p >|= fun l ->
List.map
(function
| Contract_repr.Implicit (Ed25519 pkh) -> pkh
| Contract_repr.Implicit _ -> assert false
| Contract_repr.Originated _ -> assert false)
l) ;
Raw_context.register_resolvers
Secp256k1.Public_key_hash.b58check_encoding
(fun ctxt p ->
let p = Contract_repr.Index.pkh_prefix_secp256k1 p in
Contract.Indexed_context.resolve ctxt p >|= fun l ->
List.map
(function
| Contract_repr.Implicit (Secp256k1 pkh) -> pkh
| Contract_repr.Implicit _ -> assert false
| Contract_repr.Originated _ -> assert false)
l) ;
Raw_context.register_resolvers
P256.Public_key_hash.b58check_encoding
(fun ctxt p ->
let p = Contract_repr.Index.pkh_prefix_p256 p in
Contract.Indexed_context.resolve ctxt p >|= fun l ->
List.map
(function
| Contract_repr.Implicit (P256 pkh) -> pkh
| Contract_repr.Implicit _ -> assert false
| Contract_repr.Originated _ -> assert false)
l)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment