Alpha: bootstrap accounts and contracts cleanup
This commit is contained in:
parent
dd933b422b
commit
1e9a6e9941
@ -4,8 +4,11 @@
|
||||
[ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ],
|
||||
[ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ],
|
||||
[ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ],
|
||||
[ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "10000000",
|
||||
{ "address": "TZ1Yj9xA3jp8xy9maok89VB6HtBUtrK77tFk",
|
||||
[ "tz1PooUKBaoxjBiCR2dxEtbtTUjLX3iaZQoJ", "100" ],
|
||||
[ "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", "1" ] ],
|
||||
"bootstrap_contracts": [
|
||||
{ "delegate": "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV",
|
||||
"amount": "10000000",
|
||||
"script":
|
||||
{ "code":
|
||||
[ { "prim": "parameter",
|
||||
@ -35,9 +38,7 @@
|
||||
{ "prim": "CONS" },
|
||||
{ "prim": "DIP", "args": [ [ { "prim": "NOW" } ] ] },
|
||||
{ "prim": "PAIR" } ] ] } ],
|
||||
"storage": { "int": "0" } } } ] ],
|
||||
"dictator_pubkey":
|
||||
"edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2",
|
||||
"storage": { "int": "0" } } } ],
|
||||
"time_between_blocks" : [ "1", "0" ],
|
||||
"blocks_per_roll_snapshot" : 4,
|
||||
"blocks_per_cycle" : 8,
|
||||
|
@ -38,8 +38,11 @@ init_sandboxed_client() {
|
||||
[ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ],
|
||||
[ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ],
|
||||
[ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ],
|
||||
[ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "10000000",
|
||||
{ "address": "TZ1Yj9xA3jp8xy9maok89VB6HtBUtrK77tFk",
|
||||
[ "tz1PooUKBaoxjBiCR2dxEtbtTUjLX3iaZQoJ", "100" ],
|
||||
[ "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", "1" ] ],
|
||||
"bootstrap_contracts": [
|
||||
{ "delegate": "tz1TGu6TN5GSez2ndXXeDX6LgUDvLzPLqgYV",
|
||||
"amount": "10000000",
|
||||
"script":
|
||||
{ "code":
|
||||
[ { "prim": "parameter",
|
||||
@ -69,9 +72,7 @@ init_sandboxed_client() {
|
||||
{ "prim": "CONS" },
|
||||
{ "prim": "DIP", "args": [ [ { "prim": "NOW" } ] ] },
|
||||
{ "prim": "PAIR" } ] ] } ],
|
||||
"storage": { "int": "0" } } } ] ],
|
||||
"dictator_pubkey":
|
||||
"edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2",
|
||||
"storage": { "int": "0" } } } ],
|
||||
"time_between_blocks" : [ "1", "0" ],
|
||||
"blocks_per_roll_snapshot" : 4,
|
||||
"blocks_per_cycle" : 8,
|
||||
@ -230,7 +231,6 @@ BOOTSTRAP5_PUBLIC="edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n"
|
||||
BOOTSTRAP5_SECRET="unencrypted:edsk4QLrcijEffxV31gGdN2HU7UpyJjA8drFoNcmnB28n89YjPNRFm"
|
||||
|
||||
DICTATOR_SECRET="unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
|
||||
FAUCET_ADDRESS="TZ1Yj9xA3jp8xy9maok89VB6HtBUtrK77tFk"
|
||||
|
||||
add_sandboxed_bootstrap_identities() {
|
||||
|
||||
@ -252,9 +252,6 @@ activate_alpha() {
|
||||
and key dictator \
|
||||
and parameters "${parameters_file}" \
|
||||
--timestamp $(TZ='AAA+1' date +%FT%TZ)
|
||||
|
||||
${client} remember contract faucet ${FAUCET_ADDRESS}
|
||||
|
||||
}
|
||||
|
||||
usage() {
|
||||
|
@ -9,28 +9,38 @@
|
||||
|
||||
open Misc
|
||||
|
||||
let init_account ~typecheck ctxt ({ public_key; amount; script }: Parameters_repr.bootstrap_account) =
|
||||
let public_key_hash = Signature.Public_key.hash public_key in
|
||||
match script with
|
||||
| None ->
|
||||
let contract = Contract_repr.implicit_contract public_key_hash in
|
||||
Contract_storage.credit ctxt contract amount >>=? fun ctxt ->
|
||||
let init_account ctxt
|
||||
({ public_key_hash ; public_key ; amount }: Parameters_repr.bootstrap_account) =
|
||||
let contract = Contract_repr.implicit_contract public_key_hash in
|
||||
Contract_storage.credit ctxt contract amount >>=? fun ctxt ->
|
||||
match public_key with
|
||||
| Some public_key ->
|
||||
Contract_storage.reveal_manager_key ctxt contract public_key >>=? fun ctxt ->
|
||||
Delegate_storage.set ctxt contract (Some public_key_hash) >>=? fun ctxt ->
|
||||
return ctxt
|
||||
| Some (contract, script) ->
|
||||
typecheck ctxt script >>=? fun ctxt ->
|
||||
Contract_storage.originate ctxt contract
|
||||
~balance:amount
|
||||
~manager:Signature.Public_key_hash.zero
|
||||
~script:(script, None)
|
||||
~delegate:(Some public_key_hash)
|
||||
~spendable:false
|
||||
~delegatable:false >>=? fun ctxt ->
|
||||
return ctxt
|
||||
| None -> return ctxt
|
||||
|
||||
let init ctxt ~typecheck ?ramp_up_cycles ?no_reward_cycles accounts =
|
||||
fold_left_s (init_account ~typecheck) ctxt accounts >>=? fun ctxt ->
|
||||
let init_contract ~typecheck ctxt
|
||||
({ delegate ; amount ; script }: Parameters_repr.bootstrap_contract) =
|
||||
Contract_storage.fresh_contract_from_current_nonce ctxt >>=? fun (ctxt, contract) ->
|
||||
typecheck ctxt script >>=? fun ctxt ->
|
||||
Contract_storage.originate ctxt contract
|
||||
~balance:amount
|
||||
~manager:Signature.Public_key_hash.zero
|
||||
~script:(script, None)
|
||||
~delegate:(Some delegate)
|
||||
~spendable:false
|
||||
~delegatable:false >>=? fun ctxt ->
|
||||
return ctxt
|
||||
|
||||
let init ctxt ~typecheck ?ramp_up_cycles ?no_reward_cycles accounts contracts =
|
||||
let nonce =
|
||||
Operation_hash.hash_bytes
|
||||
(* FIXME: change this nonce before lunch *)
|
||||
[ MBytes.of_string "ZERONET_INIT_ORIGINATION_NONCE" ] in
|
||||
let ctxt = Raw_context.init_origination_nonce ctxt nonce in
|
||||
fold_left_s init_account ctxt accounts >>=? fun ctxt ->
|
||||
fold_left_s (init_contract ~typecheck) ctxt contracts >>=? fun ctxt ->
|
||||
begin
|
||||
match no_reward_cycles with
|
||||
| None -> return ctxt
|
||||
|
@ -13,6 +13,7 @@ val init:
|
||||
?ramp_up_cycles:int ->
|
||||
?no_reward_cycles:int ->
|
||||
Parameters_repr.bootstrap_account list ->
|
||||
Parameters_repr.bootstrap_contract list ->
|
||||
Raw_context.t tzresult Lwt.t
|
||||
|
||||
val cycle_end:
|
||||
|
@ -19,7 +19,8 @@ let prepare_first_block ctxt ~typecheck ~level ~timestamp ~fitness =
|
||||
~typecheck
|
||||
?ramp_up_cycles:param.security_deposit_ramp_up_cycles
|
||||
?no_reward_cycles:param.no_reward_cycles
|
||||
param.bootstrap_accounts >>=? fun ctxt ->
|
||||
param.bootstrap_accounts
|
||||
param.bootstrap_contracts >>=? fun ctxt ->
|
||||
Roll_storage.init_first_cycles ctxt >>=? fun ctxt ->
|
||||
Vote_storage.init ctxt >>=? fun ctxt ->
|
||||
Storage.Last_block_priority.init ctxt 0 >>=? fun ctxt ->
|
||||
|
@ -8,13 +8,20 @@
|
||||
(**************************************************************************)
|
||||
|
||||
type bootstrap_account = {
|
||||
public_key : Signature.Public_key.t ;
|
||||
public_key_hash : Signature.Public_key_hash.t ;
|
||||
public_key : Signature.Public_key.t option ;
|
||||
amount : Tez_repr.t ;
|
||||
script : (Contract_repr.t * Script_repr.t) option ;
|
||||
}
|
||||
|
||||
type bootstrap_contract = {
|
||||
delegate : Signature.Public_key_hash.t ;
|
||||
amount : Tez_repr.t ;
|
||||
script : Script_repr.t ;
|
||||
}
|
||||
|
||||
type t = {
|
||||
bootstrap_accounts : bootstrap_account list ;
|
||||
bootstrap_contracts : bootstrap_contract list ;
|
||||
commitments : Commitment_repr.t list ;
|
||||
constants : Constants_repr.parametric ;
|
||||
security_deposit_ramp_up_cycles : int option ;
|
||||
@ -24,29 +31,43 @@ type t = {
|
||||
let bootstrap_account_encoding =
|
||||
let open Data_encoding in
|
||||
union
|
||||
[ case (Tag 0) ~title:"Non_scripted"
|
||||
[ case (Tag 0) ~title:"Public_key_known"
|
||||
(tup2
|
||||
Signature.Public_key.encoding
|
||||
Tez_repr.encoding)
|
||||
(function
|
||||
| { public_key ; amount ; script = None } ->
|
||||
| { public_key_hash ; public_key = Some public_key ; amount } ->
|
||||
assert (Signature.Public_key_hash.equal
|
||||
(Signature.Public_key.hash public_key)
|
||||
public_key_hash) ;
|
||||
Some (public_key, amount)
|
||||
| { script = Some _ } -> None)
|
||||
| { public_key = None } -> None)
|
||||
(fun (public_key, amount) ->
|
||||
{ public_key ; amount ; script = None }) ;
|
||||
case (Tag 1) ~title:"Scripted"
|
||||
(tup3
|
||||
Signature.Public_key.encoding
|
||||
Tez_repr.encoding
|
||||
(obj2
|
||||
(req "address" Contract_repr.encoding)
|
||||
(req "script" Script_repr.encoding)))
|
||||
{ public_key = Some public_key ;
|
||||
public_key_hash = Signature.Public_key.hash public_key ;
|
||||
amount }) ;
|
||||
case (Tag 1) ~title:"Public_key_unknown"
|
||||
(tup2
|
||||
Signature.Public_key_hash.encoding
|
||||
Tez_repr.encoding)
|
||||
(function
|
||||
| { public_key ; amount ; script = Some script } ->
|
||||
Some (public_key, amount, script)
|
||||
| { script = None } -> None)
|
||||
(fun (public_key, amount, script) ->
|
||||
{ public_key ; amount ; script = Some script }) ]
|
||||
| { public_key_hash ; public_key = None ; amount } ->
|
||||
Some (public_key_hash, amount)
|
||||
| { public_key = Some _ } -> None)
|
||||
(fun (public_key_hash, amount) ->
|
||||
{ public_key = None ;
|
||||
public_key_hash ;
|
||||
amount }) ]
|
||||
|
||||
let bootstrap_contract_encoding =
|
||||
let open Data_encoding in
|
||||
conv
|
||||
(fun { delegate ; amount ; script } -> (delegate, amount, script))
|
||||
(fun (delegate, amount, script) -> { delegate ; amount ; script })
|
||||
(obj3
|
||||
(req "delegate" Signature.Public_key_hash.encoding)
|
||||
(req "amount" Tez_repr.encoding)
|
||||
(req "script" Script_repr.encoding))
|
||||
|
||||
(* This encoding is used to read configuration files (e.g. sandbox.json)
|
||||
where some fields can be missing, in that case they are replaced by
|
||||
@ -249,19 +270,20 @@ let constants_encoding =
|
||||
let encoding =
|
||||
let open Data_encoding in
|
||||
conv
|
||||
(fun { bootstrap_accounts ; commitments ; constants ;
|
||||
(fun { bootstrap_accounts ; bootstrap_contracts ; commitments ; constants ;
|
||||
security_deposit_ramp_up_cycles ; no_reward_cycles } ->
|
||||
((bootstrap_accounts, commitments,
|
||||
((bootstrap_accounts, bootstrap_contracts, commitments,
|
||||
security_deposit_ramp_up_cycles, no_reward_cycles),
|
||||
constants))
|
||||
(fun ( (bootstrap_accounts, commitments,
|
||||
(fun ( (bootstrap_accounts, bootstrap_contracts, commitments,
|
||||
security_deposit_ramp_up_cycles, no_reward_cycles),
|
||||
constants) ->
|
||||
{ bootstrap_accounts ; commitments ; constants ;
|
||||
{ bootstrap_accounts ; bootstrap_contracts ; commitments ; constants ;
|
||||
security_deposit_ramp_up_cycles ; no_reward_cycles })
|
||||
(merge_objs
|
||||
(obj4
|
||||
(obj5
|
||||
(req "bootstrap_accounts" (list bootstrap_account_encoding))
|
||||
(dft "bootstrap_contracts" (list bootstrap_contract_encoding) [])
|
||||
(dft "commitments" (list Commitment_repr.encoding) [])
|
||||
(opt "security_deposit_ramp_up_cycles" int31)
|
||||
(opt "no_reward_cycles" int31))
|
||||
|
@ -8,13 +8,20 @@
|
||||
(**************************************************************************)
|
||||
|
||||
type bootstrap_account = {
|
||||
public_key : Signature.Public_key.t ;
|
||||
public_key_hash : Signature.Public_key_hash.t ;
|
||||
public_key : Signature.Public_key.t option ;
|
||||
amount : Tez_repr.t ;
|
||||
script : (Contract_repr.t * Script_repr.t) option ;
|
||||
}
|
||||
|
||||
type bootstrap_contract = {
|
||||
delegate : Signature.Public_key_hash.t ;
|
||||
amount : Tez_repr.t ;
|
||||
script : Script_repr.t ;
|
||||
}
|
||||
|
||||
type t = {
|
||||
bootstrap_accounts : bootstrap_account list ;
|
||||
bootstrap_contracts : bootstrap_contract list ;
|
||||
commitments : Commitment_repr.t list ;
|
||||
constants : Constants_repr.parametric ;
|
||||
security_deposit_ramp_up_cycles : int option ;
|
||||
|
@ -184,8 +184,8 @@ let initial_context
|
||||
no_reward_cycles
|
||||
=
|
||||
let bootstrap_accounts =
|
||||
List.map (fun (Account.{ pk = public_key ; _ }, amount) ->
|
||||
Parameters_repr.{ public_key ; amount; script = None }
|
||||
List.map (fun (Account.{ pk ; pkh ; _ }, amount) ->
|
||||
Parameters_repr.{ public_key_hash = pkh ; public_key = Some pk ; amount }
|
||||
) initial_accounts
|
||||
in
|
||||
let json =
|
||||
@ -193,6 +193,7 @@ let initial_context
|
||||
Parameters_repr.encoding
|
||||
Parameters_repr.{
|
||||
bootstrap_accounts ;
|
||||
bootstrap_contracts = [] ;
|
||||
commitments ;
|
||||
constants ;
|
||||
security_deposit_ramp_up_cycles ;
|
||||
|
Loading…
Reference in New Issue
Block a user