@0xobelisk/sui-client 1.0.5 → 1.0.7

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.
@@ -0,0 +1,225 @@
1
+ import { Http } from '../http';
2
+ import { WebSocket } from 'ws';
3
+
4
+ export interface OrderDirection {
5
+ ASC: 'ASC';
6
+ DESC: 'DESC';
7
+ }
8
+
9
+ export interface OrderBy {
10
+ field: string;
11
+ direction: OrderDirection['ASC'] | OrderDirection['DESC'];
12
+ }
13
+
14
+ export interface PageInfo {
15
+ hasNextPage: boolean;
16
+ hasPreviousPage: boolean;
17
+ startCursor?: string;
18
+ endCursor?: string;
19
+ }
20
+
21
+ export interface Transaction {
22
+ id: number;
23
+ checkpoint: number;
24
+ digest: string;
25
+ }
26
+
27
+ export interface Schema {
28
+ id: number;
29
+ name: string;
30
+ key1?: string;
31
+ key2?: string;
32
+ value: string;
33
+ last_update_checkpoint: string;
34
+ last_update_digest: string;
35
+ is_removed: boolean;
36
+ }
37
+
38
+ export interface Event {
39
+ id: number;
40
+ checkpoint: string;
41
+ digest: string;
42
+ name: string;
43
+ value: string;
44
+ }
45
+
46
+ export interface ConnectionResponse<T> {
47
+ edges: Array<{
48
+ cursor: string;
49
+ node: T;
50
+ }>;
51
+ pageInfo: PageInfo;
52
+ }
53
+
54
+ export class SuiIndexerClient {
55
+ private http: Http;
56
+
57
+ constructor(http: Http) {
58
+ this.http = http;
59
+ }
60
+
61
+ private async fetchGraphql<T>(query: string, variables?: any): Promise<T> {
62
+ return this.http.fetchGraphql({ query, variables });
63
+ }
64
+
65
+ async getTransactions(params?: {
66
+ first?: number;
67
+ after?: string;
68
+ last?: number;
69
+ before?: string;
70
+ checkpoint?: number;
71
+ orderBy?: OrderBy;
72
+ distinct?: boolean;
73
+ }) {
74
+ const query = `
75
+ query GetTransactions($first: Int, $after: String, $last: Int, $before: String, $checkpoint: Int, $orderBy: TransactionOrderBy, $distinct: Boolean) {
76
+ transactions(first: $first, after: $after, last: $last, before: $before, checkpoint: $checkpoint, orderBy: $orderBy, distinct: $distinct) {
77
+ edges {
78
+ cursor
79
+ node {
80
+ id
81
+ checkpoint
82
+ digest
83
+ }
84
+ }
85
+ pageInfo {
86
+ hasNextPage
87
+ hasPreviousPage
88
+ startCursor
89
+ endCursor
90
+ }
91
+ }
92
+ }
93
+ `;
94
+
95
+ const response = await this.fetchGraphql<{
96
+ transactions: ConnectionResponse<Transaction>;
97
+ }>(query, params);
98
+ return response.transactions;
99
+ }
100
+
101
+ async getSchemas(params?: {
102
+ first?: number;
103
+ after?: string;
104
+ last?: number;
105
+ before?: string;
106
+ name?: string;
107
+ key1?: string;
108
+ key2?: string;
109
+ orderBy?: OrderBy;
110
+ distinct?: boolean;
111
+ }): Promise<ConnectionResponse<Schema>> {
112
+ const query = `
113
+ query GetSchemas($first: Int, $after: String, $last: Int, $before: String, $name: String, $key1: String, $key2: String, $orderBy: SchemaOrderBy, $distinct: Boolean) {
114
+ schemas(first: $first, after: $after, last: $last, before: $before, name: $name, key1: $key1, key2: $key2, orderBy: $orderBy, distinct: $distinct) {
115
+ edges {
116
+ cursor
117
+ node {
118
+ id
119
+ name
120
+ key1
121
+ key2
122
+ value
123
+ last_update_checkpoint
124
+ last_update_digest
125
+ is_removed
126
+ }
127
+ }
128
+ pageInfo {
129
+ hasNextPage
130
+ hasPreviousPage
131
+ startCursor
132
+ endCursor
133
+ }
134
+ }
135
+ }
136
+ `;
137
+
138
+ const response = await this.fetchGraphql<{
139
+ schemas: ConnectionResponse<Schema>;
140
+ }>(query, params);
141
+ return response.schemas;
142
+ }
143
+
144
+ async getEvents(params?: {
145
+ first?: number;
146
+ after?: string;
147
+ last?: number;
148
+ before?: string;
149
+ name?: string;
150
+ checkpoint?: string;
151
+ orderBy?: OrderBy;
152
+ distinct?: boolean;
153
+ }) {
154
+ const query = `
155
+ query GetEvents($first: Int, $after: String, $last: Int, $before: String, $name: String, $checkpoint: String, $orderBy: EventOrderBy, $distinct: Boolean) {
156
+ events(first: $first, after: $after, last: $last, before: $before, name: $name, checkpoint: $checkpoint, orderBy: $orderBy, distinct: $distinct) {
157
+ edges {
158
+ cursor
159
+ node {
160
+ id
161
+ checkpoint
162
+ digest
163
+ name
164
+ value
165
+ }
166
+ }
167
+ pageInfo {
168
+ hasNextPage
169
+ hasPreviousPage
170
+ startCursor
171
+ endCursor
172
+ }
173
+ }
174
+ }
175
+ `;
176
+
177
+ const response = await this.fetchGraphql<{
178
+ events: ConnectionResponse<Event>;
179
+ }>(query, params);
180
+ return response.events;
181
+ }
182
+
183
+ async getStorage({
184
+ name,
185
+ key1,
186
+ key2,
187
+ first,
188
+ after,
189
+ last,
190
+ before,
191
+ orderBy,
192
+ distinct,
193
+ }: {
194
+ name: string;
195
+ key1?: string;
196
+ key2?: string;
197
+ first?: number;
198
+ after?: string;
199
+ last?: number;
200
+ before?: string;
201
+ orderBy?: OrderBy;
202
+ distinct?: boolean;
203
+ }): Promise<ConnectionResponse<Schema>> {
204
+ const schemas = await this.getSchemas({
205
+ name,
206
+ key1,
207
+ key2,
208
+ first,
209
+ after,
210
+ last,
211
+ before,
212
+ orderBy,
213
+ distinct,
214
+ });
215
+
216
+ return schemas;
217
+ }
218
+
219
+ async subscribe(
220
+ names: string[],
221
+ handleData: (data: any) => void
222
+ ): Promise<WebSocket> {
223
+ return this.http.subscribe(names, handleData);
224
+ }
225
+ }
File without changes
@@ -7,6 +7,7 @@ export interface NetworkConfig {
7
7
  txExplorer: string;
8
8
  accountExplorer: string;
9
9
  explorer: string;
10
+ indexerUrl: string;
10
11
  }
