wowok 1.5.50 → 1.5.52

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/README.md CHANGED
@@ -12,8 +12,9 @@ X: [https://x.com/Wowok_Ai](https://x.com/Wowok_Ai)
12
12
  ### Installation
13
13
 
14
14
  ```
15
- $ npm i wowok
15
+ $ npm i wowok@latest
16
16
  ```
17
+ The protocol address may change due to protocol upgrade. Please update the SDK to the latest version.
17
18
 
18
19
  ### Examples
19
20
  #### [An airdrop collection system for different behaviors, allowing three collection mechanisms:](https://github.com/wowok-ai/sdk-examples/tree/main/airdrop)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wowok",
3
- "version": "1.5.50",
3
+ "version": "1.5.52",
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
- import { FnCallType, Protocol, PassportObject, PermissionObject, GuardObject, DemandAddress, TxbObject } from './protocol';
3
- import { IsValidDesription, IsValidAddress, IsValidArgType, IsValidU64, parseObjectType } from './utils'
2
+ import { FnCallType, Protocol, PassportObject, PermissionObject, GuardObject, DemandAddress, TxbObject, ServiceObject } from './protocol';
3
+ import { IsValidDesription, IsValidAddress, IsValidArgType, IsValidU64, parseObjectType, IsValidU8 } from './utils'
4
4
  import { Errors, ERROR} from './exception'
5
5
 
6
6
  export class Demand {
@@ -107,16 +107,20 @@ export class Demand {
107
107
  }
108
108
  }
109
109
 
110
- set_guard(guard?:GuardObject, passport?:PassportObject) {
110
+ set_guard(guard?:GuardObject, service_identifier?:number, passport?:PassportObject) {
111
111
  if (guard && !Protocol.IsValidObjects([guard])) {
112
112
  ERROR(Errors.IsValidObjects, 'guard');
113
113
  }
114
-
114
+ if (service_identifier !== undefined && !IsValidU8(service_identifier)) {
115
+ ERROR(Errors.InvalidParam, 'set_guard.service_identifier');
116
+ }
117
+ let id = this.txb.pure.option('u8', service_identifier !== undefined ? service_identifier : undefined);
118
+
115
119
  if (passport) {
116
120
  if (guard) {
117
121
  this.txb.moveCall({
118
122
  target:Protocol.Instance().DemandFn('guard_set_with_passport') as FnCallType,
119
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
123
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard), id,
120
124
  Protocol.TXB_OBJECT(this.txb, this.permission)],
121
125
  typeArguments:[this.bounty_type],
122
126
  })
@@ -131,7 +135,7 @@ export class Demand {
131
135
  if (guard) {
132
136
  this.txb.moveCall({
133
137
  target:Protocol.Instance().DemandFn('guard_set') as FnCallType,
134
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
138
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard), id,
135
139
  Protocol.TXB_OBJECT(this.txb, this.permission)],
136
140
  typeArguments:[this.bounty_type],
137
141
  })
@@ -202,31 +206,48 @@ export class Demand {
202
206
  })
203
207
  }
204
208
 
205
- present(service_address: string, service_pay_type:string, tips:string, passport?:PassportObject) {
209
+ present(service: ServiceObject | number, service_pay_type:string, tips:string, passport?:PassportObject) {
206
210
  if (!IsValidDesription(tips)) {
207
- ERROR(Errors.IsValidDesription, 'tips')
208
- }
209
- if (!IsValidAddress(service_address)) {
210
- ERROR(Errors.IsValidAddress, 'service_address')
211
+ ERROR(Errors.IsValidDesription, 'present.tips')
211
212
  }
212
- if (!IsValidArgType(service_pay_type)) {
213
+ if (service_pay_type && !IsValidArgType(service_pay_type)) {
213
214
  ERROR(Errors.IsValidArgType, 'service_pay_type')
214
215
  }
215
-
216
+ if (typeof(service) === 'number') {
217
+ if (!IsValidU8(service) || !passport) {
218
+ ERROR(Errors.IsValidU8, 'present.service or present.passport')
219
+ }
220
+ } else {
221
+ if (!Protocol.IsValidObjects([service])) {
222
+ ERROR(Errors.IsValidObjects, 'present.service')
223
+ }
224
+ }
225
+
216
226
  if (passport) {
217
- this.txb.moveCall({
218
- target:Protocol.Instance().DemandFn('present_with_passport') as FnCallType,
219
- arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, service_address),
220
- this.txb.pure.string(tips)],
221
- typeArguments:[this.bounty_type, service_pay_type],
222
- })
227
+ if (typeof(service) === 'number') {
228
+ this.txb.moveCall({
229
+ target:Protocol.Instance().DemandFn('present_with_passport2') as FnCallType,
230
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(tips)],
231
+ typeArguments:[this.bounty_type],
232
+ })
233
+ } else {
234
+ this.txb.moveCall({
235
+ target:Protocol.Instance().DemandFn('present_with_passport') as FnCallType,
236
+ arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, service),
237
+ this.txb.pure.string(tips)],
238
+ typeArguments:[this.bounty_type, service_pay_type],
239
+ })
240
+ }
241
+
223
242
  } else {
224
- this.txb.moveCall({
225
- target:Protocol.Instance().DemandFn('present') as FnCallType,
226
- arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, service_address),
227
- this.txb.pure.string(tips)],
228
- typeArguments:[this.bounty_type, service_pay_type],
229
- })
243
+ if (typeof(service) !== 'number') {
244
+ this.txb.moveCall({
245
+ target:Protocol.Instance().DemandFn('present') as FnCallType,
246
+ arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, service),
247
+ this.txb.pure.string(tips)],
248
+ typeArguments:[this.bounty_type, service_pay_type],
249
+ })
250
+ }
230
251
  }
231
252
  }
