Add require builtin

This commit is contained in:
Ulf Norell
2019-06-14 10:27:07 +02:00
parent 5628cf90b8
commit 17a1fd8095
14 changed files with 19 additions and 30 deletions
+4 -6
View File
@@ -104,10 +104,10 @@ contract AEProof =
proofsByOwner : map(address, array(uint)) }
function notarize(document:string, comment:string, ipfsHash:hash) =
let _ = require(aetoken.balanceOf(caller()) > 0)
let _ = require(aetoken.balanceOf(caller()) > 0, "false")
let proofHash: uint = calculateHash(document)
let proof : proof = Map.get_(proofHash, state().proofs)
let _ = require(proof.owner == #0)
let _ = require(proof.owner == #0, "false")
let proof' : proof = proof { owner = caller()
, timestamp = block().timestamp
, proofBlock = block().height
@@ -124,12 +124,12 @@ contract AEProof =
function getProof(document) : proof =
let calcHash = calculateHash(document)
let proof = Map.get_(calcHash, state().proofs)
let _ = require(proof.owner != #0)
let _ = require(proof.owner != #0, "false")
proof
function getProofByHash(hash: uint) : proof =
let proof = Map.get_(hash, state().proofs)
let _ = require(proof.owner != #0)
let _ = require(proof.owner != #0, "false")
proof
@@ -141,5 +141,3 @@ contract AEProof =
function getProofsByOwner(owner: address): array(uint) =
Map.get(owner, state())
function require(x : bool) : unit = if(x) () else abort("false")
-2
View File
@@ -15,5 +15,3 @@ contract BasicAuth =
function to_sign(h : hash, n : int) =
Crypto.blake2b((h, n))
private function require(b : bool, err : string) =
if(!b) abort(err)
-2
View File
@@ -14,5 +14,3 @@ contract BitcoinAuth =
function to_sign(h : hash, n : int) : hash =
Crypto.blake2b((h, n))
private function require(b : bool, err : string) =
if(!b) abort(err)
-3
View File
@@ -15,9 +15,6 @@ contract DutchAuction =
Chain.spend(to, amount)
total - amount
private function require(b : bool, err : string) =
if(!b) abort(err)
// TTL set by user on posting contract, typically (start - end ) div dec
public function init(beneficiary, start, decrease) : state =
require(start > 0 && decrease > 0, "bad args")
-3
View File
@@ -77,9 +77,6 @@ contract ERC20Token =
put( state{approval_log = e :: state.approval_log })
e
private function require(b : bool, err : string) =
if(!b) abort(err)
private function sub(_a : int, _b : int) : int =
require(_b =< _a, "Error")
_a - _b
-3
View File
@@ -12,9 +12,6 @@ contract FundMe =
deadline : int,
goal : int }
private function require(b : bool, err : string) =
if(!b) abort(err)
private stateful function spend(args : spend_args) =
Chain.spend(args.recipient, args.amount)
-2
View File
@@ -108,5 +108,3 @@ contract Oracles =
Oracle.respond(o, q, Answer(question, "magic", 1337), signature = sig)
Oracle.get_answer(o, q)
private function require(b : bool, err : string) =
if(!b) abort(err)
-2
View File
@@ -20,5 +20,3 @@ contract OraclesGas =
Oracle.respond(o, q, answer)
()
private function require(b : bool, err : string) =
if(!b) abort(err)
-2
View File
@@ -33,5 +33,3 @@ contract Oracles =
q : query_id) : option(answer_t) =
Oracle.get_answer(o, q)
private function require(b : bool, err : string) =
if(!b) abort(err)
+1 -3
View File
@@ -9,8 +9,6 @@ contract VariantTypes =
function init() = Stopped
function require(b) = if(!b) abort("required")
stateful function start(bal : int) =
switch(state)
Stopped => put(Started({owner = Call.caller, balance = bal, color = Grey(0)}))
@@ -18,7 +16,7 @@ contract VariantTypes =
stateful function stop() =
switch(state)
Started(st) =>
require(Call.caller == st.owner)
require(Call.caller == st.owner, "required")
put(Stopped)
st.balance