11
12
 
12
13
  export const getDefaultURL = (
@@ -23,6 +24,7 @@ export const getDefaultURL = (
23
24
  accountExplorer:
24
25
  'https://explorer.polymedia.app/address/:address?network=local',
25
26
  explorer: 'https://explorer.polymedia.app?network=local',
27
+ indexerUrl: 'http://127.0.0.1:3001',
26
28
  };
27
29
  case 'devnet':
28
30
  return {
@@ -31,6 +33,7 @@ export const getDefaultURL = (
31
33
  txExplorer: 'https://suiscan.xyz/devnet/tx/:txHash',
32
34
  accountExplorer: 'https://suiscan.xyz/devnet/address/:address',
33
35
  explorer: 'https://suiscan.xyz/devnet',
36
+ indexerUrl: 'http://127.0.0.1:3001',
34
37
  };
35
38
  case 'testnet':
36
39
  return {
@@ -40,6 +43,7 @@ export const getDefaultURL = (
40
43
  txExplorer: 'https://suiscan.xyz/testnet/tx/:txHash',
41
44
  accountExplorer: 'https://suiscan.xyz/testnet/address/:address',
42
45
  explorer: 'https://suiscan.xyz/testnet',
46
+ indexerUrl: 'http://127.0.0.1:3001',
43
47
  };
44
48
  case 'mainnet':
45
49
  return {
@@ -49,6 +53,7 @@ export const getDefaultURL = (
49
53
  txExplorer: 'https://suiscan.xyz/mainnet/tx/:txHash',
50
54
  accountExplorer: 'https://suiscan.xyz/mainnet/address/:address',
51
55
  explorer: 'https://suiscan.xyz/mainnet',
56
+ indexerUrl: 'http://127.0.0.1:3001',
52
57
  };
53
58
  default:
54
59
  return {
@@ -58,6 +63,7 @@ export const getDefaultURL = (
58
63
  txExplorer: 'https://suiscan.xyz/testnet/tx/:txHash',
59
64
  accountExplorer: 'https://suiscan.xyz/testnet/address/:address',
60
65
  explorer: 'https://suiscan.xyz/testnet',
66
+ indexerUrl: 'http://127.0.0.1:3001',
61
67
  };
62
68
  }
63
69
  };
@@ -87,10 +87,18 @@ export class SuiInteractor {
87
87
  }) {
88
88
  for (const clientIdx in this.clients) {
89
89
  try {
90
+ const txResOptions: SuiTransactionBlockResponseOptions = {
91
+ showEvents: true,
92
+ showEffects: true,
93
+ showObjectChanges: true,
94
+ showBalanceChanges: true,
95
+ };
96
+
90
97
  return await this.clients[clientIdx].waitForTransaction({
91
98
  digest,
92
99
  timeout,
93
100
  pollInterval,
101
+ options: txResOptions,
94
102
  });
95
103
  } catch (err) {
96
104
  console.warn(
@@ -23,6 +23,7 @@ import type {
23
23
  import { SuiTx } from '../libs/suiTxBuilder';
24
24
 
25
25
  import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
26
+ import { FetchOptions } from '../libs/http';
26
27
 
27
28
  export const ObjectContentFields = record(string(), any());
28
29
  export type ObjectContentFields = Infer<typeof ObjectContentFields>;
@@ -50,6 +51,10 @@ export type DubheParams = {
50
51
  networkType?: NetworkType;
51
52
  packageId?: string;
52
53
  metadata?: SuiMoveNormalizedModules;
54
+ customFetch?: typeof fetch;
55
+ defaultOptions?: FetchOptions;
56
+ indexerUrl?: string;
57
+ indexerWsUrl?: string;
53
58
  };
54
59
 
55
60
  export type SchemaFieldType = {
@@ -28,3 +28,12 @@ export function normalizePackageId(input: string): string {
28
28
  const normalized = withoutPrefix.replace(/^0+/, '');
29
29
  return '0x' + normalized;
30
30
  }
31
+
32
+ export function convertHttpToWebSocket(url: string): string {
33
+ if (url.startsWith('https://')) {
34
+ return url.replace('https://', 'wss://');
35
+ } else if (url.startsWith('http://')) {
36
+ return url.replace('http://', 'ws://');
37
+ }
38
+ return url;
39
+ }