wowok 1.0.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/dist/community.d.ts +8 -0
- package/dist/community.js +96 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +27 -0
- package/dist/demand.js +176 -0
- package/dist/guard.js +267 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/machine.js +259 -0
- package/dist/passport.js +89 -0
- package/dist/permission.js +217 -0
- package/dist/progress.js +143 -0
- package/dist/protocol.js +177 -0
- package/dist/repository.js +206 -0
- package/dist/reward.js +192 -0
- package/dist/service.js +698 -0
- package/dist/util.js +131 -0
- package/dist/vote.js +273 -0
- package/package.json +24 -0
- package/src/demand.ts +173 -0
- package/src/guard.ts +283 -0
- package/src/index.ts +0 -0
- package/src/machine.ts +257 -0
- package/src/passport.ts +110 -0
- package/src/permission.ts +224 -0
- package/src/progress.ts +139 -0
- package/src/protocol.ts +189 -0
- package/src/repository.ts +213 -0
- package/src/reward.ts +184 -0
- package/src/service.ts +686 -0
- package/src/util.ts +134 -0
- package/src/vote.ts +251 -0
- package/tsconfig.json +110 -0
package/src/service.ts
ADDED
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
import { SuiObjectChange } from '@mysten/sui.js/client';
|
|
2
|
+
import { TransactionBlock, Inputs, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
3
|
+
import { BCS } from '@mysten/bcs';
|
|
4
|
+
import { CLOCK_OBJECT, FnCallType, GuardObject, description_data, PROTOCOL, MAX_ENDPOINT_LENGTH, name_data} from './protocol';
|
|
5
|
+
import { BCS_CONVERT } from './util';
|
|
6
|
+
import { PassportObject} from './passport'
|
|
7
|
+
import { PermissionObject } from './permission'
|
|
8
|
+
import { RepositoryObject } from './repository';
|
|
9
|
+
import { MachineObject } from './machine';
|
|
10
|
+
|
|
11
|
+
export type ServiceObject = TransactionResult;
|
|
12
|
+
export type ServiceAddress = TransactionResult;
|
|
13
|
+
|
|
14
|
+
export function service(pay_type:string, txb:TransactionBlock, permission:PermissionObject, description:string,
|
|
15
|
+
payee_address:string, endpoint_url?:string, passport?:PassportObject) : ServiceObject | undefined {
|
|
16
|
+
if (endpoint_url && endpoint_url.length > MAX_ENDPOINT_LENGTH) return undefined;
|
|
17
|
+
let endpoint = endpoint_url? txb.pure(BCS_CONVERT.ser_option_string(endpoint_url)) : txb.pure([], BCS.U8);
|
|
18
|
+
|
|
19
|
+
if (passport) {
|
|
20
|
+
return txb.moveCall({
|
|
21
|
+
target:PROTOCOL.ServiceFn('new_with_passport') as FnCallType,
|
|
22
|
+
arguments:[passport, txb.pure(description_data(description)), txb.pure(payee_address, BCS.ADDRESS), endpoint, permission],
|
|
23
|
+
typeArguments:[pay_type],
|
|
24
|
+
})
|
|
25
|
+
} else {
|
|
26
|
+
return txb.moveCall({
|
|
27
|
+
target:PROTOCOL.ServiceFn('new') as FnCallType,
|
|
28
|
+
arguments:[txb.pure(description_data(description)), txb.pure(payee_address, BCS.ADDRESS), endpoint, permission],
|
|
29
|
+
typeArguments:[pay_type],
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function launch(pay_type:string, txb:TransactionBlock, service:ServiceObject) : ServiceAddress {
|
|
35
|
+
return txb.moveCall({
|
|
36
|
+
target:PROTOCOL.ServiceFn('create') as FnCallType,
|
|
37
|
+
arguments:[service],
|
|
38
|
+
typeArguments:[pay_type]
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
export function destroy(pay_type:string, txb:TransactionBlock, service:ServiceObject) {
|
|
42
|
+
return txb.moveCall({
|
|
43
|
+
target:PROTOCOL.ServiceFn('destroy') as FnCallType,
|
|
44
|
+
arguments: [service],
|
|
45
|
+
typeArguments:[pay_type]
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
export function service_set_description(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, description:string, passport?:PassportObject) {
|
|
49
|
+
if (passport) {
|
|
50
|
+
txb.moveCall({
|
|
51
|
+
target:PROTOCOL.ServiceFn('description_set_with_passport') as FnCallType,
|
|
52
|
+
arguments:[passport, service, txb.pure(description_data(description)), permission],
|
|
53
|
+
typeArguments:[pay_type]
|
|
54
|
+
})
|
|
55
|
+
} else {
|
|
56
|
+
txb.moveCall({
|
|
57
|
+
target:PROTOCOL.ServiceFn('description_set') as FnCallType,
|
|
58
|
+
arguments:[service, txb.pure(description_data(description)), permission],
|
|
59
|
+
typeArguments:[pay_type]
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function service_set_price(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, item:string, price:number, passport?:PassportObject) {
|
|
64
|
+
if (passport) {
|
|
65
|
+
txb.moveCall({
|
|
66
|
+
target:PROTOCOL.ServiceFn('price_set_with_passport') as FnCallType,
|
|
67
|
+
arguments:[passport, service, txb.pure(item), txb.pure(price, BCS.U64), permission],
|
|
68
|
+
typeArguments:[pay_type]
|
|
69
|
+
})
|
|
70
|
+
} else {
|
|
71
|
+
txb.moveCall({
|
|
72
|
+
target:PROTOCOL.ServiceFn('price_set') as FnCallType,
|
|
73
|
+
arguments:[service, txb.pure(item), txb.pure(price, BCS.U64), permission],
|
|
74
|
+
typeArguments:[pay_type]
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function service_set_stock(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, item:string, stock:number, passport?:PassportObject) {
|
|
79
|
+
if (passport) {
|
|
80
|
+
txb.moveCall({
|
|
81
|
+
target:PROTOCOL.ServiceFn('stock_set_with_passport') as FnCallType,
|
|
82
|
+
arguments:[passport, service, txb.pure(item), txb.pure(stock, BCS.U64), permission],
|
|
83
|
+
typeArguments:[pay_type]
|
|
84
|
+
})
|
|
85
|
+
} else {
|
|
86
|
+
txb.moveCall({
|
|
87
|
+
target:PROTOCOL.ServiceFn('stock_set') as FnCallType,
|
|
88
|
+
arguments:[service, txb.pure(item), txb.pure(stock, BCS.U64), permission],
|
|
89
|
+
typeArguments:[pay_type]
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function service_add_stock(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, item:string, stock_add:number, passport?:PassportObject) {
|
|
94
|
+
if (passport) {
|
|
95
|
+
txb.moveCall({
|
|
96
|
+
target:PROTOCOL.ServiceFn('stock_add_with_passport') as FnCallType,
|
|
97
|
+
arguments:[passport, service, txb.pure(item), txb.pure(stock_add, BCS.U64), permission],
|
|
98
|
+
typeArguments:[pay_type]
|
|
99
|
+
})
|
|
100
|
+
} else {
|
|
101
|
+
txb.moveCall({
|
|
102
|
+
target:PROTOCOL.ServiceFn('stock_add') as FnCallType,
|
|
103
|
+
arguments:[service, txb.pure(item), txb.pure(stock_add, BCS.U64), permission],
|
|
104
|
+
typeArguments:[pay_type]
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export function service_reduce_stock(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, item:string, stock_reduce:number, passport?:PassportObject) {
|
|
109
|
+
if (passport) {
|
|
110
|
+
txb.moveCall({
|
|
111
|
+
target:PROTOCOL.ServiceFn('stock_reduce_with_passport') as FnCallType,
|
|
112
|
+
arguments:[passport, service, txb.pure(item), txb.pure(stock_reduce, BCS.U64), permission],
|
|
113
|
+
typeArguments:[pay_type]
|
|
114
|
+
})
|
|
115
|
+
} else {
|
|
116
|
+
txb.moveCall({
|
|
117
|
+
target:PROTOCOL.ServiceFn('stock_reduce') as FnCallType,
|
|
118
|
+
arguments:[service, txb.pure(item), txb.pure(stock_reduce, BCS.U64), permission],
|
|
119
|
+
typeArguments:[pay_type]
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function service_set_payee(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, payee:string, passport?:PassportObject) {
|
|
124
|
+
if (passport) {
|
|
125
|
+
txb.moveCall({
|
|
126
|
+
target:PROTOCOL.ServiceFn('payee_set_with_passport') as FnCallType,
|
|
127
|
+
arguments:[passport, service, txb.pure(payee, BCS.ADDRESS), permission],
|
|
128
|
+
typeArguments:[pay_type]
|
|
129
|
+
})
|
|
130
|
+
} else {
|
|
131
|
+
txb.moveCall({
|
|
132
|
+
target:PROTOCOL.ServiceFn('payee_set') as FnCallType,
|
|
133
|
+
arguments:[service, txb.pure(payee, BCS.ADDRESS), permission],
|
|
134
|
+
typeArguments:[pay_type]
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export function service_repository_add(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, repository:RepositoryObject, passport?:PassportObject) {
|
|
139
|
+
if (passport) {
|
|
140
|
+
txb.moveCall({
|
|
141
|
+
target:PROTOCOL.ServiceFn('repository_add_with_passport') as FnCallType,
|
|
142
|
+
arguments:[service, repository, permission],
|
|
143
|
+
typeArguments:[pay_type]
|
|
144
|
+
})
|
|
145
|
+
} else {
|
|
146
|
+
txb.moveCall({
|
|
147
|
+
target:PROTOCOL.ServiceFn('repository_add') as FnCallType,
|
|
148
|
+
arguments:[service, repository, permission],
|
|
149
|
+
typeArguments:[pay_type]
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export function service_repository_remove(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, repository_address:string[], removeall?:boolean, passport?:PassportObject) {
|
|
154
|
+
if (passport) {
|
|
155
|
+
if (removeall) {
|
|
156
|
+
txb.moveCall({
|
|
157
|
+
target:PROTOCOL.ServiceFn('repository_remove_all_with_passport') as FnCallType,
|
|
158
|
+
arguments:[passport, service, permission],
|
|
159
|
+
typeArguments:[pay_type]
|
|
160
|
+
})
|
|
161
|
+
} else {
|
|
162
|
+
repository_address.forEach((rep_addr) => {
|
|
163
|
+
txb.moveCall({
|
|
164
|
+
target:PROTOCOL.ServiceFn('repository_remove_with_passport') as FnCallType,
|
|
165
|
+
arguments:[passport, service, txb.pure(rep_addr, BCS.ADDRESS), permission],
|
|
166
|
+
typeArguments:[pay_type]
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
if (removeall) {
|
|
172
|
+
txb.moveCall({
|
|
173
|
+
target:PROTOCOL.ServiceFn('repository_remove_all') as FnCallType,
|
|
174
|
+
arguments:[service, permission],
|
|
175
|
+
typeArguments:[pay_type]
|
|
176
|
+
})
|
|
177
|
+
} else {
|
|
178
|
+
repository_address.forEach((rep_addr) => {
|
|
179
|
+
txb.moveCall({
|
|
180
|
+
target:PROTOCOL.ServiceFn('repository_remove') as FnCallType,
|
|
181
|
+
arguments:[service, txb.pure(rep_addr, BCS.ADDRESS), permission],
|
|
182
|
+
typeArguments:[pay_type]
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export type Service_Guard_Percent = {
|
|
189
|
+
guard:GuardObject | string;
|
|
190
|
+
percent: number;
|
|
191
|
+
}
|
|
192
|
+
export function service_add_withdraw_guards(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, guards:Service_Guard_Percent[], passport?:PassportObject) {
|
|
193
|
+
guards.forEach((guard) => {
|
|
194
|
+
let arg: string | TransactionResult = guard.guard;
|
|
195
|
+
if (typeof arg == "string") {
|
|
196
|
+
arg = txb.object(guard.guard) as TransactionResult
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (passport) {
|
|
200
|
+
txb.moveCall({
|
|
201
|
+
target:PROTOCOL.ServiceFn('withdraw_guard_add_with_passport') as FnCallType,
|
|
202
|
+
arguments:[passport, service, arg, txb.pure(guard.percent, BCS.U8), permission],
|
|
203
|
+
typeArguments:[pay_type]
|
|
204
|
+
})
|
|
205
|
+
} else {
|
|
206
|
+
txb.moveCall({
|
|
207
|
+
target:PROTOCOL.ServiceFn('withdraw_guard_add') as FnCallType,
|
|
208
|
+
arguments:[service, arg, txb.pure(guard.percent, BCS.U8), permission],
|
|
209
|
+
typeArguments:[pay_type]
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
export function service_remove_withdraw_guards(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, guard_address:string[], passport?:PassportObject) {
|
|
215
|
+
guard_address.forEach((guard) => {
|
|
216
|
+
if (passport) {
|
|
217
|
+
txb.moveCall({
|
|
218
|
+
target:PROTOCOL.ServiceFn('withdraw_guard_remove_with_passport') as FnCallType,
|
|
219
|
+
arguments:[passport, service, txb.pure(guard, BCS.ADDRESS), permission],
|
|
220
|
+
typeArguments:[pay_type]
|
|
221
|
+
})
|
|
222
|
+
} else {
|
|
223
|
+
txb.moveCall({
|
|
224
|
+
target:PROTOCOL.ServiceFn('withdraw_guard_remove') as FnCallType,
|
|
225
|
+
arguments:[service, txb.pure(guard, BCS.ADDRESS), permission],
|
|
226
|
+
typeArguments:[pay_type]
|
|
227
|
+
})
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
export function service_add_refund_guards(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, guards:Service_Guard_Percent[], passport?:PassportObject) {
|
|
232
|
+
guards.forEach((guard) => {
|
|
233
|
+
let arg: string | TransactionResult = guard.guard;
|
|
234
|
+
if (typeof arg == "string") {
|
|
235
|
+
arg = txb.object(guard.guard) as TransactionResult
|
|
236
|
+
}
|
|
237
|
+
if (passport) {
|
|
238
|
+
txb.moveCall({
|
|
239
|
+
target:PROTOCOL.ServiceFn('refund_guard_add_with_passport') as FnCallType,
|
|
240
|
+
arguments:[passport, service, arg, txb.pure(guard.percent, BCS.U8), permission],
|
|
241
|
+
typeArguments:[pay_type]
|
|
242
|
+
})
|
|
243
|
+
} else {
|
|
244
|
+
txb.moveCall({
|
|
245
|
+
target:PROTOCOL.ServiceFn('refund_guard_add') as FnCallType,
|
|
246
|
+
arguments:[service, arg, txb.pure(guard.percent, BCS.U8), permission],
|
|
247
|
+
typeArguments:[pay_type]
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
export function service_remove_refund_guards(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, guard_address:string[]) {
|
|
253
|
+
guard_address.forEach((guard) => {
|
|
254
|
+
txb.moveCall({
|
|
255
|
+
target:PROTOCOL.ServiceFn('refund_guard_remove') as FnCallType,
|
|
256
|
+
arguments:[service, txb.pure(guard, BCS.ADDRESS), permission],
|
|
257
|
+
typeArguments:[pay_type]
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
export type Service_Sale = {
|
|
262
|
+
item:string;
|
|
263
|
+
price:number;
|
|
264
|
+
stock:number;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function service_add_sale(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, sales:Service_Sale[], passport?:PassportObject) {
|
|
268
|
+
if (passport) {
|
|
269
|
+
sales.forEach((sale) => txb.moveCall({
|
|
270
|
+
target:PROTOCOL.ServiceFn('sales_add_with_passport') as FnCallType,
|
|
271
|
+
arguments:[passport, service, txb.pure(description_data(sale.item)), txb.pure(sale.price, BCS.U64), txb.pure(sale.stock, BCS.U64), permission],
|
|
272
|
+
typeArguments:[pay_type]
|
|
273
|
+
}))
|
|
274
|
+
} else {
|
|
275
|
+
sales.forEach((sale) => txb.moveCall({
|
|
276
|
+
target:PROTOCOL.ServiceFn('sales_add') as FnCallType,
|
|
277
|
+
arguments:[service, txb.pure(description_data(sale.item)), txb.pure(sale.price, BCS.U64), txb.pure(sale.stock, BCS.U64), permission],
|
|
278
|
+
typeArguments:[pay_type]
|
|
279
|
+
}))
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
export function service_remove_sale(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, sales:string[], passport?:PassportObject) {
|
|
283
|
+
if (passport) {
|
|
284
|
+
sales.forEach((sale) => txb.moveCall({
|
|
285
|
+
target:PROTOCOL.ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
286
|
+
arguments:[passport, service, txb.pure(description_data(sale)), permission],
|
|
287
|
+
typeArguments:[pay_type]
|
|
288
|
+
}))
|
|
289
|
+
} else {
|
|
290
|
+
sales.forEach((sale) => txb.moveCall({
|
|
291
|
+
target:PROTOCOL.ServiceFn('sales_remove') as FnCallType,
|
|
292
|
+
arguments:[service, txb.pure(description_data(sale)), permission],
|
|
293
|
+
typeArguments:[pay_type]
|
|
294
|
+
}))
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export enum Service_Discount_Type {
|
|
299
|
+
ratio = 0, // -off%
|
|
300
|
+
minus = 1, // -off
|
|
301
|
+
}
|
|
302
|
+
export type Service_Discount = {
|
|
303
|
+
name: string;
|
|
304
|
+
type: Service_Discount_Type;
|
|
305
|
+
off: number;
|
|
306
|
+
duration_minutes: number;
|
|
307
|
+
time_start?: number; // current time if undefined
|
|
308
|
+
price_greater?: number;
|
|
309
|
+
}
|
|
310
|
+
const MAX_DISCOUNT_TRANSFER_COUNT = 200;
|
|
311
|
+
const MAX_DISCOUNT_RECEIVER_COUNT = 100;
|
|
312
|
+
|
|
313
|
+
export type DicountDispatch = {
|
|
314
|
+
receiver: string;
|
|
315
|
+
count: number;
|
|
316
|
+
discount: Service_Discount;
|
|
317
|
+
}
|
|
318
|
+
export const MAX_DISCOUNT_COUNT_ONCE = 100;
|
|
319
|
+
|
|
320
|
+
export function service_discount_transfer(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, discount_dispatch:DicountDispatch[], passport?:PassportObject) {
|
|
321
|
+
if (discount_dispatch.length > MAX_DISCOUNT_RECEIVER_COUNT) return undefined;
|
|
322
|
+
|
|
323
|
+
for (let i = 0; i < discount_dispatch.length; i ++ ) {
|
|
324
|
+
if (discount_dispatch[i].count > MAX_DISCOUNT_TRANSFER_COUNT) {
|
|
325
|
+
return undefined
|
|
326
|
+
}
|
|
327
|
+
if (discount_dispatch[i].discount.type == Service_Discount_Type.ratio) {
|
|
328
|
+
if (discount_dispatch[i].discount.off > 100) return undefined;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
discount_dispatch.forEach((discount) => {
|
|
333
|
+
if (discount.discount.duration_minutes == 0) return;
|
|
334
|
+
if (discount.count > MAX_DISCOUNT_COUNT_ONCE || discount.count == 0) return;
|
|
335
|
+
|
|
336
|
+
let price_greater = txb.pure([], BCS.U8);
|
|
337
|
+
if (discount.discount?.price_greater) {
|
|
338
|
+
price_greater = txb.pure(BCS_CONVERT.ser_option_u64(discount.discount.price_greater));
|
|
339
|
+
}
|
|
340
|
+
let time_start = txb.pure([], BCS.U8);
|
|
341
|
+
if (discount.discount.time_start) {
|
|
342
|
+
time_start = txb.pure(BCS_CONVERT.ser_option_u64(discount.discount.time_start));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (passport) {
|
|
346
|
+
txb.moveCall({
|
|
347
|
+
target:PROTOCOL.ServiceFn('dicscount_create_with_passport') as FnCallType,
|
|
348
|
+
arguments:[passport, service, txb.pure(name_data(discount.discount.name)), txb.pure(discount.discount.type, BCS.U8), txb.pure(discount.discount.off, BCS.U64), price_greater,
|
|
349
|
+
time_start, txb.pure(discount.discount.duration_minutes, BCS.U64), txb.pure(discount.count, BCS.U64), permission, txb.pure(discount.receiver, BCS.ADDRESS), txb.object(CLOCK_OBJECT)],
|
|
350
|
+
typeArguments:[pay_type]
|
|
351
|
+
});
|
|
352
|
+
} else {
|
|
353
|
+
txb.moveCall({
|
|
354
|
+
target:PROTOCOL.ServiceFn('dicscount_create') as FnCallType,
|
|
355
|
+
arguments:[service, txb.pure(name_data(discount.discount.name)), txb.pure(discount.discount.type, BCS.U8), txb.pure(discount.discount.off, BCS.U64), price_greater,
|
|
356
|
+
time_start, txb.pure(discount.discount.duration_minutes, BCS.U64), txb.pure(discount.count, BCS.U64), permission, txb.pure(discount.receiver, BCS.ADDRESS), txb.object(CLOCK_OBJECT)],
|
|
357
|
+
typeArguments:[pay_type]
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
export type OrderObject = TransactionResult;
|
|
363
|
+
export type OrderAddress = TransactionResult;
|
|
364
|
+
|
|
365
|
+
// 同时支持withdraw guard和permission guard
|
|
366
|
+
export function service_withdraw(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, order:OrderObject, passport?:PassportObject) {
|
|
367
|
+
if (passport) {
|
|
368
|
+
txb.moveCall({
|
|
369
|
+
target:PROTOCOL.ServiceFn('withdraw_with_passport') as FnCallType,
|
|
370
|
+
arguments:[passport, service, order, passport, permission],
|
|
371
|
+
typeArguments:[pay_type]
|
|
372
|
+
})
|
|
373
|
+
} else {
|
|
374
|
+
txb.moveCall({
|
|
375
|
+
target:PROTOCOL.ServiceFn('withdraw') as FnCallType,
|
|
376
|
+
arguments:[service, order, permission],
|
|
377
|
+
typeArguments:[pay_type]
|
|
378
|
+
})
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
export function service_set_buy_guard(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, guard?:GuardObject, passport?:PassportObject) {
|
|
382
|
+
if (passport) {
|
|
383
|
+
if (guard) {
|
|
384
|
+
txb.moveCall({
|
|
385
|
+
target:PROTOCOL.ServiceFn('buy_guard_set_with_passport') as FnCallType,
|
|
386
|
+
arguments:[passport, service, guard, permission],
|
|
387
|
+
typeArguments:[pay_type]
|
|
388
|
+
})
|
|
389
|
+
} else {
|
|
390
|
+
txb.moveCall({
|
|
391
|
+
target:PROTOCOL.ServiceFn('buy_guard_none_with_passport') as FnCallType,
|
|
392
|
+
arguments:[passport, service, permission],
|
|
393
|
+
typeArguments:[pay_type]
|
|
394
|
+
})
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
if (guard) {
|
|
398
|
+
txb.moveCall({
|
|
399
|
+
target:PROTOCOL.ServiceFn('buy_guard_set') as FnCallType,
|
|
400
|
+
arguments:[service, guard, permission],
|
|
401
|
+
typeArguments:[pay_type]
|
|
402
|
+
})
|
|
403
|
+
} else {
|
|
404
|
+
txb.moveCall({
|
|
405
|
+
target:PROTOCOL.ServiceFn('buy_guard_none') as FnCallType,
|
|
406
|
+
arguments:[service, permission],
|
|
407
|
+
typeArguments:[pay_type]
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
export function service_set_machine(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, machine?:MachineObject, passport?:PassportObject) {
|
|
413
|
+
if (passport) {
|
|
414
|
+
if (machine) {
|
|
415
|
+
txb.moveCall({
|
|
416
|
+
target:PROTOCOL.ServiceFn('machine_set_with_passport') as FnCallType,
|
|
417
|
+
arguments:[passport, service, machine, permission],
|
|
418
|
+
typeArguments:[pay_type]
|
|
419
|
+
})
|
|
420
|
+
} else {
|
|
421
|
+
txb.moveCall({
|
|
422
|
+
target:PROTOCOL.ServiceFn('machine_none_with_passport') as FnCallType,
|
|
423
|
+
arguments:[passport, service, permission],
|
|
424
|
+
typeArguments:[pay_type]
|
|
425
|
+
})
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
if (machine) {
|
|
429
|
+
txb.moveCall({
|
|
430
|
+
target:PROTOCOL.ServiceFn('machine_set') as FnCallType,
|
|
431
|
+
arguments:[service, machine, permission],
|
|
432
|
+
typeArguments:[pay_type]
|
|
433
|
+
})
|
|
434
|
+
} else {
|
|
435
|
+
txb.moveCall({
|
|
436
|
+
target:PROTOCOL.ServiceFn('machine_none') as FnCallType,
|
|
437
|
+
arguments:[service, permission],
|
|
438
|
+
typeArguments:[pay_type]
|
|
439
|
+
})
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export function service_set_endpoint(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, endpoint_url?:string, passport?:PassportObject) {
|
|
445
|
+
if (endpoint_url && endpoint_url.length > MAX_ENDPOINT_LENGTH) return undefined;
|
|
446
|
+
let endpoint = endpoint_url ? txb.pure(endpoint_url) : txb.pure([], BCS.U8);
|
|
447
|
+
if (passport) {
|
|
448
|
+
txb.moveCall({
|
|
449
|
+
target:PROTOCOL.ServiceFn('endpoint_set_with_passport') as FnCallType,
|
|
450
|
+
arguments:[passport, service, endpoint, permission],
|
|
451
|
+
typeArguments:[pay_type]
|
|
452
|
+
})
|
|
453
|
+
} else {
|
|
454
|
+
txb.moveCall({
|
|
455
|
+
target:PROTOCOL.ServiceFn('endpoint_set') as FnCallType,
|
|
456
|
+
arguments:[service, endpoint, permission],
|
|
457
|
+
typeArguments:[pay_type]
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
export function service_publish(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, passport?:PassportObject) {
|
|
462
|
+
if (passport) {
|
|
463
|
+
txb.moveCall({
|
|
464
|
+
target:PROTOCOL.ServiceFn('publish_with_passport') as FnCallType,
|
|
465
|
+
arguments:[passport, service, permission],
|
|
466
|
+
typeArguments:[pay_type]
|
|
467
|
+
})
|
|
468
|
+
} else {
|
|
469
|
+
txb.moveCall({
|
|
470
|
+
target:PROTOCOL.ServiceFn('publish') as FnCallType,
|
|
471
|
+
arguments:[service, permission],
|
|
472
|
+
typeArguments:[pay_type]
|
|
473
|
+
})
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
export function service_clone(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, passport?:PassportObject) : ServiceObject{
|
|
477
|
+
if (passport) {
|
|
478
|
+
return txb.moveCall({
|
|
479
|
+
target:PROTOCOL.ServiceFn('clone_withpassport') as FnCallType,
|
|
480
|
+
arguments:[passport, service, permission],
|
|
481
|
+
typeArguments:[pay_type]
|
|
482
|
+
})
|
|
483
|
+
} else {
|
|
484
|
+
return txb.moveCall({
|
|
485
|
+
target:PROTOCOL.ServiceFn('clone') as FnCallType,
|
|
486
|
+
arguments:[service, permission],
|
|
487
|
+
typeArguments:[pay_type]
|
|
488
|
+
})
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export type Service_Buy_RequiredInfo = {
|
|
493
|
+
service_pubkey: string;
|
|
494
|
+
customer_info: string[];
|
|
495
|
+
}
|
|
496
|
+
export type Customer_RequiredInfo = {
|
|
497
|
+
service_pubkey: string;
|
|
498
|
+
customer_pubkey: string;
|
|
499
|
+
customer_info_crypt: string[];
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export function service_set_customer_required(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject,
|
|
503
|
+
service_pubkey:string, customer_required: string[], passport?:PassportObject) {
|
|
504
|
+
if (service_pubkey.length == 0 || customer_required.length == 0) return undefined;
|
|
505
|
+
|
|
506
|
+
if (passport) {
|
|
507
|
+
txb.moveCall({
|
|
508
|
+
target:PROTOCOL.ServiceFn('required_set_with_passport') as FnCallType,
|
|
509
|
+
arguments:[passport, service, txb.pure(customer_required, 'vector<string>'), txb.pure(service_pubkey, 'vector<u8>'), permission],
|
|
510
|
+
typeArguments:[pay_type]
|
|
511
|
+
})
|
|
512
|
+
} else {
|
|
513
|
+
txb.moveCall({
|
|
514
|
+
target:PROTOCOL.ServiceFn('required_set') as FnCallType,
|
|
515
|
+
arguments:[service, txb.pure(customer_required, 'vector<string>'), txb.pure(service_pubkey, 'vector<u8>'), permission],
|
|
516
|
+
typeArguments:[pay_type]
|
|
517
|
+
})
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
export function service_remove_customer_required(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, passport?:PassportObject) {
|
|
521
|
+
if (passport) {
|
|
522
|
+
txb.moveCall({
|
|
523
|
+
target:PROTOCOL.ServiceFn('required_none_with_passport') as FnCallType,
|
|
524
|
+
arguments:[passport, service, permission],
|
|
525
|
+
typeArguments:[pay_type]
|
|
526
|
+
})
|
|
527
|
+
} else {
|
|
528
|
+
txb.moveCall({
|
|
529
|
+
target:PROTOCOL.ServiceFn('required_none') as FnCallType,
|
|
530
|
+
arguments:[service, permission],
|
|
531
|
+
typeArguments:[pay_type]
|
|
532
|
+
})
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
export function service_change_required_pubkey(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, service_pubkey:string, passport?:PassportObject) {
|
|
536
|
+
if (!service_pubkey) return undefined;
|
|
537
|
+
|
|
538
|
+
if (passport) {
|
|
539
|
+
txb.moveCall({
|
|
540
|
+
target:PROTOCOL.ServiceFn('required_pubkey_set_with_passport') as FnCallType,
|
|
541
|
+
arguments:[passport, service, txb.pure(service_pubkey, 'vector<u8>'), permission],
|
|
542
|
+
typeArguments:[pay_type]
|
|
543
|
+
})
|
|
544
|
+
} else {
|
|
545
|
+
txb.moveCall({
|
|
546
|
+
target:PROTOCOL.ServiceFn('required_pubkey_set') as FnCallType,
|
|
547
|
+
arguments:[service, txb.pure(service_pubkey, 'vector<u8>'), permission],
|
|
548
|
+
typeArguments:[pay_type]
|
|
549
|
+
})
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
export function service_change_order_required_pubkey(pay_type:string, txb:TransactionBlock, service:ServiceObject,
|
|
553
|
+
permission:PermissionObject, order:OrderObject, service_pubkey:string, passport?:PassportObject) {
|
|
554
|
+
if (!service_pubkey) return undefined;
|
|
555
|
+
|
|
556
|
+
if (passport) {
|
|
557
|
+
txb.moveCall({
|
|
558
|
+
target:PROTOCOL.ServiceFn('order_pubkey_update_with_passport') as FnCallType,
|
|
559
|
+
arguments:[passport, service, order, txb.pure(service_pubkey, 'vector<u8>'), permission],
|
|
560
|
+
typeArguments:[pay_type]
|
|
561
|
+
})
|
|
562
|
+
} else {
|
|
563
|
+
txb.moveCall({
|
|
564
|
+
target:PROTOCOL.ServiceFn('order_pubkey_update') as FnCallType,
|
|
565
|
+
arguments:[service, order, txb.pure(service_pubkey, 'vector<u8>'), permission],
|
|
566
|
+
typeArguments:[pay_type]
|
|
567
|
+
})
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
export function service_pause(pay_type:string, txb:TransactionBlock, service:ServiceObject, permission:PermissionObject, pause:boolean, passport?:PassportObject) {
|
|
571
|
+
if (passport) {
|
|
572
|
+
txb.moveCall({
|
|
573
|
+
target:PROTOCOL.ServiceFn('pause_with_passport') as FnCallType,
|
|
574
|
+
arguments:[passport, service, txb.pure(pause, BCS.BOOL), permission],
|
|
575
|
+
typeArguments:[pay_type]
|
|
576
|
+
})
|
|
577
|
+
} else {
|
|
578
|
+
txb.moveCall({
|
|
579
|
+
target:PROTOCOL.ServiceFn('pause') as FnCallType,
|
|
580
|
+
arguments:[service, txb.pure(pause, BCS.BOOL), permission],
|
|
581
|
+
typeArguments:[pay_type]
|
|
582
|
+
})
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
export function customer_refund(pay_type:string, txb:TransactionBlock, service:ServiceObject, order:OrderObject, passport?:PassportObject) {
|
|
586
|
+
if (passport) {
|
|
587
|
+
txb.moveCall({
|
|
588
|
+
target:PROTOCOL.ServiceFn('refund_with_passport') as FnCallType,
|
|
589
|
+
arguments:[service, order, passport],
|
|
590
|
+
typeArguments:[pay_type]
|
|
591
|
+
})
|
|
592
|
+
} else {
|
|
593
|
+
txb.moveCall({
|
|
594
|
+
target:PROTOCOL.ServiceFn('refund') as FnCallType,
|
|
595
|
+
arguments:[service, order],
|
|
596
|
+
typeArguments:[pay_type]
|
|
597
|
+
})
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
export type Service_Buy = {
|
|
601
|
+
item: string;
|
|
602
|
+
count: number;
|
|
603
|
+
}
|
|
604
|
+
export type DiscountObject = TransactionResult;
|
|
605
|
+
export type CoinObject = TransactionResult;
|
|
606
|
+
|
|
607
|
+
export function update_order_required_info(pay_type:string, txb:TransactionBlock, service:ServiceObject,
|
|
608
|
+
order:OrderObject, customer_info_crypto: Customer_RequiredInfo) {
|
|
609
|
+
txb.moveCall({
|
|
610
|
+
target:PROTOCOL.ServiceFn('order_required_info_update') as FnCallType,
|
|
611
|
+
arguments:[service, order, txb.pure(customer_info_crypto.service_pubkey, 'vector<u8>'),
|
|
612
|
+
txb.pure(customer_info_crypto.customer_pubkey, 'vector<u8>'),
|
|
613
|
+
txb.pure(customer_info_crypto.customer_info_crypt, 'vector<string>')],
|
|
614
|
+
typeArguments:[pay_type]
|
|
615
|
+
})
|
|
616
|
+
}
|
|
617
|
+
export function buy(pay_type:string, txb:TransactionBlock, service:ServiceObject, buy_items:Service_Buy[], coin:CoinObject, discount?:DiscountObject,
|
|
618
|
+
service_machine?:MachineObject, customer_info_crypto?: Customer_RequiredInfo, passport?:PassportObject) : OrderAddress | undefined {
|
|
619
|
+
if (buy_items.length == 0) return undefined;
|
|
620
|
+
|
|
621
|
+
let i:string[] = []; let c:number[] = []; let order;
|
|
622
|
+
buy_items.forEach((item) => { i.push(item.item); c.push(item.count); })
|
|
623
|
+
|
|
624
|
+
if (passport) {
|
|
625
|
+
if (discount) {
|
|
626
|
+
order = txb.moveCall({
|
|
627
|
+
target:PROTOCOL.ServiceFn('dicount_buy_with_passport') as FnCallType,
|
|
628
|
+
arguments: [passport, service, txb.pure(BCS_CONVERT.ser_vector_string(i)),
|
|
629
|
+
txb.pure(BCS_CONVERT.ser_vector_u64(c)), coin, discount, txb.object(CLOCK_OBJECT)], typeArguments:[pay_type]
|
|
630
|
+
})} else {
|
|
631
|
+
order = txb.moveCall({
|
|
632
|
+
target:PROTOCOL.ServiceFn('buy_with_passport') as FnCallType,
|
|
633
|
+
arguments: [passport, service, txb.pure(BCS_CONVERT.ser_vector_string(i)),
|
|
634
|
+
txb.pure(BCS_CONVERT.ser_vector_u64(c)), coin],
|
|
635
|
+
typeArguments:[pay_type]
|
|
636
|
+
})}
|
|
637
|
+
} else {
|
|
638
|
+
if (discount) {
|
|
639
|
+
order = txb.moveCall({
|
|
640
|
+
target:PROTOCOL.ServiceFn('disoucnt_buy') as FnCallType,
|
|
641
|
+
arguments: [service, txb.pure(BCS_CONVERT.ser_vector_string(i)),
|
|
642
|
+
txb.pure(BCS_CONVERT.ser_vector_u64(c)), coin, discount, txb.object(CLOCK_OBJECT)],
|
|
643
|
+
typeArguments:[pay_type]
|
|
644
|
+
})} else {
|
|
645
|
+
order = txb.moveCall({
|
|
646
|
+
target:PROTOCOL.ServiceFn('buy') as FnCallType,
|
|
647
|
+
arguments: [service, txb.pure(BCS_CONVERT.ser_vector_string(i)),
|
|
648
|
+
txb.pure(BCS_CONVERT.ser_vector_u64(c)), coin],
|
|
649
|
+
typeArguments:[pay_type]
|
|
650
|
+
})}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (customer_info_crypto) {
|
|
654
|
+
update_order_required_info(pay_type, txb, service, order, customer_info_crypto);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (service_machine) {
|
|
658
|
+
return txb.moveCall({
|
|
659
|
+
target:PROTOCOL.ServiceFn('order_create_with_machine') as FnCallType,
|
|
660
|
+
arguments: [service, order, service_machine],
|
|
661
|
+
typeArguments:[pay_type]
|
|
662
|
+
})
|
|
663
|
+
} else {
|
|
664
|
+
return txb.moveCall({
|
|
665
|
+
target:PROTOCOL.ServiceFn('order_create') as FnCallType,
|
|
666
|
+
arguments: [service, order],
|
|
667
|
+
typeArguments:[pay_type]
|
|
668
|
+
})
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
export function order_bind_service_machine(pay_type:string, txb:TransactionBlock, service:ServiceObject, order:OrderObject, service_machine:MachineObject) {
|
|
673
|
+
txb.moveCall({
|
|
674
|
+
target:PROTOCOL.ServiceFn('order_create_with_machine') as FnCallType,
|
|
675
|
+
arguments: [service, order, service_machine],
|
|
676
|
+
typeArguments:[pay_type]
|
|
677
|
+
})
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export function change_permission(pay_type:string, txb:TransactionBlock, service:ServiceObject, old_permission:PermissionObject, new_permission:PermissionObject) {
|
|
681
|
+
txb.moveCall({
|
|
682
|
+
target:PROTOCOL.ServiceFn('permission_set') as FnCallType,
|
|
683
|
+
arguments: [service, old_permission, new_permission],
|
|
684
|
+
typeArguments:[pay_type]
|
|
685
|
+
})
|
|
686
|
+
}
|