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.
- package/dist/call/arbitration.d.ts +4 -3
- package/dist/call/arbitration.d.ts.map +1 -1
- package/dist/call/arbitration.js +134 -131
- package/dist/call/arbitration.js.map +1 -1
- package/dist/call/base.d.ts +15 -7
- package/dist/call/base.d.ts.map +1 -1
- package/dist/call/base.js +21 -23
- package/dist/call/base.js.map +1 -1
- package/dist/call/call.d.ts +0 -6
- package/dist/call/call.d.ts.map +1 -1
- package/dist/call/demand.d.ts +1 -0
- package/dist/call/demand.d.ts.map +1 -1
- package/dist/call/demand.js +86 -80
- package/dist/call/demand.js.map +1 -1
- package/dist/call/machine.d.ts +10 -10
- package/dist/call/machine.d.ts.map +1 -1
- package/dist/call/machine.js +174 -146
- package/dist/call/machine.js.map +1 -1
- package/dist/call/permission.d.ts +10 -9
- package/dist/call/permission.d.ts.map +1 -1
- package/dist/call/permission.js +90 -85
- package/dist/call/permission.js.map +1 -1
- package/dist/call/personal.d.ts +3 -3
- package/dist/call/personal.d.ts.map +1 -1
- package/dist/call/personal.js +6 -12
- package/dist/call/personal.js.map +1 -1
- package/dist/call/repository.d.ts +24 -8
- package/dist/call/repository.d.ts.map +1 -1
- package/dist/call/repository.js +114 -94
- package/dist/call/repository.js.map +1 -1
- package/dist/call/service.d.ts +15 -26
- package/dist/call/service.d.ts.map +1 -1
- package/dist/call/service.js +274 -264
- package/dist/call/service.js.map +1 -1
- package/dist/call/treasury.d.ts +5 -7
- package/dist/call/treasury.d.ts.map +1 -1
- package/dist/call/treasury.js +108 -97
- package/dist/call/treasury.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/query/objects.d.ts +2 -1
- package/dist/query/objects.d.ts.map +1 -1
- package/dist/query/objects.js +7 -7
- package/dist/query/objects.js.map +1 -1
- package/dist/query/owned.d.ts +2 -0
- package/dist/query/owned.d.ts.map +1 -0
- package/dist/query/owned.js +2 -0
- package/dist/query/owned.js.map +1 -0
- package/dist/query/permission.d.ts +3 -2
- package/dist/query/permission.d.ts.map +1 -1
- package/dist/query/permission.js +6 -3
- package/dist/query/permission.js.map +1 -1
- package/dist/query/treasury_received.d.ts +14 -0
- package/dist/query/treasury_received.d.ts.map +1 -0
- package/dist/query/treasury_received.js +19 -0
- package/dist/query/treasury_received.js.map +1 -0
- package/package.json +1 -1
- package/src/call/arbitration.ts +144 -141
- package/src/call/base.ts +27 -29
- package/src/call/call.ts +6 -6
- package/src/call/demand.ts +89 -81
- package/src/call/machine.ts +184 -145
- package/src/call/permission.ts +98 -90
- package/src/call/personal.ts +8 -13
- package/src/call/repository.ts +138 -95
- package/src/call/service.ts +290 -272
- package/src/call/treasury.ts +110 -99
- package/src/index.ts +1 -0
- package/src/query/objects.ts +10 -10
- package/src/query/permission.ts +9 -6
- package/src/query/treasury_received.ts +35 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/call/treasury.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TransactionBlock, IsValidArgType, PassportObject, Errors, ERROR, Permission, PermissionIndex,
|
|
2
|
-
PermissionIndexType, Treasury, Treasury_WithdrawMode,
|
|
2
|
+
PermissionIndexType, Treasury, Treasury_WithdrawMode, PermissionObject,
|
|
3
3
|
} from 'wowok';
|
|
4
4
|
import { query_objects, ObjectTreasury, Treasury_ReceivedObject } from '../query/objects.js';
|
|
5
5
|
import { AccountOrMark_Address, CallBase, CallResult, GetAccountOrMark_Address, GetObjectExisted,
|
|
6
|
-
GetObjectMain, GetObjectParam, ObjectTypedMain, TypeNamedObjectWithPermission } from "./base.js";
|
|
6
|
+
GetObjectMain, GetObjectParam, ObjectTypedMain, PayParam, TypeNamedObjectWithPermission } from "./base.js";
|
|
7
7
|
import { Account } from '../local/account.js';
|
|
8
8
|
import { LocalMark } from '../local/local.js';
|
|
9
9
|
import { get_object_address } from '../common.js';
|
|
@@ -13,7 +13,7 @@ export interface ReceiverParam {
|
|
|
13
13
|
amount: string|number;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export interface TreasuryWithdrawParam extends
|
|
16
|
+
export interface TreasuryWithdrawParam extends PayParam {
|
|
17
17
|
receiver: ReceiverParam[];
|
|
18
18
|
withdraw_guard?: string,
|
|
19
19
|
}
|
|
@@ -21,7 +21,7 @@ export interface TreasuryWithdrawParam extends WithdrawParam {
|
|
|
21
21
|
/// The execution priority is determined by the order in which the object attributes are arranged
|
|
22
22
|
export interface CallTreasury_Data {
|
|
23
23
|
object: ObjectTypedMain;
|
|
24
|
-
deposit?: {balance:string|number;
|
|
24
|
+
deposit?: {balance:string|number; param?:PayParam};
|
|
25
25
|
receive?: {received_objects:string[]} | 'recently';
|
|
26
26
|
withdraw?: TreasuryWithdrawParam;
|
|
27
27
|
|
|
@@ -41,24 +41,29 @@ export class CallTreasury extends CallBase {
|
|
|
41
41
|
this.data = data;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
protected async prepare(): Promise<void> {
|
|
45
|
+
if (!this.object_address) {
|
|
46
|
+
this.object_address = (await LocalMark.Instance().get_address(GetObjectExisted(this.data.object)));
|
|
47
|
+
if (this.object_address) {
|
|
48
|
+
await this.update_content('Treasury', this.object_address);
|
|
49
|
+
if (!this.content) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.object:' + this.object_address);
|
|
50
|
+
this.permission_address = (this.content as ObjectTreasury).permission;
|
|
51
|
+
this.type_parameter = Treasury.parseObjectType(this.content.type_raw);
|
|
52
|
+
} else {
|
|
53
|
+
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
54
|
+
if (!IsValidArgType(n?.type_parameter)) {
|
|
55
|
+
ERROR(Errors.IsValidArgType, 'CallTreasury_Data.data.object.type_parameter');
|
|
56
|
+
}
|
|
57
|
+
this.permission_address = (await LocalMark.Instance().get_address(GetObjectExisted(n?.permission)));
|
|
58
|
+
this.type_parameter = n.type_parameter;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
44
62
|
async call(account?:string) : Promise<CallResult> {
|
|
45
63
|
var checkOwner = false; const guards : string[] = [];
|
|
46
64
|
const perms : PermissionIndexType[] = [];
|
|
47
|
-
this.object_address = (await LocalMark.Instance().get_address(GetObjectExisted(this.data.object)));
|
|
48
|
-
if (this.object_address) {
|
|
49
|
-
await this.update_content('Treasury', this.object_address);
|
|
50
|
-
if (!this.content) ERROR(Errors.InvalidParam, 'CallArbitration_Data.data.object:' + this.object_address);
|
|
51
|
-
this.permission_address = (this.content as ObjectTreasury).permission;
|
|
52
|
-
this.type_parameter = Treasury.parseObjectType(this.content.type_raw);
|
|
53
|
-
} else {
|
|
54
|
-
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
55
|
-
if (!IsValidArgType(n?.type_parameter)) {
|
|
56
|
-
ERROR(Errors.IsValidArgType, 'CallTreasury_Data.data.object.type_parameter');
|
|
57
|
-
}
|
|
58
|
-
this.permission_address = (await LocalMark.Instance().get_address(GetObjectExisted(n?.permission)));
|
|
59
|
-
this.type_parameter = n.type_parameter;
|
|
60
|
-
}
|
|
61
65
|
|
|
66
|
+
await this.prepare();
|
|
62
67
|
if (this.permission_address) {
|
|
63
68
|
if (!this.data?.object) {
|
|
64
69
|
perms.push(PermissionIndex.treasury)
|
|
@@ -101,105 +106,111 @@ export class CallTreasury extends CallBase {
|
|
|
101
106
|
return await this.exec(account);
|
|
102
107
|
}
|
|
103
108
|
protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
104
|
-
let obj : Treasury | undefined ; let
|
|
109
|
+
let obj : Treasury | undefined ; let perm: Permission | undefined;
|
|
110
|
+
let permission : PermissionObject | undefined;
|
|
111
|
+
|
|
105
112
|
if (this.object_address) {
|
|
106
|
-
obj = Treasury.From(txb, this.type_parameter!, this.permission_address!, this.object_address)
|
|
113
|
+
obj = Treasury.From(txb, this.type_parameter!, this.permission_address!, this.object_address);
|
|
114
|
+
permission = this.permission_address;
|
|
107
115
|
} else {
|
|
108
116
|
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
permission = await LocalMark.Instance().get_address(GetObjectExisted(n?.permission));
|
|
118
|
+
if (!permission) {
|
|
119
|
+
perm = Permission.New(txb, GetObjectParam(n?.permission)?.description ?? '');
|
|
120
|
+
permission = perm.get_object();
|
|
111
121
|
}
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
|
|
123
|
+
obj = Treasury.New(txb, this.type_parameter!, permission,
|
|
124
|
+
this.data?.description??'', perm?undefined:passport)
|
|
114
125
|
}
|
|
115
126
|
|
|
127
|
+
if (!obj) ERROR(Errors.InvalidParam, 'CallTreasury_Data.object:' + this.object_address);
|
|
128
|
+
if (!permission) ERROR(Errors.InvalidParam, 'CallTreasury_Data.permission:' + this.permission_address);
|
|
116
129
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit.remark ??'', for_guard, for_object});
|
|
125
|
-
}
|
|
130
|
+
const pst = perm?undefined:passport;
|
|
131
|
+
if (this.data.deposit !== undefined) {
|
|
132
|
+
const coin = await Account.Instance().get_coin_object(txb, this.data.deposit.balance, account, this.type_parameter);
|
|
133
|
+
if (coin) {
|
|
134
|
+
const index = this.data.deposit?.param?.index ?? 0;
|
|
135
|
+
const [for_guard, for_object] = await LocalMark.Instance().get_many_address([this.data.deposit?.param?.for_guard, this.data.deposit?.param?.for_object])
|
|
136
|
+
obj?.deposit({coin:coin, index:BigInt(index), remark:this.data.deposit?.param?.remark ??'', for_guard, for_object});
|
|
126
137
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
}
|
|
139
|
+
if (this.data?.receive !== undefined && this.object_address) {
|
|
140
|
+
if (this.data.receive === 'recently') {
|
|
141
|
+
const r = await Treasury.GetTreasuryRecievedObject(this.object_address, this.type_parameter!);
|
|
142
|
+
if (!r) {
|
|
143
|
+
ERROR(Errors.InvalidParam, 'CallTreasury_Data.data.receive.received_objects');
|
|
144
|
+
}
|
|
145
|
+
r.received.forEach(v => {
|
|
146
|
+
obj?.receive(v.payment, v.id, pst);
|
|
147
|
+
})
|
|
148
|
+
} else if (this.data.receive?.received_objects?.length > 0) {
|
|
149
|
+
const r = await query_objects({objects:this.data.receive.received_objects});
|
|
150
|
+
if (r?.objects?.length!== this.data.receive.received_objects.length) {
|
|
151
|
+
ERROR(Errors.InvalidParam, 'CallTreasury_Data.data.receive.received_objects');
|
|
152
|
+
}
|
|
141
153
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
const v = r.objects[i] as Treasury_ReceivedObject;
|
|
147
|
-
obj?.receive(v.payment, v.object, pst);
|
|
154
|
+
for (let i=0; i<r?.objects?.length; ++i) {
|
|
155
|
+
if (r.objects[i].type !== 'Treasury_ReceivedObject') {
|
|
156
|
+
ERROR(Errors.InvalidParam, 'CallTreasury_Data.data.receive.received_objects:'+ r.objects[i].object);
|
|
148
157
|
}
|
|
158
|
+
const v = r.objects[i] as Treasury_ReceivedObject;
|
|
159
|
+
obj?.receive(v.payment, v.object, pst);
|
|
149
160
|
}
|
|
150
161
|
}
|
|
162
|
+
}
|
|
151
163
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
164
|
+
if (this.data?.withdraw !== undefined) {
|
|
165
|
+
const [for_guard, for_object] = await LocalMark.Instance().get_many_address([this.data.withdraw?.for_guard, this.data.withdraw?.for_object]);
|
|
166
|
+
const receiver = [];
|
|
167
|
+
for (let i=0;i < this.data.withdraw.receiver.length; ++i) {
|
|
168
|
+
const v = this.data.withdraw.receiver[i];
|
|
169
|
+
const address = await GetAccountOrMark_Address(v.address);
|
|
170
|
+
if (!address) ERROR(Errors.InvalidParam, 'CallTreasury_Data.data.withdraw.receiver:'+ v.address);
|
|
159
171
|
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
obj?.withdraw({items:receiver, index:this.data.withdraw.index ?? 0, remark:this.data.withdraw.remark??'',
|
|
163
|
-
for_guard, for_object, withdraw_guard: await LocalMark.Instance().get_address(this.data.withdraw.withdraw_guard)}, pst);
|
|
172
|
+
receiver.push({address:address, amount:BigInt(v.amount)})
|
|
164
173
|
}
|
|
174
|
+
obj?.withdraw({items:receiver, index:this.data.withdraw.index ?? 0, remark:this.data.withdraw.remark??'',
|
|
175
|
+
for_guard, for_object, withdraw_guard: await LocalMark.Instance().get_address(this.data.withdraw.withdraw_guard)}, pst);
|
|
176
|
+
}
|
|
165
177
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
if (this.data?.description !== undefined && this.object_address) {
|
|
179
|
+
obj?.set_description(this.data.description, pst);
|
|
180
|
+
}
|
|
181
|
+
if (this.data?.deposit_guard !== undefined) {
|
|
182
|
+
const guard = await LocalMark.Instance().get_address(this.data?.deposit_guard);
|
|
183
|
+
obj?.set_deposit_guard(guard, pst);
|
|
184
|
+
}
|
|
185
|
+
if (this.data?.withdraw_guard !== undefined) {
|
|
186
|
+
switch (this.data.withdraw_guard.op) {
|
|
187
|
+
case 'add':
|
|
188
|
+
case 'set':
|
|
189
|
+
if (this.data.withdraw_guard.op === 'set') obj?.remove_withdraw_guard([], true, pst);
|
|
190
|
+
for (let i = 0; i < this.data.withdraw_guard.data.length; ++ i) {
|
|
191
|
+
let v = this.data.withdraw_guard.data[i];
|
|
192
|
+
const guard = await LocalMark.Instance().get_address(v.guard);
|
|
193
|
+
if (guard) obj?.add_withdraw_guard(guard, BigInt(v.amount), pst);
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
case 'remove':
|
|
197
|
+
obj?.remove_withdraw_guard(await LocalMark.Instance().get_many_address2(this.data.withdraw_guard.guards), false, pst)
|
|
198
|
+
break;
|
|
187
199
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
200
|
+
case 'removeall':
|
|
201
|
+
obj?.remove_withdraw_guard([], true, pst)
|
|
202
|
+
break;
|
|
192
203
|
}
|
|
193
|
-
if (this.data?.withdraw_mode !== undefined) {
|
|
194
|
-
obj?.set_withdraw_mode(this.data.withdraw_mode, pst)
|
|
195
|
-
}
|
|
196
|
-
if (permission) {
|
|
197
|
-
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
198
|
-
await this.new_with_mark('Permission', txb, permission.launch(), GetObjectParam(n?.permission), account);
|
|
199
|
-
}
|
|
200
|
-
if (!this.object_address) {
|
|
201
|
-
await this.new_with_mark('Treasury', txb, obj.launch(), GetObjectMain(this.data?.object), account);
|
|
202
|
-
}
|
|
203
204
|
}
|
|
205
|
+
if (this.data?.withdraw_mode !== undefined) {
|
|
206
|
+
obj?.set_withdraw_mode(this.data.withdraw_mode, pst)
|
|
207
|
+
}
|
|
208
|
+
if (perm) {
|
|
209
|
+
const n = GetObjectMain(this.data.object) as TypeNamedObjectWithPermission;
|
|
210
|
+
await this.new_with_mark('Permission', txb, perm.launch(), GetObjectParam(n?.permission), account);
|
|
211
|
+
}
|
|
212
|
+
if (!this.object_address) {
|
|
213
|
+
await this.new_with_mark('Treasury', txb, obj.launch(), GetObjectMain(this.data?.object), account);
|
|
214
|
+
}
|
|
204
215
|
}
|
|
205
216
|
}
|
package/src/index.ts
CHANGED
package/src/query/objects.ts
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
import { Protocol, Machine_Node, Machine, Treasury_WithdrawMode, Treasury_Operation,
|
|
7
7
|
Repository_Type, Repository_Policy_Mode, Repository_Policy, Service_Discount_Type, Service_Sale,
|
|
8
|
-
Progress, History, ERROR, Errors,
|
|
9
|
-
|
|
10
|
-
import { CacheExpireType, CacheName,
|
|
8
|
+
Progress, History, ERROR, Errors, Bcs, Entity_Info, Tags, uint2address,
|
|
9
|
+
} from 'wowok';
|
|
10
|
+
import { CacheExpireType, CacheName, Cache } from '../local/cache.js'
|
|
11
11
|
import { LocalMark } from '../local/local.js';
|
|
12
|
+
import { AccountOrMark_Address, GetAccountOrMark_Address } from '../call/base.js';
|
|
12
13
|
|
|
13
14
|
export type ObjectBaseType = 'Demand' | 'Progress' | 'Service' | 'Machine' | 'Order' | 'Treasury' | 'Arbitration' | 'Arb' | 'Payment' | 'Guard' | 'Discount' |
|
|
14
15
|
'Personal' | 'Permission' | 'PersonalMark' | 'Repository' | 'TableItem_ProgressHistory' | 'TableItem_PermissionEntity' |
|
|
@@ -246,7 +247,7 @@ export interface ObjectsQuery {
|
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
export interface PersonalQuery {
|
|
249
|
-
address:
|
|
250
|
+
address: AccountOrMark_Address;
|
|
250
251
|
no_cache?: boolean;
|
|
251
252
|
}
|
|
252
253
|
export interface ObjectsAnswer {
|
|
@@ -351,15 +352,14 @@ export const query_objects = async (query: ObjectsQuery) : Promise<ObjectsAnswer
|
|
|
351
352
|
}
|
|
352
353
|
|
|
353
354
|
export const query_personal = async (query:PersonalQuery) : Promise<ObjectPersonal | undefined> => {
|
|
354
|
-
const addr = await
|
|
355
|
+
const addr = await GetAccountOrMark_Address(query.address);
|
|
355
356
|
if (!addr) {
|
|
356
|
-
ERROR(Errors.InvalidParam, 'query_personal.
|
|
357
|
+
ERROR(Errors.InvalidParam, 'query_personal.address')
|
|
357
358
|
}
|
|
358
|
-
query.address = addr;
|
|
359
359
|
|
|
360
360
|
if (!query.no_cache) {
|
|
361
361
|
try {
|
|
362
|
-
const cache = await Cache.Instance().cache_get(
|
|
362
|
+
const cache = await Cache.Instance().cache_get(addr, CacheName.personal);
|
|
363
363
|
if (cache) {
|
|
364
364
|
const d = JSON.parse(cache.data) as ObjectPersonal;
|
|
365
365
|
d.cache_expire = cache.expire;
|
|
@@ -367,9 +367,9 @@ export const query_personal = async (query:PersonalQuery) : Promise<ObjectPerson
|
|
|
367
367
|
}
|
|
368
368
|
} catch (e) {/*console.log(e)*/}
|
|
369
369
|
}
|
|
370
|
-
const res = await tableItemQuery_byAddress({parent:Protocol.Instance().objectEntity(), address:
|
|
370
|
+
const res = await tableItemQuery_byAddress({parent:Protocol.Instance().objectEntity(), address:addr});
|
|
371
371
|
if (res.type === 'Personal') {
|
|
372
|
-
await Cache.Instance().put(
|
|
372
|
+
await Cache.Instance().put(addr, {expire:Cache.ExpireTime(), data:JSON.stringify(res)}, CacheName.personal);
|
|
373
373
|
return res as ObjectPersonal;
|
|
374
374
|
}
|
|
375
375
|
}
|
package/src/query/permission.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* not only the permission table, but also the administrator or Builder identity.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { AccountOrMark_Address, GetAccountOrMark_Address } from '../call/base.js';
|
|
6
7
|
import { LocalMark } from '../local/local.js';
|
|
7
|
-
import { TransactionBlock, Protocol, Bcs,
|
|
8
|
+
import { TransactionBlock, Protocol, Bcs, Errors, ERROR, Permission, PermissionAnswer, BCS} from 'wowok';
|
|
8
9
|
|
|
9
10
|
export interface PermissionQuery {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
permission_object: string;
|
|
12
|
+
address: AccountOrMark_Address;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/*json: PermissionQuery; return PermissionAnswer */
|
|
@@ -22,11 +23,13 @@ export const query_permission_json = async (json:string) : Promise<string> => {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export const query_permission = async (query:PermissionQuery) : Promise<PermissionAnswer> => {
|
|
25
|
-
const object_address = await
|
|
26
|
-
|
|
26
|
+
const [object_address, entity_address] = await Promise.all([
|
|
27
|
+
LocalMark.Instance().get_address(query.permission_object),
|
|
28
|
+
GetAccountOrMark_Address(query.address),
|
|
29
|
+
]);
|
|
27
30
|
|
|
28
31
|
if (!object_address || !entity_address) {
|
|
29
|
-
ERROR(Errors.InvalidParam, '
|
|
32
|
+
ERROR(Errors.InvalidParam, 'permission.query_permission');
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
const txb = new TransactionBlock();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ERROR, Errors, Protocol, Treasury, TreasuryReceived, TreasuryReceivedObject } from "wowok";
|
|
2
|
+
import { query_objects, Treasury_ReceivedObject } from "./objects.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface QueryTreasuryReceived {
|
|
6
|
+
/** Name or address of the Treasury object. */
|
|
7
|
+
treasury_object: string;
|
|
8
|
+
/**
|
|
9
|
+
* An optional paging cursor. If provided, the query will start from the next item after the specified
|
|
10
|
+
* cursor. Default to start from the first item if not specified.
|
|
11
|
+
*/
|
|
12
|
+
cursor?: string | null | undefined;
|
|
13
|
+
/** Max number of items returned per page, default to [QUERY_MAX_RESULT_LIMIT] if not specified. */
|
|
14
|
+
limit?: number | null | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const query_treasury_received = async (query: QueryTreasuryReceived) : Promise<TreasuryReceived> => {
|
|
18
|
+
const r1 = await query_objects({objects:[query.treasury_object]});
|
|
19
|
+
if (r1?.objects?.length !== 1 || r1.objects[0].type !== 'Treasury') {
|
|
20
|
+
ERROR(Errors.InvalidParam, 'query_treasury_received: invalid treasury_object');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const type = Protocol.Instance().package('wowok')+'::payment::CoinWrapper<'+Treasury.parseObjectType(r1.objects[0].type_raw)+'>';
|
|
24
|
+
const r2 = await Protocol.Client().getOwnedObjects({owner:r1.objects[0].object, filter:{StructType: type},
|
|
25
|
+
options:{showContent:true, showType:true}, cursor:query.cursor, limit:query.limit});
|
|
26
|
+
|
|
27
|
+
let receive = BigInt(0);
|
|
28
|
+
const res: TreasuryReceivedObject[] = r2.data.map((v:any) => {
|
|
29
|
+
const i = v?.data?.content?.fields;
|
|
30
|
+
receive += BigInt(i?.coin?.fields?.balance);
|
|
31
|
+
return {payment:i?.payment, balance:i?.coin?.fields?.balance, id:v?.data?.objectId}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {balance:receive.toString(), received:res};
|
|
35
|
+
}
|