-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract.ride
130 lines (98 loc) · 3.32 KB
/
contract.ride
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{-# STDLIB_VERSION 5 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
let colorList = ["aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "purple", "red", "silver", "teal", "white", "yellow"]
func mapStrToStr(accum: List[String], next: String) = next :: accum
func paintOver(accum: List[StringEntry], next: String) = {
let array = next.split("-")
# if(parseIntValue(array[1]) < 100 && parseIntValue(array[2]) < 100) then
if(containsElement(colorList,array[0]) && parseIntValue(array[1]) < 100 && parseIntValue(array[2]) < 100) then
accum ++ [ StringEntry(array[1] + "-" + array[2], array[0]) ]
else throw("Is't walid")
}
func getLogID() = {
let logID = getInteger("logID")
if(logID != unit) then {
getIntegerValue("logID")
} else 0
}
func listStringToListString(arr: List[String]) = {
FOLD<60>(arr, [], mapStrToStr)
}
func listIntCompressToString(arr: List[String]) = {
makeString(listStringToListString(arr), "|")
}
func getUserPixelCount(address: String) = {
let pc = getInteger(address + "_pixelCount")
if(pc != unit) then {
getIntegerValue(address + "_pixelCount")
} else 0
}
func setUserPixelCount(address: String, pixelCount: Int) = {
IntegerEntry(address + "_pixelCount", pixelCount)
}
func isPaymentOk(i: Invocation, sum: Int) = {
let USDTWXG = base58'34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ'
let USDCWXG = base58'6XtHjpXbs9RRJP2Sr9GUyVqzACcby9TkThHXnjVC5CDJ'
let p = i.payments[0]
match p.assetId {
case assetId: ByteVector => (assetId == USDTWXG || assetId == USDCWXG) && p.amount >= sum
case _ => false
}
}
func getAssetId(i: Invocation) = {
let USDTWXG = base58'34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ'
let USDCWXG = base58'6XtHjpXbs9RRJP2Sr9GUyVqzACcby9TkThHXnjVC5CDJ'
let p = i.payments[0]
if(p.assetId == USDTWXG) then {
USDTWXG
} else {
USDCWXG
}
}
func recordsForDeletionMap(accum: List[StringEntry], next: String) = {
accum ++ [ DeleteEntry(next) ]
}
@Callable(i)
func draw(pixels: List[String]) = {
let address = toString(i.caller)
let userPixelCount = getUserPixelCount(address) + size(pixels)
let targetSum = 10000 * size(pixels)
if(isPaymentOk(i, targetSum)) then {
let timestamp = match blockInfoByHeight(height) {
case block:BlockInfo =>
block.timestamp case _ => 0
}
let newLogID = getLogID() + 1
FOLD<60>(pixels, [], paintOver)
++ [
StringEntry("log_" + toString(timestamp) + "_" + toString(newLogID), listIntCompressToString(pixels)),
IntegerEntry("logID", newLogID),
setUserPixelCount(address, userPixelCount),
Burn(getAssetId(i), targetSum)
]
} else {
throw("Payment amount error!")
}
}
# @Callable(i)
# func testWriteString(key: String, value: String) = {
# ([
# StringEntry(key, value)
# ])
# }
# @Callable(i)
# func testWriteInteger(key: String, value: Int) = {
# ([
# IntegerEntry(key, value)
# ])
# }
@Callable(i)
func clearBurnerList(recordsForDeletion: List[String]) = {
let caller = toString(i.caller)
if (caller == "3PNWjCoZuFyKDz5tvb2YcU5LtcDyyUAxaSh") then {
FOLD<60>(recordsForDeletion, [], recordsForDeletionMap)
} else {
throw("You are not an admin!")
}
}