wowok_agent 0.0.1 → 0.1.4
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 +88 -72
- package/src/call/{call.ts → base.ts} +37 -36
- package/src/call/demand.ts +73 -59
- package/src/call/guard.ts +261 -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 +5 -1
- package/src/objects.ts +338 -338
- package/src/permission.ts +33 -34
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@ $ npm i wowok_agent@latest
|
|
|
16
16
|
The protocol address may change due to protocol upgrade. Please update the SDK to the latest version.
|
|
17
17
|
|
|
18
18
|
### Fetures
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
- *Operation account generation and management.*
|
|
20
|
+
- *Integrate queries and operations.*
|
|
21
|
+
- *Simplifies and supports JSON-driven operations.*
|
|
22
22
|
|
|
23
23
|
|
package/package.json
CHANGED
package/src/account.ts
CHANGED
|
@@ -2,13 +2,19 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as os from 'os';
|
|
4
4
|
import { Ed25519Keypair, fromHEX, toHEX, decodeSuiPrivateKey } from 'wowok';
|
|
5
|
-
|
|
5
|
+
import { getFaucetHost, requestSuiFromFaucetV0, requestSuiFromFaucetV1 } from 'wowok';
|
|
6
6
|
export interface AccountData {
|
|
7
7
|
name: string;
|
|
8
8
|
default?: boolean;
|
|
9
9
|
key: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
export interface AccountData_Show {
|
|
13
|
+
name: string;
|
|
14
|
+
default?: boolean;
|
|
15
|
+
address: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
const Account_FileName = 'wowok.dat';
|
|
13
19
|
const Account_Key = 'wowok-data-v1';
|
|
14
20
|
|
|
@@ -184,15 +190,31 @@ export class Account {
|
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
192
|
|
|
187
|
-
list() :
|
|
193
|
+
list() : AccountData_Show[] {
|
|
188
194
|
try {
|
|
189
195
|
if (this.storage === 'File') {
|
|
190
196
|
const filePath = path.join(os.homedir(), Account_FileName);
|
|
191
|
-
|
|
197
|
+
const a = JSON.parse(fs.readFileSync(filePath, 'utf-8')) as AccountData[];
|
|
198
|
+
return a.map(v => {
|
|
199
|
+
return {name:v.name, default:v?.default, address:Ed25519Keypair.fromSecretKey(fromHEX(v.key)).getPublicKey().toSuiAddress()}
|
|
200
|
+
})
|
|
192
201
|
} else if (this.storage === 'Explorer') {
|
|
193
|
-
|
|
202
|
+
const a = JSON.parse(localStorage.getItem(Account_Key) ?? '') as AccountData[];
|
|
203
|
+
return a.map(v => {
|
|
204
|
+
return {name:v.name, default:v?.default, address:Ed25519Keypair.fromSecretKey(fromHEX(v.key)).getPublicKey().toSuiAddress()}
|
|
205
|
+
})
|
|
194
206
|
}
|
|
195
207
|
} catch (e) { console.log(e) }
|
|
196
208
|
return []
|
|
197
209
|
}
|
|
210
|
+
|
|
211
|
+
faucet(name?:string) {
|
|
212
|
+
const address = this.get_address(name, true);
|
|
213
|
+
if (address) {
|
|
214
|
+
requestSuiFromFaucetV0({host:getFaucetHost('testnet'), recipient:address}).catch(e => {
|
|
215
|
+
console.log(e)
|
|
216
|
+
requestSuiFromFaucetV1({host:getFaucetHost('testnet'), recipient:address}).catch(e => console.log(e));
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
}
|
|
198
220
|
}
|
package/src/call/arbitration.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { TransactionBlock, CallResponse} from 'wowok';
|
|
1
|
+
import { TransactionBlock, CallResponse, IsValidArgType} 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
|
-
import {
|
|
6
|
-
import { CallBase } from "./
|
|
5
|
+
import { query_objects, ObjectArbitration, } from '../objects';
|
|
6
|
+
import { CallBase, CallResult } from "./base";
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
|
|
8
|
+
export interface CallArbitration_Data {
|
|
9
|
+
object?: string; // undefined for creating a new object
|
|
10
|
+
permission?: string;
|
|
11
|
+
|
|
12
|
+
type_parameter?: string;
|
|
10
13
|
permission_new?: string;
|
|
11
14
|
description?: string;
|
|
12
15
|
bPaused?: boolean;
|
|
@@ -19,120 +22,133 @@ export class CallArbitration extends CallBase {
|
|
|
19
22
|
arb_withdraw_fee?: {arb:string; data:WithdrawFee};
|
|
20
23
|
arb_vote?: Vote;
|
|
21
24
|
arb_arbitration?: Feedback;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
}
|
|
26
|
+
export class CallArbitration extends CallBase {
|
|
27
|
+
data: CallArbitration_Data;
|
|
28
|
+
constructor (data: CallArbitration_Data) {
|
|
29
|
+
super();
|
|
30
|
+
this.data = data;
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
|
|
33
|
+
async call(account?:string) : Promise<CallResult> {
|
|
34
|
+
if (!this.data?.type_parameter || !IsValidArgType(this.data.type_parameter)) {
|
|
35
|
+
ERROR(Errors.IsValidArgType, 'arbitration.type_parameter')
|
|
36
|
+
}
|
|
28
37
|
|
|
29
38
|
var checkOwner = false; const guards : string[] = [];
|
|
30
39
|
const perms : PermissionIndexType[] = []; var obj: ObjectArbitration | undefined ;
|
|
31
40
|
|
|
32
|
-
if (this?.permission && IsValidAddress(this.permission)) {
|
|
33
|
-
if (this?.object
|
|
41
|
+
if (this.data?.permission && IsValidAddress(this.data.permission)) {
|
|
42
|
+
if (!this.data?.object) {
|
|
34
43
|
perms.push(PermissionIndex.arbitration)
|
|
35
44
|
}
|
|
36
|
-
if (this?.permission_new !== undefined) {
|
|
45
|
+
if (this.data?.permission_new !== undefined) {
|
|
37
46
|
checkOwner = true;
|
|
38
47
|
}
|
|
39
|
-
if (this?.description !== undefined && this.object
|
|
48
|
+
if (this.data?.description !== undefined && this.data.object) {
|
|
40
49
|
perms.push(PermissionIndex.arbitration_description)
|
|
41
50
|
}
|
|
42
|
-
if (this?.bPaused !== undefined) {
|
|
51
|
+
if (this.data?.bPaused !== undefined) {
|
|
43
52
|
perms.push(PermissionIndex.arbitration_pause)
|
|
44
53
|
}
|
|
45
|
-
if (this?.endpoint == undefined) { // publish is an irreversible one-time operation
|
|
54
|
+
if (this.data?.endpoint == undefined) { // publish is an irreversible one-time operation
|
|
46
55
|
perms.push(PermissionIndex.arbitration_endpoint)
|
|
47
56
|
}
|
|
48
|
-
if (this?.fee !== undefined && this.object
|
|
57
|
+
if (this.data?.fee !== undefined && this.data.object) {
|
|
49
58
|
perms.push(PermissionIndex.arbitration_fee)
|
|
50
59
|
}
|
|
51
|
-
if (this?.fee_treasury !== undefined && this.object
|
|
60
|
+
if (this.data?.fee_treasury !== undefined && this.data.object) {
|
|
52
61
|
perms.push(PermissionIndex.arbitration_treasury)
|
|
53
62
|
}
|
|
54
|
-
if (this?.usage_guard !== undefined) {
|
|
63
|
+
if (this.data?.usage_guard !== undefined) {
|
|
55
64
|
perms.push(PermissionIndex.arbitration_guard)
|
|
56
65
|
}
|
|
57
|
-
if (this?.voting_guard !== undefined) {
|
|
66
|
+
if (this.data?.voting_guard !== undefined) {
|
|
58
67
|
perms.push(PermissionIndex.arbitration_voting_guard)
|
|
59
68
|
}
|
|
60
|
-
if (this?.arb_arbitration !== undefined) {
|
|
69
|
+
if (this.data?.arb_arbitration !== undefined) {
|
|
61
70
|
perms.push(PermissionIndex.arbitration_arbitration)
|
|
62
71
|
}
|
|
63
|
-
if (this?.arb_new?.guard !== undefined) {
|
|
64
|
-
if (IsValidAddress(this.arb_new.guard)) {
|
|
65
|
-
guards.push(this.arb_new.guard)
|
|
72
|
+
if (this.data?.arb_new?.guard !== undefined) {
|
|
73
|
+
if (IsValidAddress(this.data.arb_new.guard)) {
|
|
74
|
+
guards.push(this.data.arb_new.guard)
|
|
66
75
|
} else {
|
|
67
|
-
if (!
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
obj = r.objects[0] as ObjectArbitration;
|
|
76
|
+
if (!this.data.object) { // new
|
|
77
|
+
if (this.data?.usage_guard && IsValidAddress(this.data?.usage_guard)) {
|
|
78
|
+
guards.push(this.data.usage_guard)
|
|
71
79
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
} else {
|
|
81
|
+
if (!obj) {
|
|
82
|
+
const r = await query_objects({objects:[this.data.object!], showContent:true});
|
|
83
|
+
if (r?.objects && r.objects[0].type === 'Arbitration') {
|
|
84
|
+
obj = r.objects[0] as ObjectArbitration;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (obj?.usage_guard) {
|
|
89
|
+
guards.push(obj.usage_guard)
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
|
-
if (this?.arb_vote !== undefined) {
|
|
94
|
+
if (this.data?.arb_vote !== undefined) {
|
|
79
95
|
perms.push(PermissionIndex.treasury_receive)
|
|
80
96
|
}
|
|
81
|
-
if (typeof(this?.arb_vote?.voting_guard) === 'string' && IsValidAddress(this?.arb_vote?.voting_guard)) {
|
|
82
|
-
guards.push(this?.arb_vote?.voting_guard)
|
|
97
|
+
if (typeof(this.data?.arb_vote?.voting_guard) === 'string' && IsValidAddress(this.data?.arb_vote?.voting_guard)) {
|
|
98
|
+
guards.push(this.data?.arb_vote?.voting_guard)
|
|
83
99
|
}
|
|
84
100
|
|
|
85
|
-
return await this.check_permission_and_call(this.permission, perms, guards, checkOwner, undefined, account)
|
|
101
|
+
return await this.check_permission_and_call(this.data.permission, perms, guards, checkOwner, undefined, account)
|
|
86
102
|
}
|
|
87
103
|
return this.exec(account);
|
|
88
104
|
}
|
|
89
105
|
protected async operate(txb:TransactionBlock, passport?:PassportObject) {
|
|
90
106
|
let obj : Arbitration | undefined ; let permission: any; let withdraw_treasury:any;
|
|
91
|
-
if (this.object
|
|
92
|
-
if (!this?.permission || !IsValidAddress(this?.permission)) {
|
|
107
|
+
if (!this.data.object) {
|
|
108
|
+
if (!this.data?.permission || !IsValidAddress(this.data?.permission)) {
|
|
93
109
|
permission = Permission.New(txb, '');
|
|
94
110
|
}
|
|
95
|
-
if (!this?.fee_treasury || !IsValidAddress(this?.fee_treasury)) {
|
|
96
|
-
withdraw_treasury = Treasury.New(txb, this?.type_parameter
|
|
111
|
+
if (!this.data?.fee_treasury || !IsValidAddress(this.data?.fee_treasury)) {
|
|
112
|
+
withdraw_treasury = Treasury.New(txb, this.data?.type_parameter!, permission ?? this.data?.permission, '', permission?undefined:passport);
|
|
97
113
|
}
|
|
98
|
-
obj = Arbitration.New(txb, this.type_parameter
|
|
99
|
-
BigInt(this?.fee ?? 0), withdraw_treasury??this.fee_treasury, permission?undefined:passport);
|
|
100
|
-
} else {
|
|
101
|
-
if (IsValidAddress(this.object) && this.type_parameter && this.permission && IsValidAddress(this?.permission)) {
|
|
102
|
-
obj = Arbitration.From(txb, this.type_parameter, this.permission, this.object)
|
|
114
|
+
obj = Arbitration.New(txb, this.data.type_parameter!, permission ?? this.data?.permission, this.data?.description??'',
|
|
115
|
+
BigInt(this.data?.fee ?? 0), withdraw_treasury??this.data.fee_treasury, permission?undefined:passport);
|
|
116
|
+
} else if (this.data.object) {
|
|
117
|
+
if (IsValidAddress(this.data.object) && this.data.type_parameter && this.data.permission && IsValidAddress(this.data?.permission)) {
|
|
118
|
+
obj = Arbitration.From(txb, this.data.type_parameter, this.data.permission, this.data.object)
|
|
103
119
|
}
|
|
104
120
|
}
|
|
105
121
|
|
|
106
122
|
if (obj) {
|
|
107
|
-
if (this?.description !== undefined && this.object
|
|
108
|
-
obj?.set_description(this.description, passport);
|
|
123
|
+
if (this.data?.description !== undefined && this.data.object) {
|
|
124
|
+
obj?.set_description(this.data.description, passport);
|
|
109
125
|
}
|
|
110
|
-
if (this?.bPaused !== undefined) {
|
|
111
|
-
obj?.pause(this.bPaused, passport);
|
|
126
|
+
if (this.data?.bPaused !== undefined) {
|
|
127
|
+
obj?.pause(this.data.bPaused, passport);
|
|
112
128
|
}
|
|
113
|
-
if (this?.endpoint !== undefined) {
|
|
114
|
-
obj?.set_endpoint(this.endpoint, passport)
|
|
129
|
+
if (this.data?.endpoint !== undefined) {
|
|
130
|
+
obj?.set_endpoint(this.data.endpoint, passport)
|
|
115
131
|
}
|
|
116
|
-
if (this?.fee !== undefined && this.object
|
|
117
|
-
obj?.set_fee(BigInt(this.fee), passport)
|
|
132
|
+
if (this.data?.fee !== undefined && this.data.object) {
|
|
133
|
+
obj?.set_fee(BigInt(this.data.fee), passport)
|
|
118
134
|
}
|
|
119
|
-
if (this.fee_treasury !== undefined && this.object
|
|
120
|
-
obj?.set_withdrawTreasury(this.fee_treasury, passport)
|
|
135
|
+
if (this.data.fee_treasury !== undefined && this.data.object) {
|
|
136
|
+
obj?.set_withdrawTreasury(this.data.fee_treasury, passport)
|
|
121
137
|
}
|
|
122
|
-
if (this.usage_guard !== undefined) {
|
|
123
|
-
obj?.set_guard(this.usage_guard, passport)
|
|
138
|
+
if (this.data.usage_guard !== undefined) {
|
|
139
|
+
obj?.set_guard(this.data.usage_guard, passport)
|
|
124
140
|
}
|
|
125
|
-
if (this?.voting_guard !== undefined) {
|
|
126
|
-
switch (this.voting_guard.op) {
|
|
141
|
+
if (this.data?.voting_guard !== undefined) {
|
|
142
|
+
switch (this.data.voting_guard.op) {
|
|
127
143
|
case 'add':
|
|
128
|
-
obj?.add_voting_guard(this.voting_guard.data, passport)
|
|
144
|
+
obj?.add_voting_guard(this.data.voting_guard.data, passport)
|
|
129
145
|
break;
|
|
130
146
|
case 'remove':
|
|
131
|
-
obj?.remove_voting_guard(this.voting_guard.guards, false, passport)
|
|
147
|
+
obj?.remove_voting_guard(this.data.voting_guard.guards, false, passport)
|
|
132
148
|
break;
|
|
133
149
|
case 'set':
|
|
134
150
|
obj?.remove_voting_guard([], true, passport)
|
|
135
|
-
obj?.add_voting_guard(this.voting_guard.data, passport)
|
|
151
|
+
obj?.add_voting_guard(this.data.voting_guard.data, passport)
|
|
136
152
|
break;
|
|
137
153
|
case 'removeall':
|
|
138
154
|
obj?.remove_voting_guard([], true, passport)
|
|
@@ -140,20 +156,20 @@ export class CallArbitration extends CallBase {
|
|
|
140
156
|
}
|
|
141
157
|
}
|
|
142
158
|
|
|
143
|
-
if (this?.arb_new !== undefined) {
|
|
144
|
-
obj?.dispute(this.arb_new.data, passport)
|
|
159
|
+
if (this.data?.arb_new !== undefined) {
|
|
160
|
+
obj?.dispute(this.data.arb_new.data, passport)
|
|
145
161
|
}
|
|
146
|
-
if (this?.arb_arbitration !== undefined) {
|
|
147
|
-
obj?.arbitration(this.arb_arbitration, passport)
|
|
162
|
+
if (this.data?.arb_arbitration !== undefined) {
|
|
163
|
+
obj?.arbitration(this.data.arb_arbitration, passport)
|
|
148
164
|
}
|
|
149
|
-
if (this?.arb_vote !== undefined) {
|
|
150
|
-
obj?.vote(this.arb_vote, passport)
|
|
165
|
+
if (this.data?.arb_vote !== undefined) {
|
|
166
|
+
obj?.vote(this.data.arb_vote, passport)
|
|
151
167
|
}
|
|
152
|
-
if (this?.arb_withdraw_fee !== undefined) {
|
|
153
|
-
obj?.withdraw_fee(this.arb_withdraw_fee.arb, this.arb_withdraw_fee.data, passport)
|
|
168
|
+
if (this.data?.arb_withdraw_fee !== undefined) {
|
|
169
|
+
obj?.withdraw_fee(this.data.arb_withdraw_fee.arb, this.data.arb_withdraw_fee.data, passport)
|
|
154
170
|
}
|
|
155
|
-
if (this?.permission_new !== undefined) {
|
|
156
|
-
obj?.change_permission(this.permission_new);
|
|
171
|
+
if (this.data?.permission_new !== undefined) {
|
|
172
|
+
obj?.change_permission(this.data.permission_new);
|
|
157
173
|
}
|
|
158
174
|
if (withdraw_treasury) {
|
|
159
175
|
withdraw_treasury.launch();
|
|
@@ -161,7 +177,7 @@ export class CallArbitration extends CallBase {
|
|
|
161
177
|
if (permission) {
|
|
162
178
|
permission.launch();
|
|
163
179
|
}
|
|
164
|
-
if (this.object
|
|
180
|
+
if (!this.data.object) {
|
|
165
181
|
obj?.launch();
|
|
166
182
|
}
|
|
167
183
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provide a this interface for AI
|
|
3
|
-
* Operation sequence Priority: common operation > Guard change > permission change
|
|
4
|
-
* Recommended: Changes to guard and permission are committed on-chain separately to avoid permission dependencies for other operations.
|
|
5
|
-
*/
|
|
6
1
|
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
import { Protocol, TransactionBlock, CallResponse, Guard} from 'wowok';
|
|
8
4
|
import { PassportObject, Errors, ERROR, Permission,
|
|
9
5
|
PermissionIndexType, GuardParser, Passport, WitnessFill
|
|
10
6
|
} from 'wowok';
|
|
11
|
-
import {
|
|
7
|
+
import { query_permission } from '../permission';
|
|
12
8
|
import { Account } from '../account';
|
|
13
9
|
import { ObjectBase } from '../objects';
|
|
14
10
|
|
|
@@ -17,27 +13,46 @@ export interface ResponseData extends ObjectBase {
|
|
|
17
13
|
change:'created' | 'mutated' | string;
|
|
18
14
|
}
|
|
19
15
|
|
|
16
|
+
export interface GuardInfo_forCall {
|
|
17
|
+
guard: string[];
|
|
18
|
+
witness: WitnessFill[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CallWithWitnessParam {
|
|
22
|
+
info: GuardInfo_forCall;
|
|
23
|
+
account?:string;
|
|
24
|
+
}
|
|
25
|
+
export type CallResult = GuardInfo_forCall | CallResponse | undefined;
|
|
26
|
+
|
|
27
|
+
export function ResponseData(response: CallResponse | undefined ) : ResponseData[] {
|
|
28
|
+
const res : ResponseData[] = [];
|
|
29
|
+
response?.objectChanges?.forEach(v => {
|
|
30
|
+
const type_raw: string | undefined = (v as any)?.objectType;
|
|
31
|
+
const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
|
|
32
|
+
if (type) {
|
|
33
|
+
res.push({type:type, type_raw:type_raw, object:(v as any)?.objectId, version:(v as any)?.version,
|
|
34
|
+
owner:(v as any)?.owner, change:v.type
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
20
40
|
export class CallBase {
|
|
21
|
-
object: string | 'new' ;
|
|
22
|
-
permission?: string;
|
|
23
|
-
constructor(object: string | 'new' = 'new') {
|
|
24
|
-
this.object = object;
|
|
25
|
-
}
|
|
26
41
|
// operation implementation for a call
|
|
27
42
|
protected async operate(txb:TransactionBlock, passport?:PassportObject) {};
|
|
28
|
-
|
|
43
|
+
constructor () {}
|
|
29
44
|
// return WitnessFill to resolve filling witness, and than 'call_with_witness' to complete the call;
|
|
30
45
|
// return ResponseData when the call has completed;
|
|
31
46
|
// throw an exception when errors.
|
|
32
|
-
async call(account?:string) : Promise<
|
|
33
|
-
async call_with_witness (
|
|
34
|
-
if (
|
|
35
|
-
const p: GuardParser | undefined = await GuardParser.Create([...
|
|
36
|
-
const pair = Account.Instance().get_pair(account, true);
|
|
47
|
+
async call(account?:string) : Promise<CallResult> { return undefined };
|
|
48
|
+
async call_with_witness (param: CallWithWitnessParam) : Promise<CallResponse | undefined> {
|
|
49
|
+
if (param.info.guard.length > 0) { // prepare passport
|
|
50
|
+
const p: GuardParser | undefined = await GuardParser.Create([...param.info.guard]);
|
|
51
|
+
const pair = Account.Instance().get_pair(param.account, true);
|
|
37
52
|
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
38
53
|
|
|
39
54
|
if (p) {
|
|
40
|
-
const query = await p.done(
|
|
55
|
+
const query = await p.done(param.info.witness);
|
|
41
56
|
if (query) {
|
|
42
57
|
const txb = new TransactionBlock();
|
|
43
58
|
const passport = new Passport(txb, query!);
|
|
@@ -57,13 +72,13 @@ export class CallBase {
|
|
|
57
72
|
}
|
|
58
73
|
|
|
59
74
|
protected async check_permission_and_call (permission:string, permIndex: PermissionIndexType[], guards_needed: string[],
|
|
60
|
-
checkOwner?:boolean, checkAdmin?:boolean, account?:string) : Promise<
|
|
75
|
+
checkOwner?:boolean, checkAdmin?:boolean, account?:string) : Promise<CallResult> {
|
|
61
76
|
var guards : string[] = [];
|
|
62
77
|
const pair = Account.Instance().get_pair(account, true);
|
|
63
78
|
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
64
79
|
|
|
65
80
|
if (permIndex.length > 0 || checkOwner) {
|
|
66
|
-
const p = await
|
|
81
|
+
const p = await query_permission({permission_object:permission, address:pair!.toSuiAddress()});
|
|
67
82
|
if (checkOwner && !p.owner) ERROR(Errors.noPermission, 'owner');
|
|
68
83
|
if (checkAdmin && !p.admin) ERROR(Errors.noPermission, 'admin');
|
|
69
84
|
|
|
@@ -99,7 +114,7 @@ export class CallBase {
|
|
|
99
114
|
}
|
|
100
115
|
}
|
|
101
116
|
|
|
102
|
-
return p!.future_fills();
|
|
117
|
+
return {guard:[...guards], witness:p!.future_fills()};
|
|
103
118
|
} else { // no passport needed
|
|
104
119
|
return this.exec()
|
|
105
120
|
}
|
|
@@ -116,18 +131,4 @@ export class CallBase {
|
|
|
116
131
|
options:{showObjectChanges:true},
|
|
117
132
|
});
|
|
118
133
|
}
|
|
119
|
-
|
|
120
|
-
static ResponseData(response: CallResponse | undefined ) : ResponseData[] {
|
|
121
|
-
const res : ResponseData[] = [];
|
|
122
|
-
response?.objectChanges?.forEach(v => {
|
|
123
|
-
const type_raw: string | undefined = (v as any)?.objectType;
|
|
124
|
-
const type:string | undefined = type_raw ? Protocol.Instance().object_name_from_type_repr(type_raw) : undefined;
|
|
125
|
-
if (type) {
|
|
126
|
-
res.push({type:type, type_raw:type_raw, object:(v as any)?.objectId, version:(v as any)?.version,
|
|
127
|
-
owner:(v as any)?.owner, change:v.type
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
return res;
|
|
132
|
-
}
|
|
133
134
|
}
|