-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new data publisher. LIGO files don't compile.
- Loading branch information
1 parent
a9195a8
commit 3c7c80c
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type storage = unit | ||
|
||
let%entry main | ||
(_parameter : string) | ||
storage = | ||
( [], storage ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(* A contract that sends 1 tez to anyone who asks. *) | ||
|
||
type storage = unit | ||
|
||
(* Initialize storage to (). *) | ||
let%init storage = () | ||
|
||
let%entry main | ||
(key : key_hash) | ||
_storage = | ||
let op = Account.transfer ~dest:key ~amount:1tz in | ||
( [op], () ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(* A contract that publishes data securely. *) | ||
|
||
type storage = { | ||
publisher : address; | ||
data : bytes | ||
} | ||
|
||
let%entry main (param : string) storage = | ||
if (Crypto.sha512 (Bytes.pack param)) = storage.data then | ||
if Current.amount() < 1tz then | ||
failwith "Not enough money, queries cost 1 tez." | ||
else | ||
([], storage) | ||
else if Current.sender () <> storage.publisher then | ||
failwith "Cannot authenticate." | ||
else | ||
([], storage.data <- Crypto.sha512 (Bytes.pack param)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
parameter string; | ||
storage (pair :storage (address %publisher) (bytes %data)); | ||
code { DUP ; | ||
DIP { CDR @storage_slash_1 } ; | ||
CAR @param_slash_2 ; | ||
DUUP @storage ; | ||
CDR %data ; | ||
DUUP @param ; | ||
PACK ; | ||
SHA512 ; | ||
COMPARE ; | ||
EQ ; | ||
IF { PUSH mutez 1000000 ; | ||
AMOUNT ; | ||
COMPARE ; | ||
LT ; | ||
IF { PUSH string "Not enough money, queries cost 1 tez." ; FAILWITH } | ||
{ DUUP @storage ; NIL operation ; PAIR } } | ||
{ DUUP @storage ; | ||
CAR %publisher ; | ||
SENDER ; | ||
COMPARE ; | ||
NEQ ; | ||
IF { PUSH string "Cannot authenticate." ; FAILWITH } | ||
{ DUUP @storage ; | ||
CAR %publisher ; | ||
DUUP @param ; | ||
PACK ; | ||
SHA512 ; | ||
SWAP ; | ||
PAIR %publisher %data ; | ||
NIL operation ; | ||
PAIR } } ; | ||
DIP { DROP ; DROP } }; |