1 | | - | {-# STDLIB_VERSION 5 #-} |
---|
2 | | - | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | | - | {-# CONTENT_TYPE DAPP #-} |
---|
4 | | - | let dAppAddressStr = "3P64j7L944hBMTGn6VbFF1vZ4BYdp6E1f6L" |
---|
5 | | - | |
---|
6 | | - | let dAppPublicKey = base58'94SPyyGavKJdA7irhn98EtMZsGYzKSRAwmp7xGLL6tg5' |
---|
7 | | - | |
---|
8 | | - | let dAppAddress = addressFromPublicKey(dAppPublicKey) |
---|
9 | | - | |
---|
10 | | - | let holdingsAddressStr = "3PLJP2b8dCoATtuuNmAkhTKcJ3SqGkSWy8F" |
---|
11 | | - | |
---|
12 | | - | let holdingsPublicKey = base58'8a9WKSibtVhmgYqRDxsQcD4rZBL3x9gjsf4mtaHbdykE' |
---|
13 | | - | |
---|
14 | | - | let holdingsAddress = addressFromPublicKey(holdingsPublicKey) |
---|
15 | | - | |
---|
16 | | - | let transferCostPct = 40 |
---|
17 | | - | |
---|
18 | | - | @Callable(i) |
---|
19 | | - | func addOwnerAndAmount (ownerId,assetId,amount) = [StringEntry((("sale_" + assetId) + "_originalOwner"), ownerId), IntegerEntry((("sale_" + assetId) + "_amount"), amount)] |
---|
20 | | - | |
---|
21 | | - | |
---|
22 | | - | |
---|
23 | | - | @Callable(i) |
---|
24 | | - | func revokeForSale (assetId) = { |
---|
25 | | - | let callerId = toBase58String(i.caller.bytes) |
---|
26 | | - | let ownerId = match getString(this, (("sale_" + assetId) + "_originalOwner")) { |
---|
27 | | - | case _: Unit => |
---|
28 | | - | "unset" |
---|
29 | | - | case x: String => |
---|
30 | | - | x |
---|
31 | | - | case _ => |
---|
32 | | - | throw("Match error") |
---|
33 | | - | } |
---|
34 | | - | if ((callerId != ownerId)) |
---|
35 | | - | then throw("Owners do not match") |
---|
36 | | - | else [StringEntry((("sale_" + assetId) + "_originalOwner"), ""), IntegerEntry((("sale_" + assetId) + "_amount"), 0), ScriptTransfer(i.caller, 1, fromBase58String(assetId))] |
---|
37 | | - | } |
---|
38 | | - | |
---|
39 | | - | |
---|
40 | | - | |
---|
41 | | - | @Callable(i) |
---|
42 | | - | func buyFromHoldings (assetId,userText) = { |
---|
43 | | - | let ownerId = match getString(this, (("sale_" + assetId) + "_originalOwner")) { |
---|
44 | | - | case _: Unit => |
---|
45 | | - | "unset" |
---|
46 | | - | case x: String => |
---|
47 | | - | x |
---|
48 | | - | case _ => |
---|
49 | | - | throw("Match error") |
---|
50 | | - | } |
---|
51 | | - | let paymentAmount = valueOrElse(i.payments[0].amount, 0) |
---|
52 | | - | let amount = match getInteger(this, (("sale_" + assetId) + "_amount")) { |
---|
53 | | - | case _: Unit => |
---|
54 | | - | 0 |
---|
55 | | - | case x: Int => |
---|
56 | | - | x |
---|
57 | | - | case _ => |
---|
58 | | - | throw("Match error") |
---|
59 | | - | } |
---|
60 | | - | if (if ((ownerId == "unset")) |
---|
61 | | - | then true |
---|
62 | | - | else (ownerId == "")) |
---|
63 | | - | then throw("Original owner not found ") |
---|
64 | | - | else if (if ((amount == 0)) |
---|
65 | | - | then true |
---|
66 | | - | else (amount > paymentAmount)) |
---|
67 | | - | then throw(((("Payment and amount do not match. This assets costs " + toString(amount)) + "but you sent ") + toString(paymentAmount))) |
---|
68 | | - | else { |
---|
69 | | - | let callerId = toBase58String(i.caller.bytes) |
---|
70 | | - | let res = invoke(dAppAddress, "finalizeSale", [assetId, callerId, userText], [AttachedPayment(unit, 0)]) |
---|
71 | | - | if ((res == res)) |
---|
72 | | - | then { |
---|
73 | | - | let transfer = [ScriptTransfer(i.caller, 1, fromBase58String(assetId)), StringEntry((("sale_" + assetId) + "_originalOwner"), ""), IntegerEntry((("sale_" + assetId) + "_amount"), 0)] |
---|
74 | | - | if ((ownerId != holdingsAddressStr)) |
---|
75 | | - | then { |
---|
76 | | - | let amountToRemainInHoldings = (paymentAmount / transferCostPct) |
---|
77 | | - | let amountToTransferToOwner = (paymentAmount - amountToRemainInHoldings) |
---|
78 | | - | let ownerAddress = Address(fromBase58String(ownerId)) |
---|
79 | | - | (transfer ++ [ScriptTransfer(ownerAddress, amountToTransferToOwner, unit)]) |
---|
80 | | - | } |
---|
81 | | - | else transfer |
---|
82 | | - | } |
---|
83 | | - | else throw("Strict value is not equal to itself.") |
---|
84 | | - | } |
---|
85 | | - | } |
---|
86 | | - | |
---|
87 | | - | |
---|
88 | | - | @Verifier(tx) |
---|
89 | | - | func verify () = match tx { |
---|
90 | | - | case ttx: TransferTransaction => |
---|
91 | | - | if ((addressFromPublicKey(ttx.senderPublicKey) == holdingsAddress)) |
---|
92 | | - | then true |
---|
93 | | - | else (addressFromPublicKey(ttx.senderPublicKey) == dAppAddress) |
---|
94 | | - | case _ => |
---|
95 | | - | if (if (sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey)) |
---|
96 | | - | then true |
---|
97 | | - | else (addressFromPublicKey(tx.senderPublicKey) == holdingsAddress)) |
---|
98 | | - | then true |
---|
99 | | - | else (addressFromPublicKey(tx.senderPublicKey) == dAppAddress) |
---|
100 | | - | } |
---|
101 | | - | |
---|
| 1 | + | {-# STDLIB_VERSION 3 #-} |
---|
| 2 | + | {-# CONTENT_TYPE EXPRESSION #-} |
---|
| 3 | + | let pKey0 = base58'HiVUGpeJgwXhMuFBLeQ8qzZ2QRVK7R9pGeDhs2qPTPHD' |
---|
| 4 | + | sigVerify(tx.bodyBytes, tx.proofs[0], pKey0) |
---|