wowok 1.4.22 → 1.4.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/demand.ts +3 -3
- package/src/guard.ts +9 -8
- package/src/index.ts +2 -1
- package/src/machine.ts +1 -3
- package/src/permission.ts +2 -3
- package/src/protocol.ts +6 -6
- package/src/reward.ts +10 -10
- package/src/treasury.ts +6 -6
- package/src/utils.ts +8 -11
- package/src/vote.ts +71 -33
package/package.json
CHANGED
package/src/demand.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
2
2
|
import { FnCallType, Protocol, PassportObject, PermissionObject, GuardObject, DemandAddress, TxbObject, ResourceObject} from './protocol';
|
|
3
|
-
import { IsValidDesription,
|
|
3
|
+
import { IsValidDesription, IsValidAddress, IsValidArgType, IsValidU64, } from './utils'
|
|
4
4
|
import { Errors, ERROR} from './exception'
|
|
5
5
|
|
|
6
6
|
export class Demand {
|
|
@@ -35,7 +35,7 @@ export class Demand {
|
|
|
35
35
|
if (!IsValidArgType(bounty_type)) {
|
|
36
36
|
ERROR(Errors.IsValidArgType, bounty_type);
|
|
37
37
|
}
|
|
38
|
-
if (!
|
|
38
|
+
if (!IsValidU64(time)) {
|
|
39
39
|
ERROR(Errors.IsValidUint, 'time')
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -95,7 +95,7 @@ export class Demand {
|
|
|
95
95
|
|
|
96
96
|
// minutes_duration TRUE , time is minutes count; otherwise, the deadline time
|
|
97
97
|
expand_time(minutes_duration:boolean, time: number, passport?:PassportObject) {
|
|
98
|
-
if (!
|
|
98
|
+
if (!IsValidU64(time)) {
|
|
99
99
|
ERROR(Errors.IsValidUint, 'time');
|
|
100
100
|
}
|
|
101
101
|
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
package/src/guard.ts
CHANGED
|
@@ -250,17 +250,18 @@ export class Guard {
|
|
|
250
250
|
[MODULES.vote, 'Vote-Guard Wight', 1110, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The voting weight corresponding to the Vote-Guard.', ['guard address']],
|
|
251
251
|
[MODULES.vote, 'Has Voted by Address', 1111, [ValueType.TYPE_ADDRESS], ValueType.TYPE_BOOL, 'Whether an address has already voted?', ['address']],
|
|
252
252
|
[MODULES.vote, 'Voted Weight by Address', 1112, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The weight of whether an address has been voted on.', ['adddress']],
|
|
253
|
-
[MODULES.vote, 'Has Option', 1113, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Whether a voting option is included?', ['option
|
|
254
|
-
[MODULES.vote, 'Has Object of Option', 1114, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Whether a voting option refers to an object?', ['option
|
|
255
|
-
[MODULES.vote, 'Option Object', 1115, [ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The object referenced by a voting option.', ['option
|
|
256
|
-
[MODULES.vote, 'Option Counts', 1116, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of votes for the voting option.', ['option
|
|
257
|
-
[MODULES.vote, 'Option Votes', 1117, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of voted addresses for the voting option.', ['option
|
|
253
|
+
[MODULES.vote, 'Has Option', 1113, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Whether a voting option is included?', ['option content']],
|
|
254
|
+
[MODULES.vote, 'Has Object of Option', 1114, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Whether a voting option refers to an object?', ['option content']],
|
|
255
|
+
[MODULES.vote, 'Option Object', 1115, [ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The object referenced by a voting option.', ['option content']],
|
|
256
|
+
[MODULES.vote, 'Option Counts', 1116, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of votes for the voting option.', ['option content']],
|
|
257
|
+
[MODULES.vote, 'Option Votes', 1117, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of voted addresses for the voting option.', ['option content']],
|
|
258
258
|
[MODULES.vote, 'Address Count Voted', 1118, [], ValueType.TYPE_U64, 'Total number of addresses voted.', []],
|
|
259
|
-
[MODULES.vote, 'Top1 Option by Addresses', 1119, [], ValueType.TYPE_STRING, 'The
|
|
259
|
+
[MODULES.vote, 'Top1 Option by Addresses', 1119, [], ValueType.TYPE_STRING, 'The content of the voting option ranked first by the number of voting addresses.', []],
|
|
260
260
|
[MODULES.vote, 'Top1 Counts by Addresses', 1120, [], ValueType.TYPE_U64, 'Number of votes for the top voting option by number of voting addresses.', []],
|
|
261
|
-
[MODULES.vote, 'Top1 Option by Votes', 1121, [], ValueType.TYPE_STRING, 'The
|
|
261
|
+
[MODULES.vote, 'Top1 Option by Votes', 1121, [], ValueType.TYPE_STRING, 'The content of the voting option ranked first by the number of votes.', []],
|
|
262
262
|
[MODULES.vote, 'Top1 Counts by Votes', 1122, [], ValueType.TYPE_U64, 'Number of votes for the top voting option by number of votes.', []],
|
|
263
|
-
|
|
263
|
+
[MODULES.vote, 'Voted Time by Address', 1113, [ValueType.TYPE_ADDRESS], ValueType.TYPE_U64, 'The time of whether an address has been voted on.', ['adddress']],
|
|
264
|
+
|
|
264
265
|
[MODULES.payment, 'Sender', 1200, [], ValueType.TYPE_ADDRESS, 'Payment originator address.', []],
|
|
265
266
|
[MODULES.payment, 'Total Amount', 1201, [], ValueType.TYPE_U64, "Payment amount.", []],
|
|
266
267
|
[MODULES.payment, 'Tips', 1202, [], ValueType.TYPE_STRING, 'Payment remarks.', ['address']],
|
package/src/index.ts
CHANGED
package/src/machine.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Transaction as TransactionBlock, TransactionObjectArgument, type TransactionResult } from '@mysten/sui/transactions';
|
|
2
2
|
import { Protocol, FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject, MachineAddress, GuardObject, TxbObject} from './protocol';
|
|
3
3
|
import { IsValidInt, Bcs, array_unique, IsValidArray, IsValidAddress, IsValidName, IsValidName_AllowEmpty,
|
|
4
|
-
IsValidEndpoint, IsValidDesription,
|
|
5
|
-
IsValidUintLarge,
|
|
6
|
-
IsValidU64} from './utils'
|
|
4
|
+
IsValidEndpoint, IsValidDesription, IsValidU64 } from './utils'
|
|
7
5
|
import { Permission, PermissionIndexType } from './permission';
|
|
8
6
|
import { Errors, ERROR} from './exception'
|
|
9
7
|
import { ValueType } from './protocol';
|
package/src/permission.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, Protocol} from './protocol';
|
|
2
|
-
import { array_unique, IsValidAddress, IsValidArray, IsValidDesription,
|
|
2
|
+
import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, Bcs, IsValidName, IsValidU64} from './utils';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
|
-
import { ValueType } from './protocol';
|
|
5
4
|
import { BCS } from '@mysten/bcs';
|
|
6
5
|
import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
7
6
|
|
|
@@ -565,7 +564,7 @@ export class Permission {
|
|
|
565
564
|
static BUSINESS_PERMISSIONS_START = PermissionIndex.user_defined_start;
|
|
566
565
|
|
|
567
566
|
static IsValidUserDefinedIndex = (index:number) => {
|
|
568
|
-
return index >= Permission.BUSINESS_PERMISSIONS_START &&
|
|
567
|
+
return index >= Permission.BUSINESS_PERMISSIONS_START && IsValidU64(index)
|
|
569
568
|
}
|
|
570
569
|
|
|
571
570
|
static IsValidPermissionIndex = (index:PermissionIndexType) : boolean => {
|
package/src/protocol.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { SuiClient, SuiObjectResponse, SuiObjectDataOptions, SuiTransactionBlock
|
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
4
|
import { toHEX, fromHEX, BcsReader } from '@mysten/bcs';
|
|
5
5
|
import { Transaction as TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui/transactions';
|
|
6
|
-
import { capitalize, IsValidAddress, IsValidArray, IsValidU128, IsValidU64, IsValidU8
|
|
6
|
+
import { capitalize, IsValidAddress, IsValidArray, IsValidU128, IsValidU256, IsValidU64, IsValidU8 } from './utils'
|
|
7
7
|
import { GuardConstant } from './guard';
|
|
8
8
|
import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils'
|
|
9
9
|
|
|
@@ -190,7 +190,7 @@ export const SER_VALUE: ValueTypeString[] = [
|
|
|
190
190
|
{type: ValueType.TYPE_VEC_STRING, name: '[string]', description:'ascii string array. eg:["abc", "hi"]'},
|
|
191
191
|
{type: ValueType.TYPE_STRING, name: 'string', description:'eg:"wowok"', },
|
|
192
192
|
{type: ValueType.TYPE_OPTION_STRING, name: 'option', description:'option of string. eg:none or string value'},
|
|
193
|
-
{type: ValueType.TYPE_U256, name: 'number', description:'unsigned-256 number. eg:12345678901233', validator:
|
|
193
|
+
{type: ValueType.TYPE_U256, name: 'number', description:'unsigned-256 number. eg:12345678901233', validator:IsValidU256},
|
|
194
194
|
]
|
|
195
195
|
|
|
196
196
|
//export type ConstantType = ValueType | ContextType.TYPE_WITNESS_ID;
|
|
@@ -211,10 +211,10 @@ const TESTNET = {
|
|
|
211
211
|
}
|
|
212
212
|
*/
|
|
213
213
|
const TESTNET = {
|
|
214
|
-
package: "
|
|
215
|
-
wowok_object: '
|
|
216
|
-
entity_object: '
|
|
217
|
-
treasury_cap:'
|
|
214
|
+
package: "0x0a0a86d4d364ba566d5392cd8ba7d980f4d65fc1e1586e5b2e49b0ecd8dfeae4",
|
|
215
|
+
wowok_object: '0x8e5424a7899597dc75b456d597dd0a741296c1363282a72d52421b1c85d2460e',
|
|
216
|
+
entity_object: '0xd88aaf554750437ab4148acca27e0ba51cff97c13882722a4a89289e57a7b8fa',
|
|
217
|
+
treasury_cap:'0x01079f2baa2c320afc52e0f2680167c44bbaad9a6a21514bfd2e56356028be9d',
|
|
218
218
|
}
|
|
219
219
|
const MAINNET = {
|
|
220
220
|
package: "",
|
package/src/reward.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TransactionArgument, Transaction as TransactionBlock, type TransactionResult, } from '@mysten/sui/transactions';
|
|
2
2
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
|
|
3
|
-
import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription,
|
|
3
|
+
import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidU64} from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
5
|
|
|
6
6
|
export type CoinReward = TransactionResult;
|
|
@@ -39,7 +39,7 @@ export class Reward {
|
|
|
39
39
|
if (!IsValidDesription(description)) {
|
|
40
40
|
ERROR(Errors.IsValidDesription)
|
|
41
41
|
}
|
|
42
|
-
if (!
|
|
42
|
+
if (!IsValidU64(time)) {
|
|
43
43
|
ERROR(Errors.IsValidUint, 'time')
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -96,7 +96,7 @@ export class Reward {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
expand_time(ms_expand:boolean, time:number, passport?:PassportObject) {
|
|
99
|
-
if (!
|
|
99
|
+
if (!IsValidU64(time)) {
|
|
100
100
|
ERROR(Errors.IsValidUint, 'minutes_expand')
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -117,20 +117,20 @@ export class Reward {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
add_guard(
|
|
121
|
-
if (
|
|
120
|
+
add_guard(guards:RewardGuardPortions[], passport?:PassportObject) {
|
|
121
|
+
if (guards.length === 0) return;
|
|
122
122
|
|
|
123
123
|
let bValid = true;
|
|
124
|
-
|
|
125
|
-
if (!
|
|
124
|
+
guards.forEach((v) => {
|
|
125
|
+
if (!IsValidU64(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
|
|
126
126
|
if (!Protocol.IsValidObjects([v.guard])) bValid = false;
|
|
127
127
|
})
|
|
128
128
|
if (!bValid) {
|
|
129
|
-
ERROR(Errors.InvalidParam, '
|
|
129
|
+
ERROR(Errors.InvalidParam, 'guards')
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
if (passport) {
|
|
133
|
-
|
|
133
|
+
guards.forEach((guard) =>
|
|
134
134
|
this.txb.moveCall({
|
|
135
135
|
target:Protocol.Instance().RewardFn('guard_add_with_passport') as FnCallType,
|
|
136
136
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
@@ -140,7 +140,7 @@ export class Reward {
|
|
|
140
140
|
})
|
|
141
141
|
)
|
|
142
142
|
} else {
|
|
143
|
-
|
|
143
|
+
guards.forEach((guard) =>
|
|
144
144
|
this.txb.moveCall({
|
|
145
145
|
target:Protocol.Instance().RewardFn('guard_add') as FnCallType,
|
|
146
146
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard.guard),
|
package/src/treasury.ts
CHANGED
|
@@ -86,7 +86,7 @@ export class Treasury {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
deposit(coin:CoinObject, tips:string, for_object?:string, index?:
|
|
89
|
+
deposit(coin:CoinObject, tips:string, for_object?:string, index?:bigint, from_object?:string, passport?:PassportObject) :TxbObject {
|
|
90
90
|
if (!Protocol.IsValidObjects([coin])) {
|
|
91
91
|
ERROR(Errors.IsValidObjects, 'deposit.coin')
|
|
92
92
|
}
|
|
@@ -99,7 +99,7 @@ export class Treasury {
|
|
|
99
99
|
if (from_object && !IsValidAddress(from_object)) {
|
|
100
100
|
ERROR(Errors.IsValidAddress, 'deposit.from_object')
|
|
101
101
|
}
|
|
102
|
-
if (index !== undefined && IsValidU64(index)) {
|
|
102
|
+
if (index !== undefined && !IsValidU64(index)) {
|
|
103
103
|
ERROR(Errors.InvalidParam, 'deposit.index')
|
|
104
104
|
}
|
|
105
105
|
const for_obj = this.txb.pure.option('address', for_object ?? undefined);
|
|
@@ -116,7 +116,7 @@ export class Treasury {
|
|
|
116
116
|
})
|
|
117
117
|
} else {
|
|
118
118
|
return this.txb.moveCall({
|
|
119
|
-
target:Protocol.Instance().TreasuryFn('
|
|
119
|
+
target:Protocol.Instance().TreasuryFn('deposit') as FnCallType,
|
|
120
120
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, coin),
|
|
121
121
|
this.txb.pure.string(tips), for_obj, idx, from_obj, this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
122
122
|
typeArguments:[this.token_type],
|
|
@@ -137,7 +137,7 @@ export class Treasury {
|
|
|
137
137
|
if (from_object && !IsValidAddress(from_object)) {
|
|
138
138
|
ERROR(Errors.IsValidAddress, 'free_deposit.from_object')
|
|
139
139
|
}
|
|
140
|
-
if (index !== undefined && IsValidU64(index)) {
|
|
140
|
+
if (index !== undefined && !IsValidU64(index)) {
|
|
141
141
|
ERROR(Errors.InvalidParam, 'free_deposit.index')
|
|
142
142
|
}
|
|
143
143
|
const for_obj = this.txb.pure.option('address', for_object ?? undefined);
|
|
@@ -153,7 +153,7 @@ export class Treasury {
|
|
|
153
153
|
})
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
withdraw(amount:
|
|
156
|
+
withdraw(amount:bigint, tips:string, for_object?:string, index?:bigint, to_object?:string, passport?:PassportObject) : CoinObject {
|
|
157
157
|
if (!IsValidU64(amount)) {
|
|
158
158
|
ERROR(Errors.IsValidObjects, 'withdraw.amount')
|
|
159
159
|
}
|
|
@@ -166,7 +166,7 @@ export class Treasury {
|
|
|
166
166
|
if (to_object && !IsValidAddress(to_object)) {
|
|
167
167
|
ERROR(Errors.IsValidAddress, 'withdraw.to_object')
|
|
168
168
|
}
|
|
169
|
-
if (index !== undefined && IsValidU64(index)) {
|
|
169
|
+
if (index !== undefined && !IsValidU64(index)) {
|
|
170
170
|
ERROR(Errors.InvalidParam, 'withdraw.index')
|
|
171
171
|
}
|
|
172
172
|
const for_obj = this.txb.pure.option('address', for_object ?? undefined);
|
package/src/utils.ts
CHANGED
|
@@ -399,20 +399,17 @@ export const IsValidBigint = (value:string | number | undefined | bigint, max:bi
|
|
|
399
399
|
}; return false
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
export const
|
|
403
|
-
return IsValidBigint(value,
|
|
402
|
+
export const IsValidU8 = (value:string | number | undefined | bigint, min=0) : boolean => {
|
|
403
|
+
return IsValidBigint(value, MAX_U8, BigInt(min))
|
|
404
404
|
}
|
|
405
|
-
export const
|
|
406
|
-
return IsValidBigint(value,
|
|
405
|
+
export const IsValidU64 = (value:string | number | undefined | bigint, min=0) : boolean => {
|
|
406
|
+
return IsValidBigint(value, MAX_U64, BigInt(min))
|
|
407
407
|
}
|
|
408
|
-
export const
|
|
409
|
-
return IsValidBigint(value,
|
|
408
|
+
export const IsValidU128 = (value:string | number | undefined | bigint, min=0) : boolean => {
|
|
409
|
+
return IsValidBigint(value, MAX_U128, BigInt(min))
|
|
410
410
|
}
|
|
411
|
-
export const
|
|
412
|
-
return IsValidBigint(value,
|
|
413
|
-
}
|
|
414
|
-
export const IsValidU256 = (value:string | number | undefined | bigint) : boolean => {
|
|
415
|
-
return IsValidBigint(value, MAX_U256, BigInt(0))
|
|
411
|
+
export const IsValidU256 = (value:string | number | undefined | bigint, min=0) : boolean => {
|
|
412
|
+
return IsValidBigint(value, MAX_U256, BigInt(min))
|
|
416
413
|
}
|
|
417
414
|
|
|
418
415
|
export const IsValidTokenType = (argType: string) : boolean => {
|
package/src/vote.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { FnCallType, PassportObject, PermissionObject, GuardObject, VoteAddress, Protocol, TxbObject} from './protocol';
|
|
2
|
-
import { IsValidDesription,
|
|
2
|
+
import { IsValidDesription, IsValidAddress, Bcs, array_unique, IsValidArray, IsValidName, IsValidU64, IsValidU256, IsValidU8 } from './utils';
|
|
3
3
|
import { ERROR, Errors } from './exception';
|
|
4
4
|
import { ValueType } from './protocol';
|
|
5
5
|
import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
7
|
export type VoteOption = {
|
|
10
8
|
name:string;
|
|
11
9
|
reference_address?:string;
|
|
12
10
|
}
|
|
13
11
|
|
|
12
|
+
export type QueryVotedResult = {
|
|
13
|
+
who: string;
|
|
14
|
+
voted: number[]
|
|
15
|
+
weight: bigint;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type VoteGuardWeight = {
|
|
20
|
+
guard: GuardObject;
|
|
21
|
+
weight: bigint;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type OnQueryVoted = (result: QueryVotedResult) => void;
|
|
14
25
|
export class Vote {
|
|
15
26
|
protected permission;
|
|
16
27
|
protected object : TxbObject;
|
|
@@ -35,10 +46,10 @@ export class Vote {
|
|
|
35
46
|
if (!IsValidDesription(description)) {
|
|
36
47
|
ERROR(Errors.IsValidDesription)
|
|
37
48
|
}
|
|
38
|
-
if (!
|
|
49
|
+
if (!IsValidU64(time)) {
|
|
39
50
|
ERROR(Errors.IsValidUint, 'time')
|
|
40
51
|
}
|
|
41
|
-
if (max_choice_count && !
|
|
52
|
+
if (max_choice_count && !IsValidU64(max_choice_count)) {
|
|
42
53
|
ERROR(Errors.IsValidUint, 'max_choice_count')
|
|
43
54
|
}
|
|
44
55
|
if (max_choice_count && max_choice_count > Vote.MAX_CHOICE_COUNT) {
|
|
@@ -120,25 +131,32 @@ export class Vote {
|
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
}
|
|
123
|
-
add_guard(
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
add_guard(guards:VoteGuardWeight[], passport?:PassportObject) {
|
|
135
|
+
if (guards.length === 0) return;
|
|
136
|
+
let bValid = true;
|
|
137
|
+
guards.forEach((v) => {
|
|
138
|
+
if (!IsValidU64(v.weight) || v.weight === BigInt(0)) bValid = false;
|
|
139
|
+
if (!Protocol.IsValidObjects([v.guard])) bValid = false;
|
|
140
|
+
})
|
|
141
|
+
if (!bValid) {
|
|
142
|
+
ERROR(Errors.InvalidParam, 'add_guard.gurads')
|
|
129
143
|
}
|
|
130
144
|
|
|
131
145
|
if (passport) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.txb.
|
|
146
|
+
guards.forEach((guard) => {
|
|
147
|
+
this.txb.moveCall({
|
|
148
|
+
target:Protocol.Instance().VoteFn('guard_add_with_passport') as FnCallType,
|
|
149
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard.guard),
|
|
150
|
+
this.txb.pure.u64(guard.weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
151
|
+
})
|
|
136
152
|
})
|
|
137
153
|
} else {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.txb.
|
|
154
|
+
guards.forEach((guard) => {
|
|
155
|
+
this.txb.moveCall({
|
|
156
|
+
target:Protocol.Instance().VoteFn('guard_add') as FnCallType,
|
|
157
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard.guard),
|
|
158
|
+
this.txb.pure.u64(guard.weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
159
|
+
})
|
|
142
160
|
})
|
|
143
161
|
}
|
|
144
162
|
}
|
|
@@ -186,7 +204,7 @@ export class Vote {
|
|
|
186
204
|
let bValid = true;
|
|
187
205
|
options.forEach((v) => {
|
|
188
206
|
if (!IsValidName(v.name)) bValid = false;
|
|
189
|
-
if (v?.reference_address && IsValidAddress(v.reference_address)) bValid = false;
|
|
207
|
+
if (v?.reference_address && !IsValidAddress(v.reference_address)) bValid = false;
|
|
190
208
|
})
|
|
191
209
|
if (!bValid) {
|
|
192
210
|
ERROR(Errors.InvalidParam, 'options')
|
|
@@ -214,8 +232,8 @@ export class Vote {
|
|
|
214
232
|
if (!removeall && options.length===0) {
|
|
215
233
|
return
|
|
216
234
|
}
|
|
217
|
-
if (
|
|
218
|
-
ERROR(Errors.IsValidArray, 'remove_option')
|
|
235
|
+
if (!IsValidArray(options, IsValidName)) {
|
|
236
|
+
ERROR(Errors.IsValidArray, 'remove_option.options')
|
|
219
237
|
}
|
|
220
238
|
|
|
221
239
|
if (passport) {
|
|
@@ -249,7 +267,7 @@ export class Vote {
|
|
|
249
267
|
}
|
|
250
268
|
}
|
|
251
269
|
set_max_choice_count(max_choice_count:number, passport?:PassportObject) {
|
|
252
|
-
if (!
|
|
270
|
+
if (!IsValidU64(max_choice_count) || max_choice_count > Vote.MAX_CHOICE_COUNT) {
|
|
253
271
|
ERROR(Errors.InvalidParam, 'max_choice_count')
|
|
254
272
|
}
|
|
255
273
|
|
|
@@ -297,7 +315,7 @@ export class Vote {
|
|
|
297
315
|
}
|
|
298
316
|
|
|
299
317
|
expand_deadline(ms_expand:boolean, time:number, passport?:PassportObject) {
|
|
300
|
-
if (!
|
|
318
|
+
if (!IsValidU64(time)) {
|
|
301
319
|
ERROR(Errors.IsValidUint, 'time')
|
|
302
320
|
}
|
|
303
321
|
|
|
@@ -319,38 +337,57 @@ export class Vote {
|
|
|
319
337
|
lock_guard(passport?:PassportObject) {
|
|
320
338
|
if (passport) {
|
|
321
339
|
this.txb.moveCall({
|
|
322
|
-
target:Protocol.Instance().VoteFn('
|
|
340
|
+
target:Protocol.Instance().VoteFn('guard_locked_with_passport') as FnCallType,
|
|
323
341
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
324
342
|
})
|
|
325
343
|
} else {
|
|
326
344
|
this.txb.moveCall({
|
|
327
|
-
target:Protocol.Instance().VoteFn('
|
|
345
|
+
target:Protocol.Instance().VoteFn('guard_locked') as FnCallType,
|
|
328
346
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
329
347
|
})
|
|
330
348
|
}
|
|
331
349
|
}
|
|
332
350
|
|
|
333
|
-
agree(options:
|
|
351
|
+
agree(options:number[], passport?:PassportObject) {
|
|
334
352
|
if (options.length === 0) return;
|
|
335
353
|
if (options.length > Vote.MAX_CHOICE_COUNT) {
|
|
336
|
-
ERROR(Errors.InvalidParam, 'agree')
|
|
354
|
+
ERROR(Errors.InvalidParam, 'agree.options')
|
|
355
|
+
}
|
|
356
|
+
if (!IsValidArray(options, (v:any) => {
|
|
357
|
+
return IsValidU8(v) && v <= Vote.MAX_AGREES_COUNT;
|
|
358
|
+
})) {
|
|
359
|
+
ERROR(Errors.IsValidArray, 'agree.options')
|
|
337
360
|
}
|
|
338
361
|
|
|
362
|
+
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
363
|
+
|
|
339
364
|
if (passport) {
|
|
340
365
|
this.txb.moveCall({
|
|
341
|
-
target:Protocol.Instance().VoteFn('
|
|
366
|
+
target:Protocol.Instance().VoteFn('vote_with_passport') as FnCallType,
|
|
342
367
|
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
343
|
-
this.txb.pure.vector('
|
|
368
|
+
this.txb.pure.vector('u8', array_unique(options)), this.txb.object(clock)]
|
|
344
369
|
})
|
|
345
370
|
} else {
|
|
346
371
|
this.txb.moveCall({
|
|
347
|
-
target:Protocol.Instance().VoteFn('
|
|
372
|
+
target:Protocol.Instance().VoteFn('vote') as FnCallType,
|
|
348
373
|
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
349
|
-
this.txb.pure.vector('
|
|
374
|
+
this.txb.pure.vector('u8', array_unique(options)), this.txb.object(clock)]
|
|
350
375
|
})
|
|
351
376
|
}
|
|
352
377
|
}
|
|
378
|
+
QueryVoted(address_queried:string, event:OnQueryVoted, sender?:string) {
|
|
379
|
+
Protocol.Client().devInspectTransactionBlock({sender:sender ?? address_queried, transactionBlock:this.txb}).then((res) => {
|
|
380
|
+
if (res.results && res.results[0].returnValues && res.results[0].returnValues.length !== 3 ) {
|
|
381
|
+
event({who:address_queried, error:'not match', voted:[], weight:BigInt(0)});
|
|
382
|
+
return
|
|
383
|
+
}
|
|
384
|
+
console.log((res.results as any)[0].returnValues);
|
|
353
385
|
|
|
386
|
+
}).catch((e) => {
|
|
387
|
+
console.log(e);
|
|
388
|
+
event({who:address_queried, error:'error', weight:BigInt(0), voted:[]});
|
|
389
|
+
})
|
|
390
|
+
}
|
|
354
391
|
change_permission(new_permission:PermissionObject) {
|
|
355
392
|
if (!Protocol.IsValidObjects([new_permission])) {
|
|
356
393
|
ERROR(Errors.IsValidObjects)
|
|
@@ -364,5 +401,6 @@ export class Vote {
|
|
|
364
401
|
}
|
|
365
402
|
|
|
366
403
|
static MAX_AGREES_COUNT = 100;
|
|
367
|
-
static MAX_CHOICE_COUNT = 100;
|
|
404
|
+
static MAX_CHOICE_COUNT = 100;
|
|
405
|
+
static MAX_GUARD_COUNT = 16;
|
|
368
406
|
}
|