wowok 1.2.11 → 1.3.3
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 +3 -3
- package/src/demand.ts +85 -99
- package/src/entity.ts +34 -35
- package/src/guard.ts +16 -16
- package/src/machine.ts +213 -189
- package/src/passport.ts +78 -38
- package/src/permission.ts +152 -155
- package/src/progress.ts +122 -123
- package/src/protocol.ts +29 -33
- package/src/repository.ts +147 -161
- package/src/resource.ts +43 -46
- package/src/reward.ts +108 -121
- package/src/service.ts +338 -365
- package/src/utils.ts +5 -6
- package/src/vote.ts +139 -157
- package/src/wowok.ts +19 -24
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig, TypeName, BcsReader } from '@mysten/bcs';
|
|
2
|
-
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui
|
|
3
|
-
import { SuiObjectResponse, DynamicFieldPage } from '@mysten/sui
|
|
2
|
+
import { Transaction as TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui/transactions';
|
|
3
|
+
import { SuiObjectResponse, DynamicFieldPage } from '@mysten/sui/client';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
-
import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui
|
|
5
|
+
import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui/utils'
|
|
6
6
|
import { RepositoryValueType, ValueType, Protocol } from './protocol'
|
|
7
7
|
|
|
8
8
|
export const MAX_U8 = BigInt('255');
|
|
@@ -314,7 +314,8 @@ export class Bcs {
|
|
|
314
314
|
const dislike = reader.read32();
|
|
315
315
|
return {avatar:avatar, resource:resource, like:like, dislike:dislike}*/
|
|
316
316
|
}
|
|
317
|
-
de_entInfo(data:Uint8Array) : any {
|
|
317
|
+
de_entInfo(data:Uint8Array | undefined) : any {
|
|
318
|
+
if (!data || data.length === 0) return ''
|
|
318
319
|
let r = this.bcs.de('PersonalInfo', data);
|
|
319
320
|
r.name = new TextDecoder().decode(Uint8Array.from(r.name));
|
|
320
321
|
r.description = new TextDecoder().decode(Uint8Array.from(r.description));
|
|
@@ -473,8 +474,6 @@ export const ResolveBalance = (balance:string, decimals:number) : string => {
|
|
|
473
474
|
}
|
|
474
475
|
}
|
|
475
476
|
|
|
476
|
-
export const OptionNone = (txb:TransactionBlock) : TransactionArgument => { return txb.pure([], BCS.U8) };
|
|
477
|
-
|
|
478
477
|
export type ArgType = {
|
|
479
478
|
isCoin: boolean;
|
|
480
479
|
coin: string;
|
package/src/vote.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BCS } from '@mysten/bcs';
|
|
2
1
|
import { FnCallType, PassportObject, PermissionObject, GuardObject, VoteAddress, Protocol, TxbObject} from './protocol';
|
|
3
|
-
import { IsValidDesription, IsValidUintLarge, IsValidAddress,
|
|
2
|
+
import { IsValidDesription, IsValidUintLarge, IsValidAddress, Bcs, array_unique, IsValidArray, IsValidName } from './utils';
|
|
4
3
|
import { ERROR, Errors } from './exception';
|
|
5
4
|
import { ValueType } from './protocol';
|
|
5
|
+
import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
|
|
6
6
|
|
|
7
7
|
export const MAX_AGREES_COUNT = 200;
|
|
8
8
|
export const MAX_CHOICE_COUNT = 200;
|
|
@@ -15,20 +15,20 @@ export type VoteOption = {
|
|
|
15
15
|
export class Vote {
|
|
16
16
|
protected permission;
|
|
17
17
|
protected object : TxbObject;
|
|
18
|
-
protected
|
|
18
|
+
protected txb;
|
|
19
19
|
|
|
20
20
|
get_object() { return this.object }
|
|
21
|
-
private constructor(
|
|
21
|
+
private constructor(txb:TransactionBlock, permission:PermissionObject) {
|
|
22
22
|
this.object = '';
|
|
23
|
-
this.
|
|
23
|
+
this.txb = txb;
|
|
24
24
|
this.permission = permission;
|
|
25
25
|
}
|
|
26
|
-
static From(
|
|
27
|
-
let v = new Vote(
|
|
28
|
-
v.object = Protocol.TXB_OBJECT(
|
|
26
|
+
static From(txb:TransactionBlock, permission:PermissionObject, object:TxbObject) : Vote {
|
|
27
|
+
let v = new Vote(txb, permission);
|
|
28
|
+
v.object = Protocol.TXB_OBJECT(txb, object)
|
|
29
29
|
return v
|
|
30
30
|
}
|
|
31
|
-
static New(
|
|
31
|
+
static New(txb:TransactionBlock, permission:PermissionObject, description:string, minutes_duration:boolean, time:number,
|
|
32
32
|
max_choice_count?:number, reference_address?:string, passport?:PassportObject) : Vote {
|
|
33
33
|
if (!Protocol.IsValidObjects([permission])) {
|
|
34
34
|
ERROR(Errors.IsValidObjects, 'permission')
|
|
@@ -49,40 +49,38 @@ export class Vote {
|
|
|
49
49
|
ERROR(Errors.IsValidAddress, 'reference_address')
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
let v = new Vote(
|
|
53
|
-
|
|
54
|
-
let reference =
|
|
52
|
+
let v = new Vote(txb, permission);
|
|
53
|
+
|
|
54
|
+
let reference = txb.pure.option('address', reference_address ? reference_address : undefined);
|
|
55
55
|
let choice_count = max_choice_count ? max_choice_count : 1;
|
|
56
|
-
|
|
56
|
+
const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
57
57
|
if (passport) {
|
|
58
58
|
v.object = txb.moveCall({
|
|
59
|
-
target:
|
|
60
|
-
arguments:[passport, txb.pure(description), reference, txb.
|
|
61
|
-
txb.pure(time
|
|
59
|
+
target:Protocol.Instance().VoteFn('new_with_passport') as FnCallType,
|
|
60
|
+
arguments:[passport, txb.pure.string(description), reference, txb.object(clock), txb.pure.bool(minutes_duration),
|
|
61
|
+
txb.pure.u64(time), txb.pure.u8(choice_count), Protocol.TXB_OBJECT(txb, permission)]
|
|
62
62
|
})
|
|
63
63
|
} else {
|
|
64
64
|
v.object = txb.moveCall({
|
|
65
|
-
target:
|
|
66
|
-
arguments:[txb.pure(description), reference, txb.
|
|
67
|
-
txb.pure(time
|
|
65
|
+
target:Protocol.Instance().VoteFn('new') as FnCallType,
|
|
66
|
+
arguments:[txb.pure.string(description), reference, txb.object(clock), txb.pure.bool(minutes_duration),
|
|
67
|
+
txb.pure.u64(time), txb.pure.u8(choice_count), Protocol.TXB_OBJECT(txb, permission)]
|
|
68
68
|
})
|
|
69
69
|
}
|
|
70
70
|
return v
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
launch() : VoteAddress {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object)]
|
|
74
|
+
return this.txb.moveCall({
|
|
75
|
+
target:Protocol.Instance().VoteFn('create') as FnCallType,
|
|
76
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
78
77
|
})
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
destroy() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object)]
|
|
81
|
+
this.txb.moveCall({
|
|
82
|
+
target:Protocol.Instance().VoteFn('destroy') as FnCallType,
|
|
83
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
86
84
|
})
|
|
87
85
|
}
|
|
88
86
|
|
|
@@ -90,38 +88,35 @@ export class Vote {
|
|
|
90
88
|
if (!IsValidDesription(description)) {
|
|
91
89
|
ERROR(Errors.IsValidDesription)
|
|
92
90
|
}
|
|
93
|
-
|
|
94
|
-
let txb = this.protocol.CurrentSession();
|
|
91
|
+
|
|
95
92
|
if (passport) {
|
|
96
|
-
txb.moveCall({
|
|
97
|
-
target:
|
|
98
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
93
|
+
this.txb.moveCall({
|
|
94
|
+
target:Protocol.Instance().VoteFn('description_set_with_passport') as FnCallType,
|
|
95
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
99
96
|
})
|
|
100
97
|
} else {
|
|
101
|
-
txb.moveCall({
|
|
102
|
-
target:
|
|
103
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(description), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
98
|
+
this.txb.moveCall({
|
|
99
|
+
target:Protocol.Instance().VoteFn('description_set') as FnCallType,
|
|
100
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
104
101
|
})
|
|
105
102
|
}
|
|
106
|
-
|
|
107
103
|
}
|
|
108
104
|
|
|
109
|
-
set_reference(reference_address?:string, passport?:PassportObject) {
|
|
105
|
+
set_reference(reference_address?:string|null, passport?:PassportObject) {
|
|
110
106
|
if (reference_address && !IsValidAddress(reference_address)) {
|
|
111
107
|
ERROR(Errors.IsValidAddress)
|
|
112
108
|
}
|
|
113
|
-
|
|
114
|
-
let
|
|
115
|
-
let reference = reference_address? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, reference_address)) : OptionNone(txb);
|
|
109
|
+
|
|
110
|
+
let reference = this.txb.pure.option('address', reference_address ? reference_address : undefined);
|
|
116
111
|
if (passport) {
|
|
117
|
-
txb.moveCall({
|
|
118
|
-
target:
|
|
119
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), reference, Protocol.TXB_OBJECT(txb, this.permission)]
|
|
112
|
+
this.txb.moveCall({
|
|
113
|
+
target:Protocol.Instance().VoteFn('reference_set_with_passport') as FnCallType,
|
|
114
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
120
115
|
})
|
|
121
116
|
} else {
|
|
122
|
-
txb.moveCall({
|
|
123
|
-
target:
|
|
124
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), reference, Protocol.TXB_OBJECT(txb, this.permission)]
|
|
117
|
+
this.txb.moveCall({
|
|
118
|
+
target:Protocol.Instance().VoteFn('reference_set') as FnCallType,
|
|
119
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
125
120
|
})
|
|
126
121
|
}
|
|
127
122
|
|
|
@@ -134,18 +129,17 @@ export class Vote {
|
|
|
134
129
|
ERROR(Errors.IsValidUint, 'add_guard')
|
|
135
130
|
}
|
|
136
131
|
|
|
137
|
-
let txb = this.protocol.CurrentSession();
|
|
138
132
|
if (passport) {
|
|
139
|
-
txb.moveCall({
|
|
140
|
-
target:
|
|
141
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, guard),
|
|
142
|
-
txb.pure(weight
|
|
133
|
+
this.txb.moveCall({
|
|
134
|
+
target:Protocol.Instance().VoteFn('guard_add_with_passport') as FnCallType,
|
|
135
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
|
|
136
|
+
this.txb.pure.u64(weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
143
137
|
})
|
|
144
138
|
} else {
|
|
145
|
-
txb.moveCall({
|
|
146
|
-
target:
|
|
147
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, guard),
|
|
148
|
-
txb.pure(weight
|
|
139
|
+
this.txb.moveCall({
|
|
140
|
+
target:Protocol.Instance().VoteFn('guard_add') as FnCallType,
|
|
141
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard),
|
|
142
|
+
this.txb.pure.u64(weight), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
149
143
|
})
|
|
150
144
|
}
|
|
151
145
|
}
|
|
@@ -156,33 +150,32 @@ export class Vote {
|
|
|
156
150
|
if (!IsValidArray(guard_address, IsValidAddress)) {
|
|
157
151
|
ERROR(Errors.IsValidArray, 'remove_guard')
|
|
158
152
|
}
|
|
159
|
-
|
|
160
|
-
let txb = this.protocol.CurrentSession();
|
|
153
|
+
|
|
161
154
|
if (passport) {
|
|
162
155
|
if (removeall) {
|
|
163
|
-
txb.moveCall({
|
|
164
|
-
target:
|
|
165
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
156
|
+
this.txb.moveCall({
|
|
157
|
+
target:Protocol.Instance().VoteFn('guard_remove_all_with_passport') as FnCallType,
|
|
158
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
166
159
|
})
|
|
167
160
|
} else {
|
|
168
|
-
txb.moveCall({
|
|
169
|
-
target:
|
|
170
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
171
|
-
txb.pure(array_unique(guard_address)
|
|
161
|
+
this.txb.moveCall({
|
|
162
|
+
target:Protocol.Instance().VoteFn('guard_remove_with_passport') as FnCallType,
|
|
163
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
164
|
+
this.txb.pure.vector('address', array_unique(guard_address)), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
172
165
|
})
|
|
173
166
|
}
|
|
174
167
|
} else {
|
|
175
168
|
if (removeall) {
|
|
176
|
-
txb.moveCall({
|
|
177
|
-
target:
|
|
178
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
169
|
+
this.txb.moveCall({
|
|
170
|
+
target:Protocol.Instance().VoteFn('guard_remove_all') as FnCallType,
|
|
171
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
179
172
|
})
|
|
180
173
|
} else {
|
|
181
|
-
txb.moveCall({
|
|
182
|
-
target:
|
|
183
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
184
|
-
txb.pure(array_unique(guard_address)
|
|
185
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
174
|
+
this.txb.moveCall({
|
|
175
|
+
target:Protocol.Instance().VoteFn('guard_remove') as FnCallType,
|
|
176
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
177
|
+
this.txb.pure.vector('address', array_unique(guard_address)),
|
|
178
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
186
179
|
})
|
|
187
180
|
}
|
|
188
181
|
}
|
|
@@ -200,23 +193,20 @@ export class Vote {
|
|
|
200
193
|
ERROR(Errors.InvalidParam, 'options')
|
|
201
194
|
}
|
|
202
195
|
|
|
203
|
-
let txb = this.protocol.CurrentSession();
|
|
204
196
|
options.forEach((option) => {
|
|
205
|
-
let reference = option?.reference_address
|
|
206
|
-
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, option.reference_address)) :
|
|
207
|
-
OptionNone(txb);
|
|
197
|
+
let reference = this.txb.pure.option('address', option?.reference_address) ;
|
|
208
198
|
|
|
209
199
|
if (passport) {
|
|
210
|
-
txb.moveCall({
|
|
211
|
-
target:
|
|
212
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(option.name),
|
|
213
|
-
reference, Protocol.TXB_OBJECT(txb, this.permission)]
|
|
200
|
+
this.txb.moveCall({
|
|
201
|
+
target:Protocol.Instance().VoteFn('agrees_add_with_passport') as FnCallType,
|
|
202
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(option.name),
|
|
203
|
+
reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
214
204
|
})
|
|
215
205
|
} else {
|
|
216
|
-
txb.moveCall({
|
|
217
|
-
target:
|
|
218
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(option.name),
|
|
219
|
-
reference, Protocol.TXB_OBJECT(txb, this.permission)]
|
|
206
|
+
this.txb.moveCall({
|
|
207
|
+
target:Protocol.Instance().VoteFn('agrees_add') as FnCallType,
|
|
208
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(option.name),
|
|
209
|
+
reference, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
220
210
|
})
|
|
221
211
|
}
|
|
222
212
|
})
|
|
@@ -228,34 +218,33 @@ export class Vote {
|
|
|
228
218
|
if (options && !IsValidArray(options, IsValidAddress)) {
|
|
229
219
|
ERROR(Errors.IsValidArray, 'remove_option')
|
|
230
220
|
}
|
|
231
|
-
|
|
232
|
-
let txb = this.protocol.CurrentSession();
|
|
221
|
+
|
|
233
222
|
if (passport) {
|
|
234
223
|
if (removeall) {
|
|
235
|
-
txb.moveCall({
|
|
236
|
-
target:
|
|
237
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
224
|
+
this.txb.moveCall({
|
|
225
|
+
target:Protocol.Instance().VoteFn('agrees_remove_all_with_passport') as FnCallType,
|
|
226
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
238
227
|
})
|
|
239
228
|
} else {
|
|
240
|
-
txb.moveCall({
|
|
241
|
-
target:
|
|
242
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
243
|
-
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
|
|
244
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
229
|
+
this.txb.moveCall({
|
|
230
|
+
target:Protocol.Instance().VoteFn('agrees_remove_with_passport') as FnCallType,
|
|
231
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
232
|
+
this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
|
|
233
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
245
234
|
})
|
|
246
235
|
}
|
|
247
236
|
} else {
|
|
248
237
|
if (removeall) {
|
|
249
|
-
txb.moveCall({
|
|
250
|
-
target:
|
|
251
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
238
|
+
this.txb.moveCall({
|
|
239
|
+
target:Protocol.Instance().VoteFn('agrees_remove_all') as FnCallType,
|
|
240
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
252
241
|
})
|
|
253
242
|
} else {
|
|
254
|
-
txb.moveCall({
|
|
255
|
-
target:
|
|
256
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
257
|
-
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
|
|
258
|
-
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
243
|
+
this.txb.moveCall({
|
|
244
|
+
target:Protocol.Instance().VoteFn('agrees_remove') as FnCallType,
|
|
245
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
246
|
+
this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options))),
|
|
247
|
+
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
259
248
|
})
|
|
260
249
|
}
|
|
261
250
|
}
|
|
@@ -265,47 +254,45 @@ export class Vote {
|
|
|
265
254
|
ERROR(Errors.InvalidParam, 'max_choice_count')
|
|
266
255
|
}
|
|
267
256
|
|
|
268
|
-
let txb = this.protocol.CurrentSession();
|
|
269
257
|
if (passport) {
|
|
270
|
-
txb.moveCall({
|
|
271
|
-
target:
|
|
272
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
273
|
-
txb.pure(max_choice_count
|
|
258
|
+
this.txb.moveCall({
|
|
259
|
+
target:Protocol.Instance().VoteFn('max_choice_count_set_with_passport') as FnCallType,
|
|
260
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
261
|
+
this.txb.pure.u8(max_choice_count), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
274
262
|
})
|
|
275
263
|
} else {
|
|
276
|
-
txb.moveCall({
|
|
277
|
-
target:
|
|
278
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(max_choice_count
|
|
264
|
+
this.txb.moveCall({
|
|
265
|
+
target:Protocol.Instance().VoteFn('max_choice_count_set') as FnCallType,
|
|
266
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(max_choice_count), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
279
267
|
})
|
|
280
268
|
}
|
|
281
269
|
}
|
|
282
270
|
|
|
283
271
|
open_voting(passport?:PassportObject) {
|
|
284
|
-
let txb = this.protocol.CurrentSession();
|
|
285
272
|
if (passport) {
|
|
286
|
-
txb.moveCall({
|
|
287
|
-
target:
|
|
288
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
273
|
+
this.txb.moveCall({
|
|
274
|
+
target:Protocol.Instance().VoteFn('options_locked_for_voting_with_passport') as FnCallType,
|
|
275
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
289
276
|
})
|
|
290
277
|
} else {
|
|
291
|
-
txb.moveCall({
|
|
292
|
-
target:
|
|
293
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
278
|
+
this.txb.moveCall({
|
|
279
|
+
target:Protocol.Instance().VoteFn('options_locked_for_voting') as FnCallType,
|
|
280
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
294
281
|
})
|
|
295
282
|
}
|
|
296
283
|
}
|
|
297
284
|
|
|
298
285
|
lock_deadline(passport?:PassportObject) {
|
|
299
|
-
|
|
286
|
+
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
300
287
|
if (passport) {
|
|
301
|
-
txb.moveCall({
|
|
302
|
-
target:
|
|
303
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.object(
|
|
288
|
+
this.txb.moveCall({
|
|
289
|
+
target:Protocol.Instance().VoteFn('deadline_locked_with_passport') as FnCallType,
|
|
290
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
304
291
|
})
|
|
305
292
|
} else {
|
|
306
|
-
txb.moveCall({
|
|
307
|
-
target:
|
|
308
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.object(
|
|
293
|
+
this.txb.moveCall({
|
|
294
|
+
target:Protocol.Instance().VoteFn('deadline_locked') as FnCallType,
|
|
295
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
309
296
|
})
|
|
310
297
|
}
|
|
311
298
|
}
|
|
@@ -314,34 +301,32 @@ export class Vote {
|
|
|
314
301
|
if (!IsValidUintLarge(time)) {
|
|
315
302
|
ERROR(Errors.IsValidUint, 'time')
|
|
316
303
|
}
|
|
317
|
-
|
|
318
|
-
let txb = this.protocol.CurrentSession();
|
|
304
|
+
|
|
319
305
|
if (passport) {
|
|
320
|
-
txb.moveCall({
|
|
321
|
-
target:
|
|
322
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand
|
|
323
|
-
txb.pure(time
|
|
306
|
+
this.txb.moveCall({
|
|
307
|
+
target:Protocol.Instance().VoteFn('deadline_expand_with_passport') as FnCallType,
|
|
308
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(ms_expand),
|
|
309
|
+
this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
324
310
|
})
|
|
325
311
|
} else {
|
|
326
|
-
txb.moveCall({
|
|
327
|
-
target:
|
|
328
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(ms_expand
|
|
329
|
-
txb.pure(time
|
|
312
|
+
this.txb.moveCall({
|
|
313
|
+
target:Protocol.Instance().VoteFn('deadline_expand') as FnCallType,
|
|
314
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(ms_expand),
|
|
315
|
+
this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
330
316
|
})
|
|
331
317
|
}
|
|
332
|
-
|
|
333
318
|
}
|
|
319
|
+
|
|
334
320
|
lock_guard(passport?:PassportObject) {
|
|
335
|
-
let txb = this.protocol.CurrentSession();
|
|
336
321
|
if (passport) {
|
|
337
|
-
txb.moveCall({
|
|
338
|
-
target:
|
|
339
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
322
|
+
this.txb.moveCall({
|
|
323
|
+
target:Protocol.Instance().VoteFn('guard_lock_with_passport') as FnCallType,
|
|
324
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
340
325
|
})
|
|
341
326
|
} else {
|
|
342
|
-
txb.moveCall({
|
|
343
|
-
target:
|
|
344
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, this.permission)]
|
|
327
|
+
this.txb.moveCall({
|
|
328
|
+
target:Protocol.Instance().VoteFn('guard_lock') as FnCallType,
|
|
329
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
345
330
|
})
|
|
346
331
|
}
|
|
347
332
|
}
|
|
@@ -352,32 +337,29 @@ export class Vote {
|
|
|
352
337
|
ERROR(Errors.InvalidParam, 'agree')
|
|
353
338
|
}
|
|
354
339
|
|
|
355
|
-
let txb = this.protocol.CurrentSession();
|
|
356
340
|
if (passport) {
|
|
357
|
-
txb.moveCall({
|
|
358
|
-
target:
|
|
359
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
360
|
-
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
|
|
341
|
+
this.txb.moveCall({
|
|
342
|
+
target:Protocol.Instance().VoteFn('with_passport') as FnCallType,
|
|
343
|
+
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
344
|
+
this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
|
|
361
345
|
})
|
|
362
346
|
} else {
|
|
363
|
-
txb.moveCall({
|
|
364
|
-
target:
|
|
365
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
366
|
-
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
|
|
347
|
+
this.txb.moveCall({
|
|
348
|
+
target:Protocol.Instance().VoteFn('this.object') as FnCallType,
|
|
349
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
350
|
+
this.txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(options)))]
|
|
367
351
|
})
|
|
368
352
|
}
|
|
369
|
-
|
|
370
353
|
}
|
|
371
354
|
|
|
372
355
|
change_permission(new_permission:PermissionObject) {
|
|
373
356
|
if (!Protocol.IsValidObjects([new_permission])) {
|
|
374
357
|
ERROR(Errors.IsValidObjects)
|
|
375
358
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb,this.permission), Protocol.TXB_OBJECT(txb, new_permission)],
|
|
359
|
+
|
|
360
|
+
this.txb.moveCall({
|
|
361
|
+
target:Protocol.Instance().VoteFn('this.permission_set') as FnCallType,
|
|
362
|
+
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb,this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
|
|
381
363
|
})
|
|
382
364
|
this.permission = new_permission
|
|
383
365
|
}
|
package/src/wowok.ts
CHANGED
|
@@ -1,55 +1,50 @@
|
|
|
1
|
-
import { BCS } from '@mysten/bcs';
|
|
2
1
|
import { Protocol, FnCallType, TxbObject, ResourceAddress, PermissionObject} from './protocol';
|
|
3
2
|
import { IsValidDesription, IsValidAddress, IsValidName, IsValidArray, } from './utils';
|
|
4
3
|
import { ERROR, Errors } from './exception';
|
|
5
|
-
|
|
4
|
+
import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
|
|
6
5
|
|
|
7
6
|
export class Wowok {
|
|
8
7
|
|
|
9
8
|
protected object:TxbObject;
|
|
10
|
-
protected
|
|
9
|
+
protected txb;
|
|
11
10
|
|
|
12
11
|
get_object() { return this.object }
|
|
13
|
-
private constructor(
|
|
14
|
-
this.
|
|
12
|
+
private constructor(txb:TransactionBlock) {
|
|
13
|
+
this.txb = txb;
|
|
15
14
|
this.object = '';
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
static From(
|
|
19
|
-
let r = new Wowok(
|
|
20
|
-
r.object = Protocol.TXB_OBJECT(
|
|
17
|
+
static From(txb:TransactionBlock) : Wowok {
|
|
18
|
+
let r = new Wowok(txb);
|
|
19
|
+
r.object = Protocol.TXB_OBJECT(txb, Protocol.Instance().WowokObject());
|
|
21
20
|
return r
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
register_grantor(name:string, grantee_permission:PermissionObject) {
|
|
25
24
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'register_grantor');
|
|
26
25
|
if (!Protocol.IsValidObjects([grantee_permission])) ERROR(Errors.IsValidObjects, 'register_grantor');
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
txb.moveCall({
|
|
30
|
-
target:
|
|
31
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.object(
|
|
32
|
-
Protocol.TXB_OBJECT(txb, grantee_permission)]
|
|
26
|
+
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
27
|
+
|
|
28
|
+
this.txb.moveCall({
|
|
29
|
+
target:Protocol.Instance().WowokFn('grantor_register') as FnCallType,
|
|
30
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(name), this.txb.object(clock),
|
|
31
|
+
Protocol.TXB_OBJECT(this.txb, grantee_permission)]
|
|
33
32
|
})
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
grantor_time_expand_1year(grantor:string) {
|
|
37
36
|
if (!IsValidAddress(grantor)) ERROR(Errors.IsValidAddress, 'grantor_time_expand_1year');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
target:this.protocol.WowokFn('grantor_time_expand_1year') as FnCallType,
|
|
42
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(grantor, BCS.ADDRESS)]
|
|
37
|
+
this.txb.moveCall({
|
|
38
|
+
target:Protocol.Instance().WowokFn('grantor_time_expand_1year') as FnCallType,
|
|
39
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.address(grantor)]
|
|
43
40
|
})
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
grantor_rename(new_name:string) {
|
|
47
44
|
if (!IsValidName(new_name)) ERROR(Errors.IsValidName, 'grantor_rename');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
target:this.protocol.WowokFn('grantor_time_expand_1year') as FnCallType,
|
|
52
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(new_name)]
|
|
45
|
+
this.txb.moveCall({
|
|
46
|
+
target:Protocol.Instance().WowokFn('grantor_time_expand_1year') as FnCallType,
|
|
47
|
+
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(new_name)]
|
|
53
48
|
})
|
|
54
49
|
}
|
|
55
50
|
}
|