Alpha: explicit operation for key revelation

This commit is contained in:
Grégoire Henry 2018-02-21 21:01:02 +01:00 committed by Benjamin Canou
parent fc2cd7ce5c
commit 86561363b2
6 changed files with 43 additions and 17 deletions

View File

@ -561,7 +561,6 @@ and sourced_operations =
}
| Manager_operations of {
source: Contract.contract ;
public_key: Ed25519.Public_key.t option ;
fee: Tez.t ;
counter: counter ;
operations: manager_operation list ;
@ -587,6 +586,7 @@ and amendment_operation =
}
and manager_operation =
| Reveal of Ed25519.Public_key.t
| Transaction of {
amount: Tez.t ;
parameters: Script.expr option ;

View File

@ -138,6 +138,7 @@ let apply_amendment_operation_content ctxt delegate = function
let apply_manager_operation_content
ctxt origination_nonce source = function
| Reveal _ -> return (ctxt, origination_nonce, None)
| Transaction { amount ; parameters ; destination } -> begin
Contract.spend ctxt source amount >>=? fun ctxt ->
Contract.credit ctxt destination amount >>=? fun ctxt ->
@ -224,7 +225,12 @@ let apply_sourced_operation
ctxt baker_contract pred_block block_prio
operation origination_nonce ops =
match ops with
| Manager_operations { source ; public_key ; fee ; counter ; operations = contents } ->
| Manager_operations { source ; fee ; counter ; operations = contents } ->
let public_key =
List.fold_left (fun acc op ->
match op with
| Reveal pk -> Some pk
| _ -> acc) None contents in
Contract.must_exist ctxt source >>=? fun () ->
Contract.update_manager_key ctxt source public_key >>=? fun (ctxt,public_key) ->
Operation.check_signature public_key operation >>=? fun () ->

View File

@ -305,8 +305,12 @@ module Forge = struct
let operations ctxt
block ~branch ~source ?sourcePubKey ~counter ~fee operations =
let operations =
match sourcePubKey with
| None -> operations
| Some pk -> Reveal pk :: operations in
let ops =
Manager_operations { source ; public_key = sourcePubKey ;
Manager_operations { source ;
counter ; operations ; fee } in
(RPC_context.make_call0 S.operations ctxt block
() ({ branch }, Sourced_operations ops))
@ -459,8 +463,13 @@ module Parse = struct
match contents with
| Anonymous_operations _ -> return ()
| Sourced_operations (Manager_operations op) ->
let public_key =
List.fold_left (fun acc op ->
match op with
| Reveal pk -> Some pk
| _ -> acc) None op.operations in
begin
match op.public_key with
match public_key with
| Some key -> return key
| None ->
Contract.get_manager ctxt op.source >>=? fun manager ->

View File

@ -45,7 +45,6 @@ and sourced_operations =
}
| Manager_operations of {
source: Contract_repr.contract ;
public_key: Ed25519.Public_key.t option ;
fee: Tez_repr.tez ;
counter: counter ;
operations: manager_operation list ;
@ -71,6 +70,7 @@ and amendment_operation =
}
and manager_operation =
| Reveal of Ed25519.Public_key.t
| Transaction of {
amount: Tez_repr.tez ;
parameters: Script_repr.expr option ;
@ -96,6 +96,18 @@ module Encoding = struct
open Data_encoding
let reveal_encoding =
(obj2
(req "kind" (constant "reveal"))
(req "public_key" Ed25519.Public_key.encoding))
let reveal_case tag =
case tag reveal_encoding
(function
| Reveal pkh -> Some ((), pkh)
| _ -> None)
(fun ((), pkh) -> Reveal pkh)
let transaction_encoding =
(obj4
(req "kind" (constant "transaction"))
@ -149,27 +161,27 @@ module Encoding = struct
(fun ((), key) -> Delegation key)
let manager_kind_encoding =
(obj6
(obj5
(req "kind" (constant "manager"))
(req "source" Contract_repr.encoding)
(opt "public_key" Ed25519.Public_key.encoding)
(req "fee" Tez_repr.encoding)
(req "counter" int32)
(req "operations"
(list (union ~tag_size:`Uint8 [
transaction_case (Tag 0) ;
origination_case (Tag 1) ;
delegation_case (Tag 2) ;
reveal_case (Tag 0) ;
transaction_case (Tag 1) ;
origination_case (Tag 2) ;
delegation_case (Tag 3) ;
]))))
let manager_kind_case tag =
case tag manager_kind_encoding
(function
| Manager_operations { source; public_key ; fee ; counter ;operations } ->
Some ((), source, public_key, fee, counter, operations)
| Manager_operations { source; fee ; counter ;operations } ->
Some ((), source, fee, counter, operations)
| _ -> None)
(fun ((), source, public_key, fee, counter, operations) ->
Manager_operations { source; public_key ; fee ; counter ; operations })
(fun ((), source, fee, counter, operations) ->
Manager_operations { source; fee ; counter ; operations })
let endorsement_encoding =
(obj4

View File

@ -45,7 +45,6 @@ and sourced_operations =
}
| Manager_operations of {
source: Contract_repr.contract ;
public_key: Ed25519.Public_key.t option ;
fee: Tez_repr.tez ;
counter: counter ;
operations: manager_operation list ;
@ -71,6 +70,7 @@ and amendment_operation =
}
and manager_operation =
| Reveal of Ed25519.Public_key.t
| Transaction of {
amount: Tez_repr.tez ;
parameters: Script_repr.expr option ;

View File

@ -20,10 +20,9 @@ let manager (src : Helpers_account.t) ?(fee = Tez.zero) operations context =
return @@
Manager_operations {
source = src.contract ;
public_key = Some src.pub ;
fee ;
counter ;
operations
operations = Reveal src.pub :: operations ;
}