@0xobelisk/sui-client 1.0.2 → 1.0.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/dist/dubhe.d.ts +15 -6
- package/dist/index.js +371 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +371 -43
- package/dist/index.mjs.map +1 -1
- package/dist/libs/suiInteractor/defaultConfig.d.ts +10 -0
- package/dist/libs/suiInteractor/index.d.ts +2 -0
- package/dist/libs/suiInteractor/suiInteractor.d.ts +5 -0
- package/dist/libs/suiTxBuilder/index.d.ts +15 -3
- package/dist/types/index.d.ts +7 -17
- package/package.json +3 -3
- package/src/dubhe.ts +389 -48
- package/src/libs/suiInteractor/defaultConfig.ts +63 -0
- package/src/libs/suiInteractor/index.ts +2 -0
- package/src/libs/suiInteractor/suiInteractor.ts +26 -0
- package/src/types/index.ts +24 -16
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { NetworkType } from 'src/types';
|
|
2
|
+
|
|
3
|
+
export interface NetworkConfig {
|
|
4
|
+
fullNode: string;
|
|
5
|
+
graphql?: string;
|
|
6
|
+
network: string;
|
|
7
|
+
txExplorer: string;
|
|
8
|
+
accountExplorer: string;
|
|
9
|
+
explorer: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const getDefaultURL = (
|
|
13
|
+
networkType: NetworkType = 'testnet'
|
|
14
|
+
): NetworkConfig => {
|
|
15
|
+
switch (networkType) {
|
|
16
|
+
case 'localnet':
|
|
17
|
+
return {
|
|
18
|
+
fullNode: 'http://127.0.0.1:9000',
|
|
19
|
+
graphql: 'http://127.0.0.1:9125',
|
|
20
|
+
network: 'localnet',
|
|
21
|
+
txExplorer:
|
|
22
|
+
'https://explorer.polymedia.app/txblock/:txHash?network=local',
|
|
23
|
+
accountExplorer:
|
|
24
|
+
'https://explorer.polymedia.app/address/:address?network=local',
|
|
25
|
+
explorer: 'https://explorer.polymedia.app?network=local',
|
|
26
|
+
};
|
|
27
|
+
case 'devnet':
|
|
28
|
+
return {
|
|
29
|
+
fullNode: 'https://fullnode.devnet.sui.io:443',
|
|
30
|
+
network: 'devnet',
|
|
31
|
+
txExplorer: 'https://suiscan.xyz/devnet/tx/:txHash',
|
|
32
|
+
accountExplorer: 'https://suiscan.xyz/devnet/address/:address',
|
|
33
|
+
explorer: 'https://suiscan.xyz/devnet',
|
|
34
|
+
};
|
|
35
|
+
case 'testnet':
|
|
36
|
+
return {
|
|
37
|
+
fullNode: 'https://fullnode.testnet.sui.io:443',
|
|
38
|
+
graphql: 'https://sui-testnet.mystenlabs.com/graphql',
|
|
39
|
+
network: 'testnet',
|
|
40
|
+
txExplorer: 'https://suiscan.xyz/testnet/tx/:txHash',
|
|
41
|
+
accountExplorer: 'https://suiscan.xyz/testnet/address/:address',
|
|
42
|
+
explorer: 'https://suiscan.xyz/testnet',
|
|
43
|
+
};
|
|
44
|
+
case 'mainnet':
|
|
45
|
+
return {
|
|
46
|
+
fullNode: 'https://fullnode.mainnet.sui.io:443',
|
|
47
|
+
graphql: 'https://sui-mainnet.mystenlabs.com/graphql',
|
|
48
|
+
network: 'mainnet',
|
|
49
|
+
txExplorer: 'https://suiscan.xyz/mainnet/tx/:txHash',
|
|
50
|
+
accountExplorer: 'https://suiscan.xyz/mainnet/address/:address',
|
|
51
|
+
explorer: 'https://suiscan.xyz/mainnet',
|
|
52
|
+
};
|
|
53
|
+
default:
|
|
54
|
+
return {
|
|
55
|
+
fullNode: 'https://fullnode.testnet.sui.io:443',
|
|
56
|
+
graphql: 'https://sui-testnet.mystenlabs.com/graphql',
|
|
57
|
+
network: 'testnet',
|
|
58
|
+
txExplorer: 'https://suiscan.xyz/testnet/tx/:txHash',
|
|
59
|
+
accountExplorer: 'https://suiscan.xyz/testnet/address/:address',
|
|
60
|
+
explorer: 'https://suiscan.xyz/testnet',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
@@ -76,6 +76,32 @@ export class SuiInteractor {
|
|
|
76
76
|
throw new Error('Failed to send transaction with all fullnodes');
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
async waitForTransaction({
|
|
80
|
+
digest,
|
|
81
|
+
timeout = 60 * 1000,
|
|
82
|
+
pollInterval = 2 * 1000,
|
|
83
|
+
}: {
|
|
84
|
+
digest: string;
|
|
85
|
+
timeout?: number;
|
|
86
|
+
pollInterval?: number;
|
|
87
|
+
}) {
|
|
88
|
+
for (const clientIdx in this.clients) {
|
|
89
|
+
try {
|
|
90
|
+
return await this.clients[clientIdx].waitForTransaction({
|
|
91
|
+
digest,
|
|
92
|
+
timeout,
|
|
93
|
+
pollInterval,
|
|
94
|
+
});
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.warn(
|
|
97
|
+
`Failed to wait for transaction with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
98
|
+
);
|
|
99
|
+
await delay(2000);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw new Error('Failed to wait for transaction with all fullnodes');
|
|
103
|
+
}
|
|
104
|
+
|
|
79
105
|
async getObjects(
|
|
80
106
|
ids: string[],
|
|
81
107
|
options?: SuiObjectDataOptions
|
package/src/types/index.ts
CHANGED
|
@@ -17,6 +17,8 @@ import type {
|
|
|
17
17
|
DisplayFieldsResponse,
|
|
18
18
|
SuiMoveNormalizedType,
|
|
19
19
|
MoveStruct,
|
|
20
|
+
SuiMoveNormalizedEnum,
|
|
21
|
+
SuiMoveNormalizedStruct,
|
|
20
22
|
} from '@mysten/sui/client';
|
|
21
23
|
import { SuiTx } from '../libs/suiTxBuilder';
|
|
22
24
|
|
|
@@ -118,24 +120,30 @@ export type MapMessageQuery = Record<string, ContractQuery>;
|
|
|
118
120
|
export type MapMoudleFuncTx = Record<string, MapMessageTx>;
|
|
119
121
|
export type MapMoudleFuncQuery = Record<string, MapMessageQuery>;
|
|
120
122
|
|
|
121
|
-
export type MoveStructValueType = {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
123
|
+
// export type MoveStructValueType = {
|
|
124
|
+
// fields: {
|
|
125
|
+
// type: SuiMoveNormalizedType;
|
|
126
|
+
// name: string;
|
|
127
|
+
// }[];
|
|
128
|
+
// abilities: {
|
|
129
|
+
// abilities: string[];
|
|
130
|
+
// };
|
|
131
|
+
// typeParameters: {
|
|
132
|
+
// constraints: {
|
|
133
|
+
// abilities: string[];
|
|
134
|
+
// };
|
|
135
|
+
// isPhantom: boolean;
|
|
136
|
+
// }[];
|
|
137
|
+
// };
|
|
136
138
|
export type MoveStructType = {
|
|
137
139
|
objectId: string;
|
|
138
|
-
objectType:
|
|
140
|
+
objectType: SuiMoveNormalizedStruct;
|
|
141
|
+
objectName: string;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export type MoveEnumType = {
|
|
145
|
+
objectId: string;
|
|
146
|
+
objectType: SuiMoveNormalizedEnum;
|
|
139
147
|
objectName: string;
|
|
140
148
|
};
|
|
141
149
|
|