Commit 1e41a9b5 authored by ttt's avatar ttt

update for zeronet

parent 0a2791cc
[%%version 0.165]
type register = {
k : key;
h : string;
}
type reveal = {
k3 : key;
n: nat;
}
[%%version 0.35]
type player = {
k2 : key;
h2 : string;
a: address;
h : bytes;
po: nat option;
}
......@@ -23,67 +12,67 @@ type s = {
}
type p =
| Register of register
| Preimage of reveal
| Register of bytes
| Preimage of nat
| Resolve of unit
let%init storage = {
one = (None : player option);
two = (None : player option);
}
}
let%entry main
(parameter : p)
(storage : s)
: unit * s =
: operation list * s =
match parameter with
| Register (k, h) ->
| Register h ->
begin match storage.one with
| None ->
let p = {
k2 = k;
h2 = h;
a = Current.sender ();
h = h;
po = (None : nat option);
} in
( (), storage.one <- (Some p))
( ([] : operation list), storage.one <- (Some p))
| Some _ ->
begin match storage.two with
| None ->
let p = {
k2 = k;
h2 = h;
a = Current.sender ();
h = h;
po = (None : nat option);
} in
( (), storage.two <- (Some p))
( ([] : operation list), storage.two <- (Some p))
| Some _ ->
Current.failwith "no free spots available"
end
end
| Preimage (k, preimage) ->
| Preimage p ->
begin match storage.one with
| None -> Current.failwith "registration not finished"
| Some one ->
begin match storage.two with
| None -> Current.failwith "registration not finished"
| Some two ->
if Crypto.hash one.k2 = Crypto.hash k then
let sender = Current.sender () in
let h = Crypto.blake2b (Bytes.pack p) in
if one.a = sender then
(* try to hash the preimage *)
let h = Crypto.hash preimage in
if one.h2 = h then
let one = one.po <- (Some preimage) in
( (), storage.one <- (Some one))
if one.h = h then
let one = one.po <- (Some p) in
( ([] : operation list), storage.one <- (Some one))
else
Current.failwith "invalid preimage"
else if Crypto.hash two.k2 = Crypto.hash k then
let h = Crypto.hash preimage in
if two.h2 = h then
let two = two.po <- (Some preimage) in
( (), storage.two <- (Some two))
else if two.a = sender then
if two.h = h then
let two = two.po <- (Some p) in
( ([] : operation list), storage.two <- (Some two))
else
Current.failwith "invalid preimage"
else
Current.failwith "invalid key"
Current.failwith "invalid address"
end
end
| Resolve ->
......@@ -110,14 +99,20 @@ let%entry main
two
end
in
let address = Account.default (Crypto.hash_key winner.k2) in
let c =
begin
match (Contract.at winner.a : unit contract option) with
| None -> Current.failwith "invalid contract"
| Some c -> c
end
in
let payout = Current.balance () in
let storage = {
one = (None : player option);
two = (None : player option);
} in
let (_, storage) = Contract.call address payout storage () in
( (), storage )
let op = Contract.call c payout () in
( op :: [], storage )
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment