1 | | - | {-# STDLIB_VERSION 6 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | func amountByAddrKey (addr) = ("leaseAmt_" + addr) |
---|
5 | | - | |
---|
6 | | - | |
---|
7 | | - | @Callable(i) |
---|
8 | | - | func reLease (newAmount) = { |
---|
9 | | - | let addr = toString(i.caller) |
---|
10 | | - | let addAmount = if ((size(i.payments) == 0)) |
---|
11 | | - | then 0 |
---|
12 | | - | else if (if ((size(i.payments) == 1)) |
---|
13 | | - | then (i.payments[0].assetId == unit) |
---|
14 | | - | else false) |
---|
15 | | - | then i.payments[0].amount |
---|
16 | | - | else throw("Wrong payment") |
---|
17 | | - | let oldUserAmount = valueOrElse(getInteger(amountByAddrKey(addr)), 0) |
---|
18 | | - | let totalAmount = valueOrElse(getInteger("totalLeaseAmt"), 0) |
---|
19 | | - | let userAmount = if ((addAmount > 0)) |
---|
20 | | - | then (oldUserAmount + addAmount) |
---|
21 | | - | else min([oldUserAmount, newAmount]) |
---|
22 | | - | let deltaUserAmount = (userAmount - oldUserAmount) |
---|
23 | | - | let lease = Lease(addressFromStringValue("3PnodeAddressHere"), (totalAmount + deltaUserAmount)) |
---|
24 | | - | let oldLease = getBinary("leaseId") |
---|
25 | | - | if (isDefined(oldLease)) |
---|
26 | | - | then [LeaseCancel(value(oldLease))] |
---|
27 | | - | else (nil ++ (if ((0 > deltaUserAmount)) |
---|
28 | | - | then [ScriptTransfer(i.caller, -(deltaUserAmount), unit)] |
---|
29 | | - | else (nil ++ [lease, BinaryEntry("leaseId", calculateLeaseId(lease)), IntegerEntry("totalLeaseAmt", (totalAmount + deltaUserAmount)), IntegerEntry(amountByAddrKey(addr), userAmount)]))) |
---|
30 | | - | } |
---|
31 | | - | |
---|
32 | | - | |
---|
| 1 | + | {-# STDLIB_VERSION 5 #-} |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) |
---|