wowok_agent 1.3.47 → 1.3.49

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.
Files changed (74) hide show
  1. package/dist/call/arbitration.d.ts +4 -3
  2. package/dist/call/arbitration.d.ts.map +1 -1
  3. package/dist/call/arbitration.js +134 -131
  4. package/dist/call/arbitration.js.map +1 -1
  5. package/dist/call/base.d.ts +15 -7
  6. package/dist/call/base.d.ts.map +1 -1
  7. package/dist/call/base.js +21 -23
  8. package/dist/call/base.js.map +1 -1
  9. package/dist/call/call.d.ts +0 -6
  10. package/dist/call/call.d.ts.map +1 -1
  11. package/dist/call/demand.d.ts +1 -0
  12. package/dist/call/demand.d.ts.map +1 -1
  13. package/dist/call/demand.js +86 -80
  14. package/dist/call/demand.js.map +1 -1
  15. package/dist/call/machine.d.ts +10 -10
  16. package/dist/call/machine.d.ts.map +1 -1
  17. package/dist/call/machine.js +174 -146
  18. package/dist/call/machine.js.map +1 -1
  19. package/dist/call/permission.d.ts +10 -9
  20. package/dist/call/permission.d.ts.map +1 -1
  21. package/dist/call/permission.js +90 -85
  22. package/dist/call/permission.js.map +1 -1
  23. package/dist/call/personal.d.ts +3 -3
  24. package/dist/call/personal.d.ts.map +1 -1
  25. package/dist/call/personal.js +6 -12
  26. package/dist/call/personal.js.map +1 -1
  27. package/dist/call/repository.d.ts +24 -8
  28. package/dist/call/repository.d.ts.map +1 -1
  29. package/dist/call/repository.js +114 -94
  30. package/dist/call/repository.js.map +1 -1
  31. package/dist/call/service.d.ts +15 -26
  32. package/dist/call/service.d.ts.map +1 -1
  33. package/dist/call/service.js +274 -264
  34. package/dist/call/service.js.map +1 -1
  35. package/dist/call/treasury.d.ts +5 -7
  36. package/dist/call/treasury.d.ts.map +1 -1
  37. package/dist/call/treasury.js +108 -97
  38. package/dist/call/treasury.js.map +1 -1
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +1 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/query/objects.d.ts +2 -1
  44. package/dist/query/objects.d.ts.map +1 -1
  45. package/dist/query/objects.js +7 -7
  46. package/dist/query/objects.js.map +1 -1
  47. package/dist/query/owned.d.ts +2 -0
  48. package/dist/query/owned.d.ts.map +1 -0
  49. package/dist/query/owned.js +2 -0
  50. package/dist/query/owned.js.map +1 -0
  51. package/dist/query/permission.d.ts +3 -2
  52. package/dist/query/permission.d.ts.map +1 -1
  53. package/dist/query/permission.js +6 -3
  54. package/dist/query/permission.js.map +1 -1
  55. package/dist/query/treasury_received.d.ts +14 -0
  56. package/dist/query/treasury_received.d.ts.map +1 -0
  57. package/dist/query/treasury_received.js +19 -0
  58. package/dist/query/treasury_received.js.map +1 -0
  59. package/package.json +1 -1
  60. package/src/call/arbitration.ts +144 -141
  61. package/src/call/base.ts +27 -29
  62. package/src/call/call.ts +6 -6
  63. package/src/call/demand.ts +89 -81
  64. package/src/call/machine.ts +184 -145
  65. package/src/call/permission.ts +98 -90
  66. package/src/call/personal.ts +8 -13
  67. package/src/call/repository.ts +138 -95
  68. package/src/call/service.ts +290 -272
  69. package/src/call/treasury.ts +110 -99
  70. package/src/index.ts +1 -0
  71. package/src/query/objects.ts +10 -10
  72. package/src/query/permission.ts +9 -6
  73. package/src/query/treasury_received.ts +35 -0
  74. package/tsconfig.tsbuildinfo +1 -1
@@ -7,9 +7,9 @@ import { Account } from '../local/account.js';
7
7
  /// The execution priority is determined by the order in which the object attributes are arranged
