ligo/src/proto/alpha/bootstrap_storage.ml

73 lines
2.7 KiB
OCaml
Raw Normal View History

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. *)
(* *)
(**************************************************************************)
type account = {
public_key_hash : Ed25519.Public_key_hash.t ;
public_key : Ed25519.Public_key.t ;
2016-09-08 21:13:10 +04:00
}
(* FIXME: when incresing wealth *10, the node is very slow to initialize...
this should be investigated... *)
2017-05-31 20:05:29 +04:00
let wealth = Tez_repr.of_cents_exn 4_000_000_00L
2016-09-08 21:13:10 +04:00
let init_account ctxt account =
Storage.Public_key.init ctxt account.public_key_hash account.public_key >>=? fun ctxt ->
Contract_storage.credit
ctxt
(Contract_repr.default_contract account.public_key_hash)
wealth >>=? fun ctxt ->
return ctxt
let make public_key =
{ public_key ; public_key_hash = Ed25519.Public_key.hash public_key }
let accounts ctxt =
let { Constants_repr.bootstrap_keys } = Storage.constants ctxt in
List.map make bootstrap_keys
2016-09-08 21:13:10 +04:00
let init ctxt =
fold_left_s init_account ctxt (accounts ctxt) >>=? fun ctxt ->
2016-09-08 21:13:10 +04:00
return ctxt
let account_encoding =
let open Data_encoding in
conv
(fun {public_key_hash ; public_key } ->
(public_key_hash, public_key))
(fun (public_key_hash, public_key) ->
{ public_key_hash ; public_key })
(obj2
(req "publicKeyHash" Ed25519.Public_key_hash.encoding)
(req "publicKey" Ed25519.Public_key.encoding))
2016-09-08 21:13:10 +04:00
let refill ctxt =
(* Unefficient HACK for the alphanet only... *)
Contract_storage.list ctxt >>=? fun contracts ->
List.fold_left
(fun total contract ->
Contract_storage.get_balance ctxt contract >>=? fun balance ->
total >>=? fun total -> Lwt.return Tez_repr.(total +? balance))
(return Tez_repr.zero) contracts >>=? fun total ->
2017-05-31 20:05:29 +04:00
(* The bootstrap accounts should have at least 1/2 of the total amount
of tokens. *)
let accounts = accounts ctxt in
let min_balance =
Tez_repr.(total /? 2L >>? fun r -> r /? (Int64.of_int (List.length accounts))) in
fold_left_s
(fun ctxt account ->
let contract =
Contract_repr.default_contract account.public_key_hash in
Contract_storage.get_balance ctxt contract >>=? fun balance ->
match Tez_repr.(min_balance >>? fun r -> r -? balance) with
| Error _ -> return ctxt
| Ok tez -> Contract_storage.credit ctxt contract tez)
ctxt
accounts