tx · 4veqf1rKZj98VkW5eHW4Xpq45bP1axVAgNLFxRCMHqDy
3N91zFrRoofbPpkoDbWKrQsQSdLu2EgLL8c: -0.01000000 Waves
2023.09.29 13:20 [2776572] smart account 3N91zFrRoofbPpkoDbWKrQsQSdLu2EgLL8c > SELF 0.00000000 Waves
{
"type": 13,
"id": "4veqf1rKZj98VkW5eHW4Xpq45bP1axVAgNLFxRCMHqDy",
"fee": 1000000,
"feeAssetId": null,
"timestamp": 1695982849675,
"version": 2,
"chainId": 84,
"sender": "3N91zFrRoofbPpkoDbWKrQsQSdLu2EgLL8c",
"senderPublicKey": "5FyjUYCR5Q8jvG6ri6Ysz574HerUK6r1LJzzQ7DvSkLk",
"proofs": [
"3HYyaGuF45eV83zf3YfgMxCMXpgCXJ7FoFoY51gvYEuYgjfqhuCWJa8a4Ewik5MfFCctV92DinVX3RRNQPZKkZ3x"
],
"script": "base64:BgIWCAISBgoEAgICARIECgICAhIECgIIAhUACXNlcGFyYXRvcgICX18BC211c3RBZGRyZXNzAgFpB2FkZHJlc3MDCQAAAggFAWkGY2FsbGVyBQdhZGRyZXNzBgkBBXRocm93AAEIbXVzdFRoaXMBAWkJAQttdXN0QWRkcmVzcwIFAWkFBHRoaXMAEWtTZXJ2aWNlUHVibGljS2V5AhQlc19fc2VydmljZVB1YmxpY0tleQANa0JvdFB1YmxpY0tleQIQJXNfX2JvdFB1YmxpY0tleQAOa0FjY291bnRTY3JpcHQCESVzX19hY2NvdW50U2NyaXB0AQ1hY2NvdW50U2NyaXB0AAkBE3ZhbHVlT3JFcnJvck1lc3NhZ2UCCQCcCAIFBHRoaXMFDmtBY2NvdW50U2NyaXB0AhlhY2NvdW50IHNjcmlwdCBpcyBub3Qgc2V0AA1rUmV3YXJkQW1vdW50AhAlc19fcmV3YXJkQW1vdW50AQxyZXdhcmRBbW91bnQACQETdmFsdWVPckVycm9yTWVzc2FnZQIJAJoIAgUEdGhpcwUNa1Jld2FyZEFtb3VudAIYcmV3YXJkIGFtb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WRkcmVzcwMJAAECBQckbWF0Y2gwAgpCeXRlVmVjdG9yBAFiBQckbWF0Y2gwCQAAAgUBYgkA8RUBCQENYWNjb3VudFNjcmlwdAAHBgkAAgECDmludmFsaWQgc2NyaXB0BQNuaWwDCQAAAgUGY2hlY2tzBQZjaGVja3MEDmNyZWF0b3JBZGRyZXNzCQCnCAEFEGNyZWF0b3JQdWJsaWNLZXkJAJQKAgkAzAgCCQEMSW50ZWdlckVudHJ5AgkBDmtBY2NvdW50U3RhdHVzAQUJYWNjb3VudElkBRRBQ0NPVU5UX1NUQVRVU19SRUFEWQkAzAgCCQELQmluYXJ5RW50cnkCCQEYa0FjY291bnRDcmVhdG9yUHVibGljS2V5AQUJYWNjb3VudElkBRBjcmVhdG9yUHVibGljS2V5CQDMCAIJAQtCaW5hcnlFbnRyeQIJARxrQWNjb3VudElkVG9BY2NvdW50UHVibGljS2V5AQUJYWNjb3VudElkBRBhY2NvdW50UHVibGljS2V5CQDMCAIJAQtTdHJpbmdFbnRyeQIJARprQWNjb3VudEFkZHJlc3NUb0FjY291bnRJZAEFDmFjY291bnRBZGRyZXNzBQlhY2NvdW50SWQJAMwIAgkBDlNjcmlwdFRyYW5zZmVyAwUOY3JlYXRvckFkZHJlc3MJAQxyZXdhcmRBbW91bnQABQR1bml0BQNuaWwFBHVuaXQJAAIBAiRTdHJpY3QgdmFsdWUgaXMgbm90IGVxdWFsIHRvIGl0c2VsZi4AxeKCYA==",
"height": 2776572,
"applicationStatus": "succeeded",
"spentComplexity": 0
}
View: original | compacted
Prev: 52UDy65RNS29aikC2CuuPbHQjnq13HFAUit4vngCNody
Next: ekrk3RoaYGx5v5Sm47tvYU1fNAuUmsg9N85pwhynBd3
Diff:
Old | New | | Differences |
---|
15 | 15 | | |
---|
16 | 16 | | let kBotPublicKey = "%s__botPublicKey" |
---|
17 | 17 | | |
---|
18 | | - | let kFactoryPublicKey = "%s__factoryPublicKey" |
---|
| 18 | + | let kAccountScript = "%s__accountScript" |
---|
19 | 19 | | |
---|
20 | | - | let kOwnerPublicKey = "%s__ownerPublicKey" |
---|
21 | | - | |
---|
22 | | - | let kCreatorPublicKey = "%s__creatorPublicKey" |
---|
23 | | - | |
---|
24 | | - | let kAccountScriptHash = "%s__accountScriptHash" |
---|
25 | | - | |
---|
26 | | - | func accountScriptHash () = valueOrErrorMessage(getBinary(this, kAccountScriptHash), "account script hash is not set") |
---|
27 | | - | |
---|
28 | | - | |
---|
29 | | - | let kCounter = "%s__counter" |
---|
30 | | - | |
---|
31 | | - | func counter () = valueOrElse(getInteger(this, kCounter), 0) |
---|
| 20 | + | func accountScript () = valueOrErrorMessage(getBinary(this, kAccountScript), "account script is not set") |
---|
32 | 21 | | |
---|
33 | 22 | | |
---|
34 | 23 | | let kRewardAmount = "%s__rewardAmount" |
---|
|
36 | 25 | | func rewardAmount () = valueOrErrorMessage(getInteger(this, kRewardAmount), "reward amount is not set") |
---|
37 | 26 | | |
---|
38 | 27 | | |
---|
39 | | - | func kRequestCompleted (requestId) = makeString(["%s%s", requestId, "completed"], separator) |
---|
| 28 | + | let ACCOUNT_STATUS_EMPTY = 0 |
---|
| 29 | + | |
---|
| 30 | + | let ACCOUNT_STATUS_READY = 1 |
---|
| 31 | + | |
---|
| 32 | + | func kAccountStatus (accountId) = makeString(["%s%s", accountId, "status"], separator) |
---|
40 | 33 | | |
---|
41 | 34 | | |
---|
42 | | - | func requestCompleted (requestId) = valueOrErrorMessage(getBoolean(this, kRequestCompleted(requestId)), "request is not found") |
---|
| 35 | + | func accountStatus (accountId) = valueOrErrorMessage(getInteger(this, kAccountStatus(accountId)), "account is not found") |
---|
43 | 36 | | |
---|
44 | 37 | | |
---|
45 | | - | func kRequestOwner (requestId) = makeString(["%s%s", requestId, "owner"], separator) |
---|
| 38 | + | func kAccountCreatorPublicKey (accountId) = makeString(["%s%s", accountId, "creatorPublicKey"], separator) |
---|
46 | 39 | | |
---|
47 | 40 | | |
---|
48 | | - | func requestOwner (requestId) = valueOrErrorMessage(getBinary(this, kRequestOwner(requestId)), "request is not found") |
---|
| 41 | + | func kAccountOwnerPublicKey (accountId) = makeString(["%s%s", accountId, "ownerPublicKey"], separator) |
---|
| 42 | + | |
---|
| 43 | + | |
---|
| 44 | + | func kAccountAmountAssetId (accountId) = makeString(["%s%s", accountId, "amountAssetId"], separator) |
---|
| 45 | + | |
---|
| 46 | + | |
---|
| 47 | + | func kAccountPriceAssetId (accountId) = makeString(["%s%s", accountId, "priceAssetId"], separator) |
---|
| 48 | + | |
---|
| 49 | + | |
---|
| 50 | + | func kAccountIdToAccountPublicKey (accountId) = makeString(["%s%s", accountId, "accountIdToAccountPublicKey"], separator) |
---|
| 51 | + | |
---|
| 52 | + | |
---|
| 53 | + | func kAccountAddressToAccountId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToAccountId"], separator) |
---|
49 | 54 | | |
---|
50 | 55 | | |
---|
51 | 56 | | let serviceAddress = addressFromPublicKey(getBinaryValue(this, kServicePublicKey)) |
---|
|
53 | 58 | | let botPublicKey = getBinaryValue(this, kBotPublicKey) |
---|
54 | 59 | | |
---|
55 | 60 | | @Callable(i) |
---|
56 | | - | func init (servicePublicKey,botPublicKey,accountScriptHash,rewardAmount) = { |
---|
| 61 | + | func init (servicePublicKey,botPublicKey,accountScript,rewardAmount) = { |
---|
57 | 62 | | let checkCaller = mustThis(i) |
---|
58 | 63 | | if ((checkCaller == checkCaller)) |
---|
59 | | - | then $Tuple2([BinaryEntry(kServicePublicKey, servicePublicKey), BinaryEntry(kBotPublicKey, botPublicKey), BinaryEntry(kAccountScriptHash, accountScriptHash), IntegerEntry(kRewardAmount, rewardAmount)], unit) |
---|
| 64 | + | then $Tuple2([BinaryEntry(kServicePublicKey, servicePublicKey), BinaryEntry(kBotPublicKey, botPublicKey), BinaryEntry(kAccountScript, accountScript), IntegerEntry(kRewardAmount, rewardAmount)], unit) |
---|
60 | 65 | | else throw("Strict value is not equal to itself.") |
---|
61 | 66 | | } |
---|
62 | 67 | | |
---|
63 | 68 | | |
---|
64 | 69 | | |
---|
65 | 70 | | @Callable(i) |
---|
66 | | - | func request () = { |
---|
| 71 | + | func request (amountAssetId,priceAssetId) = { |
---|
| 72 | + | let accountId = toBase58String(sha256(((i.caller.bytes + amountAssetId) + priceAssetId))) |
---|
67 | 73 | | let checks = [if ((size(i.payments) == 1)) |
---|
68 | 74 | | then true |
---|
69 | 75 | | else throw("1 payment is required"), if ((i.payments[0].assetId == unit)) |
---|
70 | 76 | | then true |
---|
71 | 77 | | else throw("invalid asset"), if ((i.payments[0].amount == rewardAmount())) |
---|
72 | 78 | | then true |
---|
73 | | - | else throw("invalid amount")] |
---|
| 79 | + | else throw("invalid amount"), if ((getInteger(this, kAccountStatus(accountId)) == unit)) |
---|
| 80 | + | then true |
---|
| 81 | + | else throw("account already exists")] |
---|
74 | 82 | | if ((checks == checks)) |
---|
75 | | - | then { |
---|
76 | | - | let requestId = toBase58String(sha256((i.caller.bytes + toBytes(counter())))) |
---|
77 | | - | $Tuple2([BooleanEntry(kRequestCompleted(requestId), false), BinaryEntry(kRequestOwner(requestId), i.callerPublicKey), IntegerEntry(kCounter, (counter() + 1))], unit) |
---|
78 | | - | } |
---|
| 83 | + | then $Tuple2([IntegerEntry(kAccountStatus(accountId), 0), BinaryEntry(kAccountOwnerPublicKey(accountId), i.callerPublicKey), BinaryEntry(kAccountAmountAssetId(accountId), amountAssetId), BinaryEntry(kAccountPriceAssetId(accountId), priceAssetId)], unit) |
---|
79 | 84 | | else throw("Strict value is not equal to itself.") |
---|
80 | 85 | | } |
---|
81 | 86 | | |
---|
82 | 87 | | |
---|
83 | 88 | | |
---|
84 | 89 | | @Callable(i) |
---|
85 | | - | func complete (requestId,accountPublicKey) = { |
---|
86 | | - | let accountAddress = addressFromPublicKey(accountPublicKey) |
---|
87 | | - | let checks = [if (!(requestCompleted(requestId))) |
---|
| 90 | + | func complete (accountId,creatorPublicKey) = { |
---|
| 91 | + | let accountPublicKey = i.callerPublicKey |
---|
| 92 | + | let accountAddress = i.caller |
---|
| 93 | + | let checks = [if ((accountStatus(accountId) == ACCOUNT_STATUS_EMPTY)) |
---|
88 | 94 | | then true |
---|
89 | | - | else throw("request is already completed"), if ((scriptHash(accountAddress) == accountScriptHash())) |
---|
90 | | - | then true |
---|
91 | | - | else throw("invalid script"), if ( match getBinary(accountAddress, kFactoryPublicKey) { |
---|
| 95 | + | else throw("account is already exists"), if ( match scriptHash(accountAddress) { |
---|
92 | 96 | | case b: ByteVector => |
---|
93 | | - | (addressFromPublicKey(b) == this) |
---|
| 97 | + | (b == blake2b256_32Kb(accountScript())) |
---|
94 | 98 | | case _ => |
---|
95 | 99 | | false |
---|
96 | 100 | | }) |
---|
97 | 101 | | then true |
---|
98 | | - | else throw("invalid factory public key"), if ( match getBinary(accountAddress, kOwnerPublicKey) { |
---|
99 | | - | case b: ByteVector => |
---|
100 | | - | (b == requestOwner(requestId)) |
---|
101 | | - | case _ => |
---|
102 | | - | false |
---|
103 | | - | }) |
---|
104 | | - | then true |
---|
105 | | - | else throw("invalid owner public key")] |
---|
| 102 | + | else throw("invalid script")] |
---|
106 | 103 | | if ((checks == checks)) |
---|
107 | 104 | | then { |
---|
108 | | - | let creatorPublicKey = valueOrErrorMessage(getBinary(accountAddress, kCreatorPublicKey), "creator public key is not set") |
---|
109 | 105 | | let creatorAddress = addressFromPublicKey(creatorPublicKey) |
---|
110 | | - | let result = invoke(accountAddress, "approve", nil, nil) |
---|
111 | | - | $Tuple2([BooleanEntry(kRequestCompleted(requestId), true), ScriptTransfer(creatorAddress, rewardAmount(), unit)], result) |
---|
| 106 | + | $Tuple2([IntegerEntry(kAccountStatus(accountId), ACCOUNT_STATUS_READY), BinaryEntry(kAccountCreatorPublicKey(accountId), creatorPublicKey), BinaryEntry(kAccountIdToAccountPublicKey(accountId), accountPublicKey), StringEntry(kAccountAddressToAccountId(accountAddress), accountId), ScriptTransfer(creatorAddress, rewardAmount(), unit)], unit) |
---|
112 | 107 | | } |
---|
113 | 108 | | else throw("Strict value is not equal to itself.") |
---|
114 | 109 | | } |
---|
Full:
Old | New | | Differences |
---|
1 | 1 | | {-# STDLIB_VERSION 6 #-} |
---|
2 | 2 | | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
3 | 3 | | {-# CONTENT_TYPE DAPP #-} |
---|
4 | 4 | | let separator = "__" |
---|
5 | 5 | | |
---|
6 | 6 | | func mustAddress (i,address) = if ((i.caller == address)) |
---|
7 | 7 | | then true |
---|
8 | 8 | | else throw() |
---|
9 | 9 | | |
---|
10 | 10 | | |
---|
11 | 11 | | func mustThis (i) = mustAddress(i, this) |
---|
12 | 12 | | |
---|
13 | 13 | | |
---|
14 | 14 | | let kServicePublicKey = "%s__servicePublicKey" |
---|
15 | 15 | | |
---|
16 | 16 | | let kBotPublicKey = "%s__botPublicKey" |
---|
17 | 17 | | |
---|
18 | | - | let kFactoryPublicKey = "%s__factoryPublicKey" |
---|
| 18 | + | let kAccountScript = "%s__accountScript" |
---|
19 | 19 | | |
---|
20 | | - | let kOwnerPublicKey = "%s__ownerPublicKey" |
---|
21 | | - | |
---|
22 | | - | let kCreatorPublicKey = "%s__creatorPublicKey" |
---|
23 | | - | |
---|
24 | | - | let kAccountScriptHash = "%s__accountScriptHash" |
---|
25 | | - | |
---|
26 | | - | func accountScriptHash () = valueOrErrorMessage(getBinary(this, kAccountScriptHash), "account script hash is not set") |
---|
27 | | - | |
---|
28 | | - | |
---|
29 | | - | let kCounter = "%s__counter" |
---|
30 | | - | |
---|
31 | | - | func counter () = valueOrElse(getInteger(this, kCounter), 0) |
---|
| 20 | + | func accountScript () = valueOrErrorMessage(getBinary(this, kAccountScript), "account script is not set") |
---|
32 | 21 | | |
---|
33 | 22 | | |
---|
34 | 23 | | let kRewardAmount = "%s__rewardAmount" |
---|
35 | 24 | | |
---|
36 | 25 | | func rewardAmount () = valueOrErrorMessage(getInteger(this, kRewardAmount), "reward amount is not set") |
---|
37 | 26 | | |
---|
38 | 27 | | |
---|
39 | | - | func kRequestCompleted (requestId) = makeString(["%s%s", requestId, "completed"], separator) |
---|
| 28 | + | let ACCOUNT_STATUS_EMPTY = 0 |
---|
| 29 | + | |
---|
| 30 | + | let ACCOUNT_STATUS_READY = 1 |
---|
| 31 | + | |
---|
| 32 | + | func kAccountStatus (accountId) = makeString(["%s%s", accountId, "status"], separator) |
---|
40 | 33 | | |
---|
41 | 34 | | |
---|
42 | | - | func requestCompleted (requestId) = valueOrErrorMessage(getBoolean(this, kRequestCompleted(requestId)), "request is not found") |
---|
| 35 | + | func accountStatus (accountId) = valueOrErrorMessage(getInteger(this, kAccountStatus(accountId)), "account is not found") |
---|
43 | 36 | | |
---|
44 | 37 | | |
---|
45 | | - | func kRequestOwner (requestId) = makeString(["%s%s", requestId, "owner"], separator) |
---|
| 38 | + | func kAccountCreatorPublicKey (accountId) = makeString(["%s%s", accountId, "creatorPublicKey"], separator) |
---|
46 | 39 | | |
---|
47 | 40 | | |
---|
48 | | - | func requestOwner (requestId) = valueOrErrorMessage(getBinary(this, kRequestOwner(requestId)), "request is not found") |
---|
| 41 | + | func kAccountOwnerPublicKey (accountId) = makeString(["%s%s", accountId, "ownerPublicKey"], separator) |
---|
| 42 | + | |
---|
| 43 | + | |
---|
| 44 | + | func kAccountAmountAssetId (accountId) = makeString(["%s%s", accountId, "amountAssetId"], separator) |
---|
| 45 | + | |
---|
| 46 | + | |
---|
| 47 | + | func kAccountPriceAssetId (accountId) = makeString(["%s%s", accountId, "priceAssetId"], separator) |
---|
| 48 | + | |
---|
| 49 | + | |
---|
| 50 | + | func kAccountIdToAccountPublicKey (accountId) = makeString(["%s%s", accountId, "accountIdToAccountPublicKey"], separator) |
---|
| 51 | + | |
---|
| 52 | + | |
---|
| 53 | + | func kAccountAddressToAccountId (accountAddress) = makeString(["%s%s", toString(accountAddress), "accountAddressToAccountId"], separator) |
---|
49 | 54 | | |
---|
50 | 55 | | |
---|
51 | 56 | | let serviceAddress = addressFromPublicKey(getBinaryValue(this, kServicePublicKey)) |
---|
52 | 57 | | |
---|
53 | 58 | | let botPublicKey = getBinaryValue(this, kBotPublicKey) |
---|
54 | 59 | | |
---|
55 | 60 | | @Callable(i) |
---|
56 | | - | func init (servicePublicKey,botPublicKey,accountScriptHash,rewardAmount) = { |
---|
| 61 | + | func init (servicePublicKey,botPublicKey,accountScript,rewardAmount) = { |
---|
57 | 62 | | let checkCaller = mustThis(i) |
---|
58 | 63 | | if ((checkCaller == checkCaller)) |
---|
59 | | - | then $Tuple2([BinaryEntry(kServicePublicKey, servicePublicKey), BinaryEntry(kBotPublicKey, botPublicKey), BinaryEntry(kAccountScriptHash, accountScriptHash), IntegerEntry(kRewardAmount, rewardAmount)], unit) |
---|
| 64 | + | then $Tuple2([BinaryEntry(kServicePublicKey, servicePublicKey), BinaryEntry(kBotPublicKey, botPublicKey), BinaryEntry(kAccountScript, accountScript), IntegerEntry(kRewardAmount, rewardAmount)], unit) |
---|
60 | 65 | | else throw("Strict value is not equal to itself.") |
---|
61 | 66 | | } |
---|
62 | 67 | | |
---|
63 | 68 | | |
---|
64 | 69 | | |
---|
65 | 70 | | @Callable(i) |
---|
66 | | - | func request () = { |
---|
| 71 | + | func request (amountAssetId,priceAssetId) = { |
---|
| 72 | + | let accountId = toBase58String(sha256(((i.caller.bytes + amountAssetId) + priceAssetId))) |
---|
67 | 73 | | let checks = [if ((size(i.payments) == 1)) |
---|
68 | 74 | | then true |
---|
69 | 75 | | else throw("1 payment is required"), if ((i.payments[0].assetId == unit)) |
---|
70 | 76 | | then true |
---|
71 | 77 | | else throw("invalid asset"), if ((i.payments[0].amount == rewardAmount())) |
---|
72 | 78 | | then true |
---|
73 | | - | else throw("invalid amount")] |
---|
| 79 | + | else throw("invalid amount"), if ((getInteger(this, kAccountStatus(accountId)) == unit)) |
---|
| 80 | + | then true |
---|
| 81 | + | else throw("account already exists")] |
---|
74 | 82 | | if ((checks == checks)) |
---|
75 | | - | then { |
---|
76 | | - | let requestId = toBase58String(sha256((i.caller.bytes + toBytes(counter())))) |
---|
77 | | - | $Tuple2([BooleanEntry(kRequestCompleted(requestId), false), BinaryEntry(kRequestOwner(requestId), i.callerPublicKey), IntegerEntry(kCounter, (counter() + 1))], unit) |
---|
78 | | - | } |
---|
| 83 | + | then $Tuple2([IntegerEntry(kAccountStatus(accountId), 0), BinaryEntry(kAccountOwnerPublicKey(accountId), i.callerPublicKey), BinaryEntry(kAccountAmountAssetId(accountId), amountAssetId), BinaryEntry(kAccountPriceAssetId(accountId), priceAssetId)], unit) |
---|
79 | 84 | | else throw("Strict value is not equal to itself.") |
---|
80 | 85 | | } |
---|
81 | 86 | | |
---|
82 | 87 | | |
---|
83 | 88 | | |
---|
84 | 89 | | @Callable(i) |
---|
85 | | - | func complete (requestId,accountPublicKey) = { |
---|
86 | | - | let accountAddress = addressFromPublicKey(accountPublicKey) |
---|
87 | | - | let checks = [if (!(requestCompleted(requestId))) |
---|
| 90 | + | func complete (accountId,creatorPublicKey) = { |
---|
| 91 | + | let accountPublicKey = i.callerPublicKey |
---|
| 92 | + | let accountAddress = i.caller |
---|
| 93 | + | let checks = [if ((accountStatus(accountId) == ACCOUNT_STATUS_EMPTY)) |
---|
88 | 94 | | then true |
---|
89 | | - | else throw("request is already completed"), if ((scriptHash(accountAddress) == accountScriptHash())) |
---|
90 | | - | then true |
---|
91 | | - | else throw("invalid script"), if ( match getBinary(accountAddress, kFactoryPublicKey) { |
---|
| 95 | + | else throw("account is already exists"), if ( match scriptHash(accountAddress) { |
---|
92 | 96 | | case b: ByteVector => |
---|
93 | | - | (addressFromPublicKey(b) == this) |
---|
| 97 | + | (b == blake2b256_32Kb(accountScript())) |
---|
94 | 98 | | case _ => |
---|
95 | 99 | | false |
---|
96 | 100 | | }) |
---|
97 | 101 | | then true |
---|
98 | | - | else throw("invalid factory public key"), if ( match getBinary(accountAddress, kOwnerPublicKey) { |
---|
99 | | - | case b: ByteVector => |
---|
100 | | - | (b == requestOwner(requestId)) |
---|
101 | | - | case _ => |
---|
102 | | - | false |
---|
103 | | - | }) |
---|
104 | | - | then true |
---|
105 | | - | else throw("invalid owner public key")] |
---|
| 102 | + | else throw("invalid script")] |
---|
106 | 103 | | if ((checks == checks)) |
---|
107 | 104 | | then { |
---|
108 | | - | let creatorPublicKey = valueOrErrorMessage(getBinary(accountAddress, kCreatorPublicKey), "creator public key is not set") |
---|
109 | 105 | | let creatorAddress = addressFromPublicKey(creatorPublicKey) |
---|
110 | | - | let result = invoke(accountAddress, "approve", nil, nil) |
---|
111 | | - | $Tuple2([BooleanEntry(kRequestCompleted(requestId), true), ScriptTransfer(creatorAddress, rewardAmount(), unit)], result) |
---|
| 106 | + | $Tuple2([IntegerEntry(kAccountStatus(accountId), ACCOUNT_STATUS_READY), BinaryEntry(kAccountCreatorPublicKey(accountId), creatorPublicKey), BinaryEntry(kAccountIdToAccountPublicKey(accountId), accountPublicKey), StringEntry(kAccountAddressToAccountId(accountAddress), accountId), ScriptTransfer(creatorAddress, rewardAmount(), unit)], unit) |
---|
112 | 107 | | } |
---|
113 | 108 | | else throw("Strict value is not equal to itself.") |
---|
114 | 109 | | } |
---|
115 | 110 | | |
---|
116 | 111 | | |
---|