8
8
  export interface CallPersonal_Data {
9
9
  information?: Entity_Info;
10
- mark?: {op:'add'; data:{entity:AccountOrMark_Address; name?:string; tags?:string[]}[]}
11
- | {op:'remove'; data:{entity:AccountOrMark_Address; tags?:string[]}[]}
12
- | {op:'removeall'; entities:AccountOrMark_Address[]}
10
+ mark?: {op:'add'; data:{address:AccountOrMark_Address; name?:string; tags?:string[]}[]}
11
+ | {op:'remove'; data:{address:AccountOrMark_Address; tags?:string[]}[]}
12
+ | {op:'removeall'; addresses:AccountOrMark_Address[]}
13
13
  | {op:'transfer'; to: AccountOrMark_Address}
14
14
  | {op:'replace'; mark_object: string}
15
15
  | {op:'destroy'}
@@ -25,13 +25,8 @@ export class CallPersonal extends CallBase {
25
25
  return await this.exec(account)
26
26
  }
27
27
  protected async operate (txb:TransactionBlock, passport?:PassportObject, account?: string) {
28
- const entity_address = (await Account.Instance().get(account))?.address;
29
- if (!entity_address) {
30
- ERROR(Errors.InvalidParam, 'account - ' + account)
31
- };
32
-
33
28
  let obj : Resource | undefined ; let entity: Entity = Entity.From(txb);
34
- const entity_data = await query_personal({address:entity_address});
29
+ const entity_data = await query_personal({address:{account_name:account}});
35
30
  if (entity_data?.mark_object) {
36
31
  obj = Resource.From(txb, entity_data.mark_object);
37
32
  } else {
@@ -57,7 +52,7 @@ export class CallPersonal extends CallBase {
57
52
  const add = [];
58
53
  for (let i = 0; i < this.data.mark.data.length; ++i) {
59
54
  const v = this.data.mark.data[i];
60
- const addr = await GetAccountOrMark_Address(v.entity);
55
+ const addr = await GetAccountOrMark_Address(v.address);
61
56
  if (addr) {
62
57
  add.push({address:addr, tags:v.tags, name:v.name})
63
58
  }
@@ -71,7 +66,7 @@ export class CallPersonal extends CallBase {
71
66
  const remove = [];
72
67
  for (let i = 0; i < this.data.mark.data.length; ++i) {
73
68
  const v = this.data.mark.data[i];
74
- const addr = await GetAccountOrMark_Address(v.entity);
69
+ const addr = await GetAccountOrMark_Address(v.address);
75
70
  if (addr) {
76
71
  remove.push({address:addr, tags:v.tags})
77
72
  }
@@ -81,8 +76,8 @@ export class CallPersonal extends CallBase {
81
76
  })
82
77
  break;
83
78
  case 'removeall':
84
- for (let i = 0; i < this.data.mark.entities.length; ++i) {
85
- const v = this.data.mark.entities[i];
79
+ for (let i = 0; i < this.data.mark.addresses.length; ++i) {
80
+ const v = this.data.mark.addresses[i];
86
81
  const addr = await GetAccountOrMark_Address(v);
87
82
  if (addr) {
88
83
  obj?.removeall(addr)
@@ -1,17 +1,49 @@
1
1
  import { TransactionBlock, PassportObject, Errors, ERROR, Permission, PermissionIndex,
2
- PermissionIndexType, Repository, Repository_Policy, Repository_Policy_Data, Repository_Policy_Data2,
3
- Repository_Policy_Data_Remove, Repository_Policy_Mode, Repository_Value,
2
+ PermissionIndexType, Repository, Repository_Policy_Mode, Repository_Value as Wowok_Repository_Value,
3
+ PermissionObject, uint2address, IsValidU256, ValueType, Repository_Policy, Repository_Value2,
4
4
  } from 'wowok';
5
- import { CallBase, CallResult, GetObjectExisted, GetObjectMain, GetObjectParam, ObjectMain, TypeNamedObjectWithPermission} from "./base.js";
5
+ import { AccountOrMark_Address, CallBase, CallResult, GetAccountOrMark_Address, GetObjectExisted, GetObjectMain, GetObjectParam, ObjectMain, ObjectsOp, TypeNamedObjectWithPermission} from "./base.js";
6
6
  import { LocalMark } from '../local/local.js';
7
7
  import { ObjectRepository } from '../query/objects.js';
8
8
 
9
9
 
10
+ // Account name, or local mark name, or address, or u256 number|bigint(eg. time number) that can be converted to address.
11
+ export type AddressID = AccountOrMark_Address | number | bigint;
12
+
13
+ export const GetAddressID = async(key:AddressID) : Promise<string | undefined> =>{
14
+ if (typeof(key) === 'number' || typeof(key) === 'bigint') {
15
+ if (IsValidU256(key)) {
16
+ return uint2address(key);
17
+ }
18
+ } else {
19
+ return await GetAccountOrMark_Address(key)
20
+ }
21
+ }
22
+
23
+ export interface Repository_Value {
24
+ address: AddressID; // UID: address or objectid
25
+ bcsBytes: Uint8Array; // BCS contents. Notice that: First Byte be the Type by caller, or specify type with 'Repository_Policy_Data.value_type' field.
26
+ }
27
+ export interface Repository_Policy_Data {
28
+ key: string;
29
+ data: Repository_Value[];
30
+ value_type?: ValueType; // Specifies a data type prefix; If the data prefix is already included in the data byte stream, there is no need to specify it.
31
+ }
32
+ export interface Repository_Policy_Data2 {
33
+ address: AddressID;
34
+ data: Repository_Value2[];
35
+ value_type?: ValueType;
36
+ }
37
+ export interface Repository_Policy_Data_Remove {
38
+ key: string;
39
+ address: AddressID;
40
+ }
41
+
10
42
  /// The execution priority is determined by the order in which the object attributes are arranged
11
43
  export interface CallRepository_Data {
12
44
  object?: ObjectMain;
13
45
  description?: string;
14
- reference?: {op:'set' | 'add' | 'remove' ; addresses:string[]} | {op:'removeall'};
46
+ reference?: ObjectsOp;
15
47
  mode?: Repository_Policy_Mode; // default: 'Relax' (POLICY_MODE_FREE)
16
48
  policy?: {op:'add' | 'set'; data:Repository_Policy[]} | {op:'remove'; keys:string[]} | {op:'removeall'} | {op:'rename'; data:{old:string; new:string}[]};
17
49
  data?: {op:'add', data: Repository_Policy_Data | Repository_Policy_Data2} | {op:'remove'; data: Repository_Policy_Data_Remove[]};
@@ -26,19 +58,24 @@ export class CallRepository extends CallBase {
26
58
  this.data = data;
27
59
  }
28
60
 
61
+ protected async prepare(): Promise<void> {
62
+ if (!this.object_address) {
63
+ this.object_address = (await LocalMark.Instance().get(GetObjectExisted(this.data?.object)))?.address;
64
+ if (this.object_address) {
65
+ await this.update_content('Repository', this.object_address);
66
+ if (!this.content) ERROR(Errors.InvalidParam, 'CallRepository_Data.data.object:' + this.object_address);
67
+ this.permission_address = (this.content as ObjectRepository).permission;
68
+ } else {
69
+ const n = GetObjectMain(this.data?.object) as TypeNamedObjectWithPermission;
70
+ this.permission_address = (await LocalMark.Instance().get_address(GetObjectExisted(n?.permission)));
71
+ }
72
+ }
73
+ }
29
74
  async call(account?:string) : Promise<CallResult> {
30
75
  var checkOwner = false;
31
76
  const perms : PermissionIndexType[] = [];
32
- this.object_address = (await LocalMark.Instance().get(GetObjectExisted(this.data?.object)))?.address;
33
- if (this.object_address) {
34
- await this.update_content('Repository', this.object_address);
35
- if (!this.content) ERROR(Errors.InvalidParam, 'CallRepository_Data.data.object:' + this.object_address);
36
- this.permission_address = (this.content as ObjectRepository).permission;
37
- } else {
38
- const n = GetObjectMain(this.data?.object) as TypeNamedObjectWithPermission;
39
- this.permission_address = (await LocalMark.Instance().get_address(GetObjectExisted(n?.permission)));
40
- }
41
77
 
78
+ await this.prepare();
42
79
  if (this.permission_address) {
43
80
  if (!this.data?.object) {
44
81
  perms.push(PermissionIndex.repository)
@@ -61,103 +98,109 @@ export class CallRepository extends CallBase {
61
98
  }
62
99
 
63
100
  protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
64
- let obj : Repository | undefined ; let permission: any;
101
+ let obj : Repository | undefined ; let perm: Permission | undefined;
102
+ let permission : PermissionObject | undefined;
103
+
65
104
  if (this.object_address) {
66
105
  obj = Repository.From(txb, this.permission_address!, this.object_address);
106
+ permission = this.permission_address;
67
107
  } else {
68
108
  const n = GetObjectMain(this.data?.object) as TypeNamedObjectWithPermission;
69
- if (!this.permission_address) {
70
- permission = Permission.New(txb, GetObjectParam(n?.permission)?.description ?? '');
109
+ permission = await LocalMark.Instance().get_address(GetObjectExisted(n?.permission));
110
+ if (!permission) {
111
+ perm = Permission.New(txb, GetObjectParam(n?.permission)?.description ?? '');
112
+ permission = perm.get_object();
71
113
  }
72
114
 
73
- obj = Repository.New(txb, permission ? permission.get_object() : this.permission_address, this.data?.description??'',
74
- this.data.mode, permission?undefined:passport);
115
+ obj = Repository.New(txb, permission, this.data?.description??'',
116
+ this.data.mode, perm?undefined:passport);
75
117
  }
76
118
 
77
- if (obj) {
78
- const pst = permission?undefined:passport;
79
- if (this.data?.description !== undefined && this.object_address) {
80
- obj?.set_description(this.data.description, pst);
81
- }
82
- if (this.data?.reference !== undefined) {
83
- switch (this.data.reference.op) {
84
- case 'set':
85
- case 'add':
86
- if (this.data.reference.op === 'set') obj?.remove_reference([], true, pst);
87
- obj?.add_reference(await LocalMark.Instance().get_many_address2(this.data.reference.addresses), pst);
88
- break;
89
- case 'remove':
90
- obj?.remove_reference(await LocalMark.Instance().get_many_address2(this.data.reference.addresses), false, pst);
91
- break;
92
- case 'removeall':
93
- obj?.remove_reference([], true, pst);
94
- break;
95
- }
96
- }
97
- if (this.data?.mode !== undefined && this.object_address) { //@ priority??
98
- obj?.set_policy_mode(this.data.mode, pst)
119
+ if (!obj) ERROR(Errors.InvalidParam, 'CallRepository_Data.object:' + this.object_address);
120
+ if (!permission) ERROR(Errors.InvalidParam, 'CallRepository_Data.permission:' + this.permission_address);
121
+
122
+ const pst = perm?undefined:passport;
123
+ if (this.data?.description !== undefined && this.object_address) {
124
+ obj?.set_description(this.data.description, pst);
125
+ }
126
+ if (this.data?.reference !== undefined) {
127
+ switch (this.data.reference.op) {
128
+ case 'set':
129
+ case 'add':
130
+ if (this.data.reference.op === 'set') obj?.remove_reference([], true, pst);
131
+ obj?.add_reference(await LocalMark.Instance().get_many_address2(this.data.reference.objects), pst);
132
+ break;
133
+ case 'remove':
134
+ obj?.remove_reference(await LocalMark.Instance().get_many_address2(this.data.reference.objects), false, pst);
135
+ break;
136
+ case 'removeall':
137
+ obj?.remove_reference([], true, pst);
138
+ break;
99
139
  }
100
- if (this.data?.policy !== undefined) {
101
- switch(this.data.policy.op) {
102
- case 'set':
103
- obj?.remove_policies([], true, pst);
104
- obj?.add_policies(this.data.policy.data, pst);
105
- break;
106
- case 'add':
107
- obj?.add_policies(this.data.policy.data, pst);
108
- break;
109
- case 'remove':
110
- obj?.remove_policies(this.data.policy.keys, false, pst);
111
- break;
112
- case 'removeall':
113
- obj?.remove_policies([], true, pst);
114
- break;
115
- case 'rename':
116
- this.data.policy.data.forEach((v) => {
117
- obj?.rename_policy(v.old, v.new, pst);
118
- })
119
- break;
120
- }
140
+ }
141
+ if (this.data?.mode !== undefined && this.object_address) { //@ priority??
142
+ obj?.set_policy_mode(this.data.mode, pst)
143
+ }
144
+ if (this.data?.policy !== undefined) {
145
+ switch(this.data.policy.op) {
146
+ case 'set':
147
+ obj?.remove_policies([], true, pst);
148
+ obj?.add_policies(this.data.policy.data, pst);
149
+ break;
150
+ case 'add':
151
+ obj?.add_policies(this.data.policy.data, pst);
152
+ break;
153
+ case 'remove':
154
+ obj?.remove_policies(this.data.policy.keys, false, pst);
155
+ break;
156
+ case 'removeall':
157
+ obj?.remove_policies([], true, pst);
158
+ break;
159
+ case 'rename':
160
+ this.data.policy.data.forEach((v) => {
161
+ obj?.rename_policy(v.old, v.new, pst);
162
+ })
163
+ break;
121
164
  }
122
- if (this.data?.data !== undefined) {
123
- switch(this.data.data.op) {
124
- case 'add':
125
- if ((this.data.data?.data as any)?.key !== undefined) {
126
- const d = (this.data.data.data as Repository_Policy_Data).data;
127
- const add: Repository_Value[] = [];
128
- for (let i=0; i<d.length; ++i) {
129
- const addr = await LocalMark.Instance().get_address(d[i].address);
130
- if (addr) {
131
- add.push({address:addr, bcsBytes:d[i].bcsBytes});
132
- }
133
- }
134
- obj?.add_data({key:(this.data.data.data as Repository_Policy_Data).key, data:add, value_type:(this.data.data.data as Repository_Policy_Data).value_type});
135
- } else if ((this.data.data?.data as any)?.address !== undefined) {
136
- const d = this.data.data.data as Repository_Policy_Data2;
137
- const addr = await LocalMark.Instance().get_address(d.address);
165
+ }
166
+ if (this.data?.data !== undefined) {
167
+ switch(this.data.data.op) {
168
+ case 'add':
169
+ if ((this.data.data?.data as any)?.key !== undefined) {
170
+ const d = (this.data.data.data as Repository_Policy_Data).data;
171
+ const add: Wowok_Repository_Value[] = [];
172
+ for (let i=0; i<d.length; ++i) {
173
+ const addr = await GetAddressID(d[i].address);
138
174
  if (addr) {
139
- obj?.add_data2({address:addr, data:d.data, value_type:d.value_type})
175
+ add.push({address:addr, bcsBytes:d[i].bcsBytes});
140
176
  }
141
177
  }
142
- break;
143
- case 'remove':
144
- for (let i=0; i<this.data.data.data.length; ++i) {
145
- const addr = await LocalMark.Instance().get_address(this.data.data.data[i].address);
146
- if (addr) {
147
- obj?.remove(addr, this.data.data.data[i].key);
148
- }
178
+ obj?.add_data({key:(this.data.data.data as Repository_Policy_Data).key, data:add, value_type:(this.data.data.data as Repository_Policy_Data).value_type});
179
+ } else if ((this.data.data?.data as any)?.address !== undefined) {
180
+ const d = this.data.data.data as Repository_Policy_Data2;
181
+ const addr = await GetAddressID(d.address);
182
+ if (addr) {
183
+ obj?.add_data2({address:addr, data:d.data, value_type:d.value_type})
184
+ }
185
+ }
186
+ break;
187
+ case 'remove':
188
+ for (let i=0; i<this.data.data.data.length; ++i) {
189
+ const addr = await GetAddressID(this.data.data.data[i].address);
190
+ if (addr) {
191
+ obj?.remove(addr, this.data.data.data[i].key);
149
192
  }
150
- break;
151
- }
193
+ }
194
+ break;
152
195
  }
196
+ }
153
197
 
154
- if (permission) {
155
- const n = GetObjectMain(this.data?.object) as TypeNamedObjectWithPermission;
156
- await this.new_with_mark('Permission', txb, permission.launch(), GetObjectParam(n?.permission), account);
157
- }
158
- if (!this.object_address) {
159
- await this.new_with_mark('Repository', txb, obj.launch(), GetObjectMain(this.data?.object), account);
160
- }
198
+ if (perm) {
199
+ const n = GetObjectMain(this.data?.object) as TypeNamedObjectWithPermission;
200
+ await this.new_with_mark('Permission', txb, perm.launch(), GetObjectParam(n?.permission), account);
161
201
  }
162
- };
202
+ if (!this.object_address) {
203
+ await this.new_with_mark('Repository', txb, obj.launch(), GetObjectMain(this.data?.object), account);
204
+ }
205
+ }
163
206
  }