Skip to content

Commit

Permalink
Piggy bank example (AU-COBRA#227)
Browse files Browse the repository at this point in the history
Signed-off-by: laurahejn <[email protected]>
Co-authored-by: 4ever2 <[email protected]>
  • Loading branch information
laurahejn and 4ever2 authored May 16, 2023
1 parent 1bf3d70 commit 7f39015
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.hidden
*.tmp
.DS_Store

# dpd-graph outputs
*.dpd
Expand Down
3 changes: 0 additions & 3 deletions examples/_CoqProject
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,3 @@ piggybank/PiggyBankCorrect.v
piggybank/PiggyBankExtractLIGO.v
piggybank/PiggyBankExtractLiquidity.v
piggybank/PiggyBankExtractRust.v
piggybank/PiggyBankPrinters.v
piggybank/PiggyBankGens.v
piggybank/PiggyBankTests.v
2 changes: 1 addition & 1 deletion examples/fa2/FA2Gens.v
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Module FA2Gens (Info : FA2TestsInfo).
Definition gTransferCallerFromTo (state : FA2Token.State)
(ledger : TokenLedger)
(tokenid : token_id)
: GOpt (Address * Address * Address) :=
: GOpt (Address * Address * Address) :=
let gAccountWithTokens := liftOpt fst (sampleFMapOpt_filter ledger.(balances) (fun p => 0 <? (snd p))) in
let policy := state.(permission_policy) in
let gSelfTransfer :=
Expand Down
9 changes: 6 additions & 3 deletions examples/piggybank/PiggyBank.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ From ConCert.Execution Require Import Monad.
From ConCert.Execution Require Import ResultMonad.
From ConCert.Execution Require Import Serializable.
From Coq Require Import List. Import ListNotations.
From Coq Require Import ZArith.
From Coq Require Import ZArith_base.



Expand Down Expand Up @@ -63,6 +63,7 @@ Section PiggyBankErrors.
Definition error_not_owner : Error := 2.
Definition error_already_smashed : Error := 3.
Definition error_amount_not_positive : Error := 4.
Definition error_amount_not_zero : Error := 5.
End PiggyBankErrors.

(** * Implementation *)
Expand All @@ -87,8 +88,9 @@ Section PiggyBankImpl.
let owner := state.(owner) in
do _ <- throwIf (is_smashed state) error_already_smashed;
do _ <- throwIf (address_neqb ctx.(ctx_from) owner) error_not_owner;
let state := state<| balance := 0 |> in
do _ <- throwIf (negb (ctx.(ctx_amount) =? 0)) error_amount_not_zero;
let acts := [act_transfer owner state.(balance)] in
let state := state<| balance := 0 |><| piggyState := Smashed |> in
Ok (state, acts).

Definition receive (chain : Chain)
Expand All @@ -107,11 +109,12 @@ Section PiggyBankImpl.
(_ : Setup)
: result State Error :=
Ok {|
balance := 0;
balance := ctx.(ctx_amount);
owner := ctx.(ctx_from);
piggyState := Intact
|}.

Definition contract : Contract Setup Msg State Error :=
build_contract init receive.

End PiggyBankImpl.
Loading

0 comments on commit 7f39015

Please sign in to comment.