Michelson (docs): fixed scrutable reservoir example.
This commit is contained in:
parent
5e06b9c719
commit
52ec257e1d
@ -1432,12 +1432,12 @@ The complete source `reservoir.tz` is:
|
|||||||
|
|
||||||
We basically want the same contract as the previous one, but instead
|
We basically want the same contract as the previous one, but instead
|
||||||
of destroying it, we want to keep it alive, storing a flag `S` so that
|
of destroying it, we want to keep it alive, storing a flag `S` so that
|
||||||
we can afterwards if the tokens have been transfered to `A` or `B`. We also
|
we can tell afterwards if the tokens have been transfered to `A` or `B`.
|
||||||
want the broker `A` to get some fee `P` in any case.
|
We also want a broker `X` to get some fee `P` in any case.
|
||||||
|
|
||||||
We thus add variables `P` and `S` to the global data of the contract,
|
We thus add variables `P` and `S` and `X` to the global data of the
|
||||||
which becomes `(Pair (S, Pair (T, Pair (Pair P N) (Pair A B))))`. `P`
|
contract, now `(Pair (S, Pair (T, Pair (Pair P N) (Pair X (Pair A B)))))`.
|
||||||
is the fee for broker `A`, `S` is the state, as a string `"open"`,
|
`P` is the fee for broker `A`, `S` is the state, as a string `"open"`,
|
||||||
`"timeout"` or `"success"`.
|
`"timeout"` or `"success"`.
|
||||||
|
|
||||||
At the beginning of the transaction:
|
At the beginning of the transaction:
|
||||||
@ -1446,18 +1446,34 @@ At the beginning of the transaction:
|
|||||||
T via a CDDAR
|
T via a CDDAR
|
||||||
P via a CDDDAAR
|
P via a CDDDAAR
|
||||||
N via a CDDDADR
|
N via a CDDDADR
|
||||||
A via a CDDDDAR
|
X via a CDDDDAR
|
||||||
B via a CDDDDDR
|
A via a CDDDDDAR
|
||||||
|
B via a CDDDDDDR
|
||||||
|
|
||||||
For the contract to stay alive, we test that all least `(Tez "1.00")` is
|
For the contract to stay alive, we test that all least `(Tez "1.00")` is
|
||||||
still available after each transaction. This value is given as an
|
still available after each transaction. This value is given as an
|
||||||
example and must be updated according to the actual Tezos minmal
|
example and must be updated according to the actual Tezos minmal
|
||||||
value for contract balance.
|
value for contract balance.
|
||||||
|
|
||||||
DUP ; CDAR # S
|
The complete source `scrutable_reservoir.tz` is:
|
||||||
|
|
||||||
|
parameter timestamp ;
|
||||||
|
storage
|
||||||
|
pair
|
||||||
|
string # S
|
||||||
|
pair
|
||||||
|
timestamp # T
|
||||||
|
pair
|
||||||
|
(pair tez tez) ; # P N
|
||||||
|
pair
|
||||||
|
(contract unit unit) # X
|
||||||
|
pair (contract unit unit) (contract unit unit) ; # A B
|
||||||
|
return unit ;
|
||||||
|
code
|
||||||
|
{ DUP ; CDAR # S
|
||||||
PUSH string "open" ;
|
PUSH string "open" ;
|
||||||
COMPARE ; NEQ ;
|
COMPARE ; NEQ ;
|
||||||
IF { FAIL ; CDR } # on "success", "timeout" or a bad init value
|
IF { FAIL } # on "success", "timeout" or a bad init value
|
||||||
{ DUP ; CDDAR ; # T
|
{ DUP ; CDDAR ; # T
|
||||||
NOW ;
|
NOW ;
|
||||||
COMPARE ; LT ;
|
COMPARE ; LT ;
|
||||||
@ -1469,38 +1485,39 @@ value for contract balance.
|
|||||||
# We compare to the cumulated amount
|
# We compare to the cumulated amount
|
||||||
BALANCE ;
|
BALANCE ;
|
||||||
COMPARE; LT ;
|
COMPARE; LT ;
|
||||||
IF { # Not enough cash, we accept the transaction
|
IF { # Not enough cash, we just accept the transaction
|
||||||
# and leave the global
|
# and leave the global untouched
|
||||||
CDR }
|
CDR }
|
||||||
{ # We transfer the fee to the broker
|
{ # Enough cash, successful ending
|
||||||
DUP ; CDDDAAR ; # P
|
|
||||||
DIP { DUP ; CDDDDAR } # A
|
|
||||||
UNIT ; TRANSFER_TOKENS ; DROP ;
|
|
||||||
# We transfer the rest to the destination
|
|
||||||
DUP ; CDDDADR ; # N
|
|
||||||
DIP { DUP ; CDDDDDR } # B
|
|
||||||
UNIT ; TRANSFER_TOKENS ; DROP ;
|
|
||||||
# We update the global
|
# We update the global
|
||||||
CDR ; CDR ; PUSH string "success" ; PAIR } }
|
CDDR ; PUSH string "success" ; PAIR ;
|
||||||
{ # After timeout
|
# We transfer the fee to the broker
|
||||||
# We try to transfer P tez to A
|
DUP ; CDDAAR ; # P
|
||||||
|
DIP { DUP ; CDDDAR } # X
|
||||||
|
UNIT ; TRANSFER_TOKENS ; DROP ;
|
||||||
|
# We transfer the rest to A
|
||||||
|
DUP ; CDDADR ; # N
|
||||||
|
DIP { DUP ; CDDDDAR } # A
|
||||||
|
UNIT ; TRANSFER_TOKENS ; DROP } }
|
||||||
|
{ # After timeout, we refund
|
||||||
|
# We update the global
|
||||||
|
CDDR ; PUSH string "timeout" ; PAIR ;
|
||||||
|
# We try to transfer the fee to the broker
|
||||||
PUSH tez "1.00" ; BALANCE ; SUB ; # available
|
PUSH tez "1.00" ; BALANCE ; SUB ; # available
|
||||||
DIP { DUP ; CDDDAAR } ;# P
|
DIP { DUP ; CDDAAR } ; # P
|
||||||
COMPARE ; LT ; # available < P
|
COMPARE ; LT ; # available < P
|
||||||
IF { PUSH tez "1.00" ; BALANCE ; SUB ; # available
|
IF { PUSH tez "1.00" ; BALANCE ; SUB ; # available
|
||||||
DIP { DUP ; CDDDDAR } # A
|
DIP { DUP ; CDDDAR } # X
|
||||||
UNIT ; TRANSFER_TOKENS ; DROP }
|
UNIT ; TRANSFER_TOKENS ; DROP }
|
||||||
{ DUP ; CDDDAAR ; # P
|
{ DUP ; CDDAAR ; # P
|
||||||
DIP { DUP ; CDDDDAR } # A
|
DIP { DUP ; CDDDAR } # X
|
||||||
UNIT ; TRANSFER_TOKENS ; DROP }
|
UNIT ; TRANSFER_TOKENS ; DROP }
|
||||||
# We transfer the rest to B
|
# We transfer the rest to B
|
||||||
PUSH tez "1.00" ; BALANCE ; SUB ; # available
|
PUSH tez "1.00" ; BALANCE ; SUB ; # available
|
||||||
DIP { DUP ; CDDDDDR } # B
|
DIP { DUP ; CDDDDDR } # B
|
||||||
UNIT ; TRANSFER_TOKENS ; DROP ;
|
UNIT ; TRANSFER_TOKENS ; DROP } }
|
||||||
# We update the global
|
|
||||||
CDR ; CDR ; PUSH string "timeout" ; PAIR } }
|
|
||||||
# return Unit
|
# return Unit
|
||||||
UNIT ; PAIR
|
UNIT ; PAIR }
|
||||||
|
|
||||||
### Forward contract
|
### Forward contract
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user