wowok_agent 0.0.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/account.ts +26 -4
- package/src/call/arbitration.ts +87 -72
- package/src/call/{call.ts → base.ts} +37 -36
- package/src/call/demand.ts +73 -59
- package/src/call/guard.ts +264 -0
- package/src/call/machine.ts +85 -77
- package/src/call/permission.ts +42 -34
- package/src/call/personal.ts +38 -30
- package/src/call/repository.ts +52 -43
- package/src/call/service.ts +140 -126
- package/src/call/treasury.ts +76 -60
- package/src/call.ts +70 -0
- package/src/index.ts +3 -1
- package/src/objects.ts +338 -338
- package/src/permission.ts +33 -34
package/src/objects.ts
CHANGED
|
@@ -291,371 +291,371 @@ export interface CachedData {
|
|
|
291
291
|
expire: number | 'INFINITE';
|
|
292
292
|
data: string | any;
|
|
293
293
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
}
|
|
294
|
+
|
|
295
|
+
/* json: ObjectsQuery string */
|
|
296
|
+
export const query_objects_json = async (json:string) : Promise<string> => {
|
|
297
|
+
try {
|
|
298
|
+
const q : ObjectsQuery = JSON.parse(json);
|
|
299
|
+
return JSON.stringify({data:await query_objects(q)});
|
|
300
|
+
} catch (e) {
|
|
301
|
+
return JSON.stringify({error:e?.toString()})
|
|
303
302
|
}
|
|
303
|
+
}
|
|
304
304
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
305
|
+
/* json: TableQuery string */
|
|
306
|
+
export const query_table_json = async (json:string) : Promise<string> => {
|
|
307
|
+
try {
|
|
308
|
+
const q : TableQuery = JSON.parse(json);
|
|
309
|
+
return JSON.stringify({data:await query_table(q)});
|
|
310
|
+
} catch (e) {
|
|
311
|
+
return JSON.stringify({error:e?.toString()})
|
|
313
312
|
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export const query_objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer> => {
|
|
316
|
+
var ret:ObjectBase[] = []; const pending : string[] = [];
|
|
317
|
+
let bCached = true; const time = new Date().getTime();
|
|
318
|
+
const cache = WowokCache.Instance().get();
|
|
319
|
+
if (cache) {
|
|
320
|
+
for (let i = 0; i < query.objects.length; ++i) {
|
|
321
|
+
try {
|
|
322
|
+
let data = cache.load(OBJECT_KEY(query.objects[i]))
|
|
323
|
+
|
|
324
|
+
if (data) {
|
|
325
|
+
const r:CachedData = JSON.parse(data);
|
|
326
|
+
|
|
327
|
+
if (r?.expire !== 'INFINITE' && (query?.no_cache || r.expire <= time) && (query.showOwner || query.showContent)) { //@ type immutable
|
|
328
|
+
pending.push(query.objects[i]);
|
|
329
|
+
} else {
|
|
330
|
+
const d = data2object(JSON.parse(r.data));
|
|
331
|
+
d.cache_expire = r.expire;
|
|
332
|
+
ret.push(d);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
} catch (e) {
|
|
336
|
+
console.log(e)
|
|
337
|
+
}
|
|
338
|
+
pending.push(query.objects[i]);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
314
341
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
342
|
+
if (pending.length > 0) {
|
|
343
|
+
const res = await Protocol.Client().multiGetObjects({ids:[...pending],
|
|
344
|
+
options:{showContent:query.showContent, showType:query.showType, showOwner:query.showOwner}});
|
|
345
|
+
const now = new Date().getTime();
|
|
318
346
|
const cache = WowokCache.Instance().get();
|
|
347
|
+
|
|
319
348
|
if (cache) {
|
|
320
|
-
|
|
349
|
+
res.forEach((i) => { // save
|
|
321
350
|
try {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
console.log(e)
|
|
337
|
-
}
|
|
338
|
-
pending.push(query.objects[i]);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (pending.length > 0) {
|
|
343
|
-
const res = await Protocol.Client().multiGetObjects({ids:[...pending],
|
|
344
|
-
options:{showContent:query.showContent, showType:query.showType, showOwner:query.showOwner}});
|
|
345
|
-
const now = new Date().getTime();
|
|
346
|
-
const cache = WowokCache.Instance().get();
|
|
347
|
-
|
|
348
|
-
if (cache) {
|
|
349
|
-
res.forEach((i) => { // save
|
|
350
|
-
try {
|
|
351
|
-
if (i?.data) {
|
|
352
|
-
const type_raw:string | undefined = i.data?.type ?? ((i.data?.content as any)?.type ?? undefined);
|
|
353
|
-
const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
|
|
354
|
-
const expire = (type === 'Guard' || type === 'Payment') ? 'INFINITE' : (cache.expire_time()+now); // guard & payment immutable
|
|
355
|
-
const r:CachedData = {expire:expire, data:JSON.stringify(i.data)}
|
|
356
|
-
cache.save(OBJECT_KEY(i.data.objectId), JSON.stringify(r));
|
|
357
|
-
}
|
|
358
|
-
} catch(e) { console.log(e) }
|
|
359
|
-
})
|
|
360
|
-
}
|
|
361
|
-
ret = ret.concat(res.map(v=>data2object(v?.data)));
|
|
362
|
-
}
|
|
363
|
-
return {objects:ret}
|
|
364
|
-
}
|
|
351
|
+
if (i?.data) {
|
|
352
|
+
const type_raw:string | undefined = i.data?.type ?? ((i.data?.content as any)?.type ?? undefined);
|
|
353
|
+
const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
|
|
354
|
+
const expire = (type === 'Guard' || type === 'Payment') ? 'INFINITE' : (cache.expire_time()+now); // guard & payment immutable
|
|
355
|
+
const r:CachedData = {expire:expire, data:JSON.stringify(i.data)}
|
|
356
|
+
cache.save(OBJECT_KEY(i.data.objectId), JSON.stringify(r));
|
|
357
|
+
}
|
|
358
|
+
} catch(e) { console.log(e) }
|
|
359
|
+
})
|
|
360
|
+
}
|
|
361
|
+
ret = ret.concat(res.map(v=>data2object(v?.data)));
|
|
362
|
+
}
|
|
363
|
+
return {objects:ret}
|
|
364
|
+
}
|
|
365
365
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
366
|
+
export const query_entity = async (address:string) : Promise<ObjectEntity> => {
|
|
367
|
+
if (!IsValidAddress(address)) ERROR(Errors.IsValidAddress, 'entity.address')
|
|
368
|
+
const res = await Protocol.Client().getDynamicFieldObject({parentId:Protocol.Instance().objectEntity(), name:{type:'address', value:address}});
|
|
369
|
+
return data2object(res?.data) as ObjectEntity
|
|
370
|
+
}
|
|
371
371
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
export const queryTableItem_DemandPresenter = async (demand_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
382
|
-
return await tableItem(tableItemQuery_byAddress(demand_object, address))
|
|
383
|
-
}
|
|
384
|
-
export const queryTableItem_PermissionEntity = async (permission_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
385
|
-
return await tableItem(tableItemQuery_byAddress(permission_object, address))
|
|
386
|
-
}
|
|
387
|
-
export const queryTableItem_ArbVote = async (arb_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
388
|
-
return await tableItem(tableItemQuery_byAddress(arb_object, address))
|
|
389
|
-
}
|
|
390
|
-
export const tableItemQuery_MachineNode = async (machine_object:string | ObjectMachine, name:string) : Promise<ObjectBase> => {
|
|
391
|
-
return await tableItem(tableItemQuery_byString(machine_object, name))
|
|
392
|
-
}
|
|
393
|
-
export const tableItemQuery_ServiceSale = async (service_object:string | ObjectService, name:string) : Promise<ObjectBase> => {
|
|
394
|
-
return await tableItem(tableItemQuery_byString(service_object, name))
|
|
395
|
-
}
|
|
396
|
-
export const tableItemQuery_ProgressHistory = async (progress_object:string | ObjectProgress, index:BigInt) : Promise<ObjectBase> => {
|
|
397
|
-
return await tableItem(tableItemQuery_byU64(progress_object, index))
|
|
398
|
-
}
|
|
399
|
-
export const tableItemQuery_TreasuryHistory = async (treasury_object:string | ObjectTreasury, index:BigInt) : Promise<ObjectBase> => {
|
|
400
|
-
return await tableItem(tableItemQuery_byU64(treasury_object, index))
|
|
401
|
-
}
|
|
402
|
-
export const tableItemQuery_RepositoryData = async (repository_object:string | ObjectRepository, address:string, name:string) : Promise<ObjectBase> => {
|
|
403
|
-
if (typeof(repository_object) !== 'string') {
|
|
404
|
-
repository_object = repository_object.object;
|
|
405
|
-
}
|
|
406
|
-
return await tableItem({parent:repository_object, key:{type:Protocol.Instance().package('wowok')+'::repository::DataKey', value:{id:address, key:name}}})
|
|
407
|
-
}
|
|
408
|
-
export const tableItemQuery_ResourceMark = async (resource_object:string | ObjectResouorce, name:string) : Promise<ObjectBase> => {
|
|
409
|
-
return await tableItem(tableItemQuery_byString(resource_object, name))
|
|
410
|
-
}
|
|
372
|
+
export const query_table = async (query:TableQuery) : Promise<TableAnswer> => {
|
|
373
|
+
const res = await Protocol.Client().getDynamicFields({parentId:query.parent, cursor:query.cursor, limit:query.limit});
|
|
374
|
+
return {items:res?.data?.map(v=>{
|
|
375
|
+
return {object:v.objectId, type:v.type, version:v.version, key:{
|
|
376
|
+
type:v.name.type, value:v.name.value
|
|
377
|
+
}}
|
|
378
|
+
}), nextCursor:res.nextCursor, hasNextPage:res.hasNextPage}
|
|
379
|
+
}
|
|
411
380
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
381
|
+
export const queryTableItem_DemandPresenter = async (demand_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
382
|
+
return await tableItem(tableItemQuery_byAddress(demand_object, address))
|
|
383
|
+
}
|
|
384
|
+
export const queryTableItem_PermissionEntity = async (permission_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
385
|
+
return await tableItem(tableItemQuery_byAddress(permission_object, address))
|
|
386
|
+
}
|
|
387
|
+
export const queryTableItem_ArbVote = async (arb_object:string | ObjectDemand, address:string) : Promise<ObjectBase> => {
|
|
388
|
+
return await tableItem(tableItemQuery_byAddress(arb_object, address))
|
|
389
|
+
}
|
|
390
|
+
export const tableItemQuery_MachineNode = async (machine_object:string | ObjectMachine, name:string) : Promise<ObjectBase> => {
|
|
391
|
+
return await tableItem(tableItemQuery_byString(machine_object, name))
|
|
392
|
+
}
|
|
393
|
+
export const tableItemQuery_ServiceSale = async (service_object:string | ObjectService, name:string) : Promise<ObjectBase> => {
|
|
394
|
+
return await tableItem(tableItemQuery_byString(service_object, name))
|
|
395
|
+
}
|
|
396
|
+
export const tableItemQuery_ProgressHistory = async (progress_object:string | ObjectProgress, index:BigInt) : Promise<ObjectBase> => {
|
|
397
|
+
return await tableItem(tableItemQuery_byU64(progress_object, index))
|
|
398
|
+
}
|
|
399
|
+
export const tableItemQuery_TreasuryHistory = async (treasury_object:string | ObjectTreasury, index:BigInt) : Promise<ObjectBase> => {
|
|
400
|
+
return await tableItem(tableItemQuery_byU64(treasury_object, index))
|
|
401
|
+
}
|
|
402
|
+
export const tableItemQuery_RepositoryData = async (repository_object:string | ObjectRepository, address:string, name:string) : Promise<ObjectBase> => {
|
|
403
|
+
if (typeof(repository_object) !== 'string') {
|
|
404
|
+
repository_object = repository_object.object;
|
|
417
405
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
406
|
+
return await tableItem({parent:repository_object, key:{type:Protocol.Instance().package('wowok')+'::repository::DataKey', value:{id:address, key:name}}})
|
|
407
|
+
}
|
|
408
|
+
export const tableItemQuery_ResourceMark = async (resource_object:string | ObjectResouorce, name:string) : Promise<ObjectBase> => {
|
|
409
|
+
return await tableItem(tableItemQuery_byString(resource_object, name))
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function tableItemQuery_byAddress(parent:string | ObjectDemand | ObjectPermission | ObjectArb, address:string) : TableItemQuery {
|
|
413
|
+
if (typeof(parent) !== 'string') {
|
|
414
|
+
parent = parent.object;
|
|
423
415
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
416
|
+
return {parent:parent, key:{type:'address', value:address}};
|
|
417
|
+
}
|
|
418
|
+
function tableItemQuery_byString(parent:string | ObjectMachine | ObjectService | ObjectResouorce, name:string) : TableItemQuery {
|
|
419
|
+
if (typeof(parent) !== 'string') {
|
|
420
|
+
parent = parent.object;
|
|
429
421
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
422
|
+
return {parent:parent, key:{type:'0x1::string::String', value:name}};
|
|
423
|
+
}
|
|
424
|
+
function tableItemQuery_byU64 (parent:string | ObjectProgress | ObjectTreasury, index:BigInt) : TableItemQuery {
|
|
425
|
+
if (typeof(parent) !== 'string') {
|
|
426
|
+
parent = parent.object;
|
|
433
427
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
428
|
+
return {parent:parent, key:{type:'u64', value:index}};
|
|
429
|
+
}
|
|
430
|
+
const tableItem = async (query:TableItemQuery) : Promise<ObjectBase> => {
|
|
431
|
+
const res = await Protocol.Client().getDynamicFieldObject({parentId:query.parent, name:{type:query.key.type, value:query.key.value}});
|
|
432
|
+
return data2object(res?.data)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export function data2object(data?:any) : ObjectBase {
|
|
436
|
+
const content = (data?.content as any)?.fields;
|
|
437
|
+
const id = data?.objectId ?? (content?.id?.id ?? undefined);
|
|
438
|
+
const type_raw:string | undefined = data?.type ?? (data?.content?.type ?? undefined);
|
|
439
|
+
const version = data?.version ?? undefined;
|
|
440
|
+
const owner = data?.owner ?? undefined;
|
|
441
|
+
const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
|
|
442
|
+
|
|
443
|
+
if (type) {
|
|
444
|
+
switch(type) {
|
|
445
|
+
case 'Permission':
|
|
446
|
+
return {object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
447
|
+
builder: content?.builder ??'', admin:content?.admin, description:content?.description??'',
|
|
448
|
+
entity_count: parseInt(content?.table?.fields?.size),
|
|
449
|
+
biz_permission:content?.user_define?.fields?.contents?.map((v:any) => {
|
|
450
|
+
return {id:parseInt(v?.fields?.key), name:v?.fields?.value}
|
|
451
|
+
})
|
|
452
|
+
} as ObjectPermission;
|
|
453
|
+
case 'Demand':
|
|
454
|
+
return {
|
|
455
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
456
|
+
permission: content?.permission, description:content?.description,
|
|
457
|
+
guard:content?.guard ? {object:content?.guard, service_id_in_guard:content?.service_identifier}:undefined,
|
|
458
|
+
time_expire:content?.time_expire, yes:content?.yes,
|
|
459
|
+
presenter_count:parseInt(content?.presenters?.fields?.size),
|
|
460
|
+
bounty: content?.bounty?.map((v:any) => {
|
|
461
|
+
return {type:v?.fields?.type, object:v?.fields?.id?.id, balance:v?.fields?.balance}
|
|
462
|
+
})
|
|
463
|
+
} as ObjectDemand;
|
|
464
|
+
case 'Machine':
|
|
465
|
+
return {
|
|
466
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
467
|
+
permission: content?.permission ?? '', description:content?.description??'',
|
|
468
|
+
bPaused: content?.bPaused, bPublished:content?.bPublished, endpoint:content?.endpoint,
|
|
469
|
+
consensus_repository:content?.consensus_repositories, node_count:parseInt(content?.nodes?.fields?.size),
|
|
470
|
+
} as ObjectMachine;
|
|
471
|
+
case 'Progress':
|
|
472
|
+
return {
|
|
473
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
474
|
+
machine: content?.machine, current: content?.current, task:content?.task,
|
|
475
|
+
parent:content?.parent, history_count:parseInt(content?.history?.fields?.contents?.fields?.size),
|
|
476
|
+
namedOperator:content?.namedOperator?.fields?.contents?.map((v:any) => {
|
|
477
|
+
return {name:v?.fields?.key, operator:v?.fields?.value}
|
|
478
|
+
}),
|
|
479
|
+
session:content?.session?.fields?.contents?.map((v:any) => {
|
|
480
|
+
return {weights:v?.fields?.value?.fields?.weight, threshold:v?.fields?.value?.fields?.threshold,
|
|
481
|
+
next_node:v?.fields?.key, forward: v?.fields?.value?.fields?.forwards?.fields?.contents?.map((i:any) => {
|
|
482
|
+
return {forward_name:i?.fields?.key, accomplished:i?.fields?.value?.fields?.accomplished,
|
|
483
|
+
msg:i?.fields?.value?.fields?.msg, orders:i?.fields?.value?.fields?.orders,
|
|
484
|
+
time:i?.fields?.value?.fields?.time, holder:i?.fields?.value?.fields?.who
|
|
485
|
+
}
|
|
486
|
+
})
|
|
487
|
+
}
|
|
488
|
+
})
|
|
489
|
+
} as ObjectProgress;
|
|
490
|
+
case 'Order':
|
|
491
|
+
return {
|
|
492
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
493
|
+
service:content?.service, amount: content?.amount, agent:content?.agent, arb:content?.dispute,
|
|
494
|
+
payer:content?.payer, progress:content?.progress, discount:content?.discount, balance:content?.payed,
|
|
495
|
+
required_info: content?.required_info ?
|
|
496
|
+
{pubkey:content?.required_info?.fields?.customer_pub, msg_encrypted:content?.required_info?.fields?.info}
|
|
497
|
+
: undefined,
|
|
498
|
+
item : content?.items?.map((v:any) => {
|
|
499
|
+
return {name:v?.fields?.name, price:v?.fields?.price, stock:v?.fields?.stock, endpoint:v?.fields?.endpoint}
|
|
500
|
+
}),
|
|
501
|
+
} as ObjectOrder;
|
|
502
|
+
case 'Service':
|
|
503
|
+
return {
|
|
504
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
505
|
+
machine:content?.machine, permission:content?.permission, description:content?.description,
|
|
506
|
+
arbitration:content?.arbitrations, bPaused:content?.bPaused, bPublished:content?.bPublished,
|
|
507
|
+
buy_guard:content?.buy_guard, endpoint:content?.endpoint, payee:content?.payee, repository:content?.repositories,
|
|
508
|
+
withdraw_guard:content?.withdraw_guard?.fields?.contents?.map((v:any) => {
|
|
509
|
+
return {object:v?.fields?.key, percent:v?.fields?.value}
|
|
510
|
+
}),
|
|
511
|
+
refund_guard:content?.refund_guard?.fields?.contents?.map((v:any) => {
|
|
512
|
+
return {object:v?.fields?.key, percent:v?.fields?.value}
|
|
513
|
+
}),
|
|
514
|
+
sales_count:parseInt(content?.sales?.fields?.size), extern_withdraw_treasury:content?.extern_withdraw_treasuries,
|
|
515
|
+
customer_required_info:content?.customer_required ?
|
|
516
|
+
{pubkey:content?.customer_required?.fields?.service_pubkey, required_info:content?.customer_required?.fields?.customer_required_info}
|
|
517
|
+
:undefined,
|
|
518
|
+
} as ObjectService;
|
|
519
|
+
case 'Treasury':
|
|
520
|
+
return {
|
|
521
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
522
|
+
permission:content?.permission, description:content?.description, withdraw_mode:content?.withdraw_mode,
|
|
523
|
+
history_count:parseInt(content?.history?.fields?.contents?.fields?.size), balance: content?.balance,
|
|
524
|
+
deposit_guard:content?.deposit_guard, withdraw_guard:content?.withdraw_guard?.fields?.contents?.map((v:any) => {
|
|
525
|
+
return {object:v?.fields?.key, percent:v?.fields?.value}
|
|
526
|
+
})
|
|
527
|
+
} as ObjectTreasury;
|
|
528
|
+
case 'Arbitration':
|
|
529
|
+
return {
|
|
530
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
531
|
+
permission:content?.permission, description:content?.description, fee:content?.fee,
|
|
532
|
+
fee_treasury:content?.fee_treasury, usage_guard:content?.usage_guard,
|
|
533
|
+
endpoint:content?.endpoint, bPaused:content?.bPaused, voting_guard:content?.voting_guard?.fields?.contents?.map((v:any) => {
|
|
534
|
+
return {object:v?.fields?.key, weights:v?.fields?.value}
|
|
535
|
+
})
|
|
536
|
+
} as ObjectArbitration;
|
|
537
|
+
case 'Arb':
|
|
538
|
+
return {
|
|
539
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
540
|
+
arbitration:content?.arbitration, description:content?.description, fee:content?.fee,
|
|
541
|
+
feedback:content?.feedback, indemnity:content?.indemnity, order:content?.order,
|
|
542
|
+
voted_count:parseInt(content?.voted?.fields?.size),
|
|
543
|
+
proposition:content?.proposition?.fields?.contents?.map((v:any) => {
|
|
544
|
+
return {proposition:v?.fields?.key, votes:v?.fields?.value}
|
|
545
|
+
})
|
|
546
|
+
} as ObjectArb;
|
|
547
|
+
case 'Repository':
|
|
548
|
+
return {
|
|
549
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
550
|
+
permission:content?.permission, description:content?.description, policy_mode:content?.policy_mode,
|
|
551
|
+
data_count:parseInt(content?.data?.fields?.size), reference:content?.reference, rep_type:content?.type,
|
|
552
|
+
policy:content?.policies?.fields?.contents?.map((v:any) => {
|
|
553
|
+
return {key:v?.fields?.key, description:v?.fields?.value?.fields?.description,
|
|
554
|
+
permissionIndex:v?.fields?.value?.fields?.permission_index, dataType:v?.fields?.value?.fields?.value_type}
|
|
462
555
|
})
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
556
|
+
} as ObjectRepository;
|
|
557
|
+
case 'Payment':
|
|
558
|
+
return {
|
|
559
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
560
|
+
signer:content?.signer, time:content?.time, remark:content?.remark, from: content?.from,
|
|
561
|
+
biz_id:content?.index, for_guard:content?.for_guard, for_object:content?.for_object,
|
|
562
|
+
amount:content?.amount, record:content?.record?.map((v:any) => {
|
|
563
|
+
return {recipient:v?.fields?.recipient, amount:v?.fields?.amount}
|
|
564
|
+
})
|
|
565
|
+
} as ObjectPayment;
|
|
566
|
+
case 'Discount':
|
|
567
|
+
return {
|
|
568
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
569
|
+
service:content?.service, time_start:content?.time_start, time_end:content?.time_end,
|
|
570
|
+
price_greater:content?.price_greater, off_type:content?.type, off:content?.off,
|
|
571
|
+
name:content?.name
|
|
572
|
+
} as ObjectDiscount;
|
|
573
|
+
case 'Guard':
|
|
574
|
+
return {
|
|
575
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
576
|
+
description:content?.description, input:Uint8Array.from(content?.input?.fields?.bytes),
|
|
577
|
+
identifier:content?.constants?.map((v:any) => {
|
|
578
|
+
return {id:v?.fields?.identifier, bWitness:v?.fields?.bWitness, value:Uint8Array.from(v?.fields?.value)}
|
|
579
|
+
})
|
|
580
|
+
} as ObjectGuard;
|
|
581
|
+
case 'Resource' :
|
|
582
|
+
return {
|
|
583
|
+
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
584
|
+
marks_count:parseInt(content?.marks?.fields?.size),
|
|
585
|
+
tags:content?.tags?.map((v:any) => {
|
|
586
|
+
return {object:v?.fields?.object, nick_name:v?.fields?.nick, tags:v?.fields?.tags}
|
|
587
|
+
})
|
|
588
|
+
} as ObjectResouorce;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const start = type_raw?.indexOf('0x2::dynamic_field::Field<');
|
|
593
|
+
if (start === 0) {
|
|
594
|
+
const end = type_raw?.substring('0x2::dynamic_field::Field<'.length);
|
|
595
|
+
if(end && Protocol.Instance().hasPackage(end)) {
|
|
596
|
+
if (end.includes('::demand::Tips>')) {
|
|
472
597
|
return {
|
|
473
|
-
object:id, type:
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return {name:v?.fields?.key, operator:v?.fields?.value}
|
|
478
|
-
}),
|
|
479
|
-
session:content?.session?.fields?.contents?.map((v:any) => {
|
|
480
|
-
return {weights:v?.fields?.value?.fields?.weight, threshold:v?.fields?.value?.fields?.threshold,
|
|
481
|
-
next_node:v?.fields?.key, forward: v?.fields?.value?.fields?.forwards?.fields?.contents?.map((i:any) => {
|
|
482
|
-
return {forward_name:i?.fields?.key, accomplished:i?.fields?.value?.fields?.accomplished,
|
|
483
|
-
msg:i?.fields?.value?.fields?.msg, orders:i?.fields?.value?.fields?.orders,
|
|
484
|
-
time:i?.fields?.value?.fields?.time, holder:i?.fields?.value?.fields?.who
|
|
485
|
-
}
|
|
486
|
-
})
|
|
487
|
-
}
|
|
488
|
-
})
|
|
489
|
-
} as ObjectProgress;
|
|
490
|
-
case 'Order':
|
|
598
|
+
object:id, type:'DemandTable_Presenter', type_raw:type_raw, owner:owner, version:version,
|
|
599
|
+
service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
|
|
600
|
+
} as TableItem_DemandPresenter;
|
|
601
|
+
} else if (end.includes('::machine::NodePair>>>')) {
|
|
491
602
|
return {
|
|
492
|
-
object:id, type:
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
{pubkey:content?.required_info?.fields?.customer_pub, msg_encrypted:content?.required_info?.fields?.info}
|
|
497
|
-
: undefined,
|
|
498
|
-
item : content?.items?.map((v:any) => {
|
|
499
|
-
return {name:v?.fields?.name, price:v?.fields?.price, stock:v?.fields?.stock, endpoint:v?.fields?.endpoint}
|
|
500
|
-
}),
|
|
501
|
-
} as ObjectOrder;
|
|
502
|
-
case 'Service':
|
|
603
|
+
object:id, type:'MachineTable_Node', type_raw:type_raw, owner:owner, version:version,
|
|
604
|
+
node:{name:content?.name, pairs:Machine.rpc_de_pair(content?.value)}
|
|
605
|
+
} as TableItem_MachineNode;
|
|
606
|
+
} else if (end.includes('::progress::History>')) {
|
|
503
607
|
return {
|
|
504
|
-
object:id, type:
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
withdraw_guard:content?.withdraw_guard?.fields?.contents?.map((v:any) => {
|
|
509
|
-
return {object:v?.fields?.key, percent:v?.fields?.value}
|
|
510
|
-
}),
|
|
511
|
-
refund_guard:content?.refund_guard?.fields?.contents?.map((v:any) => {
|
|
512
|
-
return {object:v?.fields?.key, percent:v?.fields?.value}
|
|
513
|
-
}),
|
|
514
|
-
sales_count:parseInt(content?.sales?.fields?.size), extern_withdraw_treasury:content?.extern_withdraw_treasuries,
|
|
515
|
-
customer_required_info:content?.customer_required ?
|
|
516
|
-
{pubkey:content?.customer_required?.fields?.service_pubkey, required_info:content?.customer_required?.fields?.customer_required_info}
|
|
517
|
-
:undefined,
|
|
518
|
-
} as ObjectService;
|
|
519
|
-
case 'Treasury':
|
|
608
|
+
object:id, type:'ProgressTable_History', type_raw:type_raw, owner:owner, version:version,
|
|
609
|
+
history:Progress.DeHistory(content)
|
|
610
|
+
} as TableItem_ProgressHistory;
|
|
611
|
+
} else if (end.includes('::service::Sale>')) {
|
|
520
612
|
return {
|
|
521
|
-
object:id, type:
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
} as ObjectTreasury;
|
|
528
|
-
case 'Arbitration':
|
|
613
|
+
object:id, type:'ServiceTable_Sale', type_raw:type_raw, owner:owner, version:version,
|
|
614
|
+
item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
|
|
615
|
+
endpoint:content?.value?.fields?.endpoint
|
|
616
|
+
}
|
|
617
|
+
} as TableItem_ServiceSale;
|
|
618
|
+
} else if (end.includes('::treasury::Record>')) {
|
|
529
619
|
return {
|
|
530
|
-
object:id, type:
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
})
|
|
536
|
-
} as ObjectArbitration;
|
|
537
|
-
case 'Arb':
|
|
620
|
+
object:id, type:'TreasuryTable_History', type_raw:type_raw, owner:owner, version:version,
|
|
621
|
+
id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
|
|
622
|
+
operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
|
|
623
|
+
} as TableItem_TreasuryHistory;
|
|
624
|
+
} else if (end.includes('::arb::Voted>')) {
|
|
538
625
|
return {
|
|
539
|
-
object:id, type:
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
return {proposition:v?.fields?.key, votes:v?.fields?.value}
|
|
545
|
-
})
|
|
546
|
-
} as ObjectArb;
|
|
547
|
-
case 'Repository':
|
|
626
|
+
object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
|
|
627
|
+
singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
|
|
628
|
+
weight:content?.value?.fields?.weight
|
|
629
|
+
} as TableItem_ArbVote;
|
|
630
|
+
} else if (end.includes('::permission::Perm>>')) {
|
|
548
631
|
return {
|
|
549
|
-
object:id, type:
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
policy:content?.policies?.fields?.contents?.map((v:any) => {
|
|
553
|
-
return {key:v?.fields?.key, description:v?.fields?.value?.fields?.description,
|
|
554
|
-
permissionIndex:v?.fields?.value?.fields?.permission_index, dataType:v?.fields?.value?.fields?.value_type}
|
|
555
|
-
})
|
|
556
|
-
} as ObjectRepository;
|
|
557
|
-
case 'Payment':
|
|
558
|
-
return {
|
|
559
|
-
object:id, type:type, type_raw:type_raw, owner:owner, version:version,
|
|
560
|
-
signer:content?.signer, time:content?.time, remark:content?.remark, from: content?.from,
|
|
561
|
-
biz_id:content?.index, for_guard:content?.for_guard, for_object:content?.for_object,
|
|
562
|
-
amount:content?.amount, record:content?.record?.map((v:any) => {
|
|
563
|
-
return {recipient:v?.fields?.recipient, amount:v?.fields?.amount}
|
|
632
|
+
object:id, type:'TableItem_PermissionEntity', type_raw:type_raw, owner:owner, version:version,
|
|
633
|
+
entity:content?.name, permission:content?.value?.map((v:any) => {
|
|
634
|
+
return {id:v?.fields.index, guard:v?.fields.guard}
|
|
564
635
|
})
|
|
565
|
-
} as
|
|
566
|
-
|
|
636
|
+
} as TableItem_PermissionEntity;
|
|
637
|
+
} else if (end.includes('::repository::DataKey')) {
|
|
567
638
|
return {
|
|
568
|
-
object:id, type:
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
case 'Guard':
|
|
639
|
+
object:id, type:'TableItem_RepositoryData', type_raw:type_raw, owner:owner, version:version,
|
|
640
|
+
address:content?.name?.fields?.id, key:content?.name?.fields?.key, data:Uint8Array.from(content?.value)
|
|
641
|
+
} as TableItem_RepositoryData;
|
|
642
|
+
} else if (end.includes('::entity::Ent>')) {
|
|
643
|
+
const info = Bcs.getInstance().de_entInfo(Uint8Array.from(content?.value?.fields?.avatar));
|
|
574
644
|
return {
|
|
575
|
-
object:id, type:
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
} as
|
|
581
|
-
|
|
645
|
+
object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
|
|
646
|
+
address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
|
|
647
|
+
resource_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
|
|
648
|
+
homepage:info?.homepage, name:info?.name, avatar:info?.avatar, x:info?.twitter, discord:info?.discord,
|
|
649
|
+
description:info?.description
|
|
650
|
+
} as ObjectEntity;
|
|
651
|
+
} else if (end.includes('::resource::Addresses>')) {
|
|
582
652
|
return {
|
|
583
|
-
object:id, type:
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
return {object:v?.fields?.object, nick_name:v?.fields?.nick, tags:v?.fields?.tags}
|
|
587
|
-
})
|
|
588
|
-
} as ObjectResouorce;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const start = type_raw?.indexOf('0x2::dynamic_field::Field<');
|
|
593
|
-
if (start === 0) {
|
|
594
|
-
const end = type_raw?.substring('0x2::dynamic_field::Field<'.length);
|
|
595
|
-
if(end && Protocol.Instance().hasPackage(end)) {
|
|
596
|
-
if (end.includes('::demand::Tips>')) {
|
|
597
|
-
return {
|
|
598
|
-
object:id, type:'DemandTable_Presenter', type_raw:type_raw, owner:owner, version:version,
|
|
599
|
-
service:content?.name, presenter:content?.value?.fields?.who, recommendation:content?.value?.fields?.tips
|
|
600
|
-
} as TableItem_DemandPresenter;
|
|
601
|
-
} else if (end.includes('::machine::NodePair>>>')) {
|
|
602
|
-
return {
|
|
603
|
-
object:id, type:'MachineTable_Node', type_raw:type_raw, owner:owner, version:version,
|
|
604
|
-
node:{name:content?.name, pairs:Machine.rpc_de_pair(content?.value)}
|
|
605
|
-
} as TableItem_MachineNode;
|
|
606
|
-
} else if (end.includes('::progress::History>')) {
|
|
607
|
-
return {
|
|
608
|
-
object:id, type:'ProgressTable_History', type_raw:type_raw, owner:owner, version:version,
|
|
609
|
-
history:Progress.DeHistory(content)
|
|
610
|
-
} as TableItem_ProgressHistory;
|
|
611
|
-
} else if (end.includes('::service::Sale>')) {
|
|
612
|
-
return {
|
|
613
|
-
object:id, type:'ServiceTable_Sale', type_raw:type_raw, owner:owner, version:version,
|
|
614
|
-
item:{item:content?.name, stock:content?.value?.fields?.stock, price:content?.value?.fields?.price,
|
|
615
|
-
endpoint:content?.value?.fields?.endpoint
|
|
616
|
-
}
|
|
617
|
-
} as TableItem_ServiceSale;
|
|
618
|
-
} else if (end.includes('::treasury::Record>')) {
|
|
619
|
-
return {
|
|
620
|
-
object:id, type:'TreasuryTable_History', type_raw:type_raw, owner:owner, version:version,
|
|
621
|
-
id: content?.name, payment:content?.value?.fields?.payment, signer:content?.value?.fields?.signer,
|
|
622
|
-
operation: content?.value?.fields?.op, amount: content?.value?.fields?.amount, time:content?.value?.fields?.time
|
|
623
|
-
} as TableItem_TreasuryHistory;
|
|
624
|
-
} else if (end.includes('::arb::Voted>')) {
|
|
625
|
-
return {
|
|
626
|
-
object:id, type:'ArbTable_Vote', type_raw:type_raw, owner:owner, version:version,
|
|
627
|
-
singer:content?.name, vote:content?.value?.fields?.agrees, time: content?.value?.fields?.time,
|
|
628
|
-
weight:content?.value?.fields?.weight
|
|
629
|
-
} as TableItem_ArbVote;
|
|
630
|
-
} else if (end.includes('::permission::Perm>>')) {
|
|
631
|
-
return {
|
|
632
|
-
object:id, type:'TableItem_PermissionEntity', type_raw:type_raw, owner:owner, version:version,
|
|
633
|
-
entity:content?.name, permission:content?.value?.map((v:any) => {
|
|
634
|
-
return {id:v?.fields.index, guard:v?.fields.guard}
|
|
635
|
-
})
|
|
636
|
-
} as TableItem_PermissionEntity;
|
|
637
|
-
} else if (end.includes('::repository::DataKey')) {
|
|
638
|
-
return {
|
|
639
|
-
object:id, type:'TableItem_RepositoryData', type_raw:type_raw, owner:owner, version:version,
|
|
640
|
-
address:content?.name?.fields?.id, key:content?.name?.fields?.key, data:Uint8Array.from(content?.value)
|
|
641
|
-
} as TableItem_RepositoryData;
|
|
642
|
-
} else if (end.includes('::entity::Ent>')) {
|
|
643
|
-
const info = Bcs.getInstance().de_entInfo(Uint8Array.from(content?.value?.fields?.avatar));
|
|
644
|
-
return {
|
|
645
|
-
object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
|
|
646
|
-
address:content?.name, like:content?.value?.fields?.like, dislike:content?.value?.fields?.dislike,
|
|
647
|
-
resource_object: content?.value?.fields?.resource, lastActive_digest: data?.previousTransaction,
|
|
648
|
-
homepage:info?.homepage, name:info?.name, avatar:info?.avatar, x:info?.twitter, discord:info?.discord,
|
|
649
|
-
description:info?.description
|
|
650
|
-
} as ObjectEntity;
|
|
651
|
-
} else if (end.includes('::resource::Addresses>')) {
|
|
652
|
-
return {
|
|
653
|
-
object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
|
|
654
|
-
mark_name:content?.name, objects:content?.value?.fields?.addresses
|
|
655
|
-
} as TableItem_ResourceMark;
|
|
656
|
-
}
|
|
653
|
+
object:id, type:'Entity', type_raw:type_raw, owner:owner, version:version,
|
|
654
|
+
mark_name:content?.name, objects:content?.value?.fields?.addresses
|
|
655
|
+
} as TableItem_ResourceMark;
|
|
657
656
|
}
|
|
658
657
|
}
|
|
659
|
-
return {object:id, type:type, type_raw:type_raw, owner:owner, version:version}
|
|
660
658
|
}
|
|
659
|
+
return {object:id, type:type, type_raw:type_raw, owner:owner, version:version}
|
|
661
660
|
}
|
|
661
|
+
|