wowok 1.2.7 → 1.2.9
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 +1 -1
- package/src/demand.ts +5 -5
- package/src/entity.ts +8 -0
- package/src/guard.ts +217 -144
- package/src/machine.ts +205 -53
- package/src/passport.ts +8 -8
- package/src/permission.ts +91 -119
- package/src/progress.ts +101 -43
- package/src/protocol.ts +46 -55
- package/src/repository.ts +107 -20
- package/src/resource.ts +19 -9
- package/src/reward.ts +9 -11
- package/src/service.ts +35 -33
- package/src/utils.ts +88 -43
- package/src/vote.ts +18 -21
- package/src/wowok.ts +2 -2
package/src/protocol.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { SuiClient, SuiObjectResponse, SuiObjectDataOptions, SuiTransactionBlock
|
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
4
4
|
import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
|
|
5
5
|
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
6
|
-
import { capitalize, IsValidArray } from './utils'
|
|
6
|
+
import { capitalize, IsValidAddress, IsValidArray, IsValidU128, IsValidU64, IsValidU8, IsValidUintLarge } from './utils'
|
|
7
7
|
import { GuardConstant } from './guard';
|
|
8
8
|
import { isValidSuiAddress, isValidSuiObjectId } from '@mysten/sui.js/utils'
|
|
9
9
|
|
|
@@ -76,11 +76,25 @@ export enum OperatorType {
|
|
|
76
76
|
TYPE_LOGIC_OR = 21, // OR
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
export const LogicsInfo = [
|
|
80
|
+
[OperatorType.TYPE_LOGIC_AS_U256_GREATER, 'PositiveNumber >'],
|
|
81
|
+
[OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL, 'PositiveNumber >='],
|
|
82
|
+
[OperatorType.TYPE_LOGIC_AS_U256_LESSER, 'PositiveNumber <'],
|
|
83
|
+
[OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL, 'PositiveNumber <='],
|
|
84
|
+
[OperatorType.TYPE_LOGIC_AS_U256_EQUAL, 'PositiveNumber ='],
|
|
85
|
+
[OperatorType.TYPE_LOGIC_EQUAL, 'Strict ='],
|
|
86
|
+
[OperatorType.TYPE_LOGIC_HAS_SUBSTRING, 'Sub String'],
|
|
87
|
+
[OperatorType.TYPE_LOGIC_ALWAYS_TRUE, 'Always True'],
|
|
88
|
+
[OperatorType.TYPE_LOGIC_NOT, 'Not'],
|
|
89
|
+
[OperatorType.TYPE_LOGIC_AND, 'And'],
|
|
90
|
+
[OperatorType.TYPE_LOGIC_OR, 'Or'],
|
|
91
|
+
];
|
|
92
|
+
|
|
79
93
|
export enum ValueType {
|
|
80
94
|
TYPE_BOOL = 100,
|
|
81
95
|
TYPE_ADDRESS = 101,
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
TYPE_U8 = 102,
|
|
97
|
+
TYPE_U64 = 103,
|
|
84
98
|
TYPE_VEC_U8 = 104,
|
|
85
99
|
TYPE_U128 = 105,
|
|
86
100
|
TYPE_VEC_ADDRESS = 106,
|
|
@@ -101,6 +115,7 @@ export enum ValueType {
|
|
|
101
115
|
TYPE_VEC_STRING = 121,
|
|
102
116
|
TYPE_U256 = 122,
|
|
103
117
|
}
|
|
118
|
+
|
|
104
119
|
export enum RepositoryValueType {
|
|
105
120
|
Address = 200,
|
|
106
121
|
Address_Vec = 201,
|
|
@@ -111,58 +126,42 @@ export enum RepositoryValueType {
|
|
|
111
126
|
}
|
|
112
127
|
|
|
113
128
|
export const RepositoryValueTypeInfo = [
|
|
114
|
-
{type: RepositoryValueType.Address, name:'Address', description:'Object id or Personal address.'},
|
|
115
|
-
{type: RepositoryValueType.Address_Vec, name:'Address vector', description:'Vector of address.'},
|
|
116
129
|
{type: RepositoryValueType.String, name:'String', description:'String.'},
|
|
130
|
+
{type: RepositoryValueType.Address, name:'Address', description:'Object id or Personal address.'},
|
|
131
|
+
{type: RepositoryValueType.PositiveNumber, name:'Positive number or Zero', description:'Positive number or 0. including u8, u16 ,..., u256'},
|
|
117
132
|
{type: RepositoryValueType.String_Vec, name:'String vector', description:'Vector of string.'},
|
|
118
|
-
{type: RepositoryValueType.
|
|
119
|
-
{type: RepositoryValueType.PositiveNumber_Vec, name:'Positive number vector', description:'Vector of positive number'},
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
export const ValueTypeInfo = [
|
|
123
|
-
{type:ValueType.TYPE_BOOL, name:'bool'},
|
|
124
|
-
{type:ValueType.TYPE_ADDRESS, name:'address'},
|
|
125
|
-
{type:ValueType.TYPE_U64, name:'u64'},
|
|
126
|
-
{type:ValueType.TYPE_U8, name:'u8'},
|
|
127
|
-
{type:ValueType.TYPE_VEC_U8, name:'vec-u8'},
|
|
128
|
-
{type:ValueType.TYPE_U128, name:'u128'},
|
|
129
|
-
{type:ValueType.TYPE_VEC_ADDRESS, name:'vec-address'},
|
|
130
|
-
{type:ValueType.TYPE_VEC_BOOL, name:'vec-bool'},
|
|
131
|
-
{type:ValueType.TYPE_VEC_VEC_U8, name:'vec-vec-u8'},
|
|
132
|
-
{type:ValueType.TYPE_VEC_U64, name:'vec-u64'},
|
|
133
|
-
{type:ValueType.TYPE_VEC_U128, name:'vec-u128'},
|
|
134
|
-
{type:ValueType.TYPE_OPTION_ADDRESS, name:'opt-address'},
|
|
135
|
-
{type:ValueType.TYPE_OPTION_BOOL, name:'opt-bool'},
|
|
136
|
-
{type:ValueType.TYPE_OPTION_U8, name:'opt-u8'},
|
|
137
|
-
{type:ValueType.TYPE_OPTION_U64, name:'opt-u64'},
|
|
138
|
-
{type:ValueType.TYPE_OPTION_U128, name:'opt-u128'},
|
|
139
|
-
{type:ValueType.TYPE_OPTION_U256, name:'opt-u256'},
|
|
140
|
-
{type:ValueType.TYPE_OPTION_STRING, name:'opt-string'},
|
|
141
|
-
{type:ValueType.TYPE_OPTION_VEC_U8, name:'opt-vec-u8'},
|
|
142
|
-
{type:ValueType.TYPE_VEC_U256, name:'vec-u256'},
|
|
143
|
-
{type:ValueType.TYPE_STRING, name:'string'},
|
|
144
|
-
{type:ValueType.TYPE_VEC_STRING, name:'vec-string'},
|
|
145
|
-
{type:ValueType.TYPE_U256, name:'u256'},
|
|
133
|
+
{type: RepositoryValueType.Address_Vec, name:'Address vector', description:'Vector of address.'},
|
|
134
|
+
{type: RepositoryValueType.PositiveNumber_Vec, name:'Positive number or Zero vector', description:'Vector of positive number or 0'},
|
|
146
135
|
]
|
|
147
136
|
|
|
148
137
|
export const OperatorTypeArray = (Object.values(OperatorType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
149
138
|
export const ValueTypeArray = (Object.values(ValueType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
150
|
-
export const IsValidOperatorType = (type:number) => { return OperatorTypeArray.includes(type)}
|
|
151
|
-
export const IsValidValueType = (type:number) => { return ValueTypeArray.includes(type)}
|
|
139
|
+
export const IsValidOperatorType = (type:number) : boolean => { return OperatorTypeArray.includes(type)}
|
|
140
|
+
export const IsValidValueType = (type:number) : boolean => { return ValueTypeArray.includes(type)}
|
|
152
141
|
|
|
142
|
+
export enum ContextType {
|
|
143
|
+
TYPE_SIGNER = 60,
|
|
144
|
+
TYPE_CLOCK = 61,
|
|
145
|
+
TYPE_WITNESS_ID = 62,
|
|
146
|
+
TYPE_CONSTANT = 80,
|
|
147
|
+
}
|
|
153
148
|
interface ValueTypeString {
|
|
154
|
-
type: ValueType;
|
|
149
|
+
type: ValueType | ContextType;
|
|
155
150
|
name: string;
|
|
156
151
|
description: string;
|
|
152
|
+
validator?: (value:any) => boolean;
|
|
157
153
|
}
|
|
158
154
|
|
|
159
155
|
export const SER_VALUE: ValueTypeString[] = [
|
|
160
|
-
{type: ValueType.TYPE_BOOL, name: 'bool', description:'boolean. eg:true or false'},
|
|
161
|
-
{type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af'},
|
|
162
|
-
{type:
|
|
163
|
-
{type:
|
|
164
|
-
{type:
|
|
165
|
-
{type: ValueType.
|
|
156
|
+
{type: ValueType.TYPE_BOOL, name: 'bool', description:'boolean. eg:true or false', validator:(value:any) => { return (value === true || value === false)}},
|
|
157
|
+
{type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af', validator:IsValidAddress},
|
|
158
|
+
{type: ContextType.TYPE_WITNESS_ID, name: 'future address', description:"eg: machine's future progress, service's future order", validator:IsValidAddress},
|
|
159
|
+
{type: ContextType.TYPE_SIGNER, name: 'txn signer', description:"signer address of the transaction, ", validator:IsValidAddress},
|
|
160
|
+
{type: ContextType.TYPE_CLOCK, name: 'txn time', description:"unsigned-64 number for the transaction time", validator:IsValidU64},
|
|
161
|
+
{type: ValueType.TYPE_U64, name: 'number', description:'unsigned-64 number. eg:23870233', validator:IsValidU64},
|
|
162
|
+
{type: ValueType.TYPE_U8, name: 'number', description:'unsigned-8 number. eg:255', validator:IsValidU8},
|
|
163
|
+
{type: ValueType.TYPE_VEC_U8, name: 'string', description:'string or unsigned-8 number array. eg:"[1,2,3]"'},
|
|
164
|
+
{type: ValueType.TYPE_U128, name: 'number', description:'unsigned-8 number. eg:12348900999', validator:IsValidU128},
|
|
166
165
|
{type: ValueType.TYPE_VEC_ADDRESS, name: '[address]', description:'address array. eg:[0x2277f2, 0x3344af]'},
|
|
167
166
|
{type: ValueType.TYPE_VEC_BOOL, name: '[bool]', description:'boolean array. eg:[true, false, true]'},
|
|
168
167
|
{type: ValueType.TYPE_VEC_VEC_U8, name: '[[number]]', description:'array of unsigned-8 number array. eg:["i", "like", "wowok"]'},
|
|
@@ -176,18 +175,11 @@ export const SER_VALUE: ValueTypeString[] = [
|
|
|
176
175
|
{type: ValueType.TYPE_OPTION_U256, name: 'option', description:'option of u256. eg:none or u256 value'},
|
|
177
176
|
{type: ValueType.TYPE_VEC_U256, name: '[number]', description:'unsigned-256 number array. eg:[123, 778888, 42312]'},
|
|
178
177
|
{type: ValueType.TYPE_VEC_STRING, name: '[string]', description:'ascii string array. eg:["abc", "hi"]'},
|
|
179
|
-
{type: ValueType.TYPE_STRING, name: 'string', description:'ascii string. eg:"wowok"'},
|
|
178
|
+
{type: ValueType.TYPE_STRING, name: 'string', description:'ascii string. eg:"wowok"', },
|
|
180
179
|
{type: ValueType.TYPE_OPTION_STRING, name: 'option', description:'option of string. eg:none or string value'},
|
|
181
|
-
{type: ValueType.TYPE_U256, name: 'number', description:'unsigned-256 number. eg:12345678901233'},
|
|
180
|
+
{type: ValueType.TYPE_U256, name: 'number', description:'unsigned-256 number. eg:12345678901233', validator:IsValidUintLarge},
|
|
182
181
|
]
|
|
183
182
|
|
|
184
|
-
export enum ContextType {
|
|
185
|
-
TYPE_SIGNER = 60,
|
|
186
|
-
TYPE_CLOCK = 61,
|
|
187
|
-
TYPE_WITNESS_ID = 62,
|
|
188
|
-
TYPE_CONSTANT = 80,
|
|
189
|
-
}
|
|
190
|
-
|
|
191
183
|
export type ConstantType = ValueType | ContextType.TYPE_WITNESS_ID;
|
|
192
184
|
export type Data_Type = ValueType | OperatorType | ContextType;
|
|
193
185
|
|
|
@@ -199,9 +191,9 @@ export enum ENTRYPOINT {
|
|
|
199
191
|
}
|
|
200
192
|
|
|
201
193
|
const TESTNET = {
|
|
202
|
-
package: "
|
|
203
|
-
wowok_object: '
|
|
204
|
-
entity_object: '
|
|
194
|
+
package: "0x8ba9f90c9a0e5f2199a92fdc5ea255ac9df5471289cfe40a87ac90f25d93dd5b",
|
|
195
|
+
wowok_object: '0x9d33a57a09f3ff73ba51afe6ed2e671e7d78b771e34b0a1ba66e52264e34b3fd',
|
|
196
|
+
entity_object: '0xb759e1e5569f1f8d5ae30efb6efec0a639c5ef70a7c7abcc012919cf5dae33af',
|
|
205
197
|
}
|
|
206
198
|
|
|
207
199
|
const MAINNET = {
|
|
@@ -279,7 +271,6 @@ export class Protocol {
|
|
|
279
271
|
};
|
|
280
272
|
|
|
281
273
|
MachineFn = (fn:any) => { return `${this.package}::${MODULES.machine}::${fn}`};
|
|
282
|
-
NodeFn = (fn: any) => { return `${this.package}::${MODULES.node}::${fn}`};
|
|
283
274
|
ProgressFn = (fn:any) => { return `${this.package}::${MODULES.progress}::${fn}`};
|
|
284
275
|
CommunityFn = (fn: any) => { return `${this.package}::${MODULES.community}::${fn}`};
|
|
285
276
|
RepositoryFn = (fn:any) => { return `${this.package}::${MODULES.repository}::${fn}`};
|
package/src/repository.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject} from './protocol';
|
|
3
3
|
import { PermissionIndexType, Permission } from './permission'
|
|
4
|
-
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, OptionNone, IsValidName, } from './utils';
|
|
4
|
+
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, OptionNone, IsValidName, ValueTypeConvert} from './utils';
|
|
5
5
|
import { ERROR, Errors } from './exception';
|
|
6
|
-
import {
|
|
6
|
+
import { MAX_U8, MAX_U128, MAX_U256, MAX_U64 } from './utils';
|
|
7
7
|
|
|
8
8
|
export enum Repository_Policy_Mode {
|
|
9
9
|
POLICY_MODE_FREE = 0,
|
|
10
10
|
POLICY_MODE_STRICT = 1,
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface RepData {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
dataType: RepositoryValueType;
|
|
17
|
+
data: string | string[];
|
|
18
|
+
object: string;
|
|
19
|
+
}
|
|
13
20
|
|
|
14
21
|
export type Repository_Policy = {
|
|
15
22
|
key:string;
|
|
@@ -143,14 +150,11 @@ export class Repository {
|
|
|
143
150
|
})
|
|
144
151
|
}
|
|
145
152
|
add_reference(references:string[], passport?:PassportObject) {
|
|
146
|
-
if (
|
|
147
|
-
ERROR(Errors.InvalidParam, 'add_reference')
|
|
148
|
-
}
|
|
149
|
-
|
|
153
|
+
if (references.length === 0) return;
|
|
150
154
|
if (!IsValidArray(references, IsValidAddress)) {
|
|
151
155
|
ERROR(Errors.IsValidArray, 'add_reference')
|
|
152
156
|
}
|
|
153
|
-
|
|
157
|
+
|
|
154
158
|
let txb = this.protocol.CurrentSession();
|
|
155
159
|
if (passport) {
|
|
156
160
|
txb.moveCall({
|
|
@@ -169,11 +173,9 @@ export class Repository {
|
|
|
169
173
|
}
|
|
170
174
|
}
|
|
171
175
|
remove_reference(references:string[], removeall?:boolean, passport?:PassportObject) {
|
|
172
|
-
if (
|
|
173
|
-
ERROR(Errors.InvalidParam, 'remove_reference')
|
|
174
|
-
}
|
|
176
|
+
if (references.length === 0 && !removeall) return
|
|
175
177
|
|
|
176
|
-
if (
|
|
178
|
+
if (!IsValidArray(references, IsValidAddress)) {
|
|
177
179
|
ERROR(Errors.IsValidArray, 'remove_reference')
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -212,9 +214,7 @@ export class Repository {
|
|
|
212
214
|
}
|
|
213
215
|
// add or modify the old
|
|
214
216
|
add_policies(policies:Repository_Policy[], passport?:PassportObject) {
|
|
215
|
-
if (
|
|
216
|
-
ERROR(Errors.InvalidParam, 'policies')
|
|
217
|
-
}
|
|
217
|
+
if (policies.length === 0) return;
|
|
218
218
|
|
|
219
219
|
let bValid = true;
|
|
220
220
|
policies.forEach((p) => {
|
|
@@ -252,10 +252,8 @@ export class Repository {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
remove_policies(policy_keys:string[], passport?:PassportObject) {
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
if (policy_keys && !IsValidArray(policy_keys, Repository.IsValidName)){
|
|
255
|
+
if (policy_keys.length === 0) return ;
|
|
256
|
+
if (!IsValidArray(policy_keys, Repository.IsValidName)){
|
|
259
257
|
ERROR(Errors.InvalidParam, 'policy_keys')
|
|
260
258
|
}
|
|
261
259
|
|
|
@@ -286,14 +284,14 @@ export class Repository {
|
|
|
286
284
|
txb.moveCall({
|
|
287
285
|
target:this.protocol.RepositoryFn('policy_rename_with_passport') as FnCallType,
|
|
288
286
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
289
|
-
txb.pure(policy_key
|
|
287
|
+
txb.pure(policy_key), txb.pure(new_policy_key),
|
|
290
288
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
291
289
|
})
|
|
292
290
|
} else {
|
|
293
291
|
txb.moveCall({
|
|
294
292
|
target:this.protocol.RepositoryFn('policy_rename') as FnCallType,
|
|
295
293
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
296
|
-
txb.pure(policy_key
|
|
294
|
+
txb.pure(policy_key), txb.pure(new_policy_key),
|
|
297
295
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
298
296
|
})
|
|
299
297
|
}
|
|
@@ -421,5 +419,94 @@ export class Repository {
|
|
|
421
419
|
}
|
|
422
420
|
return '';
|
|
423
421
|
}
|
|
422
|
+
|
|
423
|
+
static rpc_de_data(fields:any) : RepData [] {
|
|
424
|
+
const rep: RepData[] = fields?.map((v:any) => {
|
|
425
|
+
const value = new Uint8Array((v?.data?.content?.fields as any)?.value);
|
|
426
|
+
const type = value?.length > 0 ? value[0] as ValueType : null;
|
|
427
|
+
var d : any = value.length > 0 ? value.slice(1) : Uint8Array.from([]);
|
|
428
|
+
if (type === ValueType.TYPE_STRING) {
|
|
429
|
+
d = Bcs.getInstance().de(ValueType.TYPE_VEC_U8, d);
|
|
430
|
+
d = new TextDecoder().decode(Uint8Array.from(d));
|
|
431
|
+
} else if (type === ValueType.TYPE_VEC_STRING) {
|
|
432
|
+
d = Bcs.getInstance().de(ValueType.TYPE_VEC_VEC_U8, d) as [];
|
|
433
|
+
d = d.map((i:any) => {
|
|
434
|
+
return new TextDecoder().decode(Uint8Array.from(i));
|
|
435
|
+
})
|
|
436
|
+
} else {
|
|
437
|
+
d = Bcs.getInstance().de(value[0], d);
|
|
438
|
+
if (type === ValueType.TYPE_ADDRESS) {
|
|
439
|
+
d = '0x' + d;
|
|
440
|
+
} else if (type === ValueType.TYPE_VEC_ADDRESS) {
|
|
441
|
+
d = d.map((v:string) => { return ('0x' + v) } );
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
return {object:v?.data?.content?.fields?.id?.id, id:(v?.data?.content?.fields as any)?.name?.fields?.id,
|
|
445
|
+
name:(v?.data?.content?.fields as any)?.name?.fields?.key,
|
|
446
|
+
data:d, dataType: ValueTypeConvert(type)
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
return rep;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
static DataType2ValueType(data:string) : ValueType | undefined{
|
|
453
|
+
try {
|
|
454
|
+
const value = BigInt(data);
|
|
455
|
+
var t = ValueType.TYPE_U8;
|
|
456
|
+
if (value <= MAX_U8) {
|
|
457
|
+
} else if (value <= MAX_U64) {
|
|
458
|
+
t = ValueType.TYPE_U64;
|
|
459
|
+
} else if (value <= MAX_U128) {
|
|
460
|
+
t = ValueType.TYPE_U128;
|
|
461
|
+
} else if (value <= MAX_U256) {
|
|
462
|
+
t = ValueType.TYPE_U256;
|
|
463
|
+
} else {
|
|
464
|
+
return undefined
|
|
465
|
+
}
|
|
466
|
+
} catch (e) {
|
|
467
|
+
console.log(e)
|
|
468
|
+
} return undefined
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
static ResolveRepositoryData = (dataType:RepositoryValueType, data:string | string[]) : {type:ValueType, data: Uint8Array} | undefined => {
|
|
472
|
+
if (dataType === RepositoryValueType.String) {
|
|
473
|
+
return {type: ValueType.TYPE_STRING, data: Bcs.getInstance().ser(ValueType.TYPE_VEC_U8, new TextEncoder().encode(data.toString()))}
|
|
474
|
+
} else if (dataType === RepositoryValueType.PositiveNumber) {
|
|
475
|
+
const t = Repository.DataType2ValueType(data as string);
|
|
476
|
+
if (!t) return undefined;
|
|
477
|
+
return {type:t, data:Bcs.getInstance().ser(t, data)}
|
|
478
|
+
} else if (dataType === RepositoryValueType.Address) {
|
|
479
|
+
if (!IsValidAddress(data as string)) return undefined;
|
|
480
|
+
return {type:ValueType.TYPE_ADDRESS, data:Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, data)}
|
|
481
|
+
} else if (dataType === RepositoryValueType.Address_Vec) {
|
|
482
|
+
for(let i = 0; i < (data as string[]).length; ++i) {
|
|
483
|
+
if (!IsValidAddress((data as string[])[i])) return undefined;
|
|
484
|
+
}
|
|
485
|
+
return {type:ValueType.TYPE_VEC_ADDRESS, data:Bcs.getInstance().ser(ValueType.TYPE_VEC_ADDRESS, data)}
|
|
486
|
+
} else if (dataType === RepositoryValueType.PositiveNumber_Vec) {
|
|
487
|
+
let type = ValueType.TYPE_U8;
|
|
488
|
+
for(let i = 0; i < (data as string[]).length; ++i) {
|
|
489
|
+
const t = Repository.DataType2ValueType(data as string);
|
|
490
|
+
if (!t) return undefined;
|
|
491
|
+
if (t > type) type = t;
|
|
492
|
+
}
|
|
493
|
+
if (type === ValueType.TYPE_U8) {
|
|
494
|
+
type = ValueType.TYPE_VEC_U8;
|
|
495
|
+
} else if (type === ValueType.TYPE_U64) {
|
|
496
|
+
type = ValueType.TYPE_VEC_U64;
|
|
497
|
+
} else if (type === ValueType.TYPE_U128) {
|
|
498
|
+
type = ValueType.TYPE_VEC_U128;
|
|
499
|
+
} else {
|
|
500
|
+
type = ValueType.TYPE_VEC_U256;
|
|
501
|
+
}
|
|
502
|
+
return {type:type, data:Bcs.getInstance().ser(type, data)}
|
|
503
|
+
} else if (dataType === RepositoryValueType.String_Vec) {
|
|
504
|
+
const r = (data as string[]).map((v:string) => {
|
|
505
|
+
return new TextEncoder().encode(v);
|
|
506
|
+
})
|
|
507
|
+
return {type: ValueType.TYPE_VEC_STRING, data: Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, r)}
|
|
508
|
+
}
|
|
509
|
+
return undefined
|
|
510
|
+
}
|
|
424
511
|
}
|
|
425
512
|
|
package/src/resource.ts
CHANGED
|
@@ -36,15 +36,22 @@ export class Resource {
|
|
|
36
36
|
return r
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
launch() {
|
|
40
|
+
if (!this.object) ERROR(Errors.Fail, 'launch object Invalid');
|
|
41
|
+
let txb = this.protocol.CurrentSession();
|
|
42
|
+
txb.moveCall({
|
|
43
|
+
target:this.protocol.ResourceFn('create') as FnCallType,
|
|
44
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object)]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
39
47
|
add(name:string, object:string[]) {
|
|
40
48
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'add');
|
|
41
|
-
if (!object) ERROR(Errors.InvalidParam, 'add')
|
|
42
49
|
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'add');
|
|
43
50
|
|
|
44
51
|
let txb = this.protocol.CurrentSession();
|
|
45
52
|
txb.moveCall({
|
|
46
53
|
target:this.protocol.ResourceFn('add') as FnCallType,
|
|
47
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name
|
|
54
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.pure(object, 'vector<address>')]
|
|
48
55
|
});
|
|
49
56
|
}
|
|
50
57
|
|
|
@@ -60,22 +67,22 @@ export class Resource {
|
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
remove(name:string, object
|
|
70
|
+
remove(name:string, object:string[], removeall?:boolean) {
|
|
64
71
|
if (!IsValidName(name)) ERROR(Errors.IsValidName, 'Resource: remove');
|
|
65
|
-
if (
|
|
72
|
+
if (object.length===0 && !removeall) return;
|
|
66
73
|
|
|
67
74
|
let txb = this.protocol.CurrentSession();
|
|
68
75
|
if (removeall) {
|
|
69
76
|
txb.moveCall({
|
|
70
77
|
target:this.protocol.ResourceFn('remove_all') as FnCallType,
|
|
71
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name
|
|
78
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name)]
|
|
72
79
|
});
|
|
73
80
|
} else if(object) {
|
|
74
81
|
if (!IsValidArray(object, IsValidAddress)) ERROR(Errors.IsValidArray, 'Resource: remove');
|
|
75
82
|
|
|
76
83
|
txb.moveCall({
|
|
77
84
|
target:this.protocol.ResourceFn('remove') as FnCallType,
|
|
78
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name
|
|
85
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(name), txb.pure(object, 'vector<address>')]
|
|
79
86
|
});
|
|
80
87
|
}
|
|
81
88
|
}
|
|
@@ -98,7 +105,7 @@ export class Resource {
|
|
|
98
105
|
let txb = this.protocol.CurrentSession();
|
|
99
106
|
txb.moveCall({
|
|
100
107
|
target:this.protocol.ResourceFn('rename') as FnCallType,
|
|
101
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_name
|
|
108
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(old_name), txb.pure(new_name)]
|
|
102
109
|
});
|
|
103
110
|
}
|
|
104
111
|
|
|
@@ -109,10 +116,13 @@ export class Resource {
|
|
|
109
116
|
if (!IsValidArray(tags, IsValidName)) ERROR(Errors.IsValidArray, 'add_tags');
|
|
110
117
|
if (tags.length > Resource.MAX_TAGS) ERROR(Errors.InvalidParam, 'add_tags');
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
const txb = this.protocol.CurrentSession();
|
|
120
|
+
const encode = new TextEncoder();
|
|
121
|
+
|
|
113
122
|
txb.moveCall({
|
|
114
123
|
target:this.protocol.ResourceFn('tags_add') as FnCallType,
|
|
115
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS),
|
|
124
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(object, BCS.ADDRESS),
|
|
125
|
+
txb.pure(nick),
|
|
116
126
|
txb.pure(tags, 'vector<string>')
|
|
117
127
|
]
|
|
118
128
|
});
|
package/src/reward.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TransactionArgument, TransactionBlock, type TransactionResult } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { BCS} from '@mysten/bcs';
|
|
3
3
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RewardAddress, Protocol, TxbObject, } from './protocol';
|
|
4
|
-
import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription,
|
|
4
|
+
import { array_unique, IsValidAddress, IsValidArgType, IsValidArray, IsValidDesription, IsValidUintLarge, } from './utils';
|
|
5
5
|
import { ERROR, Errors } from './exception';
|
|
6
6
|
import { Resource } from './resource';
|
|
7
7
|
|
|
@@ -41,7 +41,7 @@ export class Reward {
|
|
|
41
41
|
if (!IsValidDesription(description)) {
|
|
42
42
|
ERROR(Errors.IsValidDesription)
|
|
43
43
|
}
|
|
44
|
-
if (!
|
|
44
|
+
if (!IsValidUintLarge(time)) {
|
|
45
45
|
ERROR(Errors.IsValidUint, 'time')
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -101,7 +101,7 @@ export class Reward {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
expand_time(ms_expand:boolean, time:number, passport?:PassportObject) {
|
|
104
|
-
if (!
|
|
104
|
+
if (!IsValidUintLarge(time)) {
|
|
105
105
|
ERROR(Errors.IsValidUint, 'minutes_expand')
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -125,13 +125,11 @@ export class Reward {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
add_guard(gurads:RewardGuardPortions[], passport?:PassportObject) {
|
|
128
|
-
if (
|
|
129
|
-
ERROR(Errors.InvalidParam, 'gurads')
|
|
130
|
-
}
|
|
128
|
+
if (gurads.length === 0) return;
|
|
131
129
|
|
|
132
130
|
let bValid = true;
|
|
133
131
|
gurads.forEach((v) => {
|
|
134
|
-
if (!
|
|
132
|
+
if (!IsValidUintLarge(v.portions) || v.portions > Reward.MAX_PORTIONS_COUNT) bValid = false;
|
|
135
133
|
if (!Protocol.IsValidObjects([v.guard])) bValid = false;
|
|
136
134
|
})
|
|
137
135
|
if (!bValid) {
|
|
@@ -162,11 +160,11 @@ export class Reward {
|
|
|
162
160
|
}
|
|
163
161
|
|
|
164
162
|
remove_guard(guards:string[], removeall?:boolean, passport?:PassportObject) {
|
|
165
|
-
if (!removeall &&
|
|
166
|
-
|
|
163
|
+
if (!removeall && guards.length===0) {
|
|
164
|
+
return
|
|
167
165
|
}
|
|
168
166
|
|
|
169
|
-
if (
|
|
167
|
+
if (!IsValidArray(guards, IsValidAddress)) {
|
|
170
168
|
ERROR(Errors.IsValidArray, 'guards')
|
|
171
169
|
}
|
|
172
170
|
|
|
@@ -333,6 +331,6 @@ export class Reward {
|
|
|
333
331
|
}
|
|
334
332
|
return '';
|
|
335
333
|
}
|
|
336
|
-
static MAX_PORTIONS_COUNT =
|
|
334
|
+
static MAX_PORTIONS_COUNT = 600;
|
|
337
335
|
static MAX_GUARD_COUNT = 16;
|
|
338
336
|
}
|