From 23c814c7830a897d2a2bb002531aa9615d16cae4 Mon Sep 17 00:00:00 2001 From: Milo Davis Date: Tue, 18 Jul 2017 16:48:33 +0200 Subject: [PATCH] Michelson: Adds DEFAULT_ACCOUNT instruction --- src/proto/alpha/docs/json-notations.md | 1 + src/proto/alpha/docs/language.md | 8 ++++++++ src/proto/alpha/script_interpreter.ml | 3 +++ src/proto/alpha/script_ir_translator.ml | 11 ++++++++--- src/proto/alpha/script_typed_ir.ml | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/proto/alpha/docs/json-notations.md b/src/proto/alpha/docs/json-notations.md index ce5f0a44a..89b7321f6 100644 --- a/src/proto/alpha/docs/json-notations.md +++ b/src/proto/alpha/docs/json-notations.md @@ -169,6 +169,7 @@ with the following JSON script description. | "NANAN" | "MANAGER" | "TRANSFER_FUNDS" + | "DEFAULT_ACCOUNT" | "CREATE_ACCOUNT" | "CREATE_CONTRACT" | "NOW" diff --git a/src/proto/alpha/docs/language.md b/src/proto/alpha/docs/language.md index 11f9ecb0c..59540f21c 100644 --- a/src/proto/alpha/docs/language.md +++ b/src/proto/alpha/docs/language.md @@ -1120,6 +1120,14 @@ for under/overflows. :: 'S -> tez :: 'S + * `DEFAULT_ACCOUNT`: + Return a default contract with the given public/private key pair. + Any funds deposited in this contract can immediately be spent by the + holder of the private key. This contract cannot execute Michelson code + and will always exist on the blockchain. + + :: key : 'S -> contract unit unit :: 'S + ### Special operations * `STEPS_TO_QUOTA`: diff --git a/src/proto/alpha/script_interpreter.ml b/src/proto/alpha/script_interpreter.ml index a213be702..762d80bfb 100644 --- a/src/proto/alpha/script_interpreter.ml +++ b/src/proto/alpha/script_interpreter.ml @@ -456,6 +456,9 @@ let rec interp ~manager ~delegate ~balance ?script:None ~spendable:true ~delegatable >>=? fun (ctxt, contract, origination) -> logged_return ~origination (Item ((Unit_t, Unit_t, contract), rest), qta - 1, ctxt) + | Default_account, Item (key, rest) -> + let contract = Contract.default_contract key in + logged_return (Item ((Unit_t, Unit_t, contract), rest), qta - 1, ctxt) | Create_contract (g, p, r), Item (manager, Item (delegate, Item (delegatable, Item (credit, Item (Lam (_, code), Item (init, rest)))))) -> diff --git a/src/proto/alpha/script_ir_translator.ml b/src/proto/alpha/script_ir_translator.ml index 906760d6d..85968cce6 100644 --- a/src/proto/alpha/script_ir_translator.ml +++ b/src/proto/alpha/script_ir_translator.ml @@ -1247,6 +1247,10 @@ and parse_instr (Tez_t, rest)))) -> return (typed loc (Create_account, Item_t (Contract_t (Unit_t, Unit_t), rest))) + | Prim (loc, "DEFAULT_ACCOUNT", []), + Item_t (Key_t, rest) -> + return + (typed loc (Default_account, Item_t (Contract_t (Unit_t, Unit_t), rest))) | Prim (loc, "CREATE_CONTRACT", []), Item_t (Key_t, Item_t @@ -1296,7 +1300,8 @@ and parse_instr | "COMPARE" | "EQ" | "NEQ" | "LT" | "GT" | "LE" | "GE" | "MANAGER" | "TRANSFER_TOKENS" | "CREATE_ACCOUNT" - | "CREATE_CONTRACT" | "NOW" | "AMOUNT" | "BALANCE" + | "CREATE_CONTRACT" | "NOW" + | "DEFAULT_ACCOUNT" | "AMOUNT" | "BALANCE" | "CHECK_SIGNATURE" | "H" | "STEPS_TO_QUOTA" as name), (_ :: _ as l)), _ -> fail (Invalid_arity (loc, name, 0, List.length l)) @@ -1339,7 +1344,7 @@ and parse_instr fail (Bad_stack (loc, "TRANSFER_TOKENS", 3, stack)) | Prim (loc, ("DROP" | "DUP" | "CAR" | "CDR" | "SOME" | "H" | "DIP" | "IF_NONE" | "LEFT" | "RIGHT" | "IF_LEFT" | "IF" - | "LOOP" | "IF_CONS" | "MANAGER" + | "LOOP" | "IF_CONS" | "MANAGER" | "DEFAULT_ACCOUNT" | "NEG" | "ABS" | "NOT" | "EQ" | "NEQ" | "LT" | "GT" | "LE" | "GE" as name), _), stack -> @@ -1369,7 +1374,7 @@ and parse_instr "LT" ; "GT" ; "LE" ; "GE" ; "MANAGER" ; "TRANSFER_TOKENS" ; "CREATE_ACCOUNT" ; "CREATE_CONTRACT" ; "NOW" ; "AMOUNT" ; "BALANCE" ; - "CHECK_SIGNATURE" ; "H" ; "STEPS_TO_QUOTA" ; + "DEFAULT_ACCOUNT" ; "CHECK_SIGNATURE" ; "H" ; "STEPS_TO_QUOTA" ; "PUSH" ; "NONE" ; "LEFT" ; "RIGHT" ; "NIL" ; "EMPTY_SET" ; "DIP" ; "CHECKED_CAST" ; "CAST" ; "LOOP" ; "IF_NONE" ; "IF_LEFT" ; "IF_CONS" ; diff --git a/src/proto/alpha/script_typed_ir.ml b/src/proto/alpha/script_typed_ir.ml index 918270526..a403813cf 100644 --- a/src/proto/alpha/script_typed_ir.ml +++ b/src/proto/alpha/script_typed_ir.ml @@ -267,6 +267,7 @@ and ('bef, 'aft) instr = | Create_account : (public_key_hash * (public_key_hash option * (bool * (Tez.t * 'rest))), (unit, unit) typed_contract * 'rest) instr + | Default_account : (public_key_hash * 'rest, (unit, unit) typed_contract * 'rest) instr | Create_contract : 'g ty * 'p ty * 'r ty -> (public_key_hash * (public_key_hash option * (bool * (Tez.t * (((Tez.t * 'p) * 'g, 'r * 'g) lambda * ('g * 'rest))))),