wowok 1.7.13 → 1.7.16
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/arbitration.d.ts.map +1 -1
- package/dist/arbitration.js +21 -32
- package/dist/arbitration.js.map +1 -1
- package/dist/entity.d.ts +1 -0
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +12 -6
- package/dist/entity.js.map +1 -1
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/exception.js.map +1 -1
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +8 -4
- package/dist/guard.js.map +1 -1
- package/dist/payment.d.ts +2 -2
- package/dist/payment.d.ts.map +1 -1
- package/dist/payment.js +2 -2
- package/dist/payment.js.map +1 -1
- package/dist/protocol.d.ts +21 -19
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +211 -58
- package/dist/protocol.js.map +1 -1
- package/dist/service.d.ts +2 -2
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +5 -6
- package/dist/service.js.map +1 -1
- package/package.json +5 -2
- package/src/arbitration.ts +0 -551
- package/src/demand.ts +0 -300
- package/src/entity.ts +0 -171
- package/src/exception.ts +0 -37
- package/src/guard.ts +0 -810
- package/src/index.ts +0 -40
- package/src/machine.ts +0 -542
- package/src/passport.ts +0 -777
- package/src/payment.ts +0 -94
- package/src/permission.ts +0 -550
- package/src/progress.ts +0 -367
- package/src/protocol.ts +0 -549
- package/src/repository.ts +0 -680
- package/src/resource.ts +0 -155
- package/src/service.ts +0 -1349
- package/src/treasury.ts +0 -425
- package/src/utils.ts +0 -660
- package/src/wowok.ts +0 -70
- package/tsconfig.json +0 -30
- package/tsconfig.tsbuildinfo +0 -1
- package/webpack.config.cjs +0 -23
package/src/demand.ts
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
2
|
-
import { FnCallType, Protocol, PassportObject, PermissionObject, GuardObject, DemandAddress, TxbObject, ServiceObject } from './protocol.js';
|
|
3
|
-
import { IsValidDesription, IsValidAddress, IsValidArgType, IsValidU64, parseObjectType, IsValidU8, IsValidLocation } from './utils.js'
|
|
4
|
-
import { Errors, ERROR} from './exception.js'
|
|
5
|
-
|
|
6
|
-
export class Demand {
|
|
7
|
-
protected bounty_type;
|
|
8
|
-
protected permission ;
|
|
9
|
-
protected object : TxbObject;
|
|
10
|
-
protected txb;
|
|
11
|
-
|
|
12
|
-
get_bounty_type() { return this.bounty_type }
|
|
13
|
-
get_object() { return this.object }
|
|
14
|
-
|
|
15
|
-
static From(txb:TransactionBlock, bounty_type:string, permission:PermissionObject, object:TxbObject) : Demand {
|
|
16
|
-
let d = new Demand(txb, bounty_type, permission)
|
|
17
|
-
d.object = Protocol.TXB_OBJECT(txb, object)
|
|
18
|
-
return d
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
private constructor(txb:TransactionBlock, bounty_type:string, permission:PermissionObject) {
|
|
22
|
-
this.bounty_type = bounty_type;
|
|
23
|
-
this.permission = permission;
|
|
24
|
-
this.txb = txb;
|
|
25
|
-
this.object = '';
|
|
26
|
-
}
|
|
27
|
-
static New(txb:TransactionBlock, bounty_type:string, minutes_duration:boolean, time:number, permission:PermissionObject, description:string,
|
|
28
|
-
passport?:PassportObject) : Demand {
|
|
29
|
-
if (!IsValidDesription(description)) {
|
|
30
|
-
ERROR(Errors.IsValidDesription);
|
|
31
|
-
}
|
|
32
|
-
if (!IsValidArgType(bounty_type)) {
|
|
33
|
-
ERROR(Errors.IsValidArgType, bounty_type);
|
|
34
|
-
}
|
|
35
|
-
if (!IsValidU64(time)) {
|
|
36
|
-
ERROR(Errors.IsValidUint, 'time')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let d = new Demand(txb, bounty_type, permission);
|
|
40
|
-
const clock = txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
41
|
-
if (minutes_duration) time = time * 1000 * 60; //@ duration minutes
|
|
42
|
-
if (passport) {
|
|
43
|
-
d.object = txb.moveCall({
|
|
44
|
-
target:Protocol.Instance().demandFn('new_with_passport') as FnCallType,
|
|
45
|
-
arguments:[passport, txb.pure.string(description), txb.pure.bool(minutes_duration), txb.pure.u64(time),
|
|
46
|
-
txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
|
|
47
|
-
typeArguments:[bounty_type],
|
|
48
|
-
})
|
|
49
|
-
} else {
|
|
50
|
-
d.object = txb.moveCall({
|
|
51
|
-
target:Protocol.Instance().demandFn('new') as FnCallType,
|
|
52
|
-
arguments:[txb.pure.string(description), txb.pure.bool(minutes_duration), txb.pure.u64(time),
|
|
53
|
-
txb.object(clock), Protocol.TXB_OBJECT(txb, permission)],
|
|
54
|
-
typeArguments:[bounty_type],
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
return d
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
launch() : DemandAddress {
|
|
61
|
-
return this.txb.moveCall({
|
|
62
|
-
target:Protocol.Instance().demandFn('create') as FnCallType,
|
|
63
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
64
|
-
typeArguments:[this.bounty_type],
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
refund(passport?:PassportObject) {
|
|
69
|
-
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
70
|
-
if (passport) {
|
|
71
|
-
this.txb.moveCall({
|
|
72
|
-
target:Protocol.Instance().demandFn('refund_with_passport') as FnCallType,
|
|
73
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
74
|
-
this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
75
|
-
typeArguments:[this.bounty_type],
|
|
76
|
-
})
|
|
77
|
-
} else {
|
|
78
|
-
this.txb.moveCall({
|
|
79
|
-
target:Protocol.Instance().demandFn('refund') as FnCallType,
|
|
80
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.object(clock), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
81
|
-
typeArguments:[this.bounty_type],
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// minutes_duration TRUE , time is minutes count; otherwise, the deadline time
|
|
87
|
-
expand_time(minutes_duration:boolean, time: number, passport?:PassportObject) {
|
|
88
|
-
if (!IsValidU64(time)) {
|
|
89
|
-
ERROR(Errors.IsValidUint, `expand_time.time ${time}`);
|
|
90
|
-
}
|
|
91
|
-
if (minutes_duration) time = time * 1000 * 60; //@ duration minutes
|
|
92
|
-
if (passport) {
|
|
93
|
-
this.txb.moveCall({
|
|
94
|
-
target:Protocol.Instance().demandFn('time_expand_with_passport') as FnCallType,
|
|
95
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(minutes_duration),
|
|
96
|
-
this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
97
|
-
typeArguments:[this.bounty_type],
|
|
98
|
-
})
|
|
99
|
-
} else {
|
|
100
|
-
this.txb.moveCall({
|
|
101
|
-
target:Protocol.Instance().demandFn('time_expand') as FnCallType,
|
|
102
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.bool(minutes_duration),
|
|
103
|
-
this.txb.pure.u64(time), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
104
|
-
typeArguments:[this.bounty_type],
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
set_guard(guard?:GuardObject, service_identifier?:number, passport?:PassportObject) {
|
|
110
|
-
if (guard && !Protocol.IsValidObjects([guard])) {
|
|
111
|
-
ERROR(Errors.IsValidObjects, 'guard');
|
|
112
|
-
}
|
|
113
|
-
if (service_identifier !== undefined && !IsValidU8(service_identifier)) {
|
|
114
|
-
ERROR(Errors.InvalidParam, 'set_guard.service_identifier');
|
|
115
|
-
}
|
|
116
|
-
let id = this.txb.pure.option('u8', service_identifier !== undefined ? service_identifier : undefined);
|
|
117
|
-
|
|
118
|
-
if (passport) {
|
|
119
|
-
if (guard) {
|
|
120
|
-
this.txb.moveCall({
|
|
121
|
-
target:Protocol.Instance().demandFn('guard_set_with_passport') as FnCallType,
|
|
122
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard), id,
|
|
123
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
124
|
-
typeArguments:[this.bounty_type],
|
|
125
|
-
})
|
|
126
|
-
} else {
|
|
127
|
-
this.txb.moveCall({
|
|
128
|
-
target:Protocol.Instance().demandFn('guard_none_with_passport') as FnCallType,
|
|
129
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
130
|
-
typeArguments:[this.bounty_type],
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
if (guard) {
|
|
135
|
-
this.txb.moveCall({
|
|
136
|
-
target:Protocol.Instance().demandFn('guard_set') as FnCallType,
|
|
137
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard), id,
|
|
138
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
139
|
-
typeArguments:[this.bounty_type],
|
|
140
|
-
})
|
|
141
|
-
} else {
|
|
142
|
-
this.txb.moveCall({
|
|
143
|
-
target:Protocol.Instance().demandFn('guard_none') as FnCallType,
|
|
144
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
145
|
-
typeArguments:[this.bounty_type],
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
set_location(location:string, passport?:PassportObject) {
|
|
152
|
-
if (!IsValidLocation(location)) {
|
|
153
|
-
ERROR(Errors.IsValidLocation, `Demand.set_location.location ${location}`);
|
|
154
|
-
}
|
|
155
|
-
if (passport) {
|
|
156
|
-
this.txb.moveCall({
|
|
157
|
-
target:Protocol.Instance().demandFn('location_set_with_passport') as FnCallType,
|
|
158
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(location),
|
|
159
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
160
|
-
typeArguments:[this.bounty_type],
|
|
161
|
-
})
|
|
162
|
-
} else {
|
|
163
|
-
this.txb.moveCall({
|
|
164
|
-
target:Protocol.Instance().demandFn('location_set') as FnCallType,
|
|
165
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(location),
|
|
166
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
167
|
-
typeArguments:[this.bounty_type],
|
|
168
|
-
})
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
set_description(description:string, passport?:PassportObject) {
|
|
173
|
-
if (!IsValidDesription(description)) {
|
|
174
|
-
ERROR(Errors.IsValidDesription);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (passport) {
|
|
178
|
-
this.txb.moveCall({
|
|
179
|
-
target:Protocol.Instance().demandFn('description_set_with_passport') as FnCallType,
|
|
180
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description),
|
|
181
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
182
|
-
typeArguments:[this.bounty_type],
|
|
183
|
-
})
|
|
184
|
-
} else {
|
|
185
|
-
this.txb.moveCall({
|
|
186
|
-
target:Protocol.Instance().demandFn('description_set') as FnCallType,
|
|
187
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
188
|
-
typeArguments:[this.bounty_type],
|
|
189
|
-
})
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
yes(service_address:string, passport?:PassportObject) {
|
|
194
|
-
if (!IsValidAddress(service_address)) {
|
|
195
|
-
ERROR(Errors.IsValidAddress, 'yes.service_address')
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (passport) {
|
|
200
|
-
this.txb.moveCall({
|
|
201
|
-
target:Protocol.Instance().demandFn('yes_with_passport') as FnCallType,
|
|
202
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
203
|
-
this.txb.pure.address(service_address),
|
|
204
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
205
|
-
typeArguments:[this.bounty_type],
|
|
206
|
-
})
|
|
207
|
-
} else {
|
|
208
|
-
this.txb.moveCall({
|
|
209
|
-
target:Protocol.Instance().demandFn('yes') as FnCallType,
|
|
210
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
211
|
-
this.txb.pure.address(service_address),
|
|
212
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)],
|
|
213
|
-
typeArguments:[this.bounty_type],
|
|
214
|
-
})
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
deposit(bounty:TxbObject) {
|
|
219
|
-
if (!Protocol.IsValidObjects([bounty])) {
|
|
220
|
-
ERROR(Errors.IsValidObjects)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
this.txb.moveCall({
|
|
224
|
-
target:Protocol.Instance().demandFn('deposit') as FnCallType,
|
|
225
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, bounty)],
|
|
226
|
-
typeArguments:[this.bounty_type],
|
|
227
|
-
})
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
present(service: ServiceObject | number, service_pay_type?:string | null, tips?:string, passport?:PassportObject) {
|
|
231
|
-
tips = tips ?? '';
|
|
232
|
-
if (!IsValidDesription(tips)) {
|
|
233
|
-
ERROR(Errors.IsValidDesription, 'present.tips')
|
|
234
|
-
}
|
|
235
|
-
if (service_pay_type && !IsValidArgType(service_pay_type)) {
|
|
236
|
-
ERROR(Errors.IsValidArgType, 'service_pay_type')
|
|
237
|
-
}
|
|
238
|
-
if (typeof(service) === 'number') {
|
|
239
|
-
if (!IsValidU8(service) || !passport) {
|
|
240
|
-
ERROR(Errors.IsValidU8, 'present.service or present.passport')
|
|
241
|
-
}
|
|
242
|
-
} else {
|
|
243
|
-
if (!Protocol.IsValidObjects([service])) {
|
|
244
|
-
ERROR(Errors.IsValidObjects, 'present.service')
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (passport) {
|
|
249
|
-
if (typeof(service) === 'number') {
|
|
250
|
-
this.txb.moveCall({
|
|
251
|
-
target:Protocol.Instance().demandFn('present_with_passport2') as FnCallType,
|
|
252
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(tips)],
|
|
253
|
-
typeArguments:[this.bounty_type],
|
|
254
|
-
})
|
|
255
|
-
} else {
|
|
256
|
-
if (!service_pay_type) {
|
|
257
|
-
ERROR(Errors.InvalidParam, 'present.service_pay_type')
|
|
258
|
-
}
|
|
259
|
-
this.txb.moveCall({
|
|
260
|
-
target:Protocol.Instance().demandFn('present_with_passport') as FnCallType,
|
|
261
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, service),
|
|
262
|
-
this.txb.pure.string(tips)],
|
|
263
|
-
typeArguments:[this.bounty_type, service_pay_type!],
|
|
264
|
-
})
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
} else {
|
|
268
|
-
if (typeof(service) !== 'number') {
|
|
269
|
-
if(!service_pay_type) {
|
|
270
|
-
ERROR(Errors.InvalidParam, 'present.service_pay_type')
|
|
271
|
-
}
|
|
272
|
-
this.txb.moveCall({
|
|
273
|
-
target:Protocol.Instance().demandFn('present') as FnCallType,
|
|
274
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, service),
|
|
275
|
-
this.txb.pure.string(tips)],
|
|
276
|
-
typeArguments:[this.bounty_type, service_pay_type!],
|
|
277
|
-
})
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
change_permission(new_permission:PermissionObject) {
|
|
282
|
-
if (!Protocol.IsValidObjects([new_permission])) {
|
|
283
|
-
ERROR(Errors.IsValidObjects)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
this.txb.moveCall({
|
|
287
|
-
target:Protocol.Instance().demandFn('permission_set') as FnCallType,
|
|
288
|
-
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
|
|
289
|
-
typeArguments:[this.bounty_type]
|
|
290
|
-
})
|
|
291
|
-
this.permission = new_permission
|
|
292
|
-
}
|
|
293
|
-
static parseObjectType = (chain_type?:string | null) : string => {
|
|
294
|
-
return parseObjectType(chain_type, 'demand::Demand<')
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
static MAX_BOUNTY_COUNT = 300;
|
|
298
|
-
static MAX_PRESENTERS_COUNT = 200;
|
|
299
|
-
}
|
|
300
|
-
|
package/src/entity.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { Protocol, FnCallType, TxbObject, ResourceAddress, ResourceObject} from './protocol.js';
|
|
2
|
-
import { IsValidDesription, IsValidAddress, IsValidName, Bcs, IsValidStringLength} from './utils.js';
|
|
3
|
-
import { ERROR, Errors } from './exception.js';
|
|
4
|
-
import { TagName, Resource } from './resource.js';
|
|
5
|
-
import { Transaction as TransactionBlock, TransactionResult } from '@mysten/sui/transactions';
|
|
6
|
-
|
|
7
|
-
export interface EntityData {
|
|
8
|
-
info?: Map<string, string>,
|
|
9
|
-
resource_object?: string,
|
|
10
|
-
like?: number,
|
|
11
|
-
dislike?: number,
|
|
12
|
-
address?:string,
|
|
13
|
-
description?: string,
|
|
14
|
-
lastActive_digest?: string,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export enum EntityInfo_Default {
|
|
18
|
-
name = 'name',
|
|
19
|
-
avatar = 'avatar',
|
|
20
|
-
x = 'x',
|
|
21
|
-
discord = 'discord',
|
|
22
|
-
location = 'location',
|
|
23
|
-
homepage = 'homepage'
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface EntityInfo {
|
|
27
|
-
title: string;
|
|
28
|
-
value: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class Entity {
|
|
32
|
-
protected object:TxbObject;
|
|
33
|
-
protected txb;
|
|
34
|
-
|
|
35
|
-
get_object() { return this.object }
|
|
36
|
-
private constructor(txb:TransactionBlock) {
|
|
37
|
-
this.txb = txb;
|
|
38
|
-
this.object = '';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static From(txb:TransactionBlock) : Entity {
|
|
42
|
-
let r = new Entity(txb);
|
|
43
|
-
r.object = Protocol.TXB_OBJECT(txb, Protocol.Instance().objectEntity());
|
|
44
|
-
return r
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
mark(resource:Resource, address:string | TransactionResult, like:TagName.Like | TagName.Dislike) {
|
|
48
|
-
if (typeof(address) === 'string' && !IsValidAddress(address)) {
|
|
49
|
-
ERROR(Errors.IsValidAddress, like);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.txb.moveCall({
|
|
53
|
-
target:Protocol.Instance().entityFn(like) as FnCallType,
|
|
54
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object()),
|
|
55
|
-
typeof(address) === 'string' ? this.txb.pure.address(address) : address]
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
add_info(info: Map<string, string>) {
|
|
60
|
-
if (info.size === 0) return ;
|
|
61
|
-
|
|
62
|
-
if (info.size > Entity.MAX_INFO_LENGTH) {
|
|
63
|
-
ERROR(Errors.IsValidValue, `Entity.update: info size too long ${info.size}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
info.forEach((v, k) => {
|
|
67
|
-
if (!IsValidName(k)) {
|
|
68
|
-
ERROR(Errors.IsValidName, `Entity.update: ${k} key too long `);
|
|
69
|
-
}
|
|
70
|
-
if (!IsValidStringLength(v, Entity.MAX_INFO_VALUE_LENGTH)) {
|
|
71
|
-
ERROR(Errors.IsValidValue, `Entity.update: ${k} value too long`);
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
const keys = Array.from(info.keys()).map(v => v.toLocaleLowerCase());
|
|
76
|
-
const values = Array.from(info.values());
|
|
77
|
-
|
|
78
|
-
this.txb.moveCall({
|
|
79
|
-
target:Protocol.Instance().entityFn('info_add') as FnCallType,
|
|
80
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
81
|
-
this.txb.pure.vector('string', keys),
|
|
82
|
-
this.txb.pure.vector('string', values)]
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
remove_info(titles:string[]) {
|
|
87
|
-
if (titles.length === 0) return ;
|
|
88
|
-
const t = titles.map(v => v.toLowerCase());
|
|
89
|
-
this.txb.moveCall({
|
|
90
|
-
target:Protocol.Instance().entityFn('info_remove') as FnCallType,
|
|
91
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
92
|
-
this.txb.pure.vector('string', t)]
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
removeall_info() {
|
|
97
|
-
this.txb.moveCall({
|
|
98
|
-
target:Protocol.Instance().entityFn('info_removeall') as FnCallType,
|
|
99
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
create_resource() : ResourceAddress {
|
|
105
|
-
return this.txb.moveCall({
|
|
106
|
-
target:Protocol.Instance().entityFn('resource_create') as FnCallType,
|
|
107
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
create_resource2(): ResourceObject {
|
|
112
|
-
return this.txb.moveCall({
|
|
113
|
-
target:Protocol.Instance().entityFn('resource_create2') as FnCallType,
|
|
114
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)]
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
set_description(description:string) {
|
|
119
|
-
if (!IsValidDesription(description)) {
|
|
120
|
-
ERROR(Errors.IsValidDesription, 'Entity.set_description');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return this.txb.moveCall({
|
|
124
|
-
target:Protocol.Instance().entityFn('description_set') as FnCallType,
|
|
125
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description)]
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
destroy_resource(resource:Resource) { // Resource must self-owned.
|
|
130
|
-
return this.txb.moveCall({
|
|
131
|
-
target:Protocol.Instance().entityFn('resource_destroy') as FnCallType,
|
|
132
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object())]
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
use_resource(resource:Resource) { // Resource must self-owned.
|
|
137
|
-
return this.txb.moveCall({
|
|
138
|
-
target:Protocol.Instance().entityFn('resource_use') as FnCallType,
|
|
139
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object())]
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
transfer_resource(resource:Resource, new_address:string) { // Resource must self-owned.
|
|
144
|
-
if (!IsValidAddress(new_address)) ERROR(Errors.IsValidAddress, 'transfer_resource');
|
|
145
|
-
|
|
146
|
-
return this.txb.moveCall({
|
|
147
|
-
target:Protocol.Instance().entityFn('resource_transfer') as FnCallType,
|
|
148
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, resource.get_object()),
|
|
149
|
-
this.txb.pure.address(new_address)]
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
static EntityData = async (address:string) : Promise<EntityData|undefined>=> {
|
|
154
|
-
if (IsValidAddress(address)) {
|
|
155
|
-
const res = await Protocol.Client().getDynamicFieldObject({
|
|
156
|
-
parentId:Protocol.Instance().objectEntity(), name:{type:'address', value:address}});
|
|
157
|
-
|
|
158
|
-
const content = (res?.data?.content as any)?.fields;
|
|
159
|
-
const info = new Map<string, string>();
|
|
160
|
-
(content?.value?.fields?.info?.fields?.contents as any)?.forEach((v:any) => {
|
|
161
|
-
info.set(v?.fields?.key, v?.fields?.value)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
return {like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike, address: address,
|
|
165
|
-
resource_object: content?.value?.fields?.resource, lastActive_digest: res?.data?.previousTransaction ?? '',
|
|
166
|
-
info : info, description:content?.value?.fields?.description}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
static MAX_INFO_LENGTH = 32;
|
|
170
|
-
static MAX_INFO_VALUE_LENGTH = 256; // The max length of each info value.
|
|
171
|
-
}
|
package/src/exception.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export enum Errors {
|
|
3
|
-
IsValidDesription = 'invalid description',
|
|
4
|
-
IsValidName = 'invalid name',
|
|
5
|
-
IsValidName_AllowEmpty = 'invalid name',
|
|
6
|
-
IsValidEndpoint = 'invalid endpoint',
|
|
7
|
-
IsValidAddress = 'invalid address',
|
|
8
|
-
IsValidArgType = 'invalid argument type',
|
|
9
|
-
IsValidTokenType = 'invalid token type',
|
|
10
|
-
IsValidUint = 'invalid uint',
|
|
11
|
-
IsValidInt = 'invalid int',
|
|
12
|
-
IsValidU64 = 'invalid u64',
|
|
13
|
-
IsValidU8 = 'invalid u8',
|
|
14
|
-
IsValidPercent = 'invalid percent',
|
|
15
|
-
IsValidArray = 'invalid array',
|
|
16
|
-
IsValidObjects = 'invalid objects',
|
|
17
|
-
AllInvalid = 'one valid at least',
|
|
18
|
-
InvalidParam = 'invalid parameter',
|
|
19
|
-
IsValidPermissionIndex = 'invalid permission index',
|
|
20
|
-
IsValidKey = 'invalid key',
|
|
21
|
-
Fail = 'fail',
|
|
22
|
-
IsValidIndentifier = 'indentifier invalid',
|
|
23
|
-
isValidHttpUrl = 'invalid url',
|
|
24
|
-
IsValidBizPermissionIndex = 'invalid biz-permission index',
|
|
25
|
-
bcsTypeInvalid = 'invalid bcs type',
|
|
26
|
-
IsValidServiceItemName = 'invalid service item name',
|
|
27
|
-
IsValidCoinType = 'not the coin type',
|
|
28
|
-
IsValidGuardIdentifier = 'guard identifier invalid',
|
|
29
|
-
noPermission = 'no permission',
|
|
30
|
-
IsValidValue = 'invalid value',
|
|
31
|
-
IsValidLocation = 'invalid location',
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const ERROR = (error:Errors, info?:any) => {
|
|
35
|
-
const e = error.toString() + (info ? (' ' + info) : '');
|
|
36
|
-
throw e;
|
|
37
|
-
}
|