wowok 1.2.3 → 1.2.5
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/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +26 -25
- package/dist/machine.js +7 -6
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +30 -28
- package/dist/permission.d.ts +3 -3
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +5 -4
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +3 -12
- package/dist/protocol.d.ts +6 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +13 -6
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +5 -15
- package/dist/service.d.ts +10 -7
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +48 -42
- package/dist/utils.d.ts +12 -24
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +164 -67
- package/dist/vote.js +8 -7
- package/package.json +1 -1
- package/src/exception.ts +1 -0
- package/src/guard.ts +26 -25
- package/src/machine.ts +7 -7
- package/src/passport.ts +30 -27
- package/src/permission.ts +5 -6
- package/src/progress.ts +4 -12
- package/src/protocol.ts +13 -6
- package/src/repository.ts +5 -14
- package/src/service.ts +51 -41
- package/src/utils.ts +166 -69
- package/src/vote.ts +8 -8
package/src/passport.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TransactionObjectInput, Inputs } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { FnCallType, GuardObject, Protocol, ContextType, OperatorType, Data_Type,
|
|
3
3
|
ValueType, SER_VALUE, IsValidOperatorType } from './protocol';
|
|
4
|
-
import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray, OPTION_NONE, readOption } from './utils';
|
|
4
|
+
import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray, OPTION_NONE, readOption, readOptionString } from './utils';
|
|
5
5
|
import { BCS, BcsReader } from '@mysten/bcs';
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
7
7
|
import { Guard } from './guard';
|
|
@@ -72,7 +72,7 @@ export class GuardParser {
|
|
|
72
72
|
switch (v.type) {
|
|
73
73
|
case ContextType.TYPE_WITNESS_ID:
|
|
74
74
|
case ValueType.TYPE_ADDRESS:
|
|
75
|
-
value = '0x' + Bcs.getInstance().de(
|
|
75
|
+
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(v.value)).toString();
|
|
76
76
|
break;
|
|
77
77
|
case ValueType.TYPE_BOOL:
|
|
78
78
|
case ValueType.TYPE_U8:
|
|
@@ -94,7 +94,7 @@ export class GuardParser {
|
|
|
94
94
|
case ValueType.TYPE_VEC_U256:
|
|
95
95
|
let de = SER_VALUE.find(s=>s.type==v.type);
|
|
96
96
|
if (!de) ERROR(Errors.Fail, 'GuardObject de error')
|
|
97
|
-
value = Bcs.getInstance().de(de!.
|
|
97
|
+
value = Bcs.getInstance().de(de!.type, Uint8Array.from(v.value));
|
|
98
98
|
break;
|
|
99
99
|
|
|
100
100
|
default:
|
|
@@ -129,61 +129,60 @@ export class GuardParser {
|
|
|
129
129
|
break;
|
|
130
130
|
case ContextType.TYPE_WITNESS_ID: // add to constant
|
|
131
131
|
case ValueType.TYPE_ADDRESS:
|
|
132
|
-
value = '0x' + Bcs.getInstance().de(
|
|
132
|
+
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
133
133
|
arr.splice(0, 32); // address
|
|
134
134
|
break;
|
|
135
135
|
case ValueType.TYPE_BOOL:
|
|
136
|
-
value = Bcs.getInstance().de(BCS.BOOL, Uint8Array.from(arr)) as boolean;
|
|
137
|
-
arr.shift();
|
|
138
|
-
break;
|
|
139
136
|
case ValueType.TYPE_U8:
|
|
140
|
-
value = Bcs.getInstance().de(
|
|
137
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as number;
|
|
141
138
|
arr.shift();
|
|
142
139
|
break;
|
|
143
140
|
case ValueType.TYPE_U64:
|
|
144
|
-
value = Bcs.getInstance().de(
|
|
141
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as number;
|
|
145
142
|
arr.splice(0, 8);
|
|
146
143
|
break;
|
|
147
144
|
case ValueType.TYPE_U128:
|
|
148
|
-
value = Bcs.getInstance().de(
|
|
145
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as bigint;
|
|
149
146
|
arr.splice(0, 16);
|
|
150
147
|
break;
|
|
151
148
|
case ValueType.TYPE_U256:
|
|
152
|
-
value = Bcs.getInstance().de(
|
|
149
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr)) as bigint;
|
|
153
150
|
arr.splice(0, 32);
|
|
154
151
|
break;
|
|
155
152
|
case ValueType.TYPE_VEC_U8:
|
|
156
153
|
case ValueType.TYPE_VEC_BOOL:
|
|
154
|
+
case ValueType.TYPE_STRING:
|
|
157
155
|
let r = ulebDecode(Uint8Array.from(arr));
|
|
158
|
-
value = Bcs.getInstance().de(
|
|
156
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
159
157
|
arr.splice(0, r.value+r.length);
|
|
160
158
|
break;
|
|
161
159
|
case ValueType.TYPE_VEC_ADDRESS:
|
|
162
160
|
r = ulebDecode(Uint8Array.from(arr));
|
|
163
|
-
value = Bcs.getInstance().de(
|
|
161
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
164
162
|
arr.splice(0, r.value*32+r.length);
|
|
165
163
|
break;
|
|
166
164
|
case ValueType.TYPE_VEC_U128:
|
|
167
165
|
r = ulebDecode(Uint8Array.from(arr));
|
|
168
|
-
value = Bcs.getInstance().de(
|
|
166
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
169
167
|
arr.splice(0, r.value*16+r.length);
|
|
170
168
|
break;
|
|
171
169
|
case ValueType.TYPE_VEC_U256:
|
|
172
170
|
r = ulebDecode(Uint8Array.from(arr));
|
|
173
|
-
value = Bcs.getInstance().de(
|
|
171
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
174
172
|
arr.splice(0, r.value*32+r.length);
|
|
175
173
|
break;
|
|
176
174
|
case ValueType.TYPE_VEC_U64:
|
|
177
175
|
r = ulebDecode(Uint8Array.from(arr));
|
|
178
|
-
value = Bcs.getInstance().de(
|
|
176
|
+
value = Bcs.getInstance().de(type as ValueType, Uint8Array.from(arr));
|
|
179
177
|
arr.splice(0, r.value*8+r.length);
|
|
180
178
|
break;
|
|
181
179
|
case ValueType.TYPE_VEC_VEC_U8:
|
|
180
|
+
case ValueType.TYPE_VEC_STRING:
|
|
182
181
|
r = ulebDecode(Uint8Array.from(arr)); arr.splice(0, r.length);
|
|
183
182
|
let res = [];
|
|
184
183
|
for (let i = 0; i < r.value; i++) {
|
|
185
184
|
let r2 = ulebDecode(Uint8Array.from(arr));
|
|
186
|
-
res.push(Bcs.getInstance().de(
|
|
185
|
+
res.push(Bcs.getInstance().de(ValueType.TYPE_VEC_U8, Uint8Array.from(arr)));
|
|
187
186
|
arr.splice(0, r2.length+r2.value);
|
|
188
187
|
}
|
|
189
188
|
value = res;
|
|
@@ -191,7 +190,7 @@ export class GuardParser {
|
|
|
191
190
|
case OperatorType.TYPE_QUERY:
|
|
192
191
|
let t = arr.splice(0, 1); // data-type
|
|
193
192
|
if (t[0] == ValueType.TYPE_ADDRESS || t[0] == ContextType.TYPE_WITNESS_ID) {
|
|
194
|
-
let addr = '0x' + Bcs.getInstance().de(
|
|
193
|
+
let addr = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
195
194
|
arr.splice(0, 32); // address
|
|
196
195
|
value = addr;
|
|
197
196
|
cmd = arr.shift()! as number; // cmd
|
|
@@ -208,35 +207,39 @@ export class GuardParser {
|
|
|
208
207
|
}
|
|
209
208
|
break;
|
|
210
209
|
case ValueType.TYPE_OPTION_ADDRESS:
|
|
211
|
-
let read = readOption(arr,
|
|
210
|
+
let read = readOption(arr, ValueType.TYPE_ADDRESS);
|
|
212
211
|
value = read.value;
|
|
213
212
|
if (!read.bNone) arr.splice(0, 32);
|
|
214
213
|
break;
|
|
215
214
|
case ValueType.TYPE_OPTION_BOOL:
|
|
216
|
-
read = readOption(arr,
|
|
215
|
+
read = readOption(arr, ValueType.TYPE_BOOL);
|
|
217
216
|
value = read.value;
|
|
218
217
|
if (!read.bNone) arr.splice(0, 1);
|
|
219
218
|
break;
|
|
220
219
|
case ValueType.TYPE_OPTION_U8:
|
|
221
|
-
read = readOption(arr,
|
|
220
|
+
read = readOption(arr, ValueType.TYPE_U8);
|
|
222
221
|
value = read.value;
|
|
223
222
|
if (!read.bNone) arr.splice(0, 1);
|
|
224
223
|
break;
|
|
225
224
|
case ValueType.TYPE_OPTION_U128:
|
|
226
|
-
read = readOption(arr,
|
|
225
|
+
read = readOption(arr, ValueType.TYPE_U128);
|
|
227
226
|
value = read.value;
|
|
228
227
|
if (!read.bNone) arr.splice(0, 16);
|
|
229
228
|
break;
|
|
230
229
|
case ValueType.TYPE_OPTION_U256:
|
|
231
|
-
read = readOption(arr,
|
|
230
|
+
read = readOption(arr, ValueType.TYPE_U256);
|
|
232
231
|
value = read.value;
|
|
233
232
|
if (!read.bNone) arr.splice(0, 32);
|
|
234
233
|
break;
|
|
235
234
|
case ValueType.TYPE_OPTION_U64:
|
|
236
|
-
read = readOption(arr,
|
|
235
|
+
read = readOption(arr, ValueType.TYPE_U64);
|
|
237
236
|
value = read.value;
|
|
238
237
|
if (!read.bNone) arr.splice(0, 8);
|
|
239
238
|
break;
|
|
239
|
+
case ValueType.TYPE_OPTION_STRING:
|
|
240
|
+
read = readOptionString(arr); // splice in it
|
|
241
|
+
value = read.value;
|
|
242
|
+
break;
|
|
240
243
|
default:
|
|
241
244
|
ERROR(Errors.Fail, 'GuardObject: parse_bcs types')
|
|
242
245
|
}
|
|
@@ -446,7 +449,7 @@ export class GuardParser {
|
|
|
446
449
|
// ValueType.TYPE_ADDRESS: Query_Cmd maybe used the address, so save it for using
|
|
447
450
|
if (v.fields.type == ContextType.TYPE_WITNESS_ID || v.fields.type == ValueType.TYPE_ADDRESS) {
|
|
448
451
|
info.constant.push({identifier:v.fields.identifier, index:this.get_index(), type:v.fields.type,
|
|
449
|
-
value_or_witness:'0x' + Bcs.getInstance().de(
|
|
452
|
+
value_or_witness:'0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(v.fields.value))});
|
|
450
453
|
}
|
|
451
454
|
}
|
|
452
455
|
});
|
|
@@ -476,7 +479,7 @@ export class GuardParser {
|
|
|
476
479
|
arr.splice(0, 1); // identifier of constant
|
|
477
480
|
break;
|
|
478
481
|
case ContextType.TYPE_WITNESS_ID: // add to constant
|
|
479
|
-
let addr = '0x' + Bcs.getInstance().de(
|
|
482
|
+
let addr = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
480
483
|
arr.splice(0, 32); // address
|
|
481
484
|
info.input_witness.push({index:this.get_index(), type:ContextType.TYPE_WITNESS_ID, value_or_witness:addr})
|
|
482
485
|
break;
|
|
@@ -503,7 +506,7 @@ export class GuardParser {
|
|
|
503
506
|
case OperatorType.TYPE_QUERY:
|
|
504
507
|
let type = arr.splice(0, 1);
|
|
505
508
|
if (type[0] == ValueType.TYPE_ADDRESS || type[0] == ContextType.TYPE_WITNESS_ID) {
|
|
506
|
-
let addr = '0x' + Bcs.getInstance().de(
|
|
509
|
+
let addr = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
507
510
|
arr.splice(0, 33); // address + cmd
|
|
508
511
|
if (type[0] == ValueType.TYPE_ADDRESS) {
|
|
509
512
|
info.query_list.push(addr);
|
package/src/permission.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BCS } from '@mysten/bcs';
|
|
|
2
2
|
import { FnCallType, TxbObject, PermissionObject, PermissionAddress, GuardObject, Protocol} from './protocol';
|
|
3
3
|
import { array_unique, IsValidAddress, IsValidArray, IsValidDesription, IsValidUint, Bcs} from './utils';
|
|
4
4
|
import { ERROR, Errors } from './exception';
|
|
5
|
-
import {
|
|
5
|
+
import { ValueType } from './protocol';
|
|
6
6
|
|
|
7
7
|
export enum PermissionIndex {
|
|
8
8
|
repository = 100,
|
|
@@ -37,9 +37,9 @@ export enum PermissionIndex {
|
|
|
37
37
|
service_repository_add = 206,
|
|
38
38
|
service_repository_remove = 207,
|
|
39
39
|
service_add_withdraw_guards = 208,
|
|
40
|
-
service_remove_withdraw_guards =
|
|
40
|
+
service_remove_withdraw_guards = 208,
|
|
41
41
|
service_add_refund_guards = 210,
|
|
42
|
-
service_remove_refund_guards =
|
|
42
|
+
service_remove_refund_guards = 210,
|
|
43
43
|
service_add_sales = 212,
|
|
44
44
|
service_remove_sales = 213,
|
|
45
45
|
service_discount_transfer = 214,
|
|
@@ -102,7 +102,7 @@ export class Permission {
|
|
|
102
102
|
protected protocol;
|
|
103
103
|
protected object : TxbObject;
|
|
104
104
|
|
|
105
|
-
get_object()
|
|
105
|
+
get_object() { return this.object }
|
|
106
106
|
private constructor(protocol:Protocol) {
|
|
107
107
|
this.protocol = protocol;
|
|
108
108
|
this.object = '';
|
|
@@ -117,7 +117,6 @@ export class Permission {
|
|
|
117
117
|
if (!IsValidDesription(description)) {
|
|
118
118
|
ERROR(Errors.IsValidDesription)
|
|
119
119
|
}
|
|
120
|
-
|
|
121
120
|
let p = new Permission(protocol);
|
|
122
121
|
let txb = protocol.CurrentSession();
|
|
123
122
|
p.object = txb.moveCall({
|
|
@@ -236,7 +235,7 @@ export class Permission {
|
|
|
236
235
|
txb.moveCall({
|
|
237
236
|
target:this.protocol.PermissionFn('remove_index') as FnCallType,
|
|
238
237
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(entity_address, BCS.ADDRESS),
|
|
239
|
-
txb.pure(Bcs.getInstance().
|
|
238
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, array_unique(index)))]
|
|
240
239
|
})
|
|
241
240
|
}
|
|
242
241
|
remove_entity(entity_address:string[]) {
|
package/src/progress.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BCS } from '@mysten/bcs';
|
|
2
2
|
import { FnCallType, PermissionObject, RepositoryObject, PassportObject, MachineObject,
|
|
3
|
-
ProgressObject, ProgressAddress, Protocol,
|
|
3
|
+
ProgressObject, ProgressAddress, Protocol, ValueType,
|
|
4
4
|
TxbObject} from './protocol';
|
|
5
5
|
import { Bcs, array_unique,IsValidName, IsValidAddress, IsValidArray, OptionNone, IsValidInt } from './utils'
|
|
6
6
|
import { ERROR, Errors } from './exception';
|
|
@@ -86,15 +86,7 @@ export class Progress {
|
|
|
86
86
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
87
87
|
})
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
91
|
-
let txb = this.protocol.CurrentSession();
|
|
92
|
-
txb.moveCall({
|
|
93
|
-
target:this.protocol.ProgressFn(like) as FnCallType,
|
|
94
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
*/
|
|
89
|
+
|
|
98
90
|
set_namedOperator(name:string, addresses:string[], passport?:PassportObject) {
|
|
99
91
|
if (!IsValidName(name)) {
|
|
100
92
|
ERROR(Errors.IsValidName, 'name')
|
|
@@ -252,8 +244,8 @@ export class Progress {
|
|
|
252
244
|
}
|
|
253
245
|
|
|
254
246
|
let txb = this.protocol.CurrentSession();
|
|
255
|
-
let diliverable = deliverables_address? txb.pure(Bcs.getInstance().
|
|
256
|
-
let sub = sub_id? txb.pure(Bcs.getInstance().
|
|
247
|
+
let diliverable = deliverables_address? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, deliverables_address)) : OptionNone(txb)
|
|
248
|
+
let sub = sub_id? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_ADDRESS, sub_id)) : OptionNone(txb)
|
|
257
249
|
|
|
258
250
|
if (passport) {
|
|
259
251
|
txb.moveCall({
|
package/src/protocol.ts
CHANGED
|
@@ -94,8 +94,12 @@ export enum ValueType {
|
|
|
94
94
|
TYPE_OPTION_U64 = 114,
|
|
95
95
|
TYPE_OPTION_U128 = 115,
|
|
96
96
|
TYPE_OPTION_U256 = 116,
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
TYPE_OPTION_STRING = 117,
|
|
98
|
+
TYPE_OPTION_VEC_U8 = 118,
|
|
99
|
+
TYPE_VEC_U256 = 119,
|
|
100
|
+
TYPE_STRING = 120,
|
|
101
|
+
TYPE_VEC_STRING = 121,
|
|
102
|
+
TYPE_U256 = 122,
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
export const OperatorTypeArray = (Object.values(OperatorType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
@@ -114,7 +118,7 @@ export const SER_VALUE: ValueTypeString[] = [
|
|
|
114
118
|
{type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af'},
|
|
115
119
|
{type: ValueType.TYPE_U64, name: 'number', description:'unsigned-64 number. eg:23870233'},
|
|
116
120
|
{type: ValueType.TYPE_U8, name: 'number', description:'unsigned-8 number. eg:255'},
|
|
117
|
-
{type: ValueType.TYPE_VEC_U8, name: '[number]', description:'unsigned-8 number array. eg:"
|
|
121
|
+
{type: ValueType.TYPE_VEC_U8, name: '[number]', description:'unsigned-8 number array. eg:"[1,2,3]"'},
|
|
118
122
|
{type: ValueType.TYPE_U128, name: 'number', description:'unsigned-8 number. eg:12348900999'},
|
|
119
123
|
{type: ValueType.TYPE_VEC_ADDRESS, name: '[address]', description:'address array. eg:[0x2277f2, 0x3344af]'},
|
|
120
124
|
{type: ValueType.TYPE_VEC_BOOL, name: '[bool]', description:'boolean array. eg:[true, false, true]'},
|
|
@@ -128,6 +132,9 @@ export const SER_VALUE: ValueTypeString[] = [
|
|
|
128
132
|
{type: ValueType.TYPE_OPTION_U128, name: 'option', description:'option of u128. eg:none or u128 value'},
|
|
129
133
|
{type: ValueType.TYPE_OPTION_U256, name: 'option', description:'option of u256. eg:none or u256 value'},
|
|
130
134
|
{type: ValueType.TYPE_VEC_U256, name: '[number]', description:'unsigned-256 number array. eg:[123, 778888, 42312]'},
|
|
135
|
+
{type: ValueType.TYPE_VEC_STRING, name: '[string]', description:'ascii string array. eg:["abc", "hi"]'},
|
|
136
|
+
{type: ValueType.TYPE_STRING, name: 'string', description:'ascii string. eg:"wowok"'},
|
|
137
|
+
{type: ValueType.TYPE_OPTION_STRING, name: 'option', description:'option of string. eg:none or string value'},
|
|
131
138
|
{type: ValueType.TYPE_U256, name: 'number', description:'unsigned-256 number. eg:12345678901233'},
|
|
132
139
|
]
|
|
133
140
|
|
|
@@ -177,9 +184,9 @@ export class Protocol {
|
|
|
177
184
|
case ENTRYPOINT.devnet:
|
|
178
185
|
break;
|
|
179
186
|
case ENTRYPOINT.testnet:
|
|
180
|
-
this.package = "
|
|
181
|
-
this.wowok_object = '
|
|
182
|
-
this.entity_object= '
|
|
187
|
+
this.package = "0x10edb3f8e11008c8c5cfe951989d10c353d885377fe6cbdfedea3b315fa6b06c";
|
|
188
|
+
this.wowok_object = '0xb2a940236a1811ff43eaf902e165155687f9c756dcdd1fc70096551bffcb89fc';
|
|
189
|
+
this.entity_object= '0x8dc27895c123c9736649a800fc58e621b7747d56f0b15a560d09a4412c42ae28';
|
|
183
190
|
this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
184
191
|
break;
|
|
185
192
|
case ENTRYPOINT.mainnet:
|
package/src/repository.ts
CHANGED
|
@@ -82,16 +82,7 @@ export class Repository {
|
|
|
82
82
|
arguments: [Protocol.TXB_OBJECT(txb, this.object)],
|
|
83
83
|
})
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
mark(like:'like' | 'unlike', resource:Resource) {
|
|
87
|
-
if (!Protocol.IsValidObjects([this.object])) return false;
|
|
88
|
-
let txb = this.protocol.CurrentSession();
|
|
89
|
-
txb.moveCall({
|
|
90
|
-
target:this.protocol.RepositoryFn(like) as FnCallType,
|
|
91
|
-
arguments: [Protocol.TXB_OBJECT(txb, resource.get_object()), Protocol.TXB_OBJECT(txb, this.object)],
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
*/
|
|
85
|
+
|
|
95
86
|
add_data(data:Repository_Policy_Data) {
|
|
96
87
|
if (!Repository.IsValidName(data.key)) {
|
|
97
88
|
ERROR(Errors.IsValidName)
|
|
@@ -235,7 +226,7 @@ export class Repository {
|
|
|
235
226
|
|
|
236
227
|
let txb = this.protocol.CurrentSession();
|
|
237
228
|
policies.forEach((policy) => {
|
|
238
|
-
let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().
|
|
229
|
+
let permission_index = policy?.permission ? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, policy.permission)) : OptionNone(txb);
|
|
239
230
|
if (passport) {
|
|
240
231
|
txb.moveCall({
|
|
241
232
|
target:this.protocol.RepositoryFn('policy_add_with_passport') as FnCallType,
|
|
@@ -277,7 +268,7 @@ export class Repository {
|
|
|
277
268
|
txb.moveCall({
|
|
278
269
|
target:this.protocol.RepositoryFn('policy_remove_with_passport') as FnCallType,
|
|
279
270
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
280
|
-
txb.pure(Bcs.getInstance().
|
|
271
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
281
272
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
282
273
|
})
|
|
283
274
|
}
|
|
@@ -291,7 +282,7 @@ export class Repository {
|
|
|
291
282
|
txb.moveCall({
|
|
292
283
|
target:this.protocol.RepositoryFn('policy_remove') as FnCallType,
|
|
293
284
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
294
|
-
txb.pure(Bcs.getInstance().
|
|
285
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(policy_keys))),
|
|
295
286
|
Protocol.TXB_OBJECT(txb, this.permission)]
|
|
296
287
|
})
|
|
297
288
|
}
|
|
@@ -371,7 +362,7 @@ export class Repository {
|
|
|
371
362
|
if(!Permission.IsValidPermissionIndex(permission_index)) {
|
|
372
363
|
ERROR(Errors.IsValidPermissionIndex)
|
|
373
364
|
}
|
|
374
|
-
index = txb.pure(Bcs.getInstance().
|
|
365
|
+
index = txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, permission_index));
|
|
375
366
|
}
|
|
376
367
|
|
|
377
368
|
if (passport) {
|
package/src/service.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig } from '@mysten/bcs';
|
|
|
2
2
|
import { IsValidArray, IsValidPercent, IsValidName_AllowEmpty, Bcs, array_unique, IsValidArgType, IsValidDesription,
|
|
3
3
|
IsValidAddress, IsValidEndpoint, OptionNone, IsValidUint, IsValidInt, IsValidName, } from './utils'
|
|
4
4
|
import { FnCallType, GuardObject, PassportObject, PermissionObject, RepositoryObject, MachineObject, ServiceAddress,
|
|
5
|
-
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol,
|
|
5
|
+
ServiceObject, DiscountObject, OrderObject, OrderAddress, CoinObject, Protocol, ValueType,
|
|
6
6
|
TxbObject} from './protocol';
|
|
7
7
|
import { ERROR, Errors } from './exception';
|
|
8
8
|
import { Resource } from './resource';
|
|
@@ -39,11 +39,12 @@ export type Customer_RequiredInfo = {
|
|
|
39
39
|
customer_info_crypt: string[];
|
|
40
40
|
}
|
|
41
41
|
export enum BuyRequiredEnum {
|
|
42
|
-
address = '
|
|
43
|
-
phone = '
|
|
44
|
-
name = '
|
|
45
|
-
postcode = '
|
|
42
|
+
address = 'address',
|
|
43
|
+
phone = 'phone',
|
|
44
|
+
name = 'name',
|
|
45
|
+
postcode = 'postcode'
|
|
46
46
|
}
|
|
47
|
+
|
|
47
48
|
export type Service_Buy = {
|
|
48
49
|
item: string;
|
|
49
50
|
max_price: number;
|
|
@@ -62,6 +63,8 @@ export class Service {
|
|
|
62
63
|
protected object : TxbObject;
|
|
63
64
|
protected protocol;
|
|
64
65
|
|
|
66
|
+
static token2coin = (token:string) => { return '0x2::coin::Coin<' + token + '>'};
|
|
67
|
+
|
|
65
68
|
get_pay_type() { return this.pay_token_type }
|
|
66
69
|
get_object() { return this.object }
|
|
67
70
|
private constructor(protocol: Protocol, pay_token_type:string, permission:PermissionObject) {
|
|
@@ -70,18 +73,18 @@ export class Service {
|
|
|
70
73
|
this.permission = permission
|
|
71
74
|
this.object = ''
|
|
72
75
|
}
|
|
73
|
-
static From(protocol: Protocol,
|
|
74
|
-
let s = new Service(protocol,
|
|
76
|
+
static From(protocol: Protocol, token_type:string, permission:PermissionObject, object:TxbObject) : Service {
|
|
77
|
+
let s = new Service(protocol, this.token2coin(token_type), permission);
|
|
75
78
|
s.object = Protocol.TXB_OBJECT(protocol.CurrentSession(), object);
|
|
76
79
|
return s
|
|
77
80
|
}
|
|
78
|
-
static New(protocol: Protocol,
|
|
81
|
+
static New(protocol: Protocol, token_type:string, permission:PermissionObject, description:string,
|
|
79
82
|
payee_address:string, endpoint?:string, passport?:PassportObject) : Service {
|
|
80
83
|
if (!Protocol.IsValidObjects([permission])) {
|
|
81
84
|
ERROR(Errors.IsValidObjects)
|
|
82
85
|
}
|
|
83
|
-
if (!IsValidArgType(
|
|
84
|
-
ERROR(Errors.IsValidArgType, '
|
|
86
|
+
if (!IsValidArgType(token_type)) {
|
|
87
|
+
ERROR(Errors.IsValidArgType, 'New: pay_token_type')
|
|
85
88
|
}
|
|
86
89
|
if (!IsValidDesription(description)) {
|
|
87
90
|
ERROR(Errors.IsValidDesription)
|
|
@@ -94,10 +97,12 @@ export class Service {
|
|
|
94
97
|
ERROR(Errors.IsValidEndpoint)
|
|
95
98
|
}
|
|
96
99
|
|
|
100
|
+
let pay_token_type = this.token2coin(token_type);
|
|
97
101
|
let s = new Service(protocol, pay_token_type, permission);
|
|
98
102
|
let txb = protocol.CurrentSession();
|
|
99
|
-
let ep = endpoint? txb.pure(Bcs.getInstance().
|
|
103
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
100
104
|
|
|
105
|
+
|
|
101
106
|
if (passport) {
|
|
102
107
|
s.object = txb.moveCall({
|
|
103
108
|
target:protocol.ServiceFn('new_with_passport') as FnCallType,
|
|
@@ -107,7 +112,7 @@ export class Service {
|
|
|
107
112
|
} else {
|
|
108
113
|
s.object = txb.moveCall({
|
|
109
114
|
target:protocol.ServiceFn('new') as FnCallType,
|
|
110
|
-
arguments:[txb.pure(description), txb.pure(payee_address, BCS.ADDRESS), ep, Protocol.TXB_OBJECT(txb, permission)],
|
|
115
|
+
arguments:[txb.pure(description, BCS.STRING), txb.pure(payee_address, BCS.ADDRESS), ep, Protocol.TXB_OBJECT(txb, permission)],
|
|
111
116
|
typeArguments:[pay_token_type],
|
|
112
117
|
})
|
|
113
118
|
}
|
|
@@ -272,8 +277,9 @@ export class Service {
|
|
|
272
277
|
}
|
|
273
278
|
}
|
|
274
279
|
repository_add(repository:RepositoryObject, passport?:PassportObject) {
|
|
275
|
-
if (!Protocol.IsValidObjects([
|
|
276
|
-
|
|
280
|
+
if (!Protocol.IsValidObjects([repository])) {
|
|
281
|
+
ERROR(Errors.IsValidObjects, 'repository_add');
|
|
282
|
+
}
|
|
277
283
|
|
|
278
284
|
let txb = this.protocol.CurrentSession();
|
|
279
285
|
if (passport) {
|
|
@@ -289,7 +295,6 @@ export class Service {
|
|
|
289
295
|
typeArguments:[this.pay_token_type]
|
|
290
296
|
})
|
|
291
297
|
}
|
|
292
|
-
|
|
293
298
|
}
|
|
294
299
|
repository_remove(repository_address?:string[], removeall?:boolean, passport?:PassportObject) {
|
|
295
300
|
if (!removeall && !repository_address) {
|
|
@@ -501,16 +506,16 @@ export class Service {
|
|
|
501
506
|
if (passport) {
|
|
502
507
|
txb.moveCall({
|
|
503
508
|
target:this.protocol.ServiceFn('sales_add_with_passport') as FnCallType,
|
|
504
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
505
|
-
txb.pure(Bcs.getInstance().
|
|
509
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
|
|
510
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
506
511
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
507
512
|
typeArguments:[this.pay_token_type]
|
|
508
513
|
})
|
|
509
514
|
} else {
|
|
510
515
|
txb.moveCall({
|
|
511
516
|
target:this.protocol.ServiceFn('sales_add') as FnCallType,
|
|
512
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
513
|
-
txb.pure(Bcs.getInstance().
|
|
517
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, names)),
|
|
518
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
514
519
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
515
520
|
typeArguments:[this.pay_token_type]
|
|
516
521
|
})
|
|
@@ -536,7 +541,7 @@ export class Service {
|
|
|
536
541
|
} else {
|
|
537
542
|
txb.moveCall({
|
|
538
543
|
target:this.protocol.ServiceFn('sales_remove_with_passport') as FnCallType,
|
|
539
|
-
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
544
|
+
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
540
545
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
541
546
|
typeArguments:[this.pay_token_type]
|
|
542
547
|
})
|
|
@@ -551,7 +556,7 @@ export class Service {
|
|
|
551
556
|
} else {
|
|
552
557
|
txb.moveCall({
|
|
553
558
|
target:this.protocol.ServiceFn('sales_remove') as FnCallType,
|
|
554
|
-
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
559
|
+
arguments:[Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, array_unique(sales!))),
|
|
555
560
|
Protocol.TXB_OBJECT(txb, this.permission)],
|
|
556
561
|
typeArguments:[this.pay_token_type]
|
|
557
562
|
})
|
|
@@ -581,9 +586,9 @@ export class Service {
|
|
|
581
586
|
let txb = this.protocol.CurrentSession();
|
|
582
587
|
discount_dispatch.forEach((discount) => {
|
|
583
588
|
let price_greater = discount.discount?.price_greater ?
|
|
584
|
-
txb.pure(Bcs.getInstance().
|
|
589
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, discount.discount.price_greater)) : OptionNone(txb);
|
|
585
590
|
let time_start = discount.discount?.time_start ?
|
|
586
|
-
txb.pure(Bcs.getInstance().
|
|
591
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_U64, discount.discount.time_start)) : OptionNone(txb);
|
|
587
592
|
|
|
588
593
|
if (passport) {
|
|
589
594
|
txb.moveCall({
|
|
@@ -702,7 +707,7 @@ export class Service {
|
|
|
702
707
|
}
|
|
703
708
|
|
|
704
709
|
let txb = this.protocol.CurrentSession();
|
|
705
|
-
let ep = endpoint? txb.pure(Bcs.getInstance().
|
|
710
|
+
let ep = endpoint? txb.pure(Bcs.getInstance().ser(ValueType.TYPE_OPTION_STRING, endpoint)) : OptionNone(txb);
|
|
706
711
|
|
|
707
712
|
if (passport) {
|
|
708
713
|
txb.moveCall({
|
|
@@ -760,21 +765,24 @@ export class Service {
|
|
|
760
765
|
ERROR(Errors.InvalidParam, 'customer_required')
|
|
761
766
|
}
|
|
762
767
|
|
|
768
|
+
let req = array_unique(customer_required) as string[];
|
|
769
|
+
console.log(req)
|
|
770
|
+
console.log(this.pay_token_type)
|
|
763
771
|
let txb = this.protocol.CurrentSession();
|
|
764
772
|
if (passport) {
|
|
765
773
|
txb.moveCall({
|
|
766
774
|
target:this.protocol.ServiceFn('required_set_with_passport') as FnCallType,
|
|
767
775
|
arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
|
|
768
|
-
txb.pure(Bcs.getInstance().
|
|
769
|
-
txb.pure(pubkey,
|
|
776
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, req)),
|
|
777
|
+
txb.pure(pubkey, BCS.STRING), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
770
778
|
typeArguments:[this.pay_token_type]
|
|
771
779
|
})
|
|
772
780
|
} else {
|
|
773
781
|
txb.moveCall({
|
|
774
782
|
target:this.protocol.ServiceFn('required_set') as FnCallType,
|
|
775
783
|
arguments:[Protocol.TXB_OBJECT(txb, this.object),
|
|
776
|
-
txb.pure(Bcs.getInstance().
|
|
777
|
-
txb.pure(pubkey,
|
|
784
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, req)),
|
|
785
|
+
txb.pure(pubkey, BCS.STRING), Protocol.TXB_OBJECT(txb, this.permission)],
|
|
778
786
|
typeArguments:[this.pay_token_type]
|
|
779
787
|
})
|
|
780
788
|
}
|
|
@@ -894,7 +902,7 @@ export class Service {
|
|
|
894
902
|
arguments:[Protocol.TXB_OBJECT(txb, this.object), Protocol.TXB_OBJECT(txb, order),
|
|
895
903
|
txb.pure(customer_info_crypto.pubkey, 'vector<u8>'),
|
|
896
904
|
txb.pure(customer_info_crypto.customer_pubkey, 'vector<u8>'),
|
|
897
|
-
txb.pure(Bcs.getInstance().
|
|
905
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_VEC_U8, array_unique(customer_info_crypto.customer_info_crypt)))],
|
|
898
906
|
typeArguments:[this.pay_token_type]
|
|
899
907
|
})
|
|
900
908
|
|
|
@@ -926,16 +934,16 @@ export class Service {
|
|
|
926
934
|
if (discount) {
|
|
927
935
|
order = txb.moveCall({
|
|
928
936
|
target:this.protocol.ServiceFn('dicount_buy_with_passport') as FnCallType,
|
|
929
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
930
|
-
txb.pure(Bcs.getInstance().
|
|
937
|
+
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
938
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
931
939
|
Protocol.TXB_OBJECT(txb, coin), Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
932
940
|
typeArguments:[this.pay_token_type]
|
|
933
941
|
})} else {
|
|
934
942
|
order = txb.moveCall({
|
|
935
943
|
target:this.protocol.ServiceFn('buy_with_passport') as FnCallType,
|
|
936
|
-
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
937
|
-
txb.pure(Bcs.getInstance().
|
|
938
|
-
txb.pure(Bcs.getInstance().
|
|
944
|
+
arguments: [passport, Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
945
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
|
|
946
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
939
947
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
940
948
|
typeArguments:[this.pay_token_type]
|
|
941
949
|
})}
|
|
@@ -943,18 +951,18 @@ export class Service {
|
|
|
943
951
|
if (discount) {
|
|
944
952
|
order = txb.moveCall({
|
|
945
953
|
target:this.protocol.ServiceFn('disoucnt_buy') as FnCallType,
|
|
946
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
947
|
-
txb.pure(Bcs.getInstance().
|
|
948
|
-
txb.pure(Bcs.getInstance().
|
|
954
|
+
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
955
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
|
|
956
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
949
957
|
Protocol.TXB_OBJECT(txb, coin),
|
|
950
958
|
Protocol.TXB_OBJECT(txb, discount), txb.object(Protocol.CLOCK_OBJECT)],
|
|
951
959
|
typeArguments:[this.pay_token_type]
|
|
952
960
|
})} else {
|
|
953
961
|
order = txb.moveCall({
|
|
954
962
|
target:this.protocol.ServiceFn('buy') as FnCallType,
|
|
955
|
-
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().
|
|
956
|
-
txb.pure(Bcs.getInstance().
|
|
957
|
-
txb.pure(Bcs.getInstance().
|
|
963
|
+
arguments: [Protocol.TXB_OBJECT(txb, this.object), txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, name)),
|
|
964
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, price)),
|
|
965
|
+
txb.pure(Bcs.getInstance().ser(ValueType.TYPE_VEC_U64, stock)),
|
|
958
966
|
Protocol.TXB_OBJECT(txb, coin)],
|
|
959
967
|
typeArguments:[this.pay_token_type]
|
|
960
968
|
})}
|
|
@@ -1007,5 +1015,7 @@ export class Service {
|
|
|
1007
1015
|
}
|
|
1008
1016
|
|
|
1009
1017
|
static MAX_DISCOUNT_COUNT_ONCE = 200;
|
|
1010
|
-
static MAX_DISCOUNT_RECEIVER_COUNT =
|
|
1018
|
+
static MAX_DISCOUNT_RECEIVER_COUNT = 20;
|
|
1019
|
+
static MAX_GUARD_COUNT = 16;
|
|
1020
|
+
static MAX_REPOSITORY_COUNT = 16;
|
|
1011
1021
|
}
|