Alpha: allow injecting a contract as bootstrap

This commit is contained in:
Pierre Chambart 2018-06-18 23:46:22 +02:00 committed by Benjamin Canou
parent 7de19f9cc0
commit a6807b4d13
7 changed files with 124 additions and 21 deletions

View File

@ -3,8 +3,39 @@
[ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ], [ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ],
[ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ], [ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ],
[ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ], [ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ],
[ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ] [ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ],
], [ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "10000000",
{ "address": "TZ1Yj9xA3jp8xy9maok89VB6HtBUtrK77tFk",
"script":
{ "code":
[ { "prim": "parameter",
"args": [ { "prim": "key_hash" } ] },
{ "prim": "storage",
"args": [ { "prim": "timestamp" } ] },
{ "prim": "code",
"args":
[ [ [ [ { "prim": "DUP" }, { "prim": "CAR" },
{ "prim": "DIP", "args": [ [ { "prim": "CDR" } ] ] } ] ],
{ "prim": "SWAP" },
{ "prim": "PUSH", "args": [ { "prim": "int" }, { "int": "300" } ] },
{ "prim": "ADD", "annots": [ "@FIVE_MINUTES_LATER" ] },
{ "prim": "NOW" },
[ [ { "prim": "COMPARE" }, { "prim": "GE" } ],
{ "prim": "IF",
"args":
[ [],
[ [ { "prim": "UNIT" },
{ "prim": "FAILWITH" } ] ] ] } ],
{ "prim": "IMPLICIT_ACCOUNT" },
{ "prim": "PUSH", "args": [ { "prim": "mutez" }, { "int": "1000000" } ] },
{ "prim": "UNIT" },
{ "prim": "TRANSFER_TOKENS" },
{ "prim": "NIL", "args": [ { "prim": "operation" } ] },
{ "prim": "SWAP" },
{ "prim": "CONS" },
{ "prim": "DIP", "args": [ [ { "prim": "NOW" } ] ] },
{ "prim": "PAIR" } ] ] } ],
"storage": { "int": "0" } } } ] ],
"dictator_pubkey": "dictator_pubkey":
"edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2",
"time_between_blocks" : [ "1", "0" ], "time_between_blocks" : [ "1", "0" ],

View File

@ -0,0 +1,7 @@
parameter key_hash ;
storage timestamp ;
code { UNPAIR ; SWAP ;
PUSH int 300 ; ADD @FIVE_MINUTES_LATER ;
NOW ; ASSERT_CMPGE ;
IMPLICIT_ACCOUNT ; PUSH mutez 1000000 ; UNIT ; TRANSFER_TOKENS ;
NIL operation ; SWAP ; CONS ; DIP { NOW } ; PAIR }

View File

