@clonegod/ttd-sui-common 1.0.99 → 1.0.101

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.
@@ -6,6 +6,7 @@ export declare class GrpcConnection {
6
6
  private metadata;
7
7
  private constructor();
8
8
  static getInstance(grpc_endpoint: string, grpc_token: string): GrpcConnection;
9
+ private static readonly CHANNEL_OPTIONS;
9
10
  private getChannel;
10
11
  createServiceClient<T>(protoFileName: string, serviceName: string): T;
11
12
  getMetadata(): grpc.Metadata;
@@ -53,23 +53,7 @@ class GrpcConnection {
53
53
  }
54
54
  getChannel() {
55
55
  if (!this.channel) {
56
- this.channel = new grpc.Channel(this.endpoint, grpc.credentials.createSsl(), {
57
- 'grpc.keepalive_time_ms': 120000,
58
- 'grpc.keepalive_timeout_ms': 10000,
59
- 'grpc.keepalive_permit_without_calls': 0,
60
- 'grpc.http2.max_pings_without_data': 1,
61
- 'grpc.http2.min_time_between_pings_ms': 120000,
62
- 'grpc.http2.min_ping_interval_without_data_ms': 120000,
63
- 'grpc.max_receive_message_length': 4 * 1024 * 1024,
64
- 'grpc.max_send_message_length': 4 * 1024 * 1024,
65
- 'grpc.initial_reconnect_backoff_ms': 1000,
66
- 'grpc.max_reconnect_backoff_ms': 30000,
67
- 'grpc.enable_retries': 1,
68
- 'grpc.retry_buffer_size': 256 * 1024,
69
- 'grpc.http2.max_frame_size': 16384,
70
- 'grpc.http2.max_header_list_size': 16384,
71
- 'grpc.http2.initial_window_size': 65535,
72
- });
56
+ this.channel = new grpc.Channel(this.endpoint, grpc.credentials.createSsl(), GrpcConnection.CHANNEL_OPTIONS);
73
57
  (0, dist_1.log_info)(`======> create grpc channel, endpoint= ${this.endpoint}`);
74
58
  }
75
59
  return this.channel;
@@ -91,9 +75,7 @@ class GrpcConnection {
91
75
  throw new Error(`Service ${serviceName} not found in proto file`);
92
76
  }
93
77
  const channel = this.getChannel();
94
- return new service(this.endpoint, grpc.credentials.createSsl(), {
95
- channelOverride: channel
96
- });
78
+ return new service(this.endpoint, grpc.credentials.createSsl(), Object.assign(Object.assign({}, GrpcConnection.CHANNEL_OPTIONS), { channelOverride: channel }));
97
79
  }
98
80
  getMetadata() {
99
81
  return this.metadata;
@@ -107,3 +89,20 @@ class GrpcConnection {
107
89
  }
108
90
  }
109
91
  exports.GrpcConnection = GrpcConnection;
92
+ GrpcConnection.CHANNEL_OPTIONS = {
93
+ 'grpc.keepalive_time_ms': 60000,
94
+ 'grpc.keepalive_timeout_ms': 10000,
95
+ 'grpc.keepalive_permit_without_calls': 0,
96
+ 'grpc.http2.max_pings_without_data': 0,
97
+ 'grpc.http2.min_time_between_pings_ms': 60000,
98
+ 'grpc.http2.min_ping_interval_without_data_ms': 60000,
99
+ 'grpc.max_receive_message_length': 4 * 1024 * 1024,
100
+ 'grpc.max_send_message_length': 4 * 1024 * 1024,
101
+ 'grpc.initial_reconnect_backoff_ms': 1000,
102
+ 'grpc.max_reconnect_backoff_ms': 30000,
103
+ 'grpc.enable_retries': 1,
104
+ 'grpc.retry_buffer_size': 256 * 1024,
105
+ 'grpc.http2.max_frame_size': 16384,
106
+ 'grpc.http2.max_header_list_size': 16384,
107
+ 'grpc.http2.initial_window_size': 65535,
108
+ };
@@ -1,5 +1,5 @@
1
1
  import { GrpcConnection } from './grpc-connection';
2
- import { ListOwnedObjectsResponse } from '../type/sui_object_types';
2
+ import { ListOwnedObjectsResponse, SuiObjectData } from '../type/sui_object_types';
3
3
  export declare class StateService {
4
4
  private stateClient;
5
5
  private connection;
@@ -7,5 +7,6 @@ export declare class StateService {
7
7
  getBalance(owner: string, coinType: string): Promise<any>;
8
8
  listBalances(owner: string): Promise<unknown>;
9
9
  getCoinInfo(coinType: string): Promise<unknown>;
10
- listOwnedObjects(owner: string, coinType?: string, limit?: number, readMask?: string[]): Promise<ListOwnedObjectsResponse>;
10
+ listOwnedObjects(owner: string, coinType?: string, limit?: number, readMask?: string[], pageTokenHex?: string): Promise<ListOwnedObjectsResponse>;
11
+ listAllOwnedObjects(owner: string, coinType?: string): Promise<SuiObjectData[]>;
11
12
  }
@@ -11,6 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.StateService = void 0;
13
13
  const utils_1 = require("../utils");
14
+ const LIST_OWNED_OBJECTS_PAGE_SIZE = 1000;
15
+ const LIST_OWNED_OBJECTS_MAX_PAGES = 5000;
14
16
  class StateService {
15
17
  constructor(connection) {
16
18
  this.connection = connection;
@@ -62,7 +64,7 @@ class StateService {
62
64
  });
63
65
  });
64
66
  }
65
- listOwnedObjects(owner, coinType, limit, readMask) {
67
+ listOwnedObjects(owner, coinType, limit, readMask, pageTokenHex) {
66
68
  return __awaiter(this, void 0, void 0, function* () {
67
69
  return new Promise((resolve, reject) => {
68
70
  const request = { owner };
@@ -74,6 +76,9 @@ class StateService {
74
76
  }
75
77
  if (limit)
76
78
  request.page_size = limit;
79
+ if (pageTokenHex && pageTokenHex.length > 0) {
80
+ request.page_token = Buffer.from(pageTokenHex, 'hex');
81
+ }
77
82
  if (readMask && readMask.length > 0) {
78
83
  request.read_mask = {
79
84
  paths: readMask
@@ -103,5 +108,24 @@ class StateService {
103
108
  });
104
109
  });
105
110
  }
111
+ listAllOwnedObjects(owner, coinType) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ var _a;
114
+ const out = [];
115
+ let pageTokenHex;
116
+ for (let page = 0; page < LIST_OWNED_OBJECTS_MAX_PAGES; page++) {
117
+ const res = yield this.listOwnedObjects(owner, coinType, LIST_OWNED_OBJECTS_PAGE_SIZE, undefined, pageTokenHex);
118
+ const r = res;
119
+ const chunk = r.objects || [];
120
+ out.push(...chunk);
121
+ const next = (_a = r.next_page_token) !== null && _a !== void 0 ? _a : r.nextPageToken;
122
+ if (!next || (typeof next === 'string' && next.length === 0)) {
123
+ break;
124
+ }
125
+ pageTokenHex = typeof next === 'string' ? next : Buffer.from(next).toString('hex');
126
+ }
127
+ return out;
128
+ });
129
+ }
106
130
  }
107
131
  exports.StateService = StateService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sui-common",
3
- "version": "1.0.99",
3
+ "version": "1.0.101",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",