wowok 1.7.13 → 1.7.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/dist/arbitration.d.ts.map +1 -1
- package/dist/arbitration.js +21 -32
- package/dist/arbitration.js.map +1 -1
- package/dist/entity.d.ts +1 -0
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +12 -6
- package/dist/entity.js.map +1 -1
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/exception.js.map +1 -1
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +8 -4
- package/dist/guard.js.map +1 -1
- package/dist/payment.d.ts +2 -2
- package/dist/payment.d.ts.map +1 -1
- package/dist/payment.js +2 -2
- package/dist/payment.js.map +1 -1
- package/dist/protocol.d.ts +21 -19
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +211 -58
- package/dist/protocol.js.map +1 -1
- package/dist/service.d.ts +2 -2
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +5 -6
- package/dist/service.js.map +1 -1
- package/package.json +5 -2
- package/src/arbitration.ts +0 -551
- package/src/demand.ts +0 -300
- package/src/entity.ts +0 -171
- package/src/exception.ts +0 -37
- package/src/guard.ts +0 -810
- package/src/index.ts +0 -40
- package/src/machine.ts +0 -542
- package/src/passport.ts +0 -777
- package/src/payment.ts +0 -94
- package/src/permission.ts +0 -550
- package/src/progress.ts +0 -367
- package/src/protocol.ts +0 -549
- package/src/repository.ts +0 -680
- package/src/resource.ts +0 -155
- package/src/service.ts +0 -1349
- package/src/treasury.ts +0 -425
- package/src/utils.ts +0 -660
- package/src/wowok.ts +0 -70
- package/tsconfig.json +0 -30
- package/tsconfig.tsbuildinfo +0 -1
- package/webpack.config.cjs +0 -23
package/src/protocol.ts
DELETED
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
import { SuiClient, SuiObjectResponse, SuiObjectDataOptions, SuiTransactionBlockResponseOptions,
|
|
2
|
-
SuiTransactionBlockResponse } from '@mysten/sui/client';
|
|
3
|
-
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { Transaction as TransactionBlock, TransactionResult, TransactionArgument } from '@mysten/sui/transactions';
|
|
5
|
-
import { capitalize, IsValidAddress, IsValidArray, IsValidU128, IsValidU256, IsValidU64, IsValidU8 } from './utils.js'
|
|
6
|
-
import { GuardConstant } from './guard.js';
|
|
7
|
-
import { isValidSuiObjectId } from '@mysten/sui/utils'
|
|
8
|
-
|
|
9
|
-
export enum MODULES {
|
|
10
|
-
machine = 'machine',
|
|
11
|
-
progress = 'progress',
|
|
12
|
-
repository = 'repository',
|
|
13
|
-
permission = 'permission',
|
|
14
|
-
passport = 'passport',
|
|
15
|
-
guard = 'guard',
|
|
16
|
-
demand = 'demand',
|
|
17
|
-
order = 'order',
|
|
18
|
-
service = 'service',
|
|
19
|
-
resource = 'resource',
|
|
20
|
-
entity = 'entity',
|
|
21
|
-
wowok = 'wowok',
|
|
22
|
-
treasury = 'treasury',
|
|
23
|
-
payment = 'payment',
|
|
24
|
-
arbitration = 'arbitration',
|
|
25
|
-
arb = 'arb',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type PermissionAddress = TransactionResult;
|
|
29
|
-
export type PermissionObject = TransactionResult | string | TransactionArgument;
|
|
30
|
-
export type RepositoryAddress = TransactionResult;
|
|
31
|
-
export type RepositoryObject = TransactionResult | string | TransactionArgument;
|
|
32
|
-
export type GuardAddress = TransactionResult;
|
|
33
|
-
export type GuardObject = TransactionResult | string | TransactionArgument ;
|
|
34
|
-
export type MachineAddress = TransactionResult;
|
|
35
|
-
export type MachineObject = TransactionResult | string | TransactionArgument;
|
|
36
|
-
export type PassportObject = TransactionResult;
|
|
37
|
-
export type DemandAddress = TransactionResult;
|
|
38
|
-
export type DemandObject = TransactionResult | string | TransactionArgument;
|
|
39
|
-
export type ServiceObject = TransactionResult | string | TransactionArgument;
|
|
40
|
-
export type ServiceAddress = TransactionResult;
|
|
41
|
-
export type ArbitrationObject = TransactionResult | string | TransactionArgument;
|
|
42
|
-
export type ArbitrationAddress = TransactionResult;
|
|
43
|
-
export type ArbObject = TransactionResult | string | TransactionArgument;
|
|
44
|
-
export type ArbAddress = TransactionResult;
|
|
45
|
-
export type ProgressObject = TransactionResult | string | TransactionArgument;
|
|
46
|
-
export type ProgressAddress = TransactionResult;
|
|
47
|
-
export type TreasuryObject = TransactionResult | string | TransactionArgument;
|
|
48
|
-
export type TreasuryAddress = TransactionResult;
|
|
49
|
-
//export type RewardObject = TransactionResult | string | TransactionArgument;
|
|
50
|
-
//export type RewardAddress = TransactionResult;
|
|
51
|
-
export type OrderObject = TransactionResult | string | TransactionArgument;
|
|
52
|
-
export type OrderAddress = TransactionResult;
|
|
53
|
-
export type DiscountObject = TransactionResult | string | TransactionArgument;
|
|
54
|
-
export type CoinObject = TransactionResult | string | TransactionArgument;
|
|
55
|
-
//export type VoteObject = TransactionResult | string | TransactionArgument;
|
|
56
|
-
//export type VoteAddress = TransactionResult;
|
|
57
|
-
export type ResourceObject = TransactionResult | string | TransactionArgument;
|
|
58
|
-
export type ResourceAddress = TransactionResult;
|
|
59
|
-
export type EntityObject = TransactionResult | string | TransactionArgument;
|
|
60
|
-
export type EntityAddress = TransactionResult;
|
|
61
|
-
export type PaymentObject = TransactionResult | string | TransactionArgument;
|
|
62
|
-
export type PaymentAddress = TransactionResult;
|
|
63
|
-
export type ReceivedObject = TransactionResult | string | TransactionArgument;
|
|
64
|
-
export type CoinWrapperObject = TransactionResult;
|
|
65
|
-
|
|
66
|
-
export type TxbAddress = string | TransactionResult;
|
|
67
|
-
export type TxbObject = string | TransactionResult | TransactionArgument | GuardObject | RepositoryObject | PermissionObject | MachineObject | PassportObject |
|
|
68
|
-
DemandObject | ServiceObject | OrderObject | DiscountObject | DemandObject | ResourceObject | EntityObject | ArbitrationObject | ArbObject | TreasuryObject;
|
|
69
|
-
|
|
70
|
-
export type WowokObject = TransactionResult;
|
|
71
|
-
export type FnCallType = `${string}::${string}::${string}`;
|
|
72
|
-
|
|
73
|
-
export enum OperatorType {
|
|
74
|
-
TYPE_QUERY = 1, // query wowok object
|
|
75
|
-
TYPE_NUMBER_ADD = 2,
|
|
76
|
-
TYPE_NUMBER_SUBTRACT = 3,
|
|
77
|
-
TYPE_NUMBER_MULTIPLY = 4,
|
|
78
|
-
TYPE_NUMBER_DEVIDE = 5,
|
|
79
|
-
TYPE_NUMBER_MOD = 6,
|
|
80
|
-
TYPE_NUMBER_ADDRESS = 7,
|
|
81
|
-
TYPE_STRING_LOWERCASE = 8, // string to lowercase
|
|
82
|
-
|
|
83
|
-
TYPE_LOGIC_AS_U256_GREATER = 11,
|
|
84
|
-
TYPE_LOGIC_AS_U256_GREATER_EQUAL = 12,
|
|
85
|
-
TYPE_LOGIC_AS_U256_LESSER = 13,
|
|
86
|
-
TYPE_LOGIC_AS_U256_LESSER_EQUAL = 14,
|
|
87
|
-
TYPE_LOGIC_AS_U256_EQUAL = 15,
|
|
88
|
-
TYPE_LOGIC_EQUAL = 16, // TYPE&DATA(vector<u8>) MUST BE EQUAL
|
|
89
|
-
TYPE_LOGIC_HAS_SUBSTRING = 17, // SUBSTRING
|
|
90
|
-
TYPE_LOGIC_NOT = 18, // NOT
|
|
91
|
-
TYPE_LOGIC_AND = 19, // AND
|
|
92
|
-
TYPE_LOGIC_OR = 20, // OR
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export const LogicsInfo = [
|
|
96
|
-
[OperatorType.TYPE_LOGIC_AS_U256_GREATER, 'Unsigned Integer >', 'The first item > anything that follows'],
|
|
97
|
-
[OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL, 'Unsigned Integer >=', 'The first item >= anything that follows'],
|
|
98
|
-
[OperatorType.TYPE_LOGIC_AS_U256_LESSER, 'Unsigned Integer <', 'The first item < anything that follows'],
|
|
99
|
-
[OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL, 'Unsigned Integer <=', 'The first item <= anything that follows'],
|
|
100
|
-
[OperatorType.TYPE_LOGIC_AS_U256_EQUAL, 'Unsigned Integer =', 'The first item = anything that follows'],
|
|
101
|
-
[OperatorType.TYPE_LOGIC_EQUAL, 'Equal', 'Data and type are exactly equal for all items'],
|
|
102
|
-
[OperatorType.TYPE_LOGIC_HAS_SUBSTRING, 'Has Sub String', 'The first string contains anything that follows'],
|
|
103
|
-
[OperatorType.TYPE_LOGIC_NOT, 'Not', 'Not operation'],
|
|
104
|
-
[OperatorType.TYPE_LOGIC_AND, 'And', 'All Items And operations'],
|
|
105
|
-
[OperatorType.TYPE_LOGIC_OR, 'Or', 'All Items Or operations'],
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
export enum ValueType {
|
|
109
|
-
TYPE_BOOL = 100,
|
|
110
|
-
TYPE_ADDRESS = 101,
|
|
111
|
-
TYPE_U8 = 102,
|
|
112
|
-
TYPE_U64 = 103,
|
|
113
|
-
TYPE_VEC_U8 = 104,
|
|
114
|
-
TYPE_U128 = 105,
|
|
115
|
-
TYPE_VEC_ADDRESS = 106,
|
|
116
|
-
TYPE_VEC_BOOL = 107,
|
|
117
|
-
TYPE_VEC_VEC_U8 = 108,
|
|
118
|
-
TYPE_VEC_U64 = 109,
|
|
119
|
-
TYPE_VEC_U128 = 110,
|
|
120
|
-
TYPE_OPTION_ADDRESS = 111,
|
|
121
|
-
TYPE_OPTION_BOOL = 112,
|
|
122
|
-
TYPE_OPTION_U8 = 113,
|
|
123
|
-
TYPE_OPTION_U64 = 114,
|
|
124
|
-
TYPE_OPTION_U128 = 115,
|
|
125
|
-
TYPE_OPTION_U256 = 116,
|
|
126
|
-
TYPE_OPTION_STRING = 117,
|
|
127
|
-
TYPE_OPTION_VEC_U8 = 118,
|
|
128
|
-
TYPE_VEC_U256 = 119,
|
|
129
|
-
TYPE_STRING = 120,
|
|
130
|
-
TYPE_VEC_STRING = 121,
|
|
131
|
-
TYPE_U256 = 122,
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export enum RepositoryValueType {
|
|
135
|
-
Address = 200,
|
|
136
|
-
Address_Vec = 201,
|
|
137
|
-
PositiveNumber = 202,
|
|
138
|
-
PositiveNumber_Vec = 203,
|
|
139
|
-
String = 204,
|
|
140
|
-
String_Vec = 205,
|
|
141
|
-
Bool = 206,
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export const RepositoryValueTypeInfo = [
|
|
145
|
-
{type: RepositoryValueType.String, name:'string', description:'String.'},
|
|
146
|
-
{type: RepositoryValueType.Address, name:'address', description:'Object id or Personal address.'},
|
|
147
|
-
{type: RepositoryValueType.PositiveNumber, name:'unsigned integer', description:'Including u8, u16 ,..., u256'},
|
|
148
|
-
{type: RepositoryValueType.String_Vec, name:'string vector', description:'Vector of string.'},
|
|
149
|
-
{type: RepositoryValueType.Address_Vec, name:'address vector', description:'Vector of address.'},
|
|
150
|
-
{type: RepositoryValueType.PositiveNumber_Vec, name:'unsigned integer vector', description:'Vector of unsigned integer'},
|
|
151
|
-
{type: RepositoryValueType.Bool, name:'bool', description:'True or False.'},
|
|
152
|
-
]
|
|
153
|
-
|
|
154
|
-
export const OperatorTypeArray = (Object.values(OperatorType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
155
|
-
export const ValueTypeArray = (Object.values(ValueType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
156
|
-
export const IsValidOperatorType = (type:number) : boolean => { return OperatorTypeArray.includes(type)}
|
|
157
|
-
export const IsValidValueType = (type:number) : boolean => { return ValueTypeArray.includes(type)}
|
|
158
|
-
export const IsNumberType = (type:ValueType | any) : boolean => { return type===ValueType.TYPE_U128 || type===ValueType.TYPE_U256 ||
|
|
159
|
-
type===ValueType.TYPE_U64 || type===ValueType.TYPE_U8
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export enum ContextType {
|
|
163
|
-
TYPE_SIGNER = 60, // address type; the signer address on verifying
|
|
164
|
-
TYPE_CLOCK = 61, // u64 type; On-chain time at validation
|
|
165
|
-
TYPE_GUARD = 62, // address type; the address of the guard being verified
|
|
166
|
-
TYPE_CONSTANT = 80,
|
|
167
|
-
}
|
|
168
|
-
interface ValueTypeString {
|
|
169
|
-
type: ValueType | ContextType;
|
|
170
|
-
name: string;
|
|
171
|
-
description: string;
|
|
172
|
-
validator?: (value:any) => boolean;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export const SER_VALUE: ValueTypeString[] = [
|
|
176
|
-
{type: ValueType.TYPE_BOOL, name: 'bool', description:'boolean. eg:true or false', validator:(value:any) => { return (value === true || value === false)}},
|
|
177
|
-
{type: ValueType.TYPE_ADDRESS, name: 'address', description:'address or object-id. eg:0x6789af', validator:IsValidAddress},
|
|
178
|
-
{type: ContextType.TYPE_SIGNER, name: 'txn signer', description:"signer address of the transaction"},
|
|
179
|
-
{type: ContextType.TYPE_GUARD, name: 'guard address', description:"current guard address"},
|
|
180
|
-
{type: ContextType.TYPE_CLOCK, name: 'txn time', description:"u64 number for the transaction time"},
|
|
181
|
-
{type: ValueType.TYPE_U64, name: 'number', description:'u64 number. eg:23870233', validator:IsValidU64},
|
|
182
|
-
{type: ValueType.TYPE_U8, name: 'number', description:'u8 number. eg:255', validator:IsValidU8},
|
|
183
|
-
{type: ValueType.TYPE_VEC_U8, name: 'string', description:'string or unsigned-8 number array. eg:"[1,2,3]"'},
|
|
184
|
-
{type: ValueType.TYPE_U128, name: 'number', description:'u128 number. eg:12348900999', validator:IsValidU128},
|
|
185
|
-
{type: ValueType.TYPE_VEC_ADDRESS, name: '[address]', description:'address array. eg:[0x2277f2, 0x3344af]'},
|
|
186
|
-
{type: ValueType.TYPE_VEC_BOOL, name: '[bool]', description:'boolean array. eg:[true, false, true]'},
|
|
187
|
-
{type: ValueType.TYPE_VEC_VEC_U8, name: '[[number]]', description:'array of u8 number array. eg:["i", "like", "wowok"]'},
|
|
188
|
-
{type: ValueType.TYPE_VEC_U64, name: '[number]', description:'u64 number array. eg:[123, 778888, 42312]'},
|
|
189
|
-
{type: ValueType.TYPE_VEC_U128, name: '[number]', description:'u128 number array. eg:[123, 778888, 42312]'},
|
|
190
|
-
{type: ValueType.TYPE_OPTION_ADDRESS, name: 'option', description:'option of address. eg:none or address'},
|
|
191
|
-
{type: ValueType.TYPE_OPTION_BOOL, name: 'option', description:'option of bool. eg:none or boolean value'},
|
|
192
|
-
{type: ValueType.TYPE_OPTION_U8, name: 'option', description:'option of u8. eg:none or u8 value'},
|
|
193
|
-
{type: ValueType.TYPE_OPTION_U64, name: 'option', description:'option of u64. eg:none or u64 value'},
|
|
194
|
-
{type: ValueType.TYPE_OPTION_U128, name: 'option', description:'option of u128. eg:none or u128 value'},
|
|
195
|
-
{type: ValueType.TYPE_OPTION_U256, name: 'option', description:'option of u256. eg:none or u256 value'},
|
|
196
|
-
{type: ValueType.TYPE_VEC_U256, name: '[number]', description:'u256 number array. eg:[123, 778888, 42312]'},
|
|
197
|
-
{type: ValueType.TYPE_VEC_STRING, name: '[string]', description:'utf8 string array. eg:["abc", "hi"]'},
|
|
198
|
-
{type: ValueType.TYPE_STRING, name: 'string', description:'utf8 string. eg:"wowok"', },
|
|
199
|
-
{type: ValueType.TYPE_OPTION_STRING, name: 'option', description:'option of utf8 string. eg:none or "some"'},
|
|
200
|
-
{type: ValueType.TYPE_U256, name: 'number', description:'u256 number. eg:12345678901233', validator:IsValidU256},
|
|
201
|
-
]
|
|
202
|
-
|
|
203
|
-
//export type ConstantType = ValueType | ContextType.TYPE_WITNESS_ID;
|
|
204
|
-
export type Data_Type = ValueType | OperatorType | ContextType;
|
|
205
|
-
|
|
206
|
-
export enum ENTRYPOINT {
|
|
207
|
-
mainnet = 'mainnet',
|
|
208
|
-
testnet = 'testnet',
|
|
209
|
-
devnet = 'devnet',
|
|
210
|
-
localnet = 'localnet'
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const TESTNET = {
|
|
214
|
-
wowok: "0x245f15f58b5e5bd790e7dcdb5bd66d647b4fc60c6265c6a91f20e33cbef54202",
|
|
215
|
-
wowok_origin:'0x245f15f58b5e5bd790e7dcdb5bd66d647b4fc60c6265c6a91f20e33cbef54202' ,
|
|
216
|
-
base: '0x5322c1df09a3d0fd4cb5cd933dc39ee11872a10b21c5aef794702661070ab182',
|
|
217
|
-
base_origin: '0x5322c1df09a3d0fd4cb5cd933dc39ee11872a10b21c5aef794702661070ab182',
|
|
218
|
-
|
|
219
|
-
wowok_object: '0x88db80974d677ab6c8a783f5c89e41ae9ecbb76962684788523f5df4acde40a4',
|
|
220
|
-
entity_object: '0x160816194a1b50534d96c73064ac69af76e1e72262adf7b17d8552a1b833a263',
|
|
221
|
-
treasury_cap:'0xc1a799cf0b3e6854359e4cd1724b20b25d612a0d951bacb7c7d208f6d26534a7',
|
|
222
|
-
oracle_object:'0xec39bc61ff38d3ed54b2a5afedc21158ff93686064f353ae169f97907b493fde',
|
|
223
|
-
}
|
|
224
|
-
const MAINNET = {
|
|
225
|
-
wowok: "",
|
|
226
|
-
wowok_origin:"",
|
|
227
|
-
base:"",
|
|
228
|
-
base_origin:"",
|
|
229
|
-
|
|
230
|
-
wowok_object: '',
|
|
231
|
-
entity_object: '',
|
|
232
|
-
treasury_cap:'',
|
|
233
|
-
oracle_object:'',
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export interface CoinTypeInfo {
|
|
237
|
-
symbol: string;
|
|
238
|
-
type: string;
|
|
239
|
-
decimals: number;
|
|
240
|
-
alias ?: boolean;
|
|
241
|
-
}
|
|
242
|
-
export class Protocol {
|
|
243
|
-
protected network = '';
|
|
244
|
-
protected packages = new Map<string, string>();
|
|
245
|
-
protected signer = '';
|
|
246
|
-
protected wowok_object = '';
|
|
247
|
-
protected entity_object = '';
|
|
248
|
-
protected treasury_cap = '';
|
|
249
|
-
protected oracle_object = '';
|
|
250
|
-
//protected graphql = '';
|
|
251
|
-
protected txb: TransactionBlock | undefined;
|
|
252
|
-
static _instance: any;
|
|
253
|
-
|
|
254
|
-
constructor(network:ENTRYPOINT=ENTRYPOINT.testnet) {
|
|
255
|
-
this.use_network(network);
|
|
256
|
-
this.new_session();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
static Instance() : Protocol {
|
|
260
|
-
if (!Protocol._instance) {
|
|
261
|
-
Protocol._instance = new Protocol();
|
|
262
|
-
}; return Protocol._instance
|
|
263
|
-
}
|
|
264
|
-
static Client() : SuiClient {
|
|
265
|
-
return new SuiClient({ url: Protocol.Instance().networkUrl() });
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
client() { return new SuiClient({url: this.networkUrl() })}
|
|
269
|
-
use_network(network:ENTRYPOINT=ENTRYPOINT.testnet) {
|
|
270
|
-
this.network = network;
|
|
271
|
-
switch(network) {
|
|
272
|
-
case ENTRYPOINT.localnet:
|
|
273
|
-
break;
|
|
274
|
-
case ENTRYPOINT.devnet:
|
|
275
|
-
break;
|
|
276
|
-
case ENTRYPOINT.testnet:
|
|
277
|
-
this.packages.set('wowok', TESTNET.wowok);
|
|
278
|
-
this.packages.set('base', TESTNET.base);
|
|
279
|
-
this.packages.set('wowok_origin', TESTNET.wowok_origin); //@ orgin package!!!
|
|
280
|
-
this.packages.set('base_origin', TESTNET.base_origin);
|
|
281
|
-
this.wowok_object = TESTNET.wowok_object;
|
|
282
|
-
this.entity_object= TESTNET.entity_object;
|
|
283
|
-
this.treasury_cap = TESTNET.treasury_cap;
|
|
284
|
-
//this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
285
|
-
this.oracle_object = TESTNET.oracle_object;
|
|
286
|
-
break;
|
|
287
|
-
case ENTRYPOINT.mainnet:
|
|
288
|
-
this.packages.set('wowok', MAINNET.wowok);
|
|
289
|
-
this.packages.set('base', MAINNET.base);
|
|
290
|
-
this.packages.set('wowok_origin', MAINNET.wowok_origin); //@ orgin package!!!
|
|
291
|
-
this.packages.set('base_origin', MAINNET.base_origin);
|
|
292
|
-
this.wowok_object = MAINNET.wowok_object;
|
|
293
|
-
this.entity_object= MAINNET.entity_object;
|
|
294
|
-
this.treasury_cap = MAINNET.treasury_cap;
|
|
295
|
-
//this.graphql = 'https://sui-mainnet.mystenlabs.com/graphql';
|
|
296
|
-
this.oracle_object = MAINNET.oracle_object;
|
|
297
|
-
break;
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
package(type:string): string {
|
|
301
|
-
return this.packages.get(type) ?? ''
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
objectWowok(): string { return this.wowok_object }
|
|
305
|
-
objectEntity(): string { return this.entity_object }
|
|
306
|
-
objectOracle(): string { return this.oracle_object }
|
|
307
|
-
objectTreasuryCap() : string { return this.treasury_cap }
|
|
308
|
-
|
|
309
|
-
networkUrl() : string {
|
|
310
|
-
switch(this.network) {
|
|
311
|
-
case ENTRYPOINT.localnet:
|
|
312
|
-
return "http://127.0.0.1:9000";
|
|
313
|
-
case ENTRYPOINT.devnet:
|
|
314
|
-
return "https://fullnode.devnet.sui.io:443";
|
|
315
|
-
case ENTRYPOINT.testnet:
|
|
316
|
-
return "https://fullnode.testnet.sui.io:443";
|
|
317
|
-
case ENTRYPOINT.mainnet:
|
|
318
|
-
return "https://fullnode.mainnet.sui.io:443";
|
|
319
|
-
}; return "";
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
machineFn = (fn:any) => { return `${this.packages.get('wowok')}::${MODULES.machine}::${fn}`};
|
|
323
|
-
progressFn = (fn:any) => { return `${this.packages.get('wowok')}::${MODULES.progress}::${fn}`};
|
|
324
|
-
repositoryFn = (fn:any) => { return `${this.packages.get('wowok')}::${MODULES.repository}::${fn}`};
|
|
325
|
-
permissionFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.permission}::${fn}`};
|
|
326
|
-
passportFn = (fn:any) => { return `${this.packages.get('wowok')}::${MODULES.passport}::${fn}`};
|
|
327
|
-
demandFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.demand}::${fn}`};
|
|
328
|
-
orderFn = (fn:any) => { return `${this.packages.get('wowok')}::${MODULES.order}::${fn}`};
|
|
329
|
-
serviceFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.service}::${fn}`};
|
|
330
|
-
resourceFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.resource}::${fn}`};
|
|
331
|
-
entityFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.entity}::${fn}`};
|
|
332
|
-
wowokFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.wowok}::${fn}`};
|
|
333
|
-
treasuryFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.treasury}::${fn}`};
|
|
334
|
-
paymentFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.payment}::${fn}`};
|
|
335
|
-
guardFn = (fn: any) => { return `${this.packages.get('base')}::${MODULES.guard}::${fn}`};
|
|
336
|
-
baseWowokFn = (fn: any) => { return `${this.packages.get('base')}::${MODULES.wowok}::${fn}`};
|
|
337
|
-
arbitrationFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.arbitration}::${fn}`};
|
|
338
|
-
arbFn = (fn: any) => { return `${this.packages.get('wowok')}::${MODULES.arb}::${fn}`};
|
|
339
|
-
|
|
340
|
-
query = async (objects: Query_Param[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
|
|
341
|
-
const client = new SuiClient({ url: this.networkUrl() });
|
|
342
|
-
const ids = objects.map((value) => value.objectid);
|
|
343
|
-
const res = await client.call('sui_multiGetObjects', [ids, options]) as SuiObjectResponse[];
|
|
344
|
-
let ret:any[] = [];
|
|
345
|
-
for (let i = 0; i < res.length; i ++ ) {
|
|
346
|
-
objects.forEach((object) => {
|
|
347
|
-
object.callback(this, res[i], object, options);
|
|
348
|
-
})
|
|
349
|
-
}
|
|
350
|
-
return res;
|
|
351
|
-
}
|
|
352
|
-
query_raw = async (objects: string[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
|
|
353
|
-
const client = new SuiClient({ url: this.networkUrl() });
|
|
354
|
-
return await client.call('sui_multiGetObjects', [objects, options]) as SuiObjectResponse[];
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
new_session = () : TransactionBlock => {
|
|
358
|
-
this.txb = new TransactionBlock();
|
|
359
|
-
return this.txb
|
|
360
|
-
}
|
|
361
|
-
sessionCurrent = () : TransactionBlock => { return this.txb ? this.txb : this.new_session() }
|
|
362
|
-
|
|
363
|
-
sign_excute = async (exes: ((protocol:Protocol, param:any) => void)[], priv_key:string, param?:any, options:SuiTransactionBlockResponseOptions={showObjectChanges:true}) : Promise<SuiTransactionBlockResponse> => {
|
|
364
|
-
const client = new SuiClient({ url: this.networkUrl() });
|
|
365
|
-
exes.forEach((e) => { e(this, param) });
|
|
366
|
-
|
|
367
|
-
const keypair = Ed25519Keypair.fromSecretKey(priv_key);
|
|
368
|
-
const response = await client.signAndExecuteTransaction({
|
|
369
|
-
transaction: this.sessionCurrent(),
|
|
370
|
-
signer: keypair,
|
|
371
|
-
options,
|
|
372
|
-
});
|
|
373
|
-
this.txb = undefined; // reset the txb to undefine
|
|
374
|
-
return response;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// used in service, discount, order, because service has COIN wrapper for TOKEN
|
|
378
|
-
static SUI_TOKEN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'; // TOKEN_TYPE
|
|
379
|
-
// used in demand, reward, ...
|
|
380
|
-
static SUI_COIN_TYPE = '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin<0x2::sui::SUI>'; // COIN TYPE
|
|
381
|
-
WOWOK_TOKEN_TYPE = () => { return this.packages.get('base') + '::wowok::WOWOK' }
|
|
382
|
-
WOWOK_COIN_TYPE = () => { return '0x2::coin::Coin<' + this.packages.get('base') + '::wowok::WOWOK>'}
|
|
383
|
-
COINS_TYPE = () => {
|
|
384
|
-
switch(this.network) {
|
|
385
|
-
case ENTRYPOINT.testnet:
|
|
386
|
-
return this.CoinTypes_Testnet.filter((v)=>v.alias !== true);
|
|
387
|
-
case ENTRYPOINT.mainnet:
|
|
388
|
-
return this.CoinTypes_Mainnet.filter((v)=>v.alias !== true);
|
|
389
|
-
}; return [];
|
|
390
|
-
}
|
|
391
|
-
update_coinType = (token_type: string, decimals:number, symbol: string) => {
|
|
392
|
-
if (!symbol || !token_type) return ;
|
|
393
|
-
switch(this.network) {
|
|
394
|
-
case ENTRYPOINT.testnet:
|
|
395
|
-
var r = this.CoinTypes_Testnet.filter((v) => v?.type !== token_type);
|
|
396
|
-
r.push({symbol:symbol, type:token_type, decimals:decimals});
|
|
397
|
-
this.CoinTypes_Testnet = r;
|
|
398
|
-
break;
|
|
399
|
-
case ENTRYPOINT.mainnet:
|
|
400
|
-
var r = this.CoinTypes_Mainnet.filter((v) => v?.type !== token_type);
|
|
401
|
-
r.push({symbol:symbol, type:token_type, decimals:decimals});
|
|
402
|
-
this.CoinTypes_Mainnet = r;
|
|
403
|
-
break;
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
explorerUrl = (objectid: string, type:'object' | 'txblock' | 'account'='object') => {
|
|
407
|
-
if (this.network === ENTRYPOINT.testnet) {
|
|
408
|
-
return 'https://testnet.suivision.xyz/' + type + '/' + objectid;
|
|
409
|
-
} else if (this.network === ENTRYPOINT.mainnet) {
|
|
410
|
-
return 'https://suivision.xyz/' + type + '/' + objectid;
|
|
411
|
-
}; return ''
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
CoinTypes_Testnet:CoinTypeInfo[] = [
|
|
415
|
-
{symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
|
|
416
|
-
{symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
|
|
417
|
-
{symbol:'WOW', type:TESTNET.base + '::wowok::WOWOK', decimals:9},
|
|
418
|
-
];
|
|
419
|
-
|
|
420
|
-
CoinTypes_Mainnet:CoinTypeInfo[] = [
|
|
421
|
-
{symbol:'SUI', type:'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI', decimals:9, alias:true},
|
|
422
|
-
{symbol:'SUI', type:'0x2::sui::SUI', decimals:9, },
|
|
423
|
-
{symbol:'WOW', type:TESTNET.base + '::wowok::WOWOK', decimals:9},
|
|
424
|
-
{symbol:'USDT', type:'0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN', decimals:6},
|
|
425
|
-
{symbol:'USDC', type:'0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN', decimals:6},
|
|
426
|
-
{symbol:'WETH', type:'0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN', decimals:8},
|
|
427
|
-
{symbol:'WBNB', type:'0xb848cce11ef3a8f62eccea6eb5b35a12c4c2b1ee1af7755d02d7bd6218e8226f::coin::COIN', decimals:8},
|
|
428
|
-
];
|
|
429
|
-
|
|
430
|
-
coinTypeInfo = (token_type: string, handler:(info:CoinTypeInfo)=>void) : CoinTypeInfo | 'loading' => {
|
|
431
|
-
if (!token_type) return 'loading';
|
|
432
|
-
let r = this.COINS_TYPE().find((v) => v?.type === token_type);
|
|
433
|
-
if (!r) {
|
|
434
|
-
Protocol.Client().getCoinMetadata({coinType:token_type}).then((res) => {
|
|
435
|
-
if (res?.decimals && res?.symbol) {
|
|
436
|
-
this.update_coinType(token_type, res?.decimals, res?.symbol);
|
|
437
|
-
handler({symbol:res.symbol, decimals:res.decimals, type:token_type});
|
|
438
|
-
}
|
|
439
|
-
}).catch((e) => {
|
|
440
|
-
console.log(e);
|
|
441
|
-
})
|
|
442
|
-
} else {
|
|
443
|
-
return r;
|
|
444
|
-
}; return 'loading';
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
static CLOCK_OBJECT = {objectId:'0x6', mutable:false, initialSharedVersion:1};
|
|
448
|
-
|
|
449
|
-
static TXB_OBJECT(txb:TransactionBlock, arg:TxbObject) : TransactionArgument {
|
|
450
|
-
if (typeof(arg) == 'string') return txb.object(arg) as TransactionArgument;
|
|
451
|
-
return arg;
|
|
452
|
-
}
|
|
453
|
-
static IsValidObjects = (arr:TxbObject[]) : boolean => {
|
|
454
|
-
return IsValidArray(arr, (v:TxbObject)=>{
|
|
455
|
-
if (!v) return false
|
|
456
|
-
if (typeof(v) === 'string' && !isValidSuiObjectId(v)) {
|
|
457
|
-
return false
|
|
458
|
-
}
|
|
459
|
-
return true
|
|
460
|
-
})
|
|
461
|
-
}
|
|
462
|
-
WOWOK_OBJECTS_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
|
|
463
|
-
{ let i = (key === MODULES.guard ? this.packages.get('base') : this.packages.get('wowok')) + '::' + key + '::'; return i + capitalize(key); })
|
|
464
|
-
WOWOK_OBJECTS_PREFIX_TYPE = () => (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) =>
|
|
465
|
-
{ return (key === MODULES.guard ? this.packages.get('base') : this.packages.get('wowok')) + '::' + key + '::'; })
|
|
466
|
-
hasPackage(pack:string) : boolean {
|
|
467
|
-
for (let value of this.packages.values()) {
|
|
468
|
-
if (pack.includes(value)) {
|
|
469
|
-
return true;
|
|
470
|
-
}
|
|
471
|
-
} return false;
|
|
472
|
-
}
|
|
473
|
-
object_name_from_type_repr = (type_repr:string) : string => {
|
|
474
|
-
if (!type_repr) return ''
|
|
475
|
-
let i = type_repr.indexOf('::');
|
|
476
|
-
if (i > 0 && this.hasPackage(type_repr.slice(0, i))) {
|
|
477
|
-
i = type_repr.indexOf('<');
|
|
478
|
-
if (i > 0) {
|
|
479
|
-
type_repr = type_repr.slice(0, i);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
let n = type_repr.lastIndexOf('::');
|
|
483
|
-
if (n > 0) {
|
|
484
|
-
return type_repr.slice(n+2);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
return ''
|
|
488
|
-
}
|
|
489
|
-
module_object_name_from_type_repr = (type_repr:string) : string => {
|
|
490
|
-
if (!type_repr) return ''
|
|
491
|
-
let i = type_repr.indexOf('::');
|
|
492
|
-
if (i > 0 && this.hasPackage(type_repr.slice(0, i))) {
|
|
493
|
-
i = type_repr.indexOf('<');
|
|
494
|
-
if (i > 0) {
|
|
495
|
-
type_repr = type_repr.slice(0, i);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
let n = type_repr.indexOf('::');
|
|
499
|
-
if (n > 0) {
|
|
500
|
-
return type_repr.slice(n+2);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
return ''
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
export class RpcResultParser {
|
|
508
|
-
static Object_Type_Extra = () => {
|
|
509
|
-
let names = (Object.keys(MODULES) as Array<keyof typeof MODULES>).map((key) => { return key + '::' + capitalize(key); });
|
|
510
|
-
names.push('order::Discount');
|
|
511
|
-
return names;
|
|
512
|
-
}
|
|
513
|
-
static objectids_from_response = (protocol:Protocol, response:SuiTransactionBlockResponse, concat_result?:Map<string, TxbObject[]>): Map<string, TxbObject[]> => {
|
|
514
|
-
//console.log(response)
|
|
515
|
-
let ret = new Map<string, string[]>();
|
|
516
|
-
if (response?.objectChanges) {
|
|
517
|
-
response.objectChanges.forEach((change) => {
|
|
518
|
-
RpcResultParser.Object_Type_Extra().forEach((name) => {
|
|
519
|
-
if (change.type == 'created' && protocol.module_object_name_from_type_repr(change.objectType)===name) {
|
|
520
|
-
if (ret.has(name)) {
|
|
521
|
-
ret.get(name)?.push(change.objectId);
|
|
522
|
-
} else {
|
|
523
|
-
ret.set(name, [change.objectId]);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
})
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
if (concat_result) {
|
|
530
|
-
ret.forEach((value, key) => {
|
|
531
|
-
if (concat_result.has(key)) {
|
|
532
|
-
concat_result.set(key, concat_result.get(key)!.concat(value));
|
|
533
|
-
} else {
|
|
534
|
-
concat_result.set(key, value);
|
|
535
|
-
}
|
|
536
|
-
})
|
|
537
|
-
}
|
|
538
|
-
return ret;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
export type Query_Param = {
|
|
543
|
-
objectid: string;
|
|
544
|
-
callback: (protocol:Protocol, response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions)=>void;
|
|
545
|
-
parser?: (result:any[], guardid: string, chain_sense_bsc:Uint8Array, constant?:GuardConstant) => boolean;
|
|
546
|
-
data?: any; // response data filted by callback
|
|
547
|
-
constants?: GuardConstant;
|
|
548
|
-
};
|
|
549
|
-
|