wowok_agent 0.1.13 → 0.1.16
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 +17 -0
- package/dist/124.index.js +1 -0
- package/dist/account.d.ts +38 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +273 -0
- package/dist/agent/empty.d.ts +1 -0
- package/dist/agent/empty.d.ts.map +1 -0
- package/dist/agent/src/account.d.ts +38 -0
- package/dist/agent/src/account.d.ts.map +1 -0
- package/dist/agent/src/cache.d.ts +46 -0
- package/dist/agent/src/cache.d.ts.map +1 -0
- package/dist/agent/src/call/arbitration.d.ts +63 -0
- package/dist/agent/src/call/arbitration.d.ts.map +1 -0
- package/dist/agent/src/call/base.d.ts +34 -0
- package/dist/agent/src/call/base.d.ts.map +1 -0
- package/dist/agent/src/call/demand.d.ts +55 -0
- package/dist/agent/src/call/demand.d.ts.map +1 -0
- package/dist/agent/src/call/guard.d.ts +44 -0
- package/dist/agent/src/call/guard.d.ts.map +1 -0
- package/dist/agent/src/call/machine.d.ts +109 -0
- package/dist/agent/src/call/machine.d.ts.map +1 -0
- package/dist/agent/src/call/object_permission.d.ts +13 -0
- package/dist/agent/src/call/object_permission.d.ts.map +1 -0
- package/dist/agent/src/call/permission.d.ts +47 -0
- package/dist/agent/src/call/permission.d.ts.map +1 -0
- package/dist/agent/src/call/personal.d.ts +43 -0
- package/dist/agent/src/call/personal.d.ts.map +1 -0
- package/dist/agent/src/call/repository.d.ts +53 -0
- package/dist/agent/src/call/repository.d.ts.map +1 -0
- package/dist/agent/src/call/service.d.ts +134 -0
- package/dist/agent/src/call/service.d.ts.map +1 -0
- package/dist/agent/src/call/treasury.d.ts +53 -0
- package/dist/agent/src/call/treasury.d.ts.map +1 -0
- package/dist/agent/src/call.d.ts +24 -0
- package/dist/agent/src/call.d.ts.map +1 -0
- package/dist/agent/src/events.d.ts +65 -0
- package/dist/agent/src/events.d.ts.map +1 -0
- package/dist/agent/src/index.d.ts +19 -0
- package/dist/agent/src/index.d.ts.map +1 -0
- package/dist/agent/src/objects.d.ts +308 -0
- package/dist/agent/src/objects.d.ts.map +1 -0
- package/dist/agent/src/permission.d.ts +12 -0
- package/dist/agent/src/permission.d.ts.map +1 -0
- package/dist/agent/src/private_info.d.ts +26 -0
- package/dist/agent/src/private_info.d.ts.map +1 -0
- package/dist/cache.d.ts +46 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +59 -0
- package/dist/call/arbitration.d.ts +63 -0
- package/dist/call/arbitration.d.ts.map +1 -0
- package/dist/call/arbitration.js +182 -0
- package/dist/call/base.d.ts +34 -0
- package/dist/call/base.d.ts.map +1 -0
- package/dist/call/base.js +131 -0
- package/dist/call/demand.d.ts +55 -0
- package/dist/call/demand.d.ts.map +1 -0
- package/dist/call/demand.js +135 -0
- package/dist/call/guard.d.ts +44 -0
- package/dist/call/guard.d.ts.map +1 -0
- package/dist/call/guard.js +244 -0
- package/dist/call/machine.d.ts +109 -0
- package/dist/call/machine.d.ts.map +1 -0
- package/dist/call/machine.js +210 -0
- package/dist/call/object_permission.d.ts +13 -0
- package/dist/call/object_permission.d.ts.map +1 -0
- package/dist/call/object_permission.js +49 -0
- package/dist/call/permission.d.ts +47 -0
- package/dist/call/permission.d.ts.map +1 -0
- package/dist/call/permission.js +95 -0
- package/dist/call/personal.d.ts +43 -0
- package/dist/call/personal.d.ts.map +1 -0
- package/dist/call/personal.js +60 -0
- package/dist/call/repository.d.ts +53 -0
- package/dist/call/repository.d.ts.map +1 -0
- package/dist/call/repository.js +125 -0
- package/dist/call/service.d.ts +134 -0
- package/dist/call/service.d.ts.map +1 -0
- package/dist/call/service.js +340 -0
- package/dist/call/treasury.d.ts +53 -0
- package/dist/call/treasury.d.ts.map +1 -0
- package/dist/call/treasury.js +161 -0
- package/dist/call.d.ts +24 -0
- package/dist/call.d.ts.map +1 -0
- package/dist/call.js +58 -0
- package/dist/empty.d.ts +1 -0
- package/dist/empty.d.ts.map +1 -0
- package/dist/empty.js +1 -0
- package/dist/events.d.ts +65 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +59 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/objects.d.ts +308 -0
- package/dist/objects.d.ts.map +1 -0
- package/dist/objects.js +448 -0
- package/dist/permission.d.ts +12 -0
- package/dist/permission.d.ts.map +1 -0
- package/dist/permission.js +40 -0
- package/dist/private_info.d.ts +26 -0
- package/dist/private_info.d.ts.map +1 -0
- package/dist/private_info.js +243 -0
- package/dist/src/account.d.ts +38 -0
- package/dist/src/account.d.ts.map +1 -0
- package/dist/src/account.js +273 -0
- package/dist/src/cache.d.ts +46 -0
- package/dist/src/cache.d.ts.map +1 -0
- package/dist/src/cache.js +59 -0
- package/dist/src/call/arbitration.d.ts +63 -0
- package/dist/src/call/arbitration.d.ts.map +1 -0
- package/dist/src/call/arbitration.js +182 -0
- package/dist/src/call/base.d.ts +34 -0
- package/dist/src/call/base.d.ts.map +1 -0
- package/dist/src/call/base.js +131 -0
- package/dist/src/call/demand.d.ts +55 -0
- package/dist/src/call/demand.d.ts.map +1 -0
- package/dist/src/call/demand.js +135 -0
- package/dist/src/call/guard.d.ts +44 -0
- package/dist/src/call/guard.d.ts.map +1 -0
- package/dist/src/call/guard.js +244 -0
- package/dist/src/call/machine.d.ts +109 -0
- package/dist/src/call/machine.d.ts.map +1 -0
- package/dist/src/call/machine.js +210 -0
- package/dist/src/call/object_permission.d.ts +13 -0
- package/dist/src/call/object_permission.d.ts.map +1 -0
- package/dist/src/call/object_permission.js +49 -0
- package/dist/src/call/permission.d.ts +47 -0
- package/dist/src/call/permission.d.ts.map +1 -0
- package/dist/src/call/permission.js +95 -0
- package/dist/src/call/personal.d.ts +43 -0
- package/dist/src/call/personal.d.ts.map +1 -0
- package/dist/src/call/personal.js +60 -0
- package/dist/src/call/repository.d.ts +53 -0
- package/dist/src/call/repository.d.ts.map +1 -0
- package/dist/src/call/repository.js +125 -0
- package/dist/src/call/service.d.ts +134 -0
- package/dist/src/call/service.d.ts.map +1 -0
- package/dist/src/call/service.js +340 -0
- package/dist/src/call/treasury.d.ts +53 -0
- package/dist/src/call/treasury.d.ts.map +1 -0
- package/dist/src/call/treasury.js +161 -0
- package/dist/src/call.d.ts +24 -0
- package/dist/src/call.d.ts.map +1 -0
- package/dist/src/call.js +58 -0
- package/dist/src/events.d.ts +65 -0
- package/dist/src/events.d.ts.map +1 -0
- package/dist/src/events.js +59 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +18 -0
- package/dist/src/objects.d.ts +308 -0
- package/dist/src/objects.d.ts.map +1 -0
- package/dist/src/objects.js +448 -0
- package/dist/src/permission.d.ts +12 -0
- package/dist/src/permission.d.ts.map +1 -0
- package/dist/src/permission.js +40 -0
- package/dist/src/private_info.d.ts +26 -0
- package/dist/src/private_info.d.ts.map +1 -0
- package/dist/src/private_info.js +243 -0
- package/dist/webpack.config.d.ts +2 -0
- package/dist/webpack.config.d.ts.map +1 -0
- package/dist/webpack.config.js +17 -0
- package/dist/wowok/src/arbitration.d.ts +63 -0
- package/dist/wowok/src/arbitration.d.ts.map +1 -0
- package/dist/wowok/src/demand.d.ts +26 -0
- package/dist/wowok/src/demand.d.ts.map +1 -0
- package/dist/wowok/src/entity.d.ts +27 -0
- package/dist/wowok/src/entity.d.ts.map +1 -0
- package/dist/wowok/src/exception.d.ts +31 -0
- package/dist/wowok/src/exception.d.ts.map +1 -0
- package/dist/wowok/src/guard.d.ts +79 -0
- package/dist/wowok/src/guard.d.ts.map +1 -0
- package/dist/wowok/src/index.d.ts +35 -0
- package/dist/wowok/src/index.d.ts.map +1 -0
- package/dist/wowok/src/machine.d.ts +67 -0
- package/dist/wowok/src/machine.d.ts.map +1 -0
- package/dist/wowok/src/passport.d.ts +86 -0
- package/dist/wowok/src/passport.d.ts.map +1 -0
- package/dist/wowok/src/payment.d.ts +16 -0
- package/dist/wowok/src/payment.d.ts.map +1 -0
- package/dist/wowok/src/permission.d.ts +150 -0
- package/dist/wowok/src/permission.d.ts.map +1 -0
- package/dist/wowok/src/progress.d.ts +72 -0
- package/dist/wowok/src/progress.d.ts.map +1 -0
- package/dist/wowok/src/protocol.d.ts +226 -0
- package/dist/wowok/src/protocol.d.ts.map +1 -0
- package/dist/wowok/src/repository.d.ts +83 -0
- package/dist/wowok/src/repository.d.ts.map +1 -0
- package/dist/wowok/src/resource.d.ts +35 -0
- package/dist/wowok/src/resource.d.ts.map +1 -0
- package/dist/wowok/src/service.d.ts +138 -0
- package/dist/wowok/src/service.d.ts.map +1 -0
- package/dist/wowok/src/treasury.d.ts +55 -0
- package/dist/wowok/src/treasury.d.ts.map +1 -0
- package/dist/wowok/src/utils.d.ts +93 -0
- package/dist/wowok/src/utils.d.ts.map +1 -0
- package/dist/wowok/src/wowok.d.ts +15 -0
- package/dist/wowok/src/wowok.d.ts.map +1 -0
- package/dist/wowok_agent/empty.d.ts +1 -0
- package/dist/wowok_agent/empty.d.ts.map +1 -0
- package/dist/wowok_agent/src/account.d.ts +38 -0
- package/dist/wowok_agent/src/account.d.ts.map +1 -0
- package/dist/wowok_agent/src/cache.d.ts +46 -0
- package/dist/wowok_agent/src/cache.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/arbitration.d.ts +63 -0
- package/dist/wowok_agent/src/call/arbitration.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/base.d.ts +34 -0
- package/dist/wowok_agent/src/call/base.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/demand.d.ts +55 -0
- package/dist/wowok_agent/src/call/demand.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/guard.d.ts +44 -0
- package/dist/wowok_agent/src/call/guard.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/machine.d.ts +109 -0
- package/dist/wowok_agent/src/call/machine.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/object_permission.d.ts +13 -0
- package/dist/wowok_agent/src/call/object_permission.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/permission.d.ts +47 -0
- package/dist/wowok_agent/src/call/permission.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/personal.d.ts +43 -0
- package/dist/wowok_agent/src/call/personal.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/repository.d.ts +53 -0
- package/dist/wowok_agent/src/call/repository.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/service.d.ts +134 -0
- package/dist/wowok_agent/src/call/service.d.ts.map +1 -0
- package/dist/wowok_agent/src/call/treasury.d.ts +53 -0
- package/dist/wowok_agent/src/call/treasury.d.ts.map +1 -0
- package/dist/wowok_agent/src/call.d.ts +24 -0
- package/dist/wowok_agent/src/call.d.ts.map +1 -0
- package/dist/wowok_agent/src/events.d.ts +65 -0
- package/dist/wowok_agent/src/events.d.ts.map +1 -0
- package/dist/wowok_agent/src/index.d.ts +19 -0
- package/dist/wowok_agent/src/index.d.ts.map +1 -0
- package/dist/wowok_agent/src/objects.d.ts +308 -0
- package/dist/wowok_agent/src/objects.d.ts.map +1 -0
- package/dist/wowok_agent/src/permission.d.ts +12 -0
- package/dist/wowok_agent/src/permission.d.ts.map +1 -0
- package/dist/wowok_agent/src/private_info.d.ts +26 -0
- package/dist/wowok_agent/src/private_info.d.ts.map +1 -0
- package/empty.ts +0 -0
- package/package.json +12 -3
- package/src/account.ts +40 -37
- package/src/call/arbitration.ts +41 -19
- package/src/call/base.ts +14 -16
- package/src/call/demand.ts +8 -7
- package/src/call/guard.ts +2 -7
- package/src/call/machine.ts +56 -35
- package/src/call/repository.ts +17 -15
- package/src/call/service.ts +87 -55
- package/src/call/treasury.ts +11 -10
- package/src/call.ts +3 -3
- package/src/index.ts +1 -1
- package/tsconfig.json +6 -2
- package/webpack.config.cjs +26 -0
package/src/account.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import * as os from 'os';
|
|
4
|
-
import { Ed25519Keypair, fromHEX, toHEX, decodeSuiPrivateKey, Protocol, CoinBalance, CoinStruct, TransactionResult, TransactionBlock, TransactionArgument, ERROR, Errors } from 'wowok';
|
|
1
|
+
|
|
2
|
+
import { Ed25519Keypair, fromHEX, toHEX, decodeSuiPrivateKey, Protocol, TransactionBlock, ERROR, Errors, } from 'wowok';
|
|
5
3
|
import { getFaucetHost, requestSuiFromFaucetV0, requestSuiFromFaucetV1 } from 'wowok';
|
|
4
|
+
import { type CoinBalance, type CoinStruct } from '@mysten/sui/client';
|
|
5
|
+
import { type TransactionArgument, type TransactionResult } from '@mysten/sui/transactions';
|
|
6
6
|
export interface AccountData {
|
|
7
7
|
name: string;
|
|
8
8
|
default?: boolean;
|
|
@@ -49,12 +49,11 @@ export class Account {
|
|
|
49
49
|
}
|
|
50
50
|
data.push({name:name, key:key, default:bDefault})
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
data = [{name:name, key:key, default:bDefault}];
|
|
52
|
+
return data
|
|
54
53
|
}
|
|
55
|
-
return data
|
|
56
54
|
}
|
|
57
|
-
} catch(e) {
|
|
55
|
+
} catch(e) { /*console.log(e)*/ }
|
|
56
|
+
return [{name:name, key:key, default:bDefault}]
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
private _default(buffer:string | null | undefined) : AccountData | undefined {
|
|
@@ -69,7 +68,7 @@ export class Account {
|
|
|
69
68
|
}
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
|
-
} catch(e) {
|
|
71
|
+
} catch(e) { /*console.log(e)*/ }
|
|
73
72
|
}
|
|
74
73
|
private _get(buffer:string | null | undefined, name?:string, bNotFoundReturnDefault?:boolean) : AccountData | undefined {
|
|
75
74
|
var data : AccountData[] | undefined;
|
|
@@ -86,7 +85,7 @@ export class Account {
|
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
|
-
} catch(e) {
|
|
88
|
+
} catch(e) { /*console.log(e)*/ }
|
|
90
89
|
}
|
|
91
90
|
private _rename(buffer:string | null | undefined, oldName:string, newName:string, bSwapIfExisted:boolean=true) : AccountData[] | undefined {
|
|
92
91
|
var data : AccountData[] | undefined;
|
|
@@ -111,51 +110,55 @@ export class Account {
|
|
|
111
110
|
return data;
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
|
-
} catch(e) {
|
|
113
|
+
} catch(e) { /*console.log(e)*/ }
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
set_storage(storage: 'File' | 'Explorer' = 'File') {
|
|
118
117
|
this.storage = storage
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
gen(name:string, bDefault?: boolean) {
|
|
120
|
+
async gen(name:string, bDefault?: boolean) {
|
|
122
121
|
try {
|
|
123
122
|
if (this.storage === 'File') {
|
|
123
|
+
const [fs, os, path] = await Promise.all([import('fs'), import('os'), import('path')]);
|
|
124
124
|
const filePath = path.join(os.homedir(), Account_FileName);
|
|
125
125
|
fs.readFile(filePath, 'utf-8', (err, d) => {
|
|
126
126
|
const data = this._add(d, name, bDefault);
|
|
127
|
-
fs.writeFileSync(filePath, JSON.stringify(data), 'utf-8')
|
|
127
|
+
fs.writeFileSync(filePath, JSON.stringify(data), 'utf-8')
|
|
128
128
|
});
|
|
129
129
|
} else if (this.storage === 'Explorer') {
|
|
130
130
|
const data = this._add(localStorage.getItem(Account_Key), name, bDefault);
|
|
131
131
|
localStorage.setItem(Account_Key, JSON.stringify(data))
|
|
132
132
|
}
|
|
133
|
-
} catch (e) { console.log(e) }
|
|
133
|
+
} catch (e) { /*console.log(e)*/ }
|
|
134
134
|
}
|
|
135
|
-
default() : AccountData | undefined {
|
|
135
|
+
async default() : Promise<AccountData | undefined> {
|
|
136
136
|
try {
|
|
137
137
|
if (this.storage === 'File') {
|
|
138
|
+
const [fs, os, path] = await Promise.all([import('fs'), import('os'), import('path')]);
|
|
138
139
|
const filePath = path.join(os.homedir(), Account_FileName);
|
|
139
140
|
return this._default(fs.readFileSync(filePath, 'utf-8'));
|
|
140
141
|
} else if (this.storage === 'Explorer') {
|
|
141
142
|
return this._default(localStorage.getItem(Account_Key));
|
|
142
143
|
}
|
|
143
|
-
} catch (e) {
|
|
144
|
+
} catch (e) { /*console.log(e)*/ }
|
|
144
145
|
}
|
|
145
|
-
get(name?: string, bNotFoundReturnDefault:boolean=true) : AccountData | undefined {
|
|
146
|
+
async get(name?: string, bNotFoundReturnDefault:boolean=true) : Promise<AccountData | undefined> {
|
|
146
147
|
try {
|
|
147
148
|
if (this.storage === 'File') {
|
|
149
|
+
const [fs, os, path] = await Promise.all([import('fs'), import('os'), import('path')]);
|
|
148
150
|
const filePath = path.join(os.homedir(), Account_FileName);
|
|
149
151
|
return this._get(fs.readFileSync(filePath, 'utf-8'), name, bNotFoundReturnDefault);
|
|
150
152
|
} else if (this.storage === 'Explorer') {
|
|
151
153
|
return this._get(localStorage.getItem(Account_Key), name, bNotFoundReturnDefault);
|
|
152
154
|
}
|
|
153
|
-
} catch (e) {
|
|
155
|
+
} catch (e) { /*console.log(e)*/ }
|
|
154
156
|
}
|
|
155
|
-
rename(oldName:string, newName:string, bSwapIfExisted:boolean=true) : boolean {
|
|
157
|
+
async rename(oldName:string, newName:string, bSwapIfExisted:boolean=true) : Promise<boolean> {
|
|
156
158
|
var res : AccountData[] | undefined;
|
|
157
159
|
try {
|
|
158
160
|
if (this.storage === 'File') {
|
|
161
|
+
const [fs, os, path] = await Promise.all([import('fs'), import('os'), import('path')]);
|
|
159
162
|
const filePath = path.join(os.homedir(), Account_FileName);
|
|
160
163
|
res = this._rename(fs.readFileSync(filePath, 'utf-8'), oldName, newName, bSwapIfExisted);
|
|
161
164
|
if (res) {fs.writeFileSync(filePath, JSON.stringify(res), 'utf-8') }
|
|
@@ -163,32 +166,33 @@ export class Account {
|
|
|
163
166
|
res = this._rename(localStorage.getItem(Account_Key), oldName, newName, bSwapIfExisted);
|
|
164
167
|
if (res) localStorage.setItem(Account_Key, JSON.stringify(res));
|
|
165
168
|
}
|
|
166
|
-
} catch (e) { console.log(e) }
|
|
169
|
+
} catch (e) { /*console.log(e)*/ }
|
|
167
170
|
return res ? true : false
|
|
168
171
|
}
|
|
169
172
|
|
|
170
|
-
get_address(name?:string, bNotFoundReturnDefault=true) : string | undefined {
|
|
171
|
-
const a = this.get(name, bNotFoundReturnDefault);
|
|
173
|
+
async get_address(name?:string, bNotFoundReturnDefault=true) : Promise<string | undefined> {
|
|
174
|
+
const a = await this.get(name, bNotFoundReturnDefault);
|
|
172
175
|
if (a) {
|
|
173
176
|
return Ed25519Keypair.fromSecretKey(fromHEX(a.key)).getPublicKey().toSuiAddress()
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
|
-
get_pubkey(name?:string, bNotFoundReturnDefault=true) : string | undefined {
|
|
177
|
-
const a = this.get(name, bNotFoundReturnDefault);
|
|
179
|
+
async get_pubkey(name?:string, bNotFoundReturnDefault=true) : Promise<string | undefined> {
|
|
180
|
+
const a = await this.get(name, bNotFoundReturnDefault);
|
|
178
181
|
if (a) {
|
|
179
182
|
return Ed25519Keypair.fromSecretKey(fromHEX(a.key)).getPublicKey().toSuiPublicKey()
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
|
-
get_pair(name?:string, bNotFoundReturnDefault=true) : Ed25519Keypair | undefined {
|
|
183
|
-
const a = this.get(name, bNotFoundReturnDefault);
|
|
185
|
+
async get_pair(name?:string, bNotFoundReturnDefault=true) : Promise<Ed25519Keypair | undefined> {
|
|
186
|
+
const a = await this.get(name, bNotFoundReturnDefault);
|
|
184
187
|
if (a) {
|
|
185
188
|
return Ed25519Keypair.fromSecretKey(fromHEX(a.key))
|
|
186
189
|
}
|
|
187
190
|
}
|
|
188
191
|
|
|
189
|
-
list() : AccountData_Show[] {
|
|
192
|
+
async list() : Promise<AccountData_Show[]> {
|
|
190
193
|
try {
|
|
191
194
|
if (this.storage === 'File') {
|
|
195
|
+
const [fs, os, path] = await Promise.all([import('fs'), import('os'), import('path')]);
|
|
192
196
|
const filePath = path.join(os.homedir(), Account_FileName);
|
|
193
197
|
const a = JSON.parse(fs.readFileSync(filePath, 'utf-8')) as AccountData[];
|
|
194
198
|
return a.map(v => {
|
|
@@ -200,23 +204,22 @@ export class Account {
|
|
|
200
204
|
return {name:v.name, default:v?.default, address:Ed25519Keypair.fromSecretKey(fromHEX(v.key)).getPublicKey().toSuiAddress()}
|
|
201
205
|
})
|
|
202
206
|
}
|
|
203
|
-
} catch (e) { console.log(e) }
|
|
207
|
+
} catch (e) { /*console.log(e)*/ }
|
|
204
208
|
return []
|
|
205
209
|
}
|
|
206
210
|
|
|
207
|
-
faucet(name?:string) {
|
|
208
|
-
const address = this.get_address(name, true);
|
|
211
|
+
async faucet(name?:string) {
|
|
212
|
+
const address = await this.get_address(name, true);
|
|
209
213
|
if (address) {
|
|
210
|
-
requestSuiFromFaucetV0({host:getFaucetHost('testnet'), recipient:address}).catch(e => {
|
|
211
|
-
console.log(e)
|
|
212
|
-
requestSuiFromFaucetV1({host:getFaucetHost('testnet'), recipient:address}).catch(e => console.log(e));
|
|
214
|
+
await requestSuiFromFaucetV0({host:getFaucetHost('testnet'), recipient:address}).catch(e => {
|
|
215
|
+
//console.log(e)
|
|
213
216
|
})
|
|
214
217
|
}
|
|
215
218
|
}
|
|
216
219
|
|
|
217
220
|
// token_type is 0x2::sui::SUI, if not specified.
|
|
218
221
|
balance = async (name?:string, token_type?:string) : Promise<CoinBalance | undefined> => {
|
|
219
|
-
const addr = this.get_address(name);
|
|
222
|
+
const addr = await this.get_address(name);
|
|
220
223
|
if (addr) {
|
|
221
224
|
return await Protocol.Client().getBalance({owner: addr, coinType:token_type});
|
|
222
225
|
}
|
|
@@ -224,14 +227,14 @@ export class Account {
|
|
|
224
227
|
|
|
225
228
|
// token_type is 0x2::sui::SUI, if not specified.
|
|
226
229
|
coin = async (name?:string, token_type?:string) : Promise<CoinStruct[] | undefined> => {
|
|
227
|
-
const addr = this.get_address(name);
|
|
230
|
+
const addr = await this.get_address(name);
|
|
228
231
|
if (addr) {
|
|
229
232
|
return (await Protocol.Client().getCoins({owner: addr, coinType:token_type})).data;
|
|
230
233
|
}
|
|
231
234
|
}
|
|
232
235
|
|
|
233
236
|
get_coin_object = async (txb: TransactionBlock, balance_required:string | bigint | number, name?:string, token_type?:string) : Promise<TransactionResult | undefined> => {
|
|
234
|
-
const addr = this.get_address(name);
|
|
237
|
+
const addr = await this.get_address(name);
|
|
235
238
|
const b = BigInt(balance_required);
|
|
236
239
|
|
|
237
240
|
if (addr && b > BigInt(0)) {
|
|
@@ -259,7 +262,7 @@ export class Account {
|
|
|
259
262
|
}
|
|
260
263
|
}
|
|
261
264
|
coin_with_balance = async(balance_required:string | bigint | number, account?:string, token_type?:string) : Promise<string | undefined> => {
|
|
262
|
-
const pair = this.get_pair(account, true);
|
|
265
|
+
const pair = await this.get_pair(account, true);
|
|
263
266
|
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
264
267
|
|
|
265
268
|
const txb = new TransactionBlock();
|
package/src/call/arbitration.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { TransactionBlock, IsValidArgType, PassportObject, IsValidAddress, Errors, ERROR, Permission, PermissionIndex,
|
|
2
|
-
PermissionIndexType, Treasury, Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee,
|
|
2
|
+
PermissionIndexType, Treasury, Arbitration, Dispute, Feedback, Vote, VotingGuard, WithdrawFee,
|
|
3
|
+
ArbObject,
|
|
3
4
|
} from 'wowok';
|
|
4
5
|
import { query_objects, ObjectArbitration, } from '../objects';
|
|
5
6
|
import { CallBase, CallResult, Namedbject} from "./base";
|
|
7
|
+
export { BCS, getSuiMoveConfig, } from '@mysten/bcs';
|
|
6
8
|
|
|
9
|
+
/// The execution priority is determined by the order in which the object attributes are arranged
|
|
7
10
|
export interface CallArbitration_Data {
|
|
8
11
|
type_parameter: string;
|
|
9
12
|
object?: {address:string} | {namedNew: Namedbject}; // undefined or {named_new...} for creating a new object
|
|
@@ -13,9 +16,9 @@ export interface CallArbitration_Data {
|
|
|
13
16
|
fee?: string;
|
|
14
17
|
fee_treasury?: {address:string} | {namedNew: Namedbject, description?:string};
|
|
15
18
|
arb_new?: {data: Dispute; guard?:string | 'fetch'; namedNew?: Namedbject}; // dispute an order, and a new Arb launched.
|
|
16
|
-
arb_withdraw_fee?: {arb
|
|
17
|
-
arb_vote?:
|
|
18
|
-
arb_arbitration?:
|
|
19
|
+
arb_withdraw_fee?: {arb?:string; data:WithdrawFee};
|
|
20
|
+
arb_vote?: {arb?: string; voting_guard?: string; agrees: number[]};
|
|
21
|
+
arb_arbitration?: {arb?:string; feedback:string; indemnity?:string};
|
|
19
22
|
usage_guard?: string;
|
|
20
23
|
voting_guard?: {op:'add' | 'set'; data:VotingGuard[]} | {op:'remove', guards:string[]} | {op:'removeall'};
|
|
21
24
|
bPaused?: boolean;
|
|
@@ -127,52 +130,71 @@ export class CallArbitration extends CallBase {
|
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
if (obj) {
|
|
133
|
+
const pst = permission?undefined:passport;
|
|
130
134
|
if (this.data?.description !== undefined && object_address) {
|
|
131
|
-
obj?.set_description(this.data.description,
|
|
135
|
+
obj?.set_description(this.data.description, pst);
|
|
132
136
|
}
|
|
133
137
|
if (this.data?.endpoint !== undefined) {
|
|
134
|
-
obj?.set_endpoint(this.data.endpoint,
|
|
138
|
+
obj?.set_endpoint(this.data.endpoint, pst)
|
|
135
139
|
}
|
|
136
140
|
if (this.data?.fee !== undefined && object_address) {
|
|
137
|
-
obj?.set_fee(BigInt(this.data.fee),
|
|
141
|
+
obj?.set_fee(BigInt(this.data.fee), pst)
|
|
138
142
|
}
|
|
139
143
|
if (treasury_address !== undefined && object_address) {
|
|
140
|
-
obj?.set_withdrawTreasury(treasury_address,
|
|
144
|
+
obj?.set_withdrawTreasury(treasury_address, pst)
|
|
141
145
|
}
|
|
146
|
+
var arb_new : ArbObject | undefined;
|
|
142
147
|
if (this.data?.arb_new !== undefined) {
|
|
143
|
-
|
|
148
|
+
arb_new = obj?.arb(this.data.arb_new.data, pst);
|
|
144
149
|
}
|
|
150
|
+
|
|
145
151
|
if (this.data?.arb_arbitration !== undefined) {
|
|
146
|
-
|
|
152
|
+
const a = this.data.arb_arbitration.arb ?? arb_new;
|
|
153
|
+
if (!a) ERROR(Errors.Fail, 'arb invalid: arb_arbitration');
|
|
154
|
+
|
|
155
|
+
obj?.arbitration({arb:a!, feedback:this.data.arb_arbitration.feedback, indemnity:this.data.arb_arbitration.indemnity}, pst)
|
|
147
156
|
}
|
|
157
|
+
|
|
148
158
|
if (this.data?.arb_vote !== undefined) {
|
|
149
|
-
|
|
159
|
+
const a = this.data.arb_vote.arb ?? arb_new;
|
|
160
|
+
if (!a) ERROR(Errors.Fail, 'arb invalid: arb_vote');
|
|
161
|
+
|
|
162
|
+
obj?.vote({arb:a!, voting_guard:this.data.arb_vote.voting_guard, agrees:this.data.arb_vote.agrees}, pst)
|
|
150
163
|
}
|
|
164
|
+
|
|
151
165
|
if (this.data?.arb_withdraw_fee !== undefined) {
|
|
152
|
-
|
|
166
|
+
const a = this.data.arb_withdraw_fee.arb ?? arb_new;
|
|
167
|
+
if (!a) ERROR(Errors.Fail, 'arb invalid: arb_withdraw_fee');
|
|
168
|
+
|
|
169
|
+
obj?.withdraw_fee(a!, this.data.arb_withdraw_fee.data, pst)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (arb_new) {
|
|
173
|
+
await this.new_with_mark(txb, obj?.arb_launch(arb_new), (this.data?.arb_new as any)?.namedNew, account);
|
|
153
174
|
}
|
|
175
|
+
|
|
154
176
|
if (this.data?.voting_guard !== undefined) {
|
|
155
177
|
switch (this.data.voting_guard.op) {
|
|
156
178
|
case 'add':
|
|
157
|
-
obj?.add_voting_guard(this.data.voting_guard.data,
|
|
179
|
+
obj?.add_voting_guard(this.data.voting_guard.data, pst)
|
|
158
180
|
break;
|
|
159
181
|
case 'remove':
|
|
160
|
-
obj?.remove_voting_guard(this.data.voting_guard.guards, false,
|
|
182
|
+
obj?.remove_voting_guard(this.data.voting_guard.guards, false, pst)
|
|
161
183
|
break;
|
|
162
184
|
case 'set':
|
|
163
|
-
obj?.remove_voting_guard([], true,
|
|
164
|
-
obj?.add_voting_guard(this.data.voting_guard.data,
|
|
185
|
+
obj?.remove_voting_guard([], true, pst)
|
|
186
|
+
obj?.add_voting_guard(this.data.voting_guard.data, pst)
|
|
165
187
|
break;
|
|
166
188
|
case 'removeall':
|
|
167
|
-
obj?.remove_voting_guard([], true,
|
|
189
|
+
obj?.remove_voting_guard([], true, pst)
|
|
168
190
|
break;
|
|
169
191
|
}
|
|
170
192
|
}
|
|
171
193
|
if (this.data.usage_guard !== undefined) {
|
|
172
|
-
obj?.set_guard(this.data.usage_guard,
|
|
194
|
+
obj?.set_guard(this.data.usage_guard, pst)
|
|
173
195
|
}
|
|
174
196
|
if (this.data?.bPaused !== undefined) {
|
|
175
|
-
obj?.pause(this.data.bPaused,
|
|
197
|
+
obj?.pause(this.data.bPaused, pst);
|
|
176
198
|
}
|
|
177
199
|
if (withdraw_treasury) {
|
|
178
200
|
await this.new_with_mark(txb, withdraw_treasury.launch(), (this.data?.fee_treasury as any)?.namedNew, account);
|
package/src/call/base.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { Protocol,
|
|
4
|
-
import { PassportObject, Errors, ERROR, Permission,
|
|
3
|
+
import { Protocol, Entity, Resource, TxbAddress, array_unique, TagName, ResourceObject, PassportObject, Errors, ERROR, Permission,
|
|
5
4
|
PermissionIndexType, GuardParser, Passport, WitnessFill
|
|
6
5
|
} from 'wowok';
|
|
7
6
|
import { query_permission } from '../permission';
|
|
8
7
|
import { Account } from '../account';
|
|
9
8
|
import { ObjectBase, queryTableItem_Personal, raw2type} from '../objects';
|
|
9
|
+
import { Transaction as TransactionBlock} from '@mysten/sui/transactions';
|
|
10
|
+
import { type SuiTransactionBlockResponse as CallResponse} from '@mysten/sui/client';
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
export interface Namedbject {
|
|
12
14
|
name?: string;
|
|
@@ -26,10 +28,6 @@ export interface GuardInfo_forCall {
|
|
|
26
28
|
witness: WitnessFill[];
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
export interface CallWithWitnessParam {
|
|
30
|
-
info: GuardInfo_forCall;
|
|
31
|
-
account?:string;
|
|
32
|
-
}
|
|
33
31
|
export type CallResult = GuardInfo_forCall | CallResponse | undefined;
|
|
34
32
|
|
|
35
33
|
|
|
@@ -56,22 +54,22 @@ export class CallBase {
|
|
|
56
54
|
// return ResponseData when the call has completed;
|
|
57
55
|
// throw an exception when errors.
|
|
58
56
|
async call(account?:string) : Promise<CallResult> { return undefined };
|
|
59
|
-
async call_with_witness (
|
|
60
|
-
if (
|
|
61
|
-
const p: GuardParser | undefined = await GuardParser.Create([...
|
|
57
|
+
async call_with_witness (info: GuardInfo_forCall, account?:string) : Promise<CallResponse | undefined> {
|
|
58
|
+
if (info.guard.length > 0) { // prepare passport
|
|
59
|
+
const p: GuardParser | undefined = await GuardParser.Create([...info.guard]);
|
|
62
60
|
|
|
63
61
|
if (p) {
|
|
64
|
-
const query = await p.done(
|
|
62
|
+
const query = await p.done(info.witness);
|
|
65
63
|
if (query) {
|
|
66
64
|
const txb = new TransactionBlock();
|
|
67
65
|
const passport = new Passport(txb, query!);
|
|
68
|
-
await this.operate(new TransactionBlock(), passport?.get_object(),
|
|
66
|
+
await this.operate(new TransactionBlock(), passport?.get_object(), account)
|
|
69
67
|
passport.destroy();
|
|
70
68
|
|
|
71
|
-
return await this.sign_and_commit(txb,
|
|
69
|
+
return await this.sign_and_commit(txb, account);
|
|
72
70
|
}
|
|
73
71
|
} else {
|
|
74
|
-
ERROR(Errors.Fail, 'guard
|
|
72
|
+
ERROR(Errors.Fail, 'guard verify')
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
}
|
|
@@ -81,7 +79,7 @@ export class CallBase {
|
|
|
81
79
|
var guards : string[] = [];
|
|
82
80
|
|
|
83
81
|
if (permIndex.length > 0 || checkOwner) {
|
|
84
|
-
const addr = Account.Instance().get_address(account);
|
|
82
|
+
const addr = await Account.Instance().get_address(account);
|
|
85
83
|
if (!addr) ERROR(Errors.InvalidParam, 'check_permission_and_call: account invalid');
|
|
86
84
|
|
|
87
85
|
const p = await query_permission({permission_object:permission, address:addr!});
|
|
@@ -131,7 +129,7 @@ export class CallBase {
|
|
|
131
129
|
const tags = named_new?.tags ? array_unique([...named_new.tags, ...innerTags]) : array_unique([...innerTags]);
|
|
132
130
|
|
|
133
131
|
if (!this.resouceObject) {
|
|
134
|
-
const addr = Account.Instance().get_address(account);
|
|
132
|
+
const addr = await Account.Instance().get_address(account);
|
|
135
133
|
if (addr) {
|
|
136
134
|
const r = await queryTableItem_Personal({address:addr}); //@ use cache
|
|
137
135
|
if (!r?.mark_object) {
|
|
@@ -149,7 +147,7 @@ export class CallBase {
|
|
|
149
147
|
}
|
|
150
148
|
|
|
151
149
|
protected async sign_and_commit(txb: TransactionBlock, account?: string) : Promise<CallResponse> {
|
|
152
|
-
const pair = Account.Instance().get_pair(account, true);
|
|
150
|
+
const pair = await Account.Instance().get_pair(account, true);
|
|
153
151
|
if (!pair) ERROR(Errors.Fail, 'account invalid')
|
|
154
152
|
|
|
155
153
|
if (this.resouceObject) {
|
package/src/call/demand.ts
CHANGED
|
@@ -103,12 +103,13 @@ export class CallDemand extends CallBase {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (obj) {
|
|
106
|
+
const pst = permission?undefined:passport;
|
|
106
107
|
if (this.data?.description !== undefined && object_address) {
|
|
107
|
-
obj?.set_description(this.data.description,
|
|
108
|
+
obj?.set_description(this.data.description, pst);
|
|
108
109
|
}
|
|
109
110
|
if (this.data?.time_expire !== undefined && object_address) {
|
|
110
111
|
obj?.expand_time(this.data.time_expire.op === 'duration' ? true : false,
|
|
111
|
-
this.data.time_expire.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire.time,
|
|
112
|
+
this.data.time_expire.op === 'duration' ? this.data.time_expire.minutes : this.data.time_expire.time, pst)
|
|
112
113
|
}
|
|
113
114
|
if (this.data?.bounty !== undefined) {
|
|
114
115
|
if (this.data.bounty.op === 'add') {
|
|
@@ -122,17 +123,17 @@ export class CallDemand extends CallBase {
|
|
|
122
123
|
if (r) obj.deposit(r)
|
|
123
124
|
}
|
|
124
125
|
} else if (this.data.bounty.op === 'reward') {
|
|
125
|
-
obj?.yes(this.data.bounty.service,
|
|
126
|
+
obj?.yes(this.data.bounty.service, pst);
|
|
126
127
|
} else if (this.data.bounty.op === 'refund') {
|
|
127
|
-
obj?.refund(
|
|
128
|
+
obj?.refund(pst);
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
if (this.data?.present !== undefined) {
|
|
131
|
-
//@ demand guard and its
|
|
132
|
-
obj?.present(this.data.present.service, this.data.present.service_pay_type, this.data.present.recommend_words,
|
|
132
|
+
//@ demand guard and its pst, if set
|
|
133
|
+
obj?.present(this.data.present.service, this.data.present.service_pay_type, this.data.present.recommend_words, pst);
|
|
133
134
|
}
|
|
134
135
|
if (this.data?.guard !== undefined) {
|
|
135
|
-
obj?.set_guard(this.data.guard.address, this.data.guard?.service_id_in_guard ?? undefined,
|
|
136
|
+
obj?.set_guard(this.data.guard.address, this.data.guard?.service_id_in_guard ?? undefined, pst)
|
|
136
137
|
}
|
|
137
138
|
if (permission) {
|
|
138
139
|
await this.new_with_mark(txb, permission.launch(), (this.data?.permission as any)?.namedNew, account);
|
package/src/call/guard.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Bcs, ContextType, ERROR, Errors, IsValidU8, OperatorType, ValueType, GUARD_QUERIES, IsValidAddress,
|
|
7
|
-
concatenate, TransactionBlock, Protocol, FnCallType, hasDuplicates, insertAtHead,
|
|
7
|
+
concatenate, TransactionBlock, Protocol, FnCallType, hasDuplicates, insertAtHead,
|
|
8
8
|
IsValidDesription, PassportObject,
|
|
9
9
|
IsValidGuardIdentifier} from "wowok";
|
|
10
10
|
import { CallBase, CallResult, Namedbject } from "./base";
|
|
@@ -22,8 +22,7 @@ export type GuardNode = { identifier: number; } // Data from GuardConst
|
|
|
22
22
|
| {logic: OperatorType.TYPE_LOGIC_AS_U256_GREATER | OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL
|
|
23
23
|
| OperatorType.TYPE_LOGIC_AS_U256_LESSER | OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL
|
|
24
24
|
| OperatorType.TYPE_LOGIC_AS_U256_EQUAL | OperatorType.TYPE_LOGIC_EQUAL | OperatorType.TYPE_LOGIC_HAS_SUBSTRING
|
|
25
|
-
| OperatorType.
|
|
26
|
-
| OperatorType.TYPE_LOGIC_AND | OperatorType.TYPE_LOGIC_OR; parameters: GuardNode[];}
|
|
25
|
+
| OperatorType.TYPE_LOGIC_NOT | OperatorType.TYPE_LOGIC_AND | OperatorType.TYPE_LOGIC_OR; parameters: GuardNode[];}
|
|
27
26
|
| {calc: OperatorType.TYPE_NUMBER_ADD | OperatorType.TYPE_NUMBER_DEVIDE | OperatorType.TYPE_NUMBER_MOD
|
|
28
27
|
| OperatorType.TYPE_NUMBER_MULTIPLY | OperatorType.TYPE_NUMBER_SUBTRACT; parameters: GuardNode[];}
|
|
29
28
|
| {value_type: ValueType; value:any; } // Data
|
|
@@ -149,10 +148,6 @@ const buildNode = (guard_node:GuardNode, type_required:ValueType | 'number' | 'v
|
|
|
149
148
|
} else if (node?.logic !== undefined) {
|
|
150
149
|
checkType(ValueType.TYPE_BOOL, type_required, node); // bool
|
|
151
150
|
switch (node?.logic) {
|
|
152
|
-
case OperatorType.TYPE_LOGIC_ALWAYS_TRUE:
|
|
153
|
-
if (node.parameters.length !== 0) ERROR(Errors.InvalidParam, 'node logic parameters length must be 0'+ JSON.stringify(node));
|
|
154
|
-
output.push(Bcs.getInstance().ser(ValueType.TYPE_U8, node.logic)); // TYPE
|
|
155
|
-
break;
|
|
156
151
|
case OperatorType.TYPE_LOGIC_AND:
|
|
157
152
|
case OperatorType.TYPE_LOGIC_OR:
|
|
158
153
|
if (node.parameters.length < 2) ERROR(Errors.InvalidParam, 'node logic parameters length must >= 2'+ JSON.stringify(node));
|