2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
open Tezos_hash
|
|
|
|
open Storage_functors
|
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
module Int32 = struct
|
|
|
|
type t = Int32.t
|
|
|
|
let encoding = Data_encoding.int32
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
module Bool = struct
|
|
|
|
type t = bool
|
|
|
|
let encoding = Data_encoding.bool
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
(** Contracts handling *)
|
|
|
|
|
|
|
|
module Contract = struct
|
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
module Raw_context =
|
|
|
|
Make_subcontext(Raw_context)(struct let name = ["contracts"] end)
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
module Global_counter =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["global_counter"] end)
|
|
|
|
(Make_value(Int32))
|
|
|
|
|
|
|
|
module Indexed_context =
|
|
|
|
Make_indexed_subcontext
|
|
|
|
(Make_subcontext(Raw_context)(struct let name = ["index"] end))
|
|
|
|
(Contract_repr.Index)
|
|
|
|
|
|
|
|
let list = Indexed_context.keys
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Balance =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["balance"] end)
|
|
|
|
(Make_value(Tez_repr))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Manager =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["manager"] end)
|
|
|
|
(Make_value(Manager_repr))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Spendable =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["spendable"] end)
|
|
|
|
(Make_value(Bool))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Delegatable =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["delegatable"] end)
|
|
|
|
(Make_value(Bool))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Delegate =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["delegate"] end)
|
|
|
|
(Make_value(Ed25519.Public_key_hash))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Counter =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["counter"] end)
|
|
|
|
(Make_value(Int32))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Code =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["code"] end)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = Script_repr.expr
|
|
|
|
let encoding = Script_repr.expr_encoding
|
|
|
|
end))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Storage =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["storage"] end)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = Script_repr.expr
|
|
|
|
let encoding = Script_repr.expr_encoding
|
|
|
|
end))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-03-09 22:17:13 +04:00
|
|
|
module Code_fees =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["code_fees"] end)
|
|
|
|
(Make_value(Tez_repr))
|
2017-03-09 22:17:13 +04:00
|
|
|
|
|
|
|
module Storage_fees =
|
2017-11-16 19:45:22 +04:00
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["storage_fees"] end)
|
|
|
|
(Make_value(Tez_repr))
|
|
|
|
|
|
|
|
module Roll_list =
|
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["roll_list"] end)
|
|
|
|
(Make_value(Roll_repr))
|
|
|
|
|
|
|
|
module Change =
|
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["change"] end)
|
|
|
|
(Make_value(Tez_repr))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
(** Rolls *)
|
|
|
|
|
|
|
|
module Cycle = struct
|
|
|
|
|
|
|
|
module Indexed_context =
|
|
|
|
Make_indexed_subcontext
|
|
|
|
(Make_subcontext(Raw_context)(struct let name = ["cycle"] end))
|
|
|
|
(Cycle_repr.Index)
|
|
|
|
|
|
|
|
module Last_roll =
|
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["last_roll"] end)
|
|
|
|
(Make_value(Roll_repr))
|
|
|
|
|
|
|
|
module Roll_owner =
|
|
|
|
Make_indexed_data_storage
|
|
|
|
(Make_subcontext
|
|
|
|
(Indexed_context.Raw_context)
|
|
|
|
(struct let name = ["roll_owners"] end))
|
|
|
|
(Roll_repr.Index)
|
|
|
|
(Make_value(Ed25519.Public_key_hash))
|
|
|
|
|
|
|
|
type nonce_status =
|
|
|
|
| Unrevealed of {
|
|
|
|
nonce_hash: Nonce_hash.t ;
|
|
|
|
delegate_to_reward: Ed25519.Public_key_hash.t ;
|
|
|
|
reward_amount: Tez_repr.t ;
|
|
|
|
}
|
|
|
|
| Revealed of Seed_repr.nonce
|
|
|
|
|
|
|
|
let nonce_status_encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
union [
|
|
|
|
case ~tag:0
|
|
|
|
(tup3
|
|
|
|
Nonce_hash.encoding
|
|
|
|
Ed25519.Public_key_hash.encoding
|
|
|
|
Tez_repr.encoding)
|
|
|
|
(function
|
|
|
|
| Unrevealed { nonce_hash ; delegate_to_reward ; reward_amount } ->
|
|
|
|
Some (nonce_hash, delegate_to_reward, reward_amount)
|
|
|
|
| _ -> None)
|
|
|
|
(fun (nonce_hash, delegate_to_reward, reward_amount) ->
|
|
|
|
Unrevealed { nonce_hash ; delegate_to_reward ; reward_amount }) ;
|
|
|
|
case ~tag:1
|
|
|
|
Seed_repr.nonce_encoding
|
|
|
|
(function
|
|
|
|
| Revealed nonce -> Some nonce
|
|
|
|
| _ -> None)
|
|
|
|
(fun nonce -> Revealed nonce)
|
|
|
|
]
|
|
|
|
|
|
|
|
module Nonce =
|
|
|
|
Make_indexed_data_storage
|
|
|
|
(Make_subcontext
|
|
|
|
(Indexed_context.Raw_context)
|
|
|
|
(struct let name = ["nonces"] end))
|
|
|
|
(Raw_level_repr.Index)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = nonce_status
|
|
|
|
let encoding = nonce_status_encoding
|
|
|
|
end))
|
|
|
|
|
|
|
|
module Seed =
|
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["random_seed"] end)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = Seed_repr.seed
|
|
|
|
let encoding = Seed_repr.seed_encoding
|
|
|
|
end))
|
|
|
|
|
|
|
|
module Reward_date =
|
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = [ "reward_date" ] end)
|
|
|
|
(Make_value(Time_repr))
|
|
|
|
|
|
|
|
module Reward_amount =
|
|
|
|
Make_indexed_data_storage
|
|
|
|
(Make_subcontext
|
|
|
|
(Indexed_context.Raw_context)
|
|
|
|
(struct let name = [ "rewards" ] end))
|
|
|
|
(Ed25519.Public_key_hash)
|
|
|
|
(Make_value(Tez_repr))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module Roll = struct
|
|
|
|
|
|
|
|
module Raw_context =
|
|
|
|
Make_subcontext(Raw_context)(struct let name = ["rolls"] end)
|
|
|
|
|
|
|
|
module Indexed_context =
|
|
|
|
Make_indexed_subcontext
|
|
|
|
(Make_subcontext(Raw_context)(struct let name = ["index"] end))
|
|
|
|
(Roll_repr.Index)
|
|
|
|
|
|
|
|
module Next =
|
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["next"] end)
|
|
|
|
(Make_value(Roll_repr))
|
|
|
|
|
|
|
|
module Limbo =
|
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["limbo"] end)
|
|
|
|
(Make_value(Roll_repr))
|
|
|
|
|
|
|
|
module Contract_roll_list = Contract.Roll_list
|
|
|
|
|
|
|
|
module Successor =
|
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["successor"] end)
|
|
|
|
(Make_value(Roll_repr))
|
|
|
|
|
|
|
|
module Contract_change = Contract.Change
|
|
|
|
|
|
|
|
module Owner =
|
|
|
|
Indexed_context.Make_map
|
|
|
|
(struct let name = ["owner"] end)
|
|
|
|
(Make_value(Contract_repr))
|
|
|
|
|
|
|
|
module Last_for_cycle = Cycle.Last_roll
|
|
|
|
module Owner_for_cycle = Cycle.Roll_owner
|
2017-03-09 22:17:13 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
(** Votes **)
|
|
|
|
|
|
|
|
module Vote = struct
|
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
module Raw_context =
|
|
|
|
Make_subcontext(Raw_context)(struct let name = ["votes"] end)
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
module Current_period_kind =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["current_period_kind"] end)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = Voting_period_repr.kind
|
|
|
|
let encoding = Voting_period_repr.kind_encoding
|
|
|
|
end))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Current_quorum =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["current_quorum"] end)
|
|
|
|
(Make_value(Int32))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Current_proposal =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["current_proposal"] end)
|
|
|
|
(Make_value(Protocol_hash))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Listings_size =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["listings_size"] end)
|
|
|
|
(Make_value(Int32))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Listings =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_indexed_data_storage
|
|
|
|
(Make_subcontext(Raw_context)(struct let name = ["listings"] end))
|
|
|
|
(Ed25519.Public_key_hash)
|
|
|
|
(Make_value(Int32))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Proposals =
|
|
|
|
Make_data_set_storage
|
2017-11-16 19:45:22 +04:00
|
|
|
(Make_subcontext(Raw_context)(struct let name = ["proposals"] end))
|
|
|
|
(Pair(Protocol_hash)(Ed25519.Public_key_hash))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Ballots =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_indexed_data_storage
|
|
|
|
(Make_subcontext(Raw_context)(struct let name = ["ballots"] end))
|
|
|
|
(Ed25519.Public_key_hash)
|
|
|
|
(Make_value(struct
|
|
|
|
type t = Vote_repr.ballot
|
|
|
|
let encoding = Vote_repr.ballot_encoding
|
|
|
|
end))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
(** Keys *)
|
|
|
|
|
|
|
|
module Public_key =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_indexed_data_storage
|
|
|
|
(Make_subcontext
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["public_keys"; "ed25519"] end))
|
|
|
|
(Ed25519.Public_key_hash)
|
|
|
|
(Make_value(Ed25519.Public_key))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(** Seed *)
|
|
|
|
|
|
|
|
module Seed = struct
|
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
type nonce_status = Cycle.nonce_status =
|
2016-09-08 21:13:10 +04:00
|
|
|
| Unrevealed of {
|
2017-11-16 19:45:22 +04:00
|
|
|
nonce_hash: Nonce_hash.t ;
|
2016-11-14 18:54:21 +04:00
|
|
|
delegate_to_reward: Ed25519.Public_key_hash.t ;
|
2016-09-08 21:13:10 +04:00
|
|
|
reward_amount: Tez_repr.t ;
|
|
|
|
}
|
|
|
|
| Revealed of Seed_repr.nonce
|
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
module Nonce = struct
|
|
|
|
open Level_repr
|
|
|
|
type context = Raw_context.t
|
|
|
|
let mem ctxt l = Cycle.Nonce.mem (ctxt, l.cycle) l.level
|
|
|
|
let get ctxt l = Cycle.Nonce.get (ctxt, l.cycle) l.level
|
|
|
|
let get_option ctxt l = Cycle.Nonce.get_option (ctxt, l.cycle) l.level
|
|
|
|
let set ctxt l v = Cycle.Nonce.set (ctxt, l.cycle) l.level v
|
|
|
|
let init ctxt l v = Cycle.Nonce.init (ctxt, l.cycle) l.level v
|
|
|
|
let init_set ctxt l v = Cycle.Nonce.init_set (ctxt, l.cycle) l.level v
|
|
|
|
let set_option ctxt l v = Cycle.Nonce.set_option (ctxt, l.cycle) l.level v
|
|
|
|
let delete ctxt l = Cycle.Nonce.delete (ctxt, l.cycle) l.level
|
|
|
|
let remove ctxt l = Cycle.Nonce.remove (ctxt, l.cycle) l.level
|
|
|
|
end
|
|
|
|
module For_cycle = Cycle.Seed
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
(** Rewards *)
|
|
|
|
|
|
|
|
module Rewards = struct
|
|
|
|
|
|
|
|
module Next =
|
2017-11-16 19:45:22 +04:00
|
|
|
Make_single_data_storage
|
|
|
|
(Raw_context)
|
|
|
|
(struct let name = ["next_cycle_to_be_rewarded"] end)
|
|
|
|
(Make_value(Cycle_repr))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
module Date = Cycle.Reward_date
|
|
|
|
module Amount = Cycle.Reward_amount
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-16 19:45:22 +04:00
|
|
|
end
|
2016-11-14 19:26:34 +04:00
|
|
|
|
|
|
|
(** Resolver *)
|
|
|
|
|
|
|
|
let () =
|
2017-11-16 19:45:22 +04:00
|
|
|
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.Default _ -> 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 p in
|
|
|
|
Contract.Indexed_context.resolve ctxt p >|= fun l ->
|
|
|
|
List.map
|
|
|
|
(function
|
|
|
|
| Contract_repr.Default s -> s
|
|
|
|
| Contract_repr.Originated _ -> assert false)
|
|
|
|
l)
|