wowok 1.6.63 → 1.6.64
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/agent_call/call.ts +150 -12
- package/src/agent_query/events.ts +5 -5
- package/src/agent_query/objects.ts +66 -4
- package/src/agent_query/permission.ts +4 -7
- package/src/arbitration.ts +39 -39
- package/src/cache.ts +54 -0
- package/src/demand.ts +20 -20
- package/src/entity.ts +15 -16
- package/src/guard.ts +6 -6
- package/src/machine.ts +48 -48
- package/src/passport.ts +15 -15
- package/src/payment.ts +2 -2
- package/src/permission.ts +25 -28
- package/src/progress.ts +22 -38
- package/src/protocol.ts +60 -61
- package/src/repository.ts +31 -31
- package/src/resource.ts +17 -16
- package/src/service.ts +96 -96
- package/src/treasury.ts +30 -30
- package/src/utils.ts +11 -5
- package/src/wowok.ts +8 -8
package/package.json
CHANGED
package/src/agent_call/call.ts
CHANGED
|
@@ -11,13 +11,15 @@ import { MultiGetObjectsParams } from '@mysten/sui/client';
|
|
|
11
11
|
import { Permission, Permission_Entity, Permission_Index, PermissionIndex, UserDefinedIndex } from '../permission';
|
|
12
12
|
import { BCS } from '@mysten/bcs';
|
|
13
13
|
import { PermissionAnswerItem, PermissionIndexType } from '../permission';
|
|
14
|
-
import { Entity } from '../entity';
|
|
14
|
+
import { Entity, Entity_Info } from '../entity';
|
|
15
15
|
import { Repository, Repository_Policy, Repository_Policy_Data, Repository_Policy_Data2, Repository_Policy_Data_Remove, Repository_Policy_Mode, } from '../repository';
|
|
16
16
|
import { Demand } from '../demand';
|
|
17
17
|
import { Machine, Machine_Forward, Machine_Node } from '../machine';
|
|
18
18
|
import { BuyRequiredEnum, Customer_RequiredInfo, DicountDispatch, Service, Service_Buy, Service_Guard_Percent, Service_Sale, WithdrawPayee } from '../service';
|
|
19
19
|
import { DepositParam, Treasury, Treasury_WithdrawMode, WithdrawParam } from '../treasury';
|
|
20
|
-
import { Arbitration, VotingGuard } from '../arbitration';
|
|
20
|
+
import { Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee } from '../arbitration';
|
|
21
|
+
import { Deliverable, ParentProgress, Progress, ProgressNext } from '../progress';
|
|
22
|
+
import { MarkName, Resource } from '../resource';
|
|
21
23
|
|
|
22
24
|
export interface CallBase {
|
|
23
25
|
object: string | 'new';
|
|
@@ -66,6 +68,13 @@ export interface CallMachine extends CallBase { //@ todo self-owned node operate
|
|
|
66
68
|
| {op:'remove pair'; pairs: {prior_node_name:string; node_name:string}[]}
|
|
67
69
|
| {op:'add forward'; data: {prior_node_name:string; node_name:string; forward:Machine_Forward; threshold?:number; old_need_remove?:string}[]}
|
|
68
70
|
| {op:'remove forward'; data:{prior_node_name:string; node_name:string; forward_name:string}[]}
|
|
71
|
+
progress_new?: {task_address?:string; };
|
|
72
|
+
progress_context_repository?: {progress:string; repository:string};
|
|
73
|
+
progress_parent?: {progress:string, parent?:ParentProgress};
|
|
74
|
+
progress_task?: {progress:string; task:string};
|
|
75
|
+
progress_namedOperator?: {progress:string; data:{name:string, operator:string[]}[]};
|
|
76
|
+
progress_hold?: {progress:string; data:ProgressNext; bHold:boolean; adminUnhold?:boolean};
|
|
77
|
+
progress_next?: {progress:string; data:ProgressNext; deliverable:Deliverable};
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
export interface CallService extends CallBase {
|
|
@@ -74,7 +83,6 @@ export interface CallService extends CallBase {
|
|
|
74
83
|
bPublished?: boolean;
|
|
75
84
|
description?: string;
|
|
76
85
|
gen_discount?: DicountDispatch[];
|
|
77
|
-
buy?: {buy_items:Service_Buy[], coin_object?:string, discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo}
|
|
78
86
|
arbitration: {op:'set' | 'add'; arbitrations:{address:string, token_type:string}[]}
|
|
79
87
|
| {op:'removeall'} | {op:'remove', addresses:string[]};
|
|
80
88
|
buy_guard?: string;
|
|
@@ -83,7 +91,7 @@ export interface CallService extends CallBase {
|
|
|
83
91
|
| {op:'removeall'} | {op:'remove', addresses:string[]};
|
|
84
92
|
machine?: string;
|
|
85
93
|
payee_treasury?:string;
|
|
86
|
-
|
|
94
|
+
clone?: {token_type_new?:string};
|
|
87
95
|
repository: {op:'set' | 'add' | 'remove' ; repositories:string[]} | {op:'removeall'};
|
|
88
96
|
withdraw_guard?: {op:'add' | 'set'; guards:Service_Guard_Percent[]}
|
|
89
97
|
| {op:'removeall'} | {op:'remove', addresses:string[]};
|
|
@@ -92,6 +100,7 @@ export interface CallService extends CallBase {
|
|
|
92
100
|
customer_required_info?: {pubkey:string; required_info:(string | BuyRequiredEnum)[]};
|
|
93
101
|
sales: {op:'add', sales:Service_Sale[]} | {op:'remove'; sales_name:string[]}
|
|
94
102
|
crypto_pubkey?: string;
|
|
103
|
+
order_new?: {buy_items:Service_Buy[], coin_object?:string, discount?:string, machine?:string, customer_info_crypto?: Customer_RequiredInfo}
|
|
95
104
|
order_required_info?: {order:string; info:Customer_RequiredInfo};
|
|
96
105
|
order_refund?: {order:string; guard?:string;} | {order:string; arb:string; arb_token_type:string}; // guard address
|
|
97
106
|
order_withdrawl?: {order:string; data:WithdrawPayee}; // guard address
|
|
@@ -120,6 +129,23 @@ export interface CallArbitration extends CallBase {
|
|
|
120
129
|
usage_guard?: string;
|
|
121
130
|
withdraw_treasury?: string;
|
|
122
131
|
voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
|
|
132
|
+
arb_new?: Dispute; // dispute an order, and a new Arb launched.
|
|
133
|
+
arb_withdraw_fee?: {arb:string; data:WithdrawFee};
|
|
134
|
+
arb_vote?: Vote;
|
|
135
|
+
arb_arbitration?: Feedback;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface CallPersonal extends CallBase {
|
|
139
|
+
information?: Entity_Info;
|
|
140
|
+
transfer_to?: string;
|
|
141
|
+
marks?: {op:'add mark'; data:{mark_name:string; address:string[]}}
|
|
142
|
+
| {op:'add address'; data:{address:string; mark_name:string[]}}
|
|
143
|
+
| {op:'remove mark'; data:{mark_name:string; address:string[]}}
|
|
144
|
+
| {op:'remove address'; data:{address:string; mark_name:string[]}}
|
|
145
|
+
| {op:'clear mark'; mark_name:string};
|
|
146
|
+
tags?: {op:'add'; data:{address:string; nick_name:string; tags:string[]}}
|
|
147
|
+
| {op:'remove'; address:string};
|
|
148
|
+
close?: boolean; // close a personal resource
|
|
123
149
|
}
|
|
124
150
|
|
|
125
151
|
export namespace Call {
|
|
@@ -416,6 +442,37 @@ export namespace Call {
|
|
|
416
442
|
break;
|
|
417
443
|
}
|
|
418
444
|
}
|
|
445
|
+
if (call?.progress_new !== undefined) {
|
|
446
|
+
Progress?.New(txb, call?.object, permission??call?.permission, call?.progress_new.task_address, passport).launch();
|
|
447
|
+
}
|
|
448
|
+
if (call?.progress_context_repository !== undefined) {
|
|
449
|
+
Progress.From(txb, call?.object, permission??call?.permission, call?.progress_context_repository.progress)
|
|
450
|
+
.set_context_repository(call?.progress_context_repository.repository, passport)
|
|
451
|
+
}
|
|
452
|
+
if (call?.progress_namedOperator !== undefined) {
|
|
453
|
+
const p = Progress.From(txb, call?.object, permission??call?.permission, call?.progress_namedOperator.progress);
|
|
454
|
+
call.progress_namedOperator.data.forEach(v => p.set_namedOperator(v.name, v.operator, passport));
|
|
455
|
+
}
|
|
456
|
+
if (call?.progress_parent !== undefined) {
|
|
457
|
+
if (call.progress_parent.parent) {
|
|
458
|
+
Progress.From(txb, call?.object, permission??call?.permission, call?.progress_parent.progress).parent(call.progress_parent.parent);
|
|
459
|
+
} else {
|
|
460
|
+
Progress.From(txb, call?.object, permission??call?.permission, call?.progress_parent.progress).parent_none();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (call?.progress_task !== undefined) {
|
|
464
|
+
Progress.From(txb, call?.object, permission??call?.permission, call?.progress_task.progress).bind_task(call.progress_task.task, passport)
|
|
465
|
+
}
|
|
466
|
+
if (call?.progress_hold !== undefined) {
|
|
467
|
+
if (call?.progress_hold.adminUnhold) {
|
|
468
|
+
Progress.From(txb, call?.object, permission??call?.permission, call?.progress_hold.progress).unhold(call.progress_hold.data, passport)
|
|
469
|
+
} else {
|
|
470
|
+
Progress.From(txb, call?.object, permission??call?.permission, call?.progress_hold.progress).hold(call.progress_hold.data, call.progress_hold.bHold)
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (call?.progress_next !== undefined) {
|
|
474
|
+
Progress.From(txb, call?.object, permission??call?.permission, call?.progress_next.progress).next(call.progress_next.data, call.progress_next.deliverable, passport)
|
|
475
|
+
}
|
|
419
476
|
if (permission) {
|
|
420
477
|
permission.launch();
|
|
421
478
|
}
|
|
@@ -463,8 +520,8 @@ export namespace Call {
|
|
|
463
520
|
if (call?.bPublished) {
|
|
464
521
|
obj.publish(passport)
|
|
465
522
|
}
|
|
466
|
-
if (call?.
|
|
467
|
-
obj.clone(call.
|
|
523
|
+
if (call?.clone !== undefined) {
|
|
524
|
+
obj.clone(call.clone?.token_type_new, true, passport)
|
|
468
525
|
}
|
|
469
526
|
if (call?.machine !== undefined) {
|
|
470
527
|
obj.set_machine(call.machine, passport)
|
|
@@ -573,25 +630,25 @@ export namespace Call {
|
|
|
573
630
|
break;
|
|
574
631
|
}
|
|
575
632
|
}
|
|
576
|
-
if (call?.
|
|
633
|
+
if (call?.order_new !== undefined) {
|
|
577
634
|
let b = BigInt(0); let coin : any;
|
|
578
|
-
call.
|
|
635
|
+
call.order_new.buy_items.forEach(v => {
|
|
579
636
|
b += BigInt(v.max_price) * BigInt(v.count)
|
|
580
637
|
})
|
|
581
638
|
if (b > BigInt(0)) {
|
|
582
639
|
if (call?.type_parameter === '0x2::sui::SUI' || call?.type_parameter === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI') {
|
|
583
640
|
coin = txb.splitCoins(txb.gas, [b])[0];
|
|
584
|
-
} else if (call?.
|
|
585
|
-
coin = txb.splitCoins(call.
|
|
641
|
+
} else if (call?.order_new.coin_object) {
|
|
642
|
+
coin = txb.splitCoins(call.order_new.coin_object, [b])[0];
|
|
586
643
|
}
|
|
587
644
|
}
|
|
588
645
|
|
|
589
646
|
if (coin) {
|
|
590
647
|
//@ crypto tools support
|
|
591
|
-
obj.buy(call.
|
|
648
|
+
obj.buy(call.order_new.buy_items, coin, call.order_new.discount, call.order_new.machine, call.order_new.customer_info_crypto, passport)
|
|
592
649
|
}
|
|
593
650
|
}
|
|
594
|
-
if (call?.order_payer !== undefined) {
|
|
651
|
+
if (call?.order_payer !== undefined && obj) {
|
|
595
652
|
obj.change_order_payer(call?.order_payer.order, call.order_payer.payer_new)
|
|
596
653
|
}
|
|
597
654
|
if (call?.order_agent !== undefined) {
|
|
@@ -742,6 +799,19 @@ export namespace Call {
|
|
|
742
799
|
}
|
|
743
800
|
}
|
|
744
801
|
|
|
802
|
+
if (call?.arb_new !== undefined) {
|
|
803
|
+
obj.dispute(call.arb_new, passport)
|
|
804
|
+
}
|
|
805
|
+
if (call?.arb_arbitration !== undefined) {
|
|
806
|
+
obj.arbitration(call.arb_arbitration, passport)
|
|
807
|
+
}
|
|
808
|
+
if (call?.arb_vote !== undefined) {
|
|
809
|
+
obj.vote(call.arb_vote, passport)
|
|
810
|
+
}
|
|
811
|
+
if (call?.arb_withdraw_fee !== undefined) {
|
|
812
|
+
obj.withdraw_fee(call.arb_withdraw_fee.arb, call.arb_withdraw_fee.data, passport)
|
|
813
|
+
}
|
|
814
|
+
|
|
745
815
|
if (withdraw_treasury) {
|
|
746
816
|
withdraw_treasury.launch();
|
|
747
817
|
}
|
|
@@ -753,4 +823,72 @@ export namespace Call {
|
|
|
753
823
|
}
|
|
754
824
|
}
|
|
755
825
|
}
|
|
826
|
+
|
|
827
|
+
export const personal = (call: CallPersonal, txb:TransactionBlock) => {
|
|
828
|
+
let obj : Resource | undefined ; let entity: Entity = Entity.From(txb);
|
|
829
|
+
if (call.object === 'new') {
|
|
830
|
+
obj = Resource.From(txb, entity.create_resource2());
|
|
831
|
+
} else {
|
|
832
|
+
if (IsValidAddress(call.object)) {
|
|
833
|
+
obj = Resource.From(txb, call.object)
|
|
834
|
+
if (call?.close) {
|
|
835
|
+
entity.destroy_resource(obj)
|
|
836
|
+
return ; //@ return
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
if (call?.information !== undefined ) {
|
|
842
|
+
entity.update(call.information)
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
if (obj?.get_object()) {
|
|
846
|
+
if (call?.marks !== undefined) {
|
|
847
|
+
switch(call.marks.op) {
|
|
848
|
+
case 'add address':
|
|
849
|
+
obj.add2(call.marks.data.address, call.marks.data.mark_name)
|
|
850
|
+
break;
|
|
851
|
+
case 'add mark':
|
|
852
|
+
if (call.marks.data.mark_name === MarkName.DislikeName || call.marks.data.mark_name === MarkName.LikeName) {
|
|
853
|
+
const n = call.marks.data.mark_name;
|
|
854
|
+
call.marks.data.address.forEach(v => entity.mark(obj, v, n))
|
|
855
|
+
} else {
|
|
856
|
+
obj.add(call.marks.data.mark_name, call.marks.data.address)
|
|
857
|
+
}
|
|
858
|
+
break;
|
|
859
|
+
case 'clear mark':
|
|
860
|
+
obj.remove(call.marks.mark_name, [], true)
|
|
861
|
+
break;
|
|
862
|
+
case 'remove address':
|
|
863
|
+
obj.remove2(call.marks.data.address, call.marks.data.mark_name)
|
|
864
|
+
break;
|
|
865
|
+
case 'remove mark':
|
|
866
|
+
if (call.marks.data.mark_name === MarkName.DislikeName || call.marks.data.mark_name === MarkName.LikeName) {
|
|
867
|
+
const n = call.marks.data.mark_name;
|
|
868
|
+
call.marks.data.address.forEach(v => entity.mark(obj, v, n))
|
|
869
|
+
} else {
|
|
870
|
+
obj.remove(call.marks.data.mark_name, call.marks.data.address)
|
|
871
|
+
}
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (call?.tags !== undefined) {
|
|
876
|
+
switch(call.tags.op) {
|
|
877
|
+
case 'add':
|
|
878
|
+
obj.add_tags(call.tags.data.address, call.tags.data.nick_name, call.tags.data.tags)
|
|
879
|
+
break;
|
|
880
|
+
case 'remove':
|
|
881
|
+
obj.remove_tags(call.tags.address)
|
|
882
|
+
break;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (call?.transfer_to !== undefined) {
|
|
886
|
+
entity.transfer_resource(obj, call.transfer_to);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
if (call.object === 'new') {
|
|
890
|
+
obj.launch();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
756
894
|
}
|
|
@@ -56,21 +56,21 @@ export interface EventAnswer {
|
|
|
56
56
|
|
|
57
57
|
export namespace EVENT_QUERY {
|
|
58
58
|
export const newArbEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
59
|
-
return await queryEvents(Protocol.Instance().
|
|
59
|
+
return await queryEvents(Protocol.Instance().package('wowok') + '::arb::NewArbEvent', option)
|
|
60
60
|
}
|
|
61
61
|
export const presentServiceEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
62
|
-
return await queryEvents(Protocol.Instance().
|
|
62
|
+
return await queryEvents(Protocol.Instance().package('wowok') + '::demand::PresentEvent', option)
|
|
63
63
|
}
|
|
64
64
|
export const newProgressEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
65
|
-
return await queryEvents(Protocol.Instance().
|
|
65
|
+
return await queryEvents(Protocol.Instance().package('wowok') + '::progress::NewProgressEvent', option)
|
|
66
66
|
}
|
|
67
67
|
export const newOrderEvents = async(option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
68
|
-
return await queryEvents(Protocol.Instance().
|
|
68
|
+
return await queryEvents(Protocol.Instance().package('wowok') + '::order::NewOrderEvent', option)
|
|
69
69
|
}
|
|
70
70
|
const queryEvents = async(type:string, option?:EventQueryOption) : Promise<EventAnswer> => {
|
|
71
71
|
const res = await Protocol.Client().queryEvents({query:{MoveEventType:type}, cursor:option?.cursor, limit:option?.limit, order:option?.order});
|
|
72
72
|
const data = res?.data?.map((v:any) => {
|
|
73
|
-
if (v?.packageId === Protocol.Instance().
|
|
73
|
+
if (v?.packageId === Protocol.Instance().package('wowok')) {
|
|
74
74
|
if (v?.type?.includes('::order::NewOrderEvent')) {
|
|
75
75
|
return {
|
|
76
76
|
id: v?.id, time: v?.timestampMs, type_raw:v?.type, sender:v?.sender, type:'NewOrderEvent',
|
|
@@ -11,6 +11,7 @@ import { Machine_Node, Machine } from '../machine';
|
|
|
11
11
|
import { Progress, History } from '../progress';
|
|
12
12
|
import { ERROR, Errors } from '../exception';
|
|
13
13
|
import { IsValidAddress, Bcs } from '../utils';
|
|
14
|
+
import { WowokCache, OBJECT_KEY } from '../cache';
|
|
14
15
|
export interface ObjectBase {
|
|
15
16
|
object: string;
|
|
16
17
|
type?: string | 'Demand' | 'Progress' | 'Service' | 'Machine' | 'Order' | 'Treasury' | 'Arbitration' | 'Arb' | 'Payment' | 'Guard' |
|
|
@@ -20,7 +21,9 @@ export interface ObjectBase {
|
|
|
20
21
|
type_raw?: string;
|
|
21
22
|
owner?: any;
|
|
22
23
|
version?: string;
|
|
24
|
+
cache_expire?: number;
|
|
23
25
|
}
|
|
26
|
+
|
|
24
27
|
export interface ObjectPermission extends ObjectBase {
|
|
25
28
|
builder: string;
|
|
26
29
|
admin: string[];
|
|
@@ -248,11 +251,18 @@ export interface TableItem_ResourceMark extends ObjectBase {
|
|
|
248
251
|
objects: string[];
|
|
249
252
|
}
|
|
250
253
|
|
|
254
|
+
export enum CacheType {
|
|
255
|
+
localStorage = 'localStorage', // for explorer
|
|
256
|
+
memoryStorage = 'memoryStorage', // for console
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const MEMORY_STORAGE = new Map<string, string>();
|
|
251
260
|
export interface ObjectsQuery {
|
|
252
261
|
objects: string[];
|
|
253
262
|
showType?: boolean;
|
|
254
263
|
showContent?: boolean;
|
|
255
264
|
showOwner?: boolean;
|
|
265
|
+
no_cache?: boolean;
|
|
256
266
|
}
|
|
257
267
|
export interface ObjectsAnswer {
|
|
258
268
|
objects?: ObjectBase[];
|
|
@@ -280,6 +290,10 @@ interface TableItemQuery {
|
|
|
280
290
|
key: {type:string, value:unknown};
|
|
281
291
|
}
|
|
282
292
|
|
|
293
|
+
export interface CacheData {
|
|
294
|
+
expire: number;
|
|
295
|
+
data: string | any;
|
|
296
|
+
}
|
|
283
297
|
export namespace OBJECT_QUERY {
|
|
284
298
|
/* json: ObjectsQuery string */
|
|
285
299
|
export const objects_json = async (json:string) : Promise<string> => {
|
|
@@ -302,17 +316,65 @@ export namespace OBJECT_QUERY {
|
|
|
302
316
|
}
|
|
303
317
|
|
|
304
318
|
export const objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer> => {
|
|
319
|
+
const ret:ObjectBase[] = []; let bCached = true; const time = new Date().getTime();
|
|
320
|
+
const cache = WowokCache.Instance().get();
|
|
321
|
+
if (!query?.no_cache && cache) {
|
|
322
|
+
try {
|
|
323
|
+
for (let i = 0; i < query.objects.length; ++i) {
|
|
324
|
+
let data = cache.load(OBJECT_KEY(query.objects[i]))
|
|
325
|
+
|
|
326
|
+
if (data) {
|
|
327
|
+
const r:CacheData = JSON.parse(data);
|
|
328
|
+
const d = data2object(JSON.parse(r.data));
|
|
329
|
+
d.cache_expire = r.expire;
|
|
330
|
+
|
|
331
|
+
if (r?.expire <= time && (query.showOwner || query.showContent)) {
|
|
332
|
+
bCached = false;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
ret.push(d);
|
|
337
|
+
} else {
|
|
338
|
+
bCached = false; break;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (bCached) {
|
|
343
|
+
return {objects:ret}
|
|
344
|
+
}
|
|
345
|
+
} catch(e) {
|
|
346
|
+
console.log(e);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
305
350
|
if (query.objects.length > 0) {
|
|
306
351
|
const res = await Protocol.Client().multiGetObjects({ids:query.objects,
|
|
307
352
|
options:{showContent:query.showContent, showType:query.showType, showOwner:query.showOwner}});
|
|
308
|
-
|
|
353
|
+
const now = new Date().getTime();
|
|
354
|
+
const cache = WowokCache.Instance().get();
|
|
355
|
+
|
|
356
|
+
if (cache) {
|
|
357
|
+
res.forEach((i) => { // save
|
|
358
|
+
try {
|
|
359
|
+
if (i?.data) {
|
|
360
|
+
const type_raw:string | undefined = i.data?.type ?? ((i.data?.content as any)?.type ?? undefined);
|
|
361
|
+
const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
|
|
362
|
+
const expire = (type === 'Guard' || type === 'Payment') ? 86400000000 : cache.expire_time(); // guard & payment immutable
|
|
363
|
+
const r:CacheData = {expire:expire+now, data:JSON.stringify(i.data)}
|
|
364
|
+
cache.save(OBJECT_KEY(i.data.objectId), JSON.stringify(r));
|
|
365
|
+
}
|
|
366
|
+
} catch(e) { console.log(e) }
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
|
|
309
370
|
return {objects:res.map(v=>data2object(v?.data))}
|
|
310
371
|
}
|
|
311
372
|
return {objects:[]}
|
|
312
373
|
}
|
|
374
|
+
|
|
313
375
|
export const entity = async (address:string) : Promise<ObjectEntity> => {
|
|
314
376
|
if (!IsValidAddress(address)) ERROR(Errors.IsValidAddress, 'entity.address')
|
|
315
|
-
const res = await Protocol.Client().getDynamicFieldObject({parentId:Protocol.Instance().
|
|
377
|
+
const res = await Protocol.Client().getDynamicFieldObject({parentId:Protocol.Instance().objectEntity(), name:{type:'address', value:address}});
|
|
316
378
|
return data2object(res?.data) as ObjectEntity
|
|
317
379
|
}
|
|
318
380
|
|
|
@@ -350,7 +412,7 @@ export namespace OBJECT_QUERY {
|
|
|
350
412
|
if (typeof(repository_object) !== 'string') {
|
|
351
413
|
repository_object = repository_object.object;
|
|
352
414
|
}
|
|
353
|
-
return await tableItem({parent:repository_object, key:{type:Protocol.Instance().
|
|
415
|
+
return await tableItem({parent:repository_object, key:{type:Protocol.Instance().package('wowok')+'::repository::DataKey', value:{id:address, key:name}}})
|
|
354
416
|
}
|
|
355
417
|
export const tableItemQuery_ResourceMark = async (resource_object:string | ObjectResouorce, name:string) : Promise<ObjectBase> => {
|
|
356
418
|
return await tableItem(tableItemQuery_byString(resource_object, name))
|
|
@@ -379,7 +441,7 @@ export namespace OBJECT_QUERY {
|
|
|
379
441
|
return data2object(res?.data)
|
|
380
442
|
}
|
|
381
443
|
|
|
382
|
-
function data2object(data?:any) : ObjectBase {
|
|
444
|
+
export function data2object(data?:any) : ObjectBase {
|
|
383
445
|
const content = (data?.content as any)?.fields;
|
|
384
446
|
const id = data?.objectId ?? (content?.id?.id ?? undefined);
|
|
385
447
|
const type_raw:string | undefined = data?.type ?? (data?.content?.type ?? undefined);
|
|
@@ -48,13 +48,10 @@ export namespace PERMISSION_QUERY {
|
|
|
48
48
|
if (perm === Permission.PERMISSION_ADMIN || perm === Permission.PERMISSION_OWNER_AND_ADMIN) {
|
|
49
49
|
return {who:query.address, admin:true, owner:perm%2===1, items:[], object:query.permission_object}
|
|
50
50
|
} else {
|
|
51
|
-
const perms = Bcs.getInstance().
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
items.push({query:perms[i], permission:true, guard:guards[i] ? ('0x'+guards[i]) : undefined})
|
|
56
|
-
}
|
|
57
|
-
return {who:query.address, admin:false, owner:perm%2===1, items:items, object:query.permission_object};
|
|
51
|
+
const perms = Bcs.getInstance().de_perms(Uint8Array.from((res.results as any)[0].returnValues[1][0]));
|
|
52
|
+
return {who:query.address, admin:false, owner:perm%2===1, items:perms.map((v:any)=>{
|
|
53
|
+
return {query:v?.index, permission:true, guard:v?.guard}
|
|
54
|
+
}), object:query.permission_object};
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
}
|