2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
(* This is the genesis protocol: initialise the state *)
|
2017-04-10 15:01:22 +04:00
|
|
|
let initialize store =
|
2016-09-08 21:13:10 +04:00
|
|
|
Roll_storage.init store >>=? fun store ->
|
|
|
|
Seed_storage.init store >>=? fun store ->
|
|
|
|
Contract_storage.init store >>=? fun store ->
|
|
|
|
Reward_storage.init store >>=? fun store ->
|
|
|
|
Bootstrap_storage.init store >>=? fun store ->
|
2016-10-26 19:02:10 +04:00
|
|
|
Roll_storage.freeze_rolls_for_cycle
|
2016-09-08 21:13:10 +04:00
|
|
|
store Cycle_repr.root >>=? fun store ->
|
2016-10-26 19:02:10 +04:00
|
|
|
Roll_storage.freeze_rolls_for_cycle
|
2016-09-08 21:13:10 +04:00
|
|
|
store Cycle_repr.(succ root) >>=? fun store ->
|
|
|
|
Vote_storage.init store >>=? fun store ->
|
|
|
|
return store
|
|
|
|
|
|
|
|
type error +=
|
|
|
|
| Unimplemented_sandbox_migration
|
|
|
|
|
2017-04-10 15:01:22 +04:00
|
|
|
let may_initialize ctxt ~level ~timestamp ~fitness =
|
|
|
|
Storage.prepare ~level ~timestamp ~fitness ctxt >>=? fun (ctxt, first_block) ->
|
|
|
|
if first_block then
|
|
|
|
initialize ctxt
|
|
|
|
else
|
|
|
|
return ctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let configure_sandbox ctxt json =
|
|
|
|
let json =
|
|
|
|
match json with
|
|
|
|
| None -> `O []
|
|
|
|
| Some json -> json in
|
2017-04-10 15:01:22 +04:00
|
|
|
Storage.is_first_block ctxt >>=? function
|
|
|
|
| true ->
|
2016-09-08 21:13:10 +04:00
|
|
|
Storage.set_sandboxed ctxt json >>= fun ctxt ->
|
2017-04-10 14:14:11 +04:00
|
|
|
return ctxt
|
2017-04-10 15:01:22 +04:00
|
|
|
| false ->
|
2016-09-08 21:13:10 +04:00
|
|
|
Storage.get_sandboxed ctxt >>=? function
|
|
|
|
| None ->
|
|
|
|
fail Unimplemented_sandbox_migration
|
|
|
|
| Some _ ->
|
|
|
|
(* FIXME GRGR fail if parameter changed! *)
|
|
|
|
(* failwith "Changing sandbox parameter is not yet implemented" *)
|
|
|
|
return ctxt
|