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 = {
|
2016-11-14 18:54:21 +04:00
|
|
|
public_key_hash : Ed25519.Public_key_hash.t ;
|
2017-02-28 05:56:40 +04:00
|
|
|
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... *)
|
|
|
|
let wealth = Tez_repr.of_cents_exn 2_000_000_00L
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-02-28 05:56:40 +04:00
|
|
|
|
|
|
|
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 =
|
2017-02-28 05:56:40 +04:00
|
|
|
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
|
2017-02-28 05:56:40 +04:00
|
|
|
(fun {public_key_hash ; public_key } ->
|
|
|
|
(public_key_hash, public_key))
|
|
|
|
(fun (public_key_hash, public_key) ->
|
|
|
|
{ public_key_hash ; public_key })
|
|
|
|
(obj2
|
2016-11-14 18:54:21 +04:00
|
|
|
(req "publicKeyHash" Ed25519.Public_key_hash.encoding)
|
2017-02-28 05:56:40 +04:00
|
|
|
(req "publicKey" Ed25519.Public_key.encoding))
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-10 18:43:04 +04:00
|
|
|
let refill ctxt =
|
2017-02-28 05:56:40 +04:00
|
|
|
(* Unefficient HACK for the alphanet only... *)
|
2017-02-24 20:14:20 +04:00
|
|
|
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 ->
|
|
|
|
(* The 5 bootstrap accounts should have at least 1/2 of the total amount
|
|
|
|
of tokens. *)
|
2017-02-28 05:56:40 +04:00
|
|
|
let accounts = accounts ctxt in
|
2017-02-24 20:14:20 +04:00
|
|
|
let min_balance =
|
2017-03-10 17:39:22 +04:00
|
|
|
Tez_repr.(total /? 2L >>? fun r -> r /? (Int64.of_int (List.length accounts))) in
|
2017-02-10 18:43:04 +04:00
|
|
|
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 ->
|
2017-03-10 17:39:22 +04:00
|
|
|
match Tez_repr.(min_balance >>? fun r -> r -? balance) with
|
2017-02-10 18:43:04 +04:00
|
|
|
| Error _ -> return ctxt
|
|
|
|
| Ok tez -> Contract_storage.credit ctxt contract tez)
|
|
|
|
ctxt
|
|
|
|
accounts
|