@clonegod/ttd-sui-common 1.0.99 → 1.0.100

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.
@@ -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.100",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",