@ -32,20 +32,51 @@ init_sandboxed_client() {
if ! [ -f "$parameters_file" ]; then if ! [ -f "$parameters_file" ]; then
cat > "$parameters_file" <<EOF cat > "$parameters_file" <<EOF
{ "bootstrap_accounts": { "bootstrap_accounts": [
[
[ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "4000000000000" ], [ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "4000000000000" ],
[ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ], [ "edpktzNbDAUjUk697W7gYg2CRuBQjyPxbEg8dLccYYwKSKvkPvjtV9", "4000000000000" ],
[ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ], [ "edpkuTXkJDGcFd5nh6VvMz8phXxU3Bi7h6hqgywNFi1vZTfQNnS1RV", "4000000000000" ],
[ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ], [ "edpkuFrRoDSEbJYgxRtLx2ps82UdaYc1WwfS9sE11yhauZt5DgCHbU", "4000000000000" ],
[ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ] [ "edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n", "4000000000000" ],
], [ "edpkuBknW28nW72KG6RoHtYW7p12T6GKc7nAbwYX5m8Wd9sDVC9yav", "10000000",
{ "address": "TZ1Yj9xA3jp8xy9maok89VB6HtBUtrK77tFk",
"script":
{ "code":
[ { "prim": "parameter",
"args": [ { "prim": "key_hash" } ] },
{ "prim": "storage",
"args": [ { "prim": "timestamp" } ] },
{ "prim": "code",
"args":
[ [ [ [ { "prim": "DUP" }, { "prim": "CAR" },
{ "prim": "DIP", "args": [ [ { "prim": "CDR" } ] ] } ] ],
{ "prim": "SWAP" },
{ "prim": "PUSH", "args": [ { "prim": "int" }, { "int": "300" } ] },
{ "prim": "ADD", "annots": [ "@FIVE_MINUTES_LATER" ] },
{ "prim": "NOW" },
[ [ { "prim": "COMPARE" }, { "prim": "GE" } ],
{ "prim": "IF",
"args":
[ [],
[ [ { "prim": "UNIT" },
{ "prim": "FAILWITH" } ] ] ] } ],
{ "prim": "IMPLICIT_ACCOUNT" },
{ "prim": "PUSH", "args": [ { "prim": "mutez" }, { "int": "1000000" } ] },
{ "prim": "UNIT" },
{ "prim": "TRANSFER_TOKENS" },
{ "prim": "NIL", "args": [ { "prim": "operation" } ] },
{ "prim": "SWAP" },
{ "prim": "CONS" },
{ "prim": "DIP", "args": [ [ { "prim": "NOW" } ] ] },
{ "prim": "PAIR" } ] ] } ],
"storage": { "int": "0" } } } ] ],
"dictator_pubkey": "dictator_pubkey":
"edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2", "edpkuSLWfVU1Vq7Jg9FucPyKmma6otcMHac9zG4oU1KMHSTBpJuGQ2",
"time_between_blocks" : [ "1", "0" ], "time_between_blocks" : [ "1", "0" ],
"blocks_per_roll_snapshot" : 4, "blocks_per_roll_snapshot" : 4,
"blocks_per_cycle" : 8, "blocks_per_cycle" : 8,
"preserved_cycles" : 2 "preserved_cycles" : 2,
"proof_of_work_threshold": "-1"
} }
EOF EOF
fi fi
@ -199,6 +230,7 @@ BOOTSTRAP5_PUBLIC="edpkv8EUUH68jmo3f7Um5PezmfGrRF24gnfLpH3sVNwJnV5bVCxL2n"
BOOTSTRAP5_SECRET="unencrypted:edsk4QLrcijEffxV31gGdN2HU7UpyJjA8drFoNcmnB28n89YjPNRFm" BOOTSTRAP5_SECRET="unencrypted:edsk4QLrcijEffxV31gGdN2HU7UpyJjA8drFoNcmnB28n89YjPNRFm"
DICTATOR_SECRET="unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6" DICTATOR_SECRET="unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
FAUCET_ADDRESS="TZ1Yj9xA3jp8xy9maok89VB6HtBUtrK77tFk"
add_sandboxed_bootstrap_identities() { add_sandboxed_bootstrap_identities() {
@ -209,7 +241,6 @@ add_sandboxed_bootstrap_identities() {
${client} import secret key bootstrap5 ${BOOTSTRAP5_SECRET} ${client} import secret key bootstrap5 ${BOOTSTRAP5_SECRET}
${client} import secret key dictator ${DICTATOR_SECRET} ${client} import secret key dictator ${DICTATOR_SECRET}
} }
activate_alpha() { activate_alpha() {
@ -222,6 +253,8 @@ activate_alpha() {
and parameters "${parameters_file}" \ and parameters "${parameters_file}" \
--timestamp $(TZ='AAA+1' date +%FT%TZ) --timestamp $(TZ='AAA+1' date +%FT%TZ)
${client} remember contract faucet ${FAUCET_ADDRESS}
} }
usage() { usage() {

View File

@ -9,13 +9,24 @@
open Misc open Misc
let init_account ctxt (account: Parameters_repr.bootstrap_account) = let init_account ctxt ({ public_key; amount; script }: Parameters_repr.bootstrap_account) =
let public_key_hash = Signature.Public_key.hash account.public_key in 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 let contract = Contract_repr.implicit_contract public_key_hash in
Contract_storage.credit ctxt contract account.amount >>=? fun ctxt -> Contract_storage.credit ctxt contract amount >>=? fun ctxt ->
Contract_storage.reveal_manager_key ctxt contract account.public_key >>=? fun ctxt -> Contract_storage.reveal_manager_key ctxt contract public_key >>=? fun ctxt ->
Delegate_storage.set ctxt contract (Some public_key_hash) >>=? fun ctxt -> Delegate_storage.set ctxt contract (Some public_key_hash) >>=? fun ctxt ->
return ctxt return ctxt
| Some (contract, script) ->
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
let init ctxt ?ramp_up_cycles ?no_reward_cycles accounts = let init ctxt ?ramp_up_cycles ?no_reward_cycles accounts =
fold_left_s init_account ctxt accounts >>=? fun ctxt -> fold_left_s init_account ctxt accounts >>=? fun ctxt ->

View File

@ -10,6 +10,7 @@
type bootstrap_account = { type bootstrap_account = {
public_key : Signature.Public_key.t ; public_key : Signature.Public_key.t ;
amount : Tez_repr.t ; amount : Tez_repr.t ;
script : (Contract_repr.t * Script_repr.t) option ;
} }
type t = { type t = {
@ -22,11 +23,30 @@ type t = {
let bootstrap_account_encoding = let bootstrap_account_encoding =
let open Data_encoding in let open Data_encoding in
conv union
(fun { public_key ; amount } -> (public_key, amount)) [ case (Tag 0) ~title:"Non_scripted"
(fun (public_key, amount) -> { public_key ; amount }) (tup2
(tup2 Signature.Public_key.encoding Tez_repr.encoding) Signature.Public_key.encoding
Tez_repr.encoding)
(function
| { public_key ; amount ; script = None } ->
Some (public_key, amount)
| { script = Some _ } -> 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)))
(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 }) ]
(* This encoding is used to read configuration files (e.g. sandbox.json) (* 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 where some fields can be missing, in that case they are replaced by

View File

@ -10,6 +10,7 @@
type bootstrap_account = { type bootstrap_account = {
public_key : Signature.Public_key.t ; public_key : Signature.Public_key.t ;
amount : Tez_repr.t ; amount : Tez_repr.t ;
script : (Contract_repr.t * Script_repr.t) option ;
} }
type t = { type t = {

View File

@ -185,7 +185,7 @@ let initial_context
= =
let bootstrap_accounts = let bootstrap_accounts =
List.map (fun (Account.{ pk = public_key ; _ }, amount) -> List.map (fun (Account.{ pk = public_key ; _ }, amount) ->
Parameters_repr.{ public_key ; amount } Parameters_repr.{ public_key ; amount; script = None }
) initial_accounts ) initial_accounts
in in
let json = let json =