wowok_agent 0.1.6 → 0.1.9
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/account.ts +1 -0
- package/src/cache.ts +5 -6
- package/src/call/arbitration.ts +45 -39
- package/src/call/base.ts +58 -44
- package/src/call/demand.ts +27 -21
- package/src/call/entity_permission.ts +14 -12
- package/src/call/guard.ts +17 -18
- package/src/call/machine.ts +38 -25
- package/src/call/personal.ts +32 -55
- package/src/call/repository.ts +27 -21
- package/src/call/service.ts +43 -33
- package/src/call/treasury.ts +27 -21
- package/src/call.ts +1 -2
- package/src/events.ts +10 -1
- package/src/objects.ts +76 -44
- package/src/entity.ts +0 -60
package/package.json
CHANGED
package/src/account.ts
CHANGED
|
@@ -240,6 +240,7 @@ export class Account {
|
|
|
240
240
|
|
|
241
241
|
if (addr && b > BigInt(0)) {
|
|
242
242
|
if (!token_type || token_type === '0x2::sui::SUI' || token_type === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI') {
|
|
243
|
+
console.log(1)
|
|
243
244
|
return txb.splitCoins(txb.gas, [balance_required]);
|
|
244
245
|
} else {
|
|
245
246
|
const r = await Protocol.Client().getCoins({owner: addr, coinType:token_type});
|
package/src/cache.ts
CHANGED
|
@@ -19,16 +19,15 @@ export abstract class CacheData {
|
|
|
19
19
|
|
|
20
20
|
export enum CacheName {
|
|
21
21
|
object = 'OBJECT',
|
|
22
|
-
|
|
22
|
+
personal = 'PERSONAL',
|
|
23
|
+
table = 'TABLE'
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export const OBJECT_KEY = (object_address: string) : string => {
|
|
26
|
-
return object_address + Protocol.Instance().package('wowok_origin') +
|
|
27
|
-
}
|
|
28
|
-
export const PERSONAL_RESOURCE_KEY = (person_address: string) : string => {
|
|
29
|
-
return person_address + Protocol.Instance().package('wowok_origin') + CacheName.resource + '-V2';
|
|
26
|
+
export const OBJECT_KEY = (object_address: string, name:CacheName) : string => {
|
|
27
|
+
return object_address + Protocol.Instance().package('wowok_origin') + name + '-V2';
|
|
30
28
|
}
|
|
31
29
|
|
|
30
|
+
|
|
32
31
|
export interface PersonalResouceCache {
|
|
33
32
|
address: string;
|
|
34
33
|
resource: string;
|
package/src/call/arbitration.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { TransactionBlock,
|
|
1
|
+
import { TransactionBlock, IsValidArgType, Resource, ResourceObject, } from 'wowok';
|
|
2
2
|
import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex, PermissionIndexType, Treasury,
|
|
3
3
|
Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee, WitnessFill
|
|
4
4
|
} from 'wowok';
|
|
5
5
|
import { query_objects, ObjectArbitration, } from '../objects';
|
|
6
|
-
import { CallBase, CallResult, AddressMark } from "./base";
|
|
6
|
+
import { CallBase, CallResult, AddressMark, Namedbject} from "./base";
|
|
7
7
|
|
|
8
8
|
export interface CallArbitration_Data {
|
|
9
|
-
object?: string; // undefined for creating a new object
|
|
10
|
-
permission?: string;
|
|
9
|
+
object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
|
|
10
|
+
permission?: {address:string} | {namedNew: Namedbject, description?:string};
|
|
11
11
|
mark?:AddressMark;
|
|
12
12
|
type_parameter?: string;
|
|
13
13
|
permission_new?: string;
|
|
@@ -15,10 +15,10 @@ export interface CallArbitration_Data {
|
|
|
15
15
|
bPaused?: boolean;
|
|
16
16
|
endpoint?: string;
|
|
17
17
|
fee?: string;
|
|
18
|
-
fee_treasury?: string;
|
|
18
|
+
fee_treasury?: {address:string} | {namedNew: Namedbject, description?:string};
|
|
19
19
|
usage_guard?: string;
|
|
20
20
|
voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
|
|
21
|
-
arb_new?: {data: Dispute; guard?:string | 'fetch'}; // dispute an order, and a new Arb launched.
|
|
21
|
+
arb_new?: {data: Dispute; guard?:string | 'fetch'; namedNew?: Namedbject}; // dispute an order, and a new Arb launched.
|
|
22
22
|
arb_withdraw_fee?: {arb:string; data:WithdrawFee};
|
|
23
23
|
arb_vote?: Vote;
|
|
24
24
|
arb_arbitration?: Feedback;
|
|
@@ -37,15 +37,18 @@ export class CallArbitration extends CallBase {
|
|
|
37
37
|
|
|
38
38
|
var checkOwner = false; const guards : string[] = [];
|
|
39
39
|
const perms : PermissionIndexType[] = []; var obj: ObjectArbitration | undefined ;
|
|
40
|
+
const permission_address = (this.data?.permission as any)?.address;
|
|
41
|
+
const object_address = (this.data?.object as any)?.address;
|
|
42
|
+
const treasury_address = (this.data?.fee_treasury as any)?.address;
|
|
40
43
|
|
|
41
|
-
if (
|
|
44
|
+
if (permission_address && IsValidAddress(permission_address)) {
|
|
42
45
|
if (!this.data?.object) {
|
|
43
46
|
perms.push(PermissionIndex.arbitration)
|
|
44
47
|
}
|
|
45
48
|
if (this.data?.permission_new !== undefined) {
|
|
46
49
|
checkOwner = true;
|
|
47
50
|
}
|
|
48
|
-
if (this.data?.description !== undefined &&
|
|
51
|
+
if (this.data?.description !== undefined && object_address) {
|
|
49
52
|
perms.push(PermissionIndex.arbitration_description)
|
|
50
53
|
}
|
|
51
54
|
if (this.data?.bPaused !== undefined) {
|
|
@@ -54,10 +57,10 @@ export class CallArbitration extends CallBase {
|
|
|
54
57
|
if (this.data?.endpoint == undefined) { // publish is an irreversible one-time operation
|
|
55
58
|
perms.push(PermissionIndex.arbitration_endpoint)
|
|
56
59
|
}
|
|
57
|
-
if (this.data?.fee !== undefined &&
|
|
60
|
+
if (this.data?.fee !== undefined && object_address) {
|
|
58
61
|
perms.push(PermissionIndex.arbitration_fee)
|
|
59
62
|
}
|
|
60
|
-
if (
|
|
63
|
+
if (treasury_address !== undefined && object_address) {
|
|
61
64
|
perms.push(PermissionIndex.arbitration_treasury)
|
|
62
65
|
}
|
|
63
66
|
if (this.data?.usage_guard !== undefined) {
|
|
@@ -73,13 +76,13 @@ export class CallArbitration extends CallBase {
|
|
|
73
76
|
if (IsValidAddress(this.data.arb_new.guard)) {
|
|
74
77
|
guards.push(this.data.arb_new.guard)
|
|
75
78
|
} else {
|
|
76
|
-
if (!
|
|
79
|
+
if (!object_address) { // new
|
|
77
80
|
if (this.data?.usage_guard && IsValidAddress(this.data?.usage_guard)) {
|
|
78
81
|
guards.push(this.data.usage_guard)
|
|
79
82
|
}
|
|
80
83
|
} else {
|
|
81
84
|
if (!obj) {
|
|
82
|
-
const r = await query_objects({objects:[
|
|
85
|
+
const r = await query_objects({objects:[object_address], showContent:true});
|
|
83
86
|
if (r?.objects && r.objects[0].type === 'Arbitration') {
|
|
84
87
|
obj = r.objects[0] as ObjectArbitration;
|
|
85
88
|
}
|
|
@@ -98,29 +101,37 @@ export class CallArbitration extends CallBase {
|
|
|
98
101
|
guards.push(this.data?.arb_vote?.voting_guard)
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
return await this.check_permission_and_call(
|
|
104
|
+
return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
|
|
102
105
|
}
|
|
103
106
|
return await this.exec(account);
|
|
104
107
|
}
|
|
105
108
|
protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
106
109
|
let obj : Arbitration | undefined ; let permission: any; let withdraw_treasury:any;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
const permission_address = (this.data?.permission as any)?.address;
|
|
111
|
+
const object_address = (this.data?.object as any)?.address;
|
|
112
|
+
const treasury_address = (this.data?.fee_treasury as any)?.address;
|
|
113
|
+
|
|
114
|
+
if (!object_address) {
|
|
115
|
+
if (!permission_address || !IsValidAddress(permission_address)) {
|
|
116
|
+
const d = (this.data?.permission as any)?.description ?? '';
|
|
117
|
+
permission = Permission.New(txb, d);
|
|
110
118
|
}
|
|
111
|
-
if (!
|
|
112
|
-
|
|
119
|
+
if (!treasury_address || !IsValidAddress(treasury_address)) {
|
|
120
|
+
const d = (this.data?.fee_treasury as any)?.description ?? '';
|
|
121
|
+
withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ? permission.get_object() : permission_address,
|
|
122
|
+
d, permission?undefined:passport);
|
|
113
123
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
|
|
125
|
+
obj = Arbitration.New(txb, this.data.type_parameter!, permission ? permission.get_object() : permission_address, this.data?.description??'',
|
|
126
|
+
BigInt(this.data?.fee ?? 0), withdraw_treasury? withdraw_treasury.get_object() : treasury_address, permission?undefined:passport);
|
|
127
|
+
} else if (object_address) {
|
|
128
|
+
if (IsValidAddress(object_address) && this.data.type_parameter && permission_address) {
|
|
129
|
+
obj = Arbitration.From(txb, this.data.type_parameter, permission_address, object_address)
|
|
119
130
|
}
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
if (obj) {
|
|
123
|
-
if (this.data?.description !== undefined &&
|
|
134
|
+
if (this.data?.description !== undefined && object_address) {
|
|
124
135
|
obj?.set_description(this.data.description, passport);
|
|
125
136
|
}
|
|
126
137
|
if (this.data?.bPaused !== undefined) {
|
|
@@ -129,11 +140,11 @@ export class CallArbitration extends CallBase {
|
|
|
129
140
|
if (this.data?.endpoint !== undefined) {
|
|
130
141
|
obj?.set_endpoint(this.data.endpoint, passport)
|
|
131
142
|
}
|
|
132
|
-
if (this.data?.fee !== undefined &&
|
|
143
|
+
if (this.data?.fee !== undefined && object_address) {
|
|
133
144
|
obj?.set_fee(BigInt(this.data.fee), passport)
|
|
134
145
|
}
|
|
135
|
-
if (
|
|
136
|
-
obj?.set_withdrawTreasury(
|
|
146
|
+
if (treasury_address !== undefined && object_address) {
|
|
147
|
+
obj?.set_withdrawTreasury(treasury_address, passport)
|
|
137
148
|
}
|
|
138
149
|
if (this.data.usage_guard !== undefined) {
|
|
139
150
|
obj?.set_guard(this.data.usage_guard, passport)
|
|
@@ -157,7 +168,7 @@ export class CallArbitration extends CallBase {
|
|
|
157
168
|
}
|
|
158
169
|
|
|
159
170
|
if (this.data?.arb_new !== undefined) {
|
|
160
|
-
obj?.dispute(this.data.arb_new.data, passport)
|
|
171
|
+
this.new_with_mark(txb, obj?.dispute(this.data.arb_new.data, passport), (this.data?.arb_new as any)?.namedNew, account);
|
|
161
172
|
}
|
|
162
173
|
if (this.data?.arb_arbitration !== undefined) {
|
|
163
174
|
obj?.arbitration(this.data.arb_arbitration, passport)
|
|
@@ -171,22 +182,17 @@ export class CallArbitration extends CallBase {
|
|
|
171
182
|
if (this.data?.permission_new !== undefined) {
|
|
172
183
|
obj?.change_permission(this.data.permission_new);
|
|
173
184
|
}
|
|
185
|
+
|
|
174
186
|
if (withdraw_treasury) {
|
|
175
|
-
withdraw_treasury.launch();
|
|
187
|
+
this.new_with_mark(txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
|
|
176
188
|
}
|
|
177
189
|
if (permission) {
|
|
178
|
-
permission.launch();
|
|
179
|
-
}
|
|
180
|
-
var mark : TransactionResult | string | undefined ;
|
|
181
|
-
if (!this.data.object) {
|
|
182
|
-
mark = obj?.launch();
|
|
183
|
-
} else {
|
|
184
|
-
mark = this.data.object;
|
|
190
|
+
this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
|
|
185
191
|
}
|
|
186
192
|
|
|
187
|
-
if (
|
|
188
|
-
this.
|
|
189
|
-
}
|
|
193
|
+
if (!object_address) {
|
|
194
|
+
this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
|
|
195
|
+
}
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
}
|
package/src/call/base.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { Protocol, TransactionBlock, CallResponse, Guard, TransactionArgument, Entity, IsValidAddress, Resource, TxbObject, TransactionResult} from 'wowok';
|
|
3
|
+
import { Protocol, TransactionBlock, CallResponse, Guard, TransactionArgument, Entity, IsValidAddress, Resource, TxbObject, TransactionResult, TxbAddress, array_unique, TagName, ResourceObject} from 'wowok';
|
|
4
4
|
import { PassportObject, Errors, ERROR, Permission,
|
|
5
5
|
PermissionIndexType, GuardParser, Passport, WitnessFill
|
|
6
6
|
} from 'wowok';
|
|
7
7
|
import { query_permission } from '../permission';
|
|
8
8
|
import { Account } from '../account';
|
|
9
|
-
import { ObjectBase} from '../objects';
|
|
10
|
-
|
|
9
|
+
import { ObjectBase, queryTableItem_Personal} from '../objects';
|
|
10
|
+
|
|
11
|
+
export interface Namedbject {
|
|
12
|
+
name: string;
|
|
13
|
+
tags?: string[];
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
export interface AddressMark {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
address: TxbAddress;
|
|
18
|
+
name?: string;
|
|
19
|
+
tags: string[];
|
|
16
20
|
}
|
|
17
21
|
export interface ResponseData extends ObjectBase {
|
|
18
22
|
change:'created' | 'mutated' | string;
|
|
@@ -28,7 +32,7 @@ export interface CallWithWitnessParam {
|
|
|
28
32
|
}
|
|
29
33
|
export type CallResult = GuardInfo_forCall | CallResponse | undefined;
|
|
30
34
|
|
|
31
|
-
export function ResponseData(response: CallResponse | undefined
|
|
35
|
+
export function ResponseData(response: CallResponse | undefined) : ResponseData[] {
|
|
32
36
|
const res : ResponseData[] = [];
|
|
33
37
|
response?.objectChanges?.forEach(v => {
|
|
34
38
|
const type_raw: string | undefined = (v as any)?.objectType;
|
|
@@ -41,8 +45,10 @@ export function ResponseData(response: CallResponse | undefined ) : ResponseData
|
|
|
41
45
|
})
|
|
42
46
|
return res;
|
|
43
47
|
}
|
|
48
|
+
|
|
44
49
|
export class CallBase {
|
|
45
50
|
// operation implementation for a call
|
|
51
|
+
resouceObject:ResourceObject | undefined;
|
|
46
52
|
protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {};
|
|
47
53
|
constructor () {}
|
|
48
54
|
// return WitnessFill to resolve filling witness, and than 'call_with_witness' to complete the call;
|
|
@@ -52,22 +58,16 @@ export class CallBase {
|
|
|
52
58
|
async call_with_witness (param: CallWithWitnessParam) : Promise<CallResponse | undefined> {
|
|
53
59
|
if (param.info.guard.length > 0) { // prepare passport
|
|
54
60
|
const p: GuardParser | undefined = await GuardParser.Create([...param.info.guard]);
|
|
55
|
-
const pair = Account.Instance().get_pair(param.account, true);
|
|
56
|
-
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
57
61
|
|
|
58
62
|
if (p) {
|
|
59
63
|
const query = await p.done(param.info.witness);
|
|
60
64
|
if (query) {
|
|
61
65
|
const txb = new TransactionBlock();
|
|
62
66
|
const passport = new Passport(txb, query!);
|
|
63
|
-
this.operate(new TransactionBlock(), passport?.get_object(), param?.account)
|
|
67
|
+
await this.operate(new TransactionBlock(), passport?.get_object(), param?.account)
|
|
64
68
|
passport.destroy();
|
|
65
|
-
|
|
66
|
-
return await
|
|
67
|
-
transaction: txb,
|
|
68
|
-
signer: pair!,
|
|
69
|
-
options:{showObjectChanges:true},
|
|
70
|
-
});
|
|
69
|
+
|
|
70
|
+
return await this.sign_and_commit(txb, param.account);
|
|
71
71
|
}
|
|
72
72
|
} else {
|
|
73
73
|
ERROR(Errors.Fail, 'guard finish_passport')
|
|
@@ -78,11 +78,12 @@ export class CallBase {
|
|
|
78
78
|
protected async check_permission_and_call (permission:string, permIndex: PermissionIndexType[], guards_needed: string[],
|
|
79
79
|
checkOwner?:boolean, checkAdmin?:boolean, account?:string) : Promise<CallResult> {
|
|
80
80
|
var guards : string[] = [];
|
|
81
|
-
const pair = Account.Instance().get_pair(account, true);
|
|
82
|
-
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
83
81
|
|
|
84
82
|
if (permIndex.length > 0 || checkOwner) {
|
|
85
|
-
const
|
|
83
|
+
const addr = Account.Instance().get_address(account);
|
|
84
|
+
if (!addr) ERROR(Errors.InvalidParam, 'check_permission_and_call: account invalid');
|
|
85
|
+
|
|
86
|
+
const p = await query_permission({permission_object:permission, address:addr!});
|
|
86
87
|
if (checkOwner && !p.owner) ERROR(Errors.noPermission, 'owner');
|
|
87
88
|
if (checkAdmin && !p.admin) ERROR(Errors.noPermission, 'admin');
|
|
88
89
|
|
|
@@ -107,14 +108,10 @@ export class CallBase {
|
|
|
107
108
|
if (query) {
|
|
108
109
|
const txb = new TransactionBlock();
|
|
109
110
|
const passport = new Passport(txb, query!);
|
|
110
|
-
this.operate(new TransactionBlock(), passport?.get_object(), account)
|
|
111
|
+
await this.operate(new TransactionBlock(), passport?.get_object(), account)
|
|
111
112
|
passport.destroy();
|
|
112
|
-
|
|
113
|
-
return await
|
|
114
|
-
transaction: txb,
|
|
115
|
-
signer: pair!,
|
|
116
|
-
options:{showObjectChanges:true},
|
|
117
|
-
});
|
|
113
|
+
|
|
114
|
+
return await this.sign_and_commit(txb, account);
|
|
118
115
|
}
|
|
119
116
|
}
|
|
120
117
|
|
|
@@ -124,31 +121,48 @@ export class CallBase {
|
|
|
124
121
|
}
|
|
125
122
|
}
|
|
126
123
|
protected async exec (account?:string) : Promise<CallResponse> {
|
|
124
|
+
const txb = new TransactionBlock();
|
|
125
|
+
await this.operate(txb, undefined, account);
|
|
126
|
+
return await this.sign_and_commit(txb, account);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
protected async new_with_mark(txb:TransactionBlock, object:TxbAddress, named_new?:Namedbject, account?:string, innerTags:string[]=[TagName.Launch]) {
|
|
130
|
+
const tags = named_new?.tags ? array_unique([...named_new.tags, ...innerTags]) : array_unique([...innerTags]);
|
|
131
|
+
|
|
132
|
+
if (!this.resouceObject) {
|
|
133
|
+
const addr = Account.Instance().get_address(account);
|
|
134
|
+
if (addr) {
|
|
135
|
+
const r = await queryTableItem_Personal({address:addr}); //@ use cache
|
|
136
|
+
if (!r?.mark_object) {
|
|
137
|
+
this.resouceObject = Entity.From(txb).create_resource2(); // new
|
|
138
|
+
} else {
|
|
139
|
+
Resource.From(txb, r.mark_object).add(object, tags, named_new?.name);
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
ERROR(Errors.InvalidParam, 'account - ' + account)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (this.resouceObject) {
|
|
147
|
+
Resource.From(txb, this.resouceObject).add(object, tags, named_new?.name);
|
|
148
|
+
} else {
|
|
149
|
+
ERROR(Errors.Fail, 'invalid personal mark')
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected async sign_and_commit(txb: TransactionBlock, account?: string) : Promise<CallResponse> {
|
|
127
154
|
const pair = Account.Instance().get_pair(account, true);
|
|
128
155
|
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
129
156
|
|
|
130
|
-
|
|
131
|
-
|
|
157
|
+
if (this.resouceObject) {
|
|
158
|
+
Resource.From(txb, this.resouceObject).launch(); //@ resource launch, if created.
|
|
159
|
+
this.resouceObject = undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
132
162
|
return await Protocol.Client().signAndExecuteTransaction({
|
|
133
163
|
transaction: txb,
|
|
134
164
|
signer: pair!,
|
|
135
165
|
options:{showObjectChanges:true},
|
|
136
166
|
});
|
|
137
167
|
}
|
|
138
|
-
|
|
139
|
-
protected mark = async (txb:TransactionBlock, object: string | TransactionResult, mark:AddressMark, account?:string) => {
|
|
140
|
-
const addr = Account.Instance().get_address(account);
|
|
141
|
-
if (addr) {
|
|
142
|
-
const r = await query_entity(addr);
|
|
143
|
-
if (r?.resource) {
|
|
144
|
-
const resource = Resource.From(txb, r.resource);
|
|
145
|
-
resource.add_tags(object, mark.nick_name??'', mark.tags);
|
|
146
|
-
if (mark.groups.length > 0) {
|
|
147
|
-
resource.add2(object, mark.groups);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
ERROR(Errors.InvalidParam, 'account - ' + account)
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
168
|
}
|
package/src/call/demand.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { TransactionBlock, IsValidArgType, IsValidCoinType } from 'wowok';
|
|
1
|
+
import { TransactionBlock, IsValidArgType, IsValidCoinType, Resource, ResourceObject } from 'wowok';
|
|
2
2
|
import { PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
|
|
3
3
|
PermissionIndexType, Demand, } from 'wowok';
|
|
4
4
|
import { query_objects, ObjectDemand } from '../objects';
|
|
5
|
-
import { CallBase, CallResult } from "./base";
|
|
5
|
+
import { CallBase, CallResult, Namedbject } from "./base";
|
|
6
6
|
import { Account } from '../account';
|
|
7
7
|
|
|
8
8
|
export interface CallDemand_Data {
|
|
9
|
-
object?: string; // undefined for creating a new object
|
|
10
|
-
permission?: string;
|
|
9
|
+
object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
|
|
10
|
+
permission?: {address:string} | {namedNew: Namedbject, description?:string};
|
|
11
|
+
|
|
11
12
|
type_parameter?: string;
|
|
12
13
|
guard?: {address:string; service_id_in_guard?:number};
|
|
13
14
|
description?: string;
|
|
@@ -30,15 +31,17 @@ export class CallDemand extends CallBase {
|
|
|
30
31
|
|
|
31
32
|
var checkOwner = false; const guards : string[] = [];
|
|
32
33
|
const perms : PermissionIndexType[] = [];
|
|
34
|
+
const permission_address = (this.data?.permission as any)?.address;
|
|
35
|
+
const object_address = (this.data?.object as any)?.address;
|
|
33
36
|
|
|
34
|
-
if (
|
|
37
|
+
if (permission_address && IsValidAddress(permission_address)) {
|
|
35
38
|
if (!this.data?.object) {
|
|
36
39
|
perms.push(PermissionIndex.demand)
|
|
37
40
|
}
|
|
38
|
-
if (this.data?.description !== undefined &&
|
|
41
|
+
if (this.data?.description !== undefined && object_address) {
|
|
39
42
|
perms.push(PermissionIndex.demand_description)
|
|
40
43
|
}
|
|
41
|
-
if (this.data?.time_expire !== undefined &&
|
|
44
|
+
if (this.data?.time_expire !== undefined && object_address) {
|
|
42
45
|
perms.push(PermissionIndex.demand_expand_time)
|
|
43
46
|
}
|
|
44
47
|
if (this.data?.guard !== undefined) {
|
|
@@ -54,12 +57,12 @@ export class CallDemand extends CallBase {
|
|
|
54
57
|
if (IsValidAddress(this.data.present.guard)) {
|
|
55
58
|
guards.push(this.data.present.guard)
|
|
56
59
|
} else {
|
|
57
|
-
if (!
|
|
60
|
+
if (!object_address) { // new
|
|
58
61
|
if (this.data?.guard?.address && IsValidAddress(this.data?.guard.address)) {
|
|
59
62
|
guards.push(this.data.guard.address)
|
|
60
63
|
}
|
|
61
64
|
} else {
|
|
62
|
-
const r = await query_objects({objects:[
|
|
65
|
+
const r = await query_objects({objects:[object_address], showContent:true});
|
|
63
66
|
if (r?.objects && r?.objects[0]?.type === 'Demand') {
|
|
64
67
|
const obj = (r?.objects[0] as ObjectDemand);
|
|
65
68
|
if (obj?.guard) {
|
|
@@ -69,37 +72,40 @@ export class CallDemand extends CallBase {
|
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
|
-
return await this.check_permission_and_call(
|
|
75
|
+
return await this.check_permission_and_call(permission_address, perms, guards, checkOwner, undefined, account)
|
|
73
76
|
}
|
|
74
77
|
return await this.exec(account);
|
|
75
78
|
}
|
|
76
79
|
protected async operate(txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
77
80
|
let obj : Demand | undefined ; let permission: any;
|
|
81
|
+
const permission_address = (this.data?.permission as any)?.address;
|
|
82
|
+
const object_address = (this.data?.object as any)?.address;
|
|
78
83
|
|
|
79
|
-
if (!
|
|
80
|
-
if (!
|
|
81
|
-
|
|
84
|
+
if (!object_address) {
|
|
85
|
+
if (!permission_address || !IsValidAddress(permission_address)) {
|
|
86
|
+
const d = (this.data?.permission as any)?.description ?? '';
|
|
87
|
+
permission = Permission.New(txb, d);
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
if (this.data.time_expire !== undefined) {
|
|
85
91
|
obj = Demand.New(txb, this.data.type_parameter!, this.data.time_expire?.op === 'duration' ? true : false,
|
|
86
92
|
this.data.time_expire?.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire?.time,
|
|
87
|
-
permission ? permission.get_object():
|
|
93
|
+
permission ? permission.get_object(): permission_address, this.data?.description??'', permission?undefined:passport)
|
|
88
94
|
} else {
|
|
89
95
|
obj = Demand.New(txb, this.data.type_parameter!, true, 30*24*60, // 30days default
|
|
90
|
-
permission ? permission.get_object():
|
|
96
|
+
permission ? permission.get_object(): permission_address, this.data?.description??'', permission?undefined:passport)
|
|
91
97
|
}
|
|
92
98
|
} else {
|
|
93
|
-
if (IsValidAddress(
|
|
94
|
-
obj = Demand.From(txb, this.data.type_parameter,
|
|
99
|
+
if (IsValidAddress(object_address) && this.data.type_parameter && this.data.permission && IsValidAddress(permission_address)) {
|
|
100
|
+
obj = Demand.From(txb, this.data.type_parameter, permission_address, object_address)
|
|
95
101
|
}
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
if (obj) {
|
|
99
|
-
if (this.data?.description !== undefined &&
|
|
105
|
+
if (this.data?.description !== undefined && object_address) {
|
|
100
106
|
obj?.set_description(this.data.description, passport);
|
|
101
107
|
}
|
|
102
|
-
if (this.data?.time_expire !== undefined &&
|
|
108
|
+
if (this.data?.time_expire !== undefined && object_address) {
|
|
103
109
|
obj?.expand_time(this.data.time_expire.op === 'duration' ? true : false,
|
|
104
110
|
this.data.time_expire.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire.time, passport)
|
|
105
111
|
}
|
|
@@ -128,10 +134,10 @@ export class CallDemand extends CallBase {
|
|
|
128
134
|
obj?.set_guard(this.data.guard.address, this.data.guard?.service_id_in_guard ?? undefined, passport)
|
|
129
135
|
}
|
|
130
136
|
if (permission) {
|
|
131
|
-
permission.launch();
|
|
137
|
+
this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
|
|
132
138
|
}
|
|
133
139
|
if (!this.data.object) {
|
|
134
|
-
obj
|
|
140
|
+
this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
143
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CallBase, CallResult } from "./base";
|
|
2
|
-
import { TransactionBlock, CallResponse} from 'wowok';
|
|
1
|
+
import { CallBase, CallResult, Namedbject } from "./base";
|
|
2
|
+
import { TransactionBlock, CallResponse, Resource, ResourceObject} from 'wowok';
|
|
3
3
|
import { PassportObject, IsValidAddress, Errors, ERROR, Permission, Permission_Entity, Permission_Index, UserDefinedIndex,
|
|
4
4
|
PermissionIndexType, WitnessFill
|
|
5
5
|
} from 'wowok';
|
|
6
6
|
|
|
7
7
|
export interface CallEntityPermission_Data {
|
|
8
|
-
object?: string; // undefined for creating a new object
|
|
8
|
+
object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
|
|
9
9
|
builder?: string;
|
|
10
10
|
admin?: {op:'add' | 'remove' | 'set', admins:string[]};
|
|
11
11
|
description?: string;
|
|
@@ -23,7 +23,9 @@ export class CallEntityPermission extends CallBase {
|
|
|
23
23
|
|
|
24
24
|
async call(account?:string) : Promise<CallResult> {
|
|
25
25
|
var checkOwner = false; var checkAdmin = false;
|
|
26
|
-
|
|
26
|
+
const object_address = (this.data?.object as any)?.address;
|
|
27
|
+
|
|
28
|
+
if (object_address && IsValidAddress(object_address)) {
|
|
27
29
|
if (this.data?.builder !== undefined || this.data?.admin !== undefined) {
|
|
28
30
|
checkOwner = true;
|
|
29
31
|
}
|
|
@@ -33,18 +35,18 @@ export class CallEntityPermission extends CallBase {
|
|
|
33
35
|
if (this.data?.description !== undefined) {
|
|
34
36
|
checkAdmin = true;
|
|
35
37
|
}
|
|
36
|
-
return await this.check_permission_and_call(
|
|
38
|
+
return await this.check_permission_and_call(object_address, [], [], checkOwner, checkAdmin, account)
|
|
37
39
|
}
|
|
38
40
|
return await this.exec(account)
|
|
39
41
|
}
|
|
40
|
-
protected async operate (txb:TransactionBlock, passport?:PassportObject) {
|
|
42
|
+
protected async operate (txb:TransactionBlock, passport?:PassportObject, account?:string) {
|
|
41
43
|
let obj : Permission | undefined ;
|
|
42
|
-
|
|
44
|
+
const object_address = (this.data?.object as any)?.address;
|
|
45
|
+
|
|
46
|
+
if (!object_address || !IsValidAddress(object_address)) {
|
|
43
47
|
obj = Permission.New(txb, this.data?.description??'');
|
|
44
48
|
} else {
|
|
45
|
-
|
|
46
|
-
obj = Permission.From(txb, this.data.object)
|
|
47
|
-
}
|
|
49
|
+
obj = Permission.From(txb, object_address)
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
if (obj) {
|
|
@@ -102,8 +104,8 @@ export class CallEntityPermission extends CallBase {
|
|
|
102
104
|
if (this.data?.builder !== undefined ) {
|
|
103
105
|
obj?.change_owner(this.data.builder);
|
|
104
106
|
}
|
|
105
|
-
if (!
|
|
106
|
-
obj
|
|
107
|
+
if (!object_address) {
|
|
108
|
+
this.new_with_mark(txb, obj.launch(), (this.data?.object as any)?.namedNew, account);
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
}
|