232
253
  change_permission(new_permission:PermissionObject) {
package/src/exception.ts CHANGED
@@ -10,6 +10,7 @@ export enum Errors {
10
10
  IsValidUint = 'invalid uint',
11
11
  IsValidInt = 'invalid int',
12
12
  IsValidU64 = 'invalid u64',
13
+ IsValidU8 = 'invalid u8',
13
14
  IsValidPercent = 'invalid percent',
14
15
  IsValidArray = 'invalid array',
15
16
  IsValidObjects = 'invalid objects',
package/src/guard.ts CHANGED
@@ -21,6 +21,14 @@ export interface Guard_Options {
21
21
  group?: string;
22
22
  }
23
23
 
24
+ export interface GuardAnswer {
25
+ txb: TransactionBlock;
26
+ err?: string;
27
+ identifiers: number[];
28
+ }
29
+
30
+ export type OnQueryAnswer = (answer: GuardAnswer) => void;
31
+
24
32
  export class Guard {
25
33
  static MAX_INPUT_LENGTH = 10240;
26
34
  // static MAX_PAYLOADS_LENGTH = 4096;
@@ -104,6 +112,27 @@ export class Guard {
104
112
  arguments: []
105
113
  });
106
114
  }
115
+
116
+ static QueryAddressIdentifiers(guard:GuardObject, onQueryAnswer:OnQueryAnswer, sender:string) {
117
+ const txb = new TransactionBlock();
118
+ txb.moveCall({
119
+ target: Protocol.Instance().GuardFn('query_address_identifiers') as FnCallType,
120
+ arguments: [txb.object(guard)]
121
+ })
122
+
123
+ Protocol.Client().devInspectTransactionBlock({sender:sender, transactionBlock:txb}).then((res) => {
124
+ if (res.results && res.results[0]?.returnValues && res.results[0]?.returnValues?.length !== 1 ) {
125
+ onQueryAnswer({err:'not match', txb:txb, identifiers:[]});
126
+ return
127
+ }
128
+ const identifiers = Bcs.getInstance().de('vector<u8>', Uint8Array.from((res.results as any)[0].returnValues[0][0]));
129
+ onQueryAnswer({identifiers:identifiers, txb:txb});
130
+ }).catch((e) => {
131
+ console.log(e);
132
+ onQueryAnswer({err:e, txb:txb, identifiers:[]});
133
+ })
134
+ }
135
+
107
136
  static QUERIES:any[] = [
108
137
  // module, 'name', 'id', [input], output
109
138
  [MODULES.permission, 'Owner', 1, [], ValueType.TYPE_ADDRESS, "Owner's address."],
package/src/protocol.ts CHANGED
@@ -221,14 +221,14 @@ const TESTNET = {
221
221
  }
222
222
  */
223
223
  const TESTNET = {
224
- wowok: "0x03ff6124da870ac002831580572339292d12eed6d41bc1e15c20a63b725e4d13",
225
- wowok_origin:'0x03ff6124da870ac002831580572339292d12eed6d41bc1e15c20a63b725e4d13' ,
226
- base: '0x697414cbf771c0cb0ab4e2ec335fc310a19936b628cfdb0d8d4190042ee998f9',
227
- base_origin: '0x697414cbf771c0cb0ab4e2ec335fc310a19936b628cfdb0d8d4190042ee998f9',
228
-
229
- wowok_object: '0x05929fea08ee82f0711ae25590dcd58182af81ff34cc275eb1caca4f7c7041f5',
230
- entity_object: '0x42e6da560324e891e8d695464da3ccc9f1fc0d33bc3b962cb7338d8f9198a595',
231
- treasury_cap:'0x66a76f713edd26d4db2aa64343edc10e3df6cacbd66f2e5c5e5b6fbddac6e575',
224
+ wowok: "0x4cd9cecc9720f778678a8d7c4005834a99aff27bb573b15738fbbc6419e380ac",
225
+ wowok_origin:'0x4cd9cecc9720f778678a8d7c4005834a99aff27bb573b15738fbbc6419e380ac' ,
226
+ base: '0x985dd058e7f7d6c216b8a55d0170c47c1a6db048a8045c56c6cca4ba9333684d',
227
+ base_origin: '0x985dd058e7f7d6c216b8a55d0170c47c1a6db048a8045c56c6cca4ba9333684d',
228
+
229
+ wowok_object: '0x60aab3dc3e911a5f952a97fd411531b4e1e61676cdf0f8fe10685ce15310dd31',
230
+ entity_object: '0xec60850cde84c92bad3a161f7c5db4f7b86440e1fdc819be94523a29fff67497',
231
+ treasury_cap:'0x4bf3375d58afc7b9de3335e777223b3fad16f154305c313d65ec75c2183e2df9',
232
232
  }
233
233
  const MAINNET = {
234
234
  wowok: "",
package/dist/graphql.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export declare const GRAPHQL_OBJECTS_TYPE: import("graphql/language/ast").DocumentNode;
2
- export declare const GRAPHQL_CHILD_OBJECT: import("graphql/language/ast").DocumentNode;
3
- export declare const GRAPHQL_OBJECT: import("graphql/language/ast").DocumentNode;
4
- export declare const GRAPHQL_OWNER: import("graphql/language/ast").DocumentNode;
5
- export declare const GRAPHQL_OBJECTS: import("graphql/language/ast").DocumentNode;
6
- export declare const GRAPHQL_DECIMALS: import("graphql/language/ast").DocumentNode;
7
- //# sourceMappingURL=graphql.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../src/graphql.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,6CAgB/B,CAAC;AACH,eAAO,MAAM,oBAAoB,6CAW/B,CAAC;AAEH,eAAO,MAAM,cAAc,6CAmCzB,CAAC;AAEH,eAAO,MAAM,aAAa,6CA2BxB,CAAC;AAEH,eAAO,MAAM,eAAe,6CAgB1B,CAAC;AAEH,eAAO,MAAM,gBAAgB,6CAM3B,CAAC"}
package/dist/graphql.js DELETED
@@ -1,118 +0,0 @@
1
- import { gql } from "graphql-tag";
2
- export const GRAPHQL_OBJECTS_TYPE = gql(`
3
- query objects_type_version($filter:ObjectFilter!) {
4
- objects(filter:$filter) {
5
- nodes {
6
- address
7
- version
8
- asMoveObject {
9
- contents {
10
- type {
11
- repr
12
- }
13
- }
14
- }
15
- }
16
- }
17
- }
18
- `);
19
- export const GRAPHQL_CHILD_OBJECT = gql(`
20
- query object($ObjectID:SuiAddress!) {
21
- object(address:$ObjectID) {
22
- address
23
- asMoveObject {
24
- contents {
25
- json
26
- }
27
- }
28
- }
29
- }
30
- `);
31
- export const GRAPHQL_OBJECT = gql(`
32
- query object($ObjectID:SuiAddress!) {
33
- object(address:$ObjectID) {
34
- address
35
- asMoveObject {
36
- contents {
37
- json
38
- type {
39
- repr
40
- }
41
- }
42
- }
43
- dynamicFields {
44
- pageInfo {
45
- hasNextPage
46
- endCursor
47
- }
48
- nodes {
49
- name {
50
- json
51
- }
52
- value {
53
- ... on MoveValue {
54
- json
55
- }
56
- ... on MoveObject {
57
- contents {
58
- json
59
- }
60
- }
61
- }
62
- }
63
- }
64
- }
65
- }
66
- `);
67
- export const GRAPHQL_OWNER = gql(`
68
- query owner($ObjectID:SuiAddress!) {
69
- owner (address: $ObjectID) {
70
- address
71
- dynamicFields {
72
- pageInfo {
73
- hasNextPage
74
- endCursor
75
- }
76
- nodes {
77
- name {
78
- json
79
- }
80
- value {
81
- ... on MoveValue {
82
- json
83
- }
84
- ... on MoveObject {
85
- contents {
86
- json
87
- }
88
- }
89
- }
90
- }
91
- }
92
- }
93
- }
94
- `);
95
- export const GRAPHQL_OBJECTS = gql(`
96
- query objects($filter:ObjectFilter!){
97
- objects(filter:$filter) {
98
- nodes {
99
- address
100
- asMoveObject {
101
- contents {
102
- json
103
- type {
104
- repr
105
- }
106
- }
107
- }
108
- }
109
- }
110
- }
111
- `);
112
- export const GRAPHQL_DECIMALS = gql(`
113
- query getTotalSupply($coinType: String!) {
114
- coinMetadata(coinType: $coinType) {
115
- decimals
116
- }
117
- }
118
- `);
package/dist/reward.d.ts DELETED
@@ -1,35 +0,0 @@
1
- import { type TransactionResult } from '@mysten/sui.js/transactions';
2
- import { GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject } from './protocol';
3
- export type CoinReward = TransactionResult;
4
- export type RewardGuardPortions = {
5
- guard: GuardObject;
6
- portions: number;
7
- };
8
- export declare class Reward {
9
- protected earnest_type: string;
10
- protected permission: PermissionObject;
11
- protected object: TxbObject;
12
- protected protocol: Protocol;
13
- get_earnest_type(): string;
14
- get_object(): TxbObject;
15
- private constructor();
16
- static From(protocol: Protocol, earnest_type: string, permission: PermissionObject, object: TxbObject): Reward;
17
- static New(protocol: Protocol, earnest_type: string, permission: PermissionObject, description: string, ms_expand: boolean, time: number, passport?: PassportObject): Reward;
18
- launch(): RewardAddress;
19
- destroy(): void;
20
- refund(passport?: PassportObject): void;
21
- expand_time(ms_expand: boolean, time: number, passport?: PassportObject): void;
22
- add_guard(gurads: RewardGuardPortions[], passport?: PassportObject): void;
23
- remove_guard(guards: string[], removeall?: boolean, passport?: PassportObject): void;
24
- allow_repeat_claim(allow_repeat_claim: boolean, passport?: PassportObject): void;
25
- set_description(description: string, passport?: PassportObject): void;
26
- lock_guards(passport?: PassportObject): void;
27
- claim(passport?: PassportObject): void;
28
- deposit(rewards: TransactionResult[]): void;
29
- allow_claim(bAllowClaim: boolean, passport?: PassportObject): void;
30
- change_permission(new_permission: PermissionObject): void;
31
- static parseObjectType: (chain_type: string) => string;
32
- static MAX_PORTIONS_COUNT: number;
33
- static MAX_GUARD_COUNT: number;
34
- }
35
- //# sourceMappingURL=reward.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reward.d.ts","sourceRoot":"","sources":["../src/reward.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAE5G,OAAO,EAAc,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAG,MAAM,YAAY,CAAC;AAK5H,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAC3C,MAAM,MAAM,mBAAmB,GAAG;IAC9B,KAAK,EAAC,WAAW,CAAC;IAClB,QAAQ,EAAC,MAAM,CAAC;CACnB,CAAA;AAED,qBAAa,MAAM;IACf,SAAS,CAAC,YAAY,SAAC;IACvB,SAAS,CAAC,UAAU,mBAAE;IACtB,SAAS,CAAC,MAAM,EAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,QAAQ,WAAC;IAEnB,gBAAgB;IAChB,UAAU;IACV,OAAO;IAMP,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAC,QAAQ,EAAE,YAAY,EAAC,MAAM,EAAE,UAAU,EAAC,gBAAgB,EAAE,MAAM,EAAC,SAAS,GAAI,MAAM;IAK3G,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAC,QAAQ,EAAE,YAAY,EAAC,MAAM,EAAE,UAAU,EAAC,gBAAgB,EAAE,WAAW,EAAC,MAAM,EAC9F,SAAS,EAAC,OAAO,EAAE,IAAI,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc,GAAI,MAAM;IAmCtE,MAAM,IAAI,aAAa;IASvB,OAAO;IAQP,MAAM,CAAC,QAAQ,CAAC,EAAC,cAAc;IAiB/B,WAAW,CAAC,SAAS,EAAC,OAAO,EAAE,IAAI,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAwBpE,SAAS,CAAC,MAAM,EAAC,mBAAmB,EAAE,EAAE,QAAQ,CAAC,EAAC,cAAc;IAqChE,YAAY,CAAC,MAAM,EAAC,MAAM,EAAE,EAAE,SAAS,CAAC,EAAC,OAAO,EAAE,QAAQ,CAAC,EAAC,cAAc;IA2C1E,kBAAkB,CAAC,kBAAkB,EAAC,OAAO,EAAE,QAAQ,CAAC,EAAC,cAAc;IAmBvE,eAAe,CAAC,WAAW,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAqB5D,WAAW,CAAC,QAAQ,CAAC,EAAC,cAAc;IAiBpC,KAAK,CAAC,QAAQ,CAAC,EAAC,cAAc;IAiB9B,OAAO,CAAC,OAAO,EAAC,iBAAiB,EAAE;IAanC,WAAW,CAAC,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAC,cAAc;IAkB1D,iBAAiB,CAAC,cAAc,EAAC,gBAAgB;IAajD,MAAM,CAAC,eAAe,eAAe,MAAM,KAAI,MAAM,CAUpD;IACD,MAAM,CAAC,kBAAkB,SAAO;IAChC,MAAM,CAAC,eAAe,SAAM;CAC/B"}
package/dist/reward.js DELETED
@@ -1,315 +0,0 @@
1
- import { BCS } from '@mysten/bcs';
2
- import { Protocol, } from './protocol';
3
- import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidUint, } from './utils';
4
- import { ERROR, Errors } from './exception';
5
- export class Reward {
6
- earnest_type;
7
- permission;
8
- object;
9
- protocol;
10
- get_earnest_type() { return this.earnest_type; }
11
- get_object() { return this.object; }
12
- constructor(protocol, earnest_type, permission) {
13
- this.protocol = protocol;
14
- this.earnest_type = earnest_type;
15
- this.permission = permission;
16
- this.object = '';
17
- }
18
- static From(protocol, earnest_type, permission, object) {
19
- let r = new Reward(protocol, earnest_type, permission);
20
- r.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
21
- return r;
22
- }
23
- static New(protocol, earnest_type, permission, description, ms_expand, time, passport) {
24
- if (!Protocol.IsValidObjects([permission])) {
25
- ERROR(Errors.IsValidObjects, 'permission');
26
- }
27
- if (!IsValidArgType(earnest_type)) {
28
- ERROR(Errors.IsValidArgType, 'earnest_type');
29
- }
30
- if (!IsValidDesription(description)) {
31
- ERROR(Errors.IsValidDesription);
32
- }
33
- if (!IsValidUint(time)) {
34
- ERROR(Errors.IsValidUint, 'time');
35
- }
36
- let r = new Reward(protocol, earnest_type, permission);
37
- let txb = protocol.CurrentSession();
38
- if (passport) {
39
- r.object = txb.moveCall({
40
- target: protocol.RewardFn('new_with_passport'),
41
- arguments: [passport, txb.pure(description), txb.pure(ms_expand, BCS.BOOL), txb.pure(time, BCS.U64),
42
- txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, permission)],
43
- typeArguments: [earnest_type]
44
- });
45
- }
46
- else {
47
- r.object = txb.moveCall({
48
- target: protocol.RewardFn('new'),
49
- arguments: [txb.pure(description), txb.pure(ms_expand, BCS.BOOL), txb.pure(time, BCS.U64),
50
- txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, permission)],
51
- typeArguments: [earnest_type]
52
- });
53
- }
54
- return r;
55
- }
56
- launch() {
57
- let txb = this.protocol.CurrentSession();
58
- return txb.moveCall({
59
- target: this.protocol.RewardFn('create'),
60
- arguments: [Protocol.TXB_OBJECT(txb, this.object)],
61
- typeArguments: [this.earnest_type]
62
- });
63
- }
64
- destroy() {
65
- let txb = this.protocol.CurrentSession();
66
- txb.moveCall({
67
- target: this.protocol.RewardFn('destroy'),
68
- arguments: [Protocol.TXB_OBJECT(txb, this.object)],
69
- });
70
- }
71
- refund(passport) {
72
- let txb = this.protocol.CurrentSession();
73
- if (passport) {
74
- txb.moveCall({
75
- target: this.protocol.RewardFn('refund_with_passport'),
76
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)],
77
- typeArguments: [this.earnest_type]
78
- });
79
- }
80
- else {
81
- txb.moveCall({
82
- target: this.protocol.RewardFn('refund'),
83
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)],
84
- typeArguments: [this.earnest_type]
85
- });
86
- }
87
- }
88
- expand_time(ms_expand, time, passport) {
89
- if (!IsValidUint(time)) {
90
- ERROR(Errors.IsValidUint, 'minutes_expand');
91
- }
92
- let txb = this.protocol.CurrentSession();
93
- if (passport) {
94
- txb.moveCall({
95
- target: this.protocol.RewardFn('time_expand_with_passport'),
96
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
97
- txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)],
98
- typeArguments: [this.earnest_type]
99
- });
100
- }
101
- else {
102
- txb.moveCall({
103
- target: this.protocol.RewardFn('time_expand'),
104
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
105
- txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)],
106
- typeArguments: [this.earnest_type]
107
- });
108
- }
109
- }
110
- add_guard(gurads, passport) {
111
- if (!gurads) {
112
- ERROR(Errors.InvalidParam, 'gurads');
113
- }
114
- let bValid = true;
115
- gurads.forEach((v) => {
116
- if (!IsValidUint(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT)
117
- bValid = false;
118
- if (!Protocol.IsValidObjects([v.guard]))
119
- bValid = false;
120
- });
121
- if (!bValid) {
122
- ERROR(Errors.InvalidParam, 'gurads');
123
- }
124
- let txb = this.protocol.CurrentSession();
125
- if (passport) {
126
- gurads.forEach((guard) => txb.moveCall({
127
- target: this.protocol.RewardFn('guard_add_with_passport'),
128
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
129
- Protocol.TXB_OBJECT(txb, guard.guard), txb.pure(guard.portions, BCS.U8),
130
- Protocol.TXB_OBJECT(txb, this.permission)],
131
- typeArguments: [this.earnest_type]
132
- }));
133
- }
134
- else {
135
- gurads.forEach((guard) => txb.moveCall({
136
- target: this.protocol.RewardFn('guard_add'),
137
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, guard.guard),
138
- txb.pure(guard.portions, BCS.U8), Protocol.TXB_OBJECT(txb, this.permission)],
139
- typeArguments: [this.earnest_type]
140
- }));
141
- }
142
- }
143
- remove_guard(guards, removeall, passport) {
144
- if (!removeall && !guards) {
145
- ERROR(Errors.AllInvalid, 'guards & removeall');
146
- }
147
- if (guards && !IsValidArray(guards, IsValidAddress)) {
148
- ERROR(Errors.IsValidArray, 'guards');
149
- }
150
- let txb = this.protocol.CurrentSession();
151
- if (passport) {
152
- if (removeall) {
153
- txb.moveCall({
154
- target: this.protocol.RewardFn('guard_remove_all_with_passport'),
155
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
156
- typeArguments: [this.earnest_type]
157
- });
158
- }
159
- else {
160
- txb.moveCall({
161
- target: this.protocol.RewardFn('guard_remove_with_passport'),
162
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(array_unique(guards), 'vector<address>'),
163
- Protocol.TXB_OBJECT(txb, this.permission)],
164
- typeArguments: [this.earnest_type]
165
- });
166
- }
167
- }
168
- else {
169
- if (removeall) {
170
- txb.moveCall({
171
- target: this.protocol.RewardFn('guard_remove_all'),
172
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
173
- typeArguments: [this.earnest_type]
174
- });
175
- }
176
- else {
177
- txb.moveCall({
178
- target: this.protocol.RewardFn('guard_remove'),
179
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(guards, 'vector<address>'),
180
- Protocol.TXB_OBJECT(txb, this.permission)],
181
- typeArguments: [this.earnest_type]
182
- });
183
- }
184
- }
185
- }
186
- allow_repeat_claim(allow_repeat_claim, passport) {
187
- let txb = this.protocol.CurrentSession();
188
- if (passport) {
189
- txb.moveCall({
190
- target: this.protocol.RewardFn('allow_repeat_claim_with_passport'),
191
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission),
192
- txb.pure(allow_repeat_claim, BCS.BOOL)],
193
- typeArguments: [this.earnest_type]
194
- });
195
- }
196
- else {
197
- txb.moveCall({
198
- target: this.protocol.RewardFn('allow_repeat_claim'),
199
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission),
200
- txb.pure(allow_repeat_claim, BCS.BOOL)],
201
- typeArguments: [this.earnest_type]
202
- });
203
- }
204
- }
205
- set_description(description, passport) {
206
- if (!IsValidDesription(description)) {
207
- ERROR(Errors.IsValidDesription);
208
- }
209
- let txb = this.protocol.CurrentSession();
210
- if (passport) {
211
- txb.moveCall({
212
- target: this.protocol.RewardFn('description_set_with_passport'),
213
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)],
214
- typeArguments: [this.earnest_type]
215
- });
216
- }
217
- else {
218
- txb.moveCall({
219
- target: this.protocol.RewardFn('description_set'),
220
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)],
221
- typeArguments: [this.earnest_type]
222
- });
223
- }
224
- }
225
- lock_guards(passport) {
226
- let txb = this.protocol.CurrentSession();
227
- if (passport) {
228
- txb.moveCall({
229
- target: this.protocol.RewardFn('guard_lock_with_passport'),
230
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
231
- typeArguments: [this.earnest_type]
232
- });
233
- }
234
- else {
235
- txb.moveCall({
236
- target: this.protocol.RewardFn('guard_lock'),
237
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)],
238
- typeArguments: [this.earnest_type]
239
- });
240
- }
241
- }
242
- claim(passport) {
243
- let txb = this.protocol.CurrentSession();
244
- if (passport) {
245
- txb.moveCall({
246
- target: this.protocol.RewardFn('claim_with_passport'),
247
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT)],
248
- typeArguments: [this.earnest_type]
249
- });
250
- }
251
- else {
252
- txb.moveCall({
253
- target: this.protocol.RewardFn('claim'),
254
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT)],
255
- typeArguments: [this.earnest_type]
256
- });
257
- }
258
- ;
259
- }
260
- deposit(rewards) {
261
- console.log(rewards);
262
- if (!rewards || !Protocol.IsValidObjects(rewards)) {
263
- ERROR(Errors.IsValidArray);
264
- }
265
- let txb = this.protocol.CurrentSession();
266
- txb.moveCall({
267
- target: this.protocol.RewardFn('deposit'),
268
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.makeMoveVec({ objects: array_unique(rewards) })],
269
- typeArguments: [this.earnest_type]
270
- });
271
- }
272
- allow_claim(bAllowClaim, passport) {
273
- let txb = this.protocol.CurrentSession();
274
- if (passport) {
275
- txb.moveCall({
276
- target: this.protocol.RewardFn('allow_claim_with_passport'),
277
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission),
278
- txb.pure(bAllowClaim, BCS.BOOL)],
279
- typeArguments: [this.earnest_type]
280
- });
281
- }
282
- else {
283
- txb.moveCall({
284
- target: this.protocol.RewardFn('allow_claim'),
285
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), txb.pure(bAllowClaim, BCS.BOOL)],
286
- typeArguments: [this.earnest_type]
287
- });
288
- }
289
- }
290
- change_permission(new_permission) {
291
- if (!Protocol.IsValidObjects([new_permission])) {
292
- ERROR(Errors.IsValidObjects);
293
- }
294
- let txb = this.protocol.CurrentSession();
295
- txb.moveCall({
296
- target: this.protocol.RewardFn('permission_set'),
297
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
298
- typeArguments: [this.earnest_type]
299
- });
300
- this.permission = new_permission;
301
- }
302
- static parseObjectType = (chain_type) => {
303
- if (chain_type) {
304
- const s = 'reward::Reward<';
305
- const i = chain_type.indexOf(s);
306
- if (i > 0) {
307
- let r = chain_type.slice(i + s.length, chain_type.length - 1);
308
- return r;
309
- }
310
- }
311
- return '';
312
- };
313
- static MAX_PORTIONS_COUNT = 255;
314
- static MAX_GUARD_COUNT = 16;
315
- }
package/dist/vote.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { PassportObject, PermissionObject, GuardObject, VoteAddress, Protocol, TxbObject } from './protocol';
2
- export declare const MAX_AGREES_COUNT = 200;
3
- export declare const MAX_CHOICE_COUNT = 200;
4
- export type VoteOption = {
5
- name: string;
6
- reference_address?: string;
7
- };
8
- export declare class Vote {
9
- protected permission: PermissionObject;
10
- protected object: TxbObject;
11
- protected protocol: Protocol;
12
- get_object(): TxbObject;
13
- private constructor();
14
- static From(protocol: Protocol, permission: PermissionObject, object: TxbObject): Vote;
15
- static New(protocol: Protocol, permission: PermissionObject, description: string, minutes_duration: boolean, time: number, max_choice_count?: number, reference_address?: string, passport?: PassportObject): Vote;
16
- launch(): VoteAddress;
17
- destroy(): void;
18
- set_description(description: string, passport?: PassportObject): void;
19
- set_reference(reference_address?: string, passport?: PassportObject): void;
20
- add_guard(guard: GuardObject, weight: number, passport?: PassportObject): void;
21
- remove_guard(guard_address: string[], removeall?: boolean, passport?: PassportObject): void;
22
- add_option(options: VoteOption[], passport?: PassportObject): void;
23
- remove_option(options: string[], removeall?: boolean, passport?: PassportObject): void;
24
- set_max_choice_count(max_choice_count: number, passport?: PassportObject): void;
25
- open_voting(passport?: PassportObject): void;
26
- lock_deadline(passport?: PassportObject): void;
27
- expand_deadline(ms_expand: boolean, time: number, passport?: PassportObject): void;
28
- lock_guard(passport?: PassportObject): void;
29
- agree(options: string[], passport?: PassportObject): void;
30
- change_permission(new_permission: PermissionObject): void;
31
- }
32
- //# sourceMappingURL=vote.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vote.d.ts","sourceRoot":"","sources":["../src/vote.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,YAAY,CAAC;AAKxH,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,MAAM,MAAM,UAAU,GAAG;IACrB,IAAI,EAAC,MAAM,CAAC;IACZ,iBAAiB,CAAC,EAAC,MAAM,CAAC;CAC7B,CAAA;AAED,qBAAa,IAAI;IACb,SAAS,CAAC,UAAU,mBAAC;IACrB,SAAS,CAAC,MAAM,EAAG,SAAS,CAAC;IAC7B,SAAS,CAAC,QAAQ,WAAC;IAEnB,UAAU;IACV,OAAO;IAKP,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAC,QAAQ,EAAE,UAAU,EAAC,gBAAgB,EAAE,MAAM,EAAC,SAAS,GAAI,IAAI;IAKpF,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAC,QAAQ,EAAE,UAAU,EAAC,gBAAgB,EAAE,WAAW,EAAC,MAAM,EAAE,gBAAgB,EAAC,OAAO,EAAG,IAAI,EAAC,MAAM,EACjH,gBAAgB,CAAC,EAAC,MAAM,EAAE,iBAAiB,CAAC,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc,GAAI,IAAI;IAyCzF,MAAM,IAAK,WAAW;IAQtB,OAAO;IAQP,eAAe,CAAC,WAAW,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAoB5D,aAAa,CAAC,iBAAiB,CAAC,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAoBjE,SAAS,CAAC,KAAK,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAwBpE,YAAY,CAAC,aAAa,EAAC,MAAM,EAAE,EAAE,SAAS,CAAC,EAAC,OAAO,EAAE,QAAQ,CAAC,EAAC,cAAc;IAwCjF,UAAU,CAAC,OAAO,EAAC,UAAU,EAAE,EAAE,QAAQ,CAAC,EAAC,cAAc;IAmCzD,aAAa,CAAC,OAAO,EAAC,MAAM,EAAE,EAAE,SAAS,CAAC,EAAC,OAAO,EAAE,QAAQ,CAAC,EAAC,cAAc;IAuC5E,oBAAoB,CAAC,gBAAgB,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAoBtE,WAAW,CAAC,QAAQ,CAAC,EAAC,cAAc;IAepC,aAAa,CAAC,QAAQ,CAAC,EAAC,cAAc;IAetC,eAAe,CAAC,SAAS,EAAC,OAAO,EAAE,IAAI,EAAC,MAAM,EAAE,QAAQ,CAAC,EAAC,cAAc;IAqBxE,UAAU,CAAC,QAAQ,CAAC,EAAC,cAAc;IAenC,KAAK,CAAC,OAAO,EAAC,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAC,cAAc;IAsBhD,iBAAiB,CAAC,cAAc,EAAC,gBAAgB;CAYpD"}
package/dist/vote.js DELETED
@@ -1,367 +0,0 @@
1
- import { BCS } from '@mysten/bcs';
2
- import { Protocol } from './protocol';
3
- import { IsValidDesription, IsValidUint, IsValidAddress, OptionNone, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
4
- import { ERROR, Errors } from './exception';
5
- import { ValueType } from './protocol';
6
- export const MAX_AGREES_COUNT = 200;
7
- export const MAX_CHOICE_COUNT = 200;
8
- export class Vote {
9
- permission;
10
- object;
11
- protocol;
12
- get_object() { return this.object; }
13
- constructor(protocol, permission) {
14
- this.object = '';
15
- this.protocol = protocol;
16
- this.permission = permission;
17
- }
18
- static From(protocol, permission, object) {
19
- let v = new Vote(protocol, permission);
20
- v.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
21
- return v;
22
- }
23
- static New(protocol, permission, description, minutes_duration, time, max_choice_count, reference_address, passport) {
24
- if (!Protocol.IsValidObjects([permission])) {
25
- ERROR(Errors.IsValidObjects, 'permission');
26
- }
27
- if (!IsValidDesription(description)) {
28
- ERROR(Errors.IsValidDesription);
29
- }
30
- if (!IsValidUint(time)) {
31
- ERROR(Errors.IsValidUint, 'time');
32
- }
33
- if (max_choice_count && !IsValidUint(max_choice_count)) {
34
- ERROR(Errors.IsValidUint, 'max_choice_count');
35
- }
36
- if (max_choice_count && max_choice_count > MAX_CHOICE_COUNT) {
37
- ERROR(Errors.InvalidParam, 'max_choice_count');
38
- }
39
- if (reference_address && !IsValidAddress(reference_address)) {
40
- ERROR(Errors.IsValidAddress, 'reference_address');
41
- }
42
- let v = new Vote(protocol, permission);
43
- let txb = protocol.CurrentSession();
44
- let reference = reference_address ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
45
- let choice_count = max_choice_count ? max_choice_count : 1;
46
- if (passport) {
47
- v.object = txb.moveCall({
48
- target: protocol.VoteFn('new_with_passport'),
49
- arguments: [passport, txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT), txb.pure(minutes_duration, BCS.BOOL),
50
- txb.pure(time, BCS.U64), txb.pure(choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, permission)]
51
- });
52
- }
53
- else {
54
- v.object = txb.moveCall({
55
- target: protocol.VoteFn('new'),
56
- arguments: [txb.pure(description), reference, txb.pure(Protocol.CLOCK_OBJECT), txb.pure(minutes_duration, BCS.BOOL),
57
- txb.pure(time, BCS.U64), txb.pure(choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, permission)]
58
- });
59
- }
60
- return v;
61
- }
62
- launch() {
63
- let txb = this.protocol.CurrentSession();
64
- return txb.moveCall({
65
- target: this.protocol.VoteFn('create'),
66
- arguments: [Protocol.TXB_OBJECT(txb, this.object)]
67
- });
68
- }
69
- destroy() {
70
- let txb = this.protocol.CurrentSession();
71
- txb.moveCall({
72
- target: this.protocol.VoteFn('destroy'),
73
- arguments: [Protocol.TXB_OBJECT(txb, this.object)]
74
- });
75
- }
76
- set_description(description, passport) {
77
- if (!IsValidDesription(description)) {
78
- ERROR(Errors.IsValidDesription);
79
- }
80
- let txb = this.protocol.CurrentSession();
81
- if (passport) {
82
- txb.moveCall({
83
- target: this.protocol.VoteFn('description_set_with_passport'),
84
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
85
- });
86
- }
87
- else {
88
- txb.moveCall({
89
- target: this.protocol.VoteFn('description_set'),
90
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
91
- });
92
- }
93
- }
94
- set_reference(reference_address, passport) {
95
- if (reference_address && !IsValidAddress(reference_address)) {
96
- ERROR(Errors.IsValidAddress);
97
- }
98
- let txb = this.protocol.CurrentSession();
99
- let reference = reference_address ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
100
- if (passport) {
101
- txb.moveCall({
102
- target: this.protocol.VoteFn('reference_set_with_passport'),
103
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), reference, Protocol.TXB_OBJECT(txb, this.permission)]
104
- });
105
- }
106
- else {
107
- txb.moveCall({
108
- target: this.protocol.VoteFn('reference_set'),
109
- arguments: [Protocol.TXB_OBJECT(txb, this.object), reference, Protocol.TXB_OBJECT(txb, this.permission)]
110
- });
111
- }
112
- }
113
- add_guard(guard, weight, passport) {
114
- if (!Protocol.IsValidObjects([guard])) {
115
- ERROR(Errors.IsValidObjects, 'guard');
116
- }
117
- if (!IsValidUint(weight)) {
118
- ERROR(Errors.IsValidUint, 'weight');
119
- }
120
- let txb = this.protocol.CurrentSession();
121
- if (passport) {
122
- txb.moveCall({
123
- target: this.protocol.VoteFn('guard_add_with_passport'),
124
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, guard),
125
- txb.pure(weight, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
126
- });
127
- }
128
- else {
129
- txb.moveCall({
130
- target: this.protocol.VoteFn('guard_add'),
131
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, guard),
132
- txb.pure(weight, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
133
- });
134
- }
135
- }
136
- remove_guard(guard_address, removeall, passport) {
137
- if (!removeall && !guard_address) {
138
- ERROR(Errors.AllInvalid, 'guard_address & removeall');
139
- }
140
- if (guard_address && !IsValidArray(guard_address, IsValidAddress)) {
141
- ERROR(Errors.IsValidArray, 'guard_address');
142
- }
143
- let txb = this.protocol.CurrentSession();
144
- if (passport) {
145
- if (removeall) {
146
- txb.moveCall({
147
- target: this.protocol.VoteFn('guard_remove_all_with_passport'),
148
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
149
- });
150
- }
151
- else {
152
- txb.moveCall({
153
- target: this.protocol.VoteFn('guard_remove_with_passport'),
154
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
155
- txb.pure(array_unique(guard_address), 'vector<address>'), Protocol.TXB_OBJECT(txb, this.permission)]
156
- });
157
- }
158
- }
159
- else {
160
- if (removeall) {
161
- txb.moveCall({
162
- target: this.protocol.VoteFn('guard_remove_all'),
163
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
164
- });
165
- }
166
- else {
167
- txb.moveCall({
168
- target: this.protocol.VoteFn('guard_remove'),
169
- arguments: [Protocol.TXB_OBJECT(txb, this.object),
170
- txb.pure(array_unique(guard_address), 'vector<address>'),
171
- Protocol.TXB_OBJECT(txb, this.permission)]
172
- });
173
- }
174
- }
175
- }
176
- add_option(options, passport) {
177
- if (!options) {
178
- ERROR(Errors.InvalidParam, 'options');
179
- }
180
- let bValid = true;
181
- options.forEach((v) => {
182
- if (!IsValidName(v.name))
183
- bValid = false;
184
- if (v?.reference_address && IsValidAddress(v.reference_address))
185
- bValid = false;
186
- });
187
- if (!bValid) {
188
- ERROR(Errors.InvalidParam, 'options');
189
- }
190
- let txb = this.protocol.CurrentSession();
191
- options.forEach((option) => {
192
- let reference = option?.reference_address ?
193
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, option.reference_address)) :
194
- OptionNone(txb);
195
- if (passport) {
196
- txb.moveCall({
197
- target: this.protocol.VoteFn('agrees_add_with_passport'),
198
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(option.name),
199
- reference, Protocol.TXB_OBJECT(txb, this.permission)]
200
- });
201
- }
202
- else {
203
- txb.moveCall({
204
- target: this.protocol.VoteFn('agrees_add'),
205
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(option.name),
206
- reference, Protocol.TXB_OBJECT(txb, this.permission)]
207
- });
208
- }
209
- });
210
- }
211
- remove_option(options, removeall, passport) {
212
- if (!removeall && !options) {
213
- ERROR(Errors.AllInvalid, 'options & removeall');
214
- }
215
- if (options && !IsValidArray(options, IsValidAddress)) {
216
- ERROR(Errors.IsValidArray, 'options');
217
- }
218
- let txb = this.protocol.CurrentSession();
219
- if (passport) {
220
- if (removeall) {
221
- txb.moveCall({
222
- target: this.protocol.VoteFn('agrees_remove_all_with_passport'),
223
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
224
- });
225
- }
226
- else {
227
- txb.moveCall({
228
- target: this.protocol.VoteFn('agrees_remove_with_passport'),
229
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
230
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
231
- Protocol.TXB_OBJECT(txb, this.permission)]
232
- });
233
- }
234
- }
235
- else {
236
- if (removeall) {
237
- txb.moveCall({
238
- target: this.protocol.VoteFn('agrees_remove_all'),
239
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
240
- });
241
- }
242
- else {
243
- txb.moveCall({
244
- target: this.protocol.VoteFn('agrees_remove'),
245
- arguments: [Protocol.TXB_OBJECT(txb, this.object),
246
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
247
- Protocol.TXB_OBJECT(txb, this.permission)]
248
- });
249
- }
250
- }
251
- }
252
- set_max_choice_count(max_choice_count, passport) {
253
- if (!IsValidUint(max_choice_count) || max_choice_count > MAX_CHOICE_COUNT) {
254
- ERROR(Errors.InvalidParam, 'max_choice_count');
255
- }
256
- let txb = this.protocol.CurrentSession();
257
- if (passport) {
258
- txb.moveCall({
259
- target: this.protocol.VoteFn('max_choice_count_set_with_passport'),
260
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
261
- txb.pure(max_choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, this.permission)]
262
- });
263
- }
264
- else {
265
- txb.moveCall({
266
- target: this.protocol.VoteFn('max_choice_count_set'),
267
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(max_choice_count, BCS.U8), Protocol.TXB_OBJECT(txb, this.permission)]
268
- });
269
- }
270
- }
271
- open_voting(passport) {
272
- let txb = this.protocol.CurrentSession();
273
- if (passport) {
274
- txb.moveCall({
275
- target: this.protocol.VoteFn('options_locked_for_voting_with_passport'),
276
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
277
- });
278
- }
279
- else {
280
- txb.moveCall({
281
- target: this.protocol.VoteFn('options_locked_for_voting'),
282
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
283
- });
284
- }
285
- }
286
- lock_deadline(passport) {
287
- let txb = this.protocol.CurrentSession();
288
- if (passport) {
289
- txb.moveCall({
290
- target: this.protocol.VoteFn('deadline_locked_with_passport'),
291
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)]
292
- });
293
- }
294
- else {
295
- txb.moveCall({
296
- target: this.protocol.VoteFn('deadline_locked'),
297
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.object(Protocol.CLOCK_OBJECT), Protocol.TXB_OBJECT(txb, this.permission)]
298
- });
299
- }
300
- }
301
- expand_deadline(ms_expand, time, passport) {
302
- if (!IsValidUint(time)) {
303
- ERROR(Errors.IsValidUint, 'time');
304
- }
305
- let txb = this.protocol.CurrentSession();
306
- if (passport) {
307
- txb.moveCall({
308
- target: this.protocol.VoteFn('deadline_expand_with_passport'),
309
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
310
- txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
311
- });
312
- }
313
- else {
314
- txb.moveCall({
315
- target: this.protocol.VoteFn('deadline_expand'),
316
- arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand, BCS.BOOL),
317
- txb.pure(time, BCS.U64), Protocol.TXB_OBJECT(txb, this.permission)]
318
- });
319
- }
320
- }
321
- lock_guard(passport) {
322
- let txb = this.protocol.CurrentSession();
323
- if (passport) {
324
- txb.moveCall({
325
- target: this.protocol.VoteFn('guard_lock_with_passport'),
326
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
327
- });
328
- }
329
- else {
330
- txb.moveCall({
331
- target: this.protocol.VoteFn('guard_lock'),
332
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
333
- });
334
- }
335
- }
336
- agree(options, passport) {
337
- if (!options || options.length > MAX_CHOICE_COUNT) {
338
- ERROR(Errors.InvalidParam, 'options');
339
- }
340
- let txb = this.protocol.CurrentSession();
341
- if (passport) {
342
- txb.moveCall({
343
- target: this.protocol.VoteFn('with_passport'),
344
- arguments: [passport, Protocol.TXB_OBJECT(txb, this.object),
345
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
346
- });
347
- }
348
- else {
349
- txb.moveCall({
350
- target: this.protocol.VoteFn('this.object'),
351
- arguments: [Protocol.TXB_OBJECT(txb, this.object),
352
- txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
353
- });
354
- }
355
- }
356
- change_permission(new_permission) {
357
- if (!Protocol.IsValidObjects([new_permission])) {
358
- ERROR(Errors.IsValidObjects);
359
- }
360
- let txb = this.protocol.CurrentSession();
361
- txb.moveCall({
362
- target: this.protocol.VoteFn('this.permission_set'),
363
- arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
364
- });
365
- this.permission = new_permission;
366
- }
367
- }