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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.4.22",
3
+ "version": "1.4.25",
4
4
  "description": "Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
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, IsValidUintLarge, IsValidAddress, IsValidArgType, } from './utils'
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 (!IsValidUintLarge(time)) {
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 (!IsValidUintLarge(time)) {
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 name']],
254
- [MODULES.vote, 'Has Object of Option', 1114, [ValueType.TYPE_STRING], ValueType.TYPE_BOOL, 'Whether a voting option refers to an object?', ['option name']],
255
- [MODULES.vote, 'Option Object', 1115, [ValueType.TYPE_STRING], ValueType.TYPE_ADDRESS, 'The object referenced by a voting option.', ['option name']],
256
- [MODULES.vote, 'Option Counts', 1116, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of votes for the voting option.', ['option name']],
257
- [MODULES.vote, 'Option Votes', 1117, [ValueType.TYPE_STRING], ValueType.TYPE_U64, 'The number of voted addresses for the voting option.', ['option name']],
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 name of the voting option ranked first by the number of voting addresses.', []],
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 name of the voting option ranked first by the number of votes.', []],
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
@@ -13,4 +13,5 @@ export * from './service'
13
13
  export * from './graphql'
14
14
  export * from './entity'
15
15
  export * from './wowok'
16
- export * from './resource'
16
+ export * from './resource'
17
+ export * from './treasury'
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, IsValidUintLarge, Bcs, IsValidName} from './utils';
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 && IsValidUintLarge(index)
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, IsValidUintLarge } from './utils'
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:IsValidUintLarge},
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: "0xf108d64c8143ec040da0d5538e834a67f0a9c661f92011195b60f51b3bc33a46",
215
- wowok_object: '0xc4fc2a42a5fbcfc68b3d8ac079e4d5a07f637c541e0183446a9da655965cda5e',
216
- entity_object: '0x8bbab9023092dc89c3c60c766b204c0dfbe3da46a2de486d8ab92ba91a4c905f',
217
- treasury_cap:'0x07e7b3c355b63bade82c1e0e2653e655a1b20da6cc531db5707ad1292fd418e4',
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, IsValidUintLarge, } from './utils';
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 (!IsValidUintLarge(time)) {
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 (!IsValidUintLarge(time)) {
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(gurads:RewardGuardPortions[], passport?:PassportObject) {
121
- if (gurads.length === 0) return;
120
+ add_guard(guards:RewardGuardPortions[], passport?:PassportObject) {
121
+ if (guards.length === 0) return;
122
122
 
123
123
  let bValid = true;
124
- gurads.forEach((v) => {
125
- if (!IsValidUintLarge(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
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, 'gurads')
129
+ ERROR(Errors.InvalidParam, 'guards')
130
130
  }
131
131
 
132
132
  if (passport) {
133
- gurads.forEach((guard) =>
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
- gurads.forEach((guard) =>
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?:number, from_object?:string, passport?:PassportObject) :TxbObject {
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('deposit_with_passport') as FnCallType,
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:number, tips:string, for_object?:string, index?:number, to_object?:string, passport?:PassportObject) : CoinObject {
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 IsValidUintLarge = (value:string | number | undefined | bigint) : boolean => {
403
- return IsValidBigint(value, MAX_U64, BigInt(0))
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 IsValidU8 = (value:string | number | undefined | bigint) : boolean => {
406
- return IsValidBigint(value, MAX_U8, BigInt(0))
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 IsValidU64 = (value:string | number | undefined | bigint) : boolean => {
409
- return IsValidBigint(value, MAX_U64, BigInt(0))
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 IsValidU128 = (value:string | number | undefined | bigint) : boolean => {
412
- return IsValidBigint(value, MAX_U128, BigInt(0))
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, IsValidUintLarge, IsValidAddress, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
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 (!IsValidUintLarge(time)) {
49
+ if (!IsValidU64(time)) {
39
50
  ERROR(Errors.IsValidUint, 'time')
40
51
  }
41
- if (max_choice_count && !IsValidUintLarge(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(guard:GuardObject, weight:number, passport?:PassportObject) {
124
- if (!Protocol.IsValidObjects([guard])) {
125
- ERROR(Errors.IsValidObjects, 'add_guard')
126
- }
127
- if (!IsValidUintLarge(weight)) {
128
- ERROR(Errors.IsValidUint, 'add_guard')
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
- this.txb.moveCall({
133
- target:Protocol.Instance().VoteFn('guard_add_with_passport') as FnCallType,
134
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
135
- this.txb.pure.u64(weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
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
- this.txb.moveCall({
139
- target:Protocol.Instance().VoteFn('guard_add') as FnCallType,
140
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
141
- this.txb.pure.u64(weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
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 (options && !IsValidArray(options, IsValidAddress)) {
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 (!IsValidUintLarge(max_choice_count) || max_choice_count > Vote.MAX_CHOICE_COUNT) {
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 (!IsValidUintLarge(time)) {
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('guard_lock_with_passport') as FnCallType,
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('guard_lock') as FnCallType,
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:string[], passport?:PassportObject) {
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('with_passport') as FnCallType,
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('string', array_unique(options))]
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('this.object') as FnCallType,
372
+ target:Protocol.Instance().VoteFn('vote') as FnCallType,
348
373
  arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
349
- this.txb.pure.vector('string', array_unique(options))]
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
  }