@secondlayer/sdk 6.28.0 → 6.28.1

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/index.d.ts CHANGED
@@ -1801,6 +1801,12 @@ declare class Index extends BaseClient {
1801
1801
  readonly pox: PoxResource;
1802
1802
  private listFtTransfers;
1803
1803
  private listNftTransfers;
1804
+ /** Shared keyset-pagination loop for every `walk*` feed: seed the cursor from
1805
+ * `cursor`/`fromCursor` (and `fromHeight` 0 on the first page), then page until
1806
+ * the cursor stops advancing or a short page signals the tail. `list` merges the
1807
+ * resource's filter params; `itemsOf` selects the envelope's item array. PoX
1808
+ * cycles use a numeric cursor and are walked separately. */
1809
+ private keysetWalk;
1804
1810
  private walkFtTransfers;
1805
1811
  private walkNftTransfers;
1806
1812
  private listEvents;
package/dist/index.js CHANGED
@@ -835,55 +835,36 @@ class Index extends BaseClient {
835
835
  to_height: params.toHeight
836
836
  })}`);
837
837
  }
838
- async* walkFtTransfers(params = {}) {
838
+ async* keysetWalk(params, list, itemsOf) {
839
839
  const batchSize = params.batchSize ?? 200;
840
840
  let cursor = params.cursor ?? params.fromCursor ?? null;
841
841
  let firstPage = true;
842
842
  while (!params.signal?.aborted) {
843
- const envelope = await this.listFtTransfers({
844
- ...params,
843
+ const envelope = await list({
845
844
  limit: batchSize,
846
845
  cursor: firstPage ? params.cursor : cursor,
847
846
  fromCursor: firstPage ? params.fromCursor : undefined,
848
847
  fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
849
848
  });
850
- for (const event of envelope.events) {
849
+ const items = itemsOf(envelope);
850
+ for (const item of items) {
851
851
  if (params.signal?.aborted)
852
852
  return;
853
- yield event;
853
+ yield item;
854
854
  }
855
855
  const nextCursor = envelope.next_cursor;
856
- if (!nextCursor || nextCursor === cursor || envelope.events.length < batchSize) {
856
+ if (!nextCursor || nextCursor === cursor || items.length < batchSize) {
857
857
  return;
858
858
  }
859
859
  cursor = nextCursor;
860
860
  firstPage = false;
861
861
  }
862
862
  }
863
- async* walkNftTransfers(params = {}) {
864
- const batchSize = params.batchSize ?? 200;
865
- let cursor = params.cursor ?? params.fromCursor ?? null;
866
- let firstPage = true;
867
- while (!params.signal?.aborted) {
868
- const envelope = await this.listNftTransfers({
869
- ...params,
870
- limit: batchSize,
871
- cursor: firstPage ? params.cursor : cursor,
872
- fromCursor: firstPage ? params.fromCursor : undefined,
873
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
874
- });
875
- for (const event of envelope.events) {
876
- if (params.signal?.aborted)
877
- return;
878
- yield event;
879
- }
880
- const nextCursor = envelope.next_cursor;
881
- if (!nextCursor || nextCursor === cursor || envelope.events.length < batchSize) {
882
- return;
883
- }
884
- cursor = nextCursor;
885
- firstPage = false;
886
- }
863
+ walkFtTransfers(params = {}) {
864
+ return this.keysetWalk(params, (page) => this.listFtTransfers({ ...params, ...page }), (e) => e.events);
865
+ }
866
+ walkNftTransfers(params = {}) {
867
+ return this.keysetWalk(params, (page) => this.listNftTransfers({ ...params, ...page }), (e) => e.events);
887
868
  }
888
869
  async listEvents(params) {
889
870
  return this.request("GET", `/v1/index/events${buildQuery({
@@ -901,30 +882,8 @@ class Index extends BaseClient {
901
882
  tx_context: params.txContext ? "true" : undefined
902
883
  })}`);
903
884
  }
904
- async* walkEvents(params) {
905
- const batchSize = params.batchSize ?? 200;
906
- let cursor = params.cursor ?? params.fromCursor ?? null;
907
- let firstPage = true;
908
- while (!params.signal?.aborted) {
909
- const envelope = await this.listEvents({
910
- ...params,
911
- limit: batchSize,
912
- cursor: firstPage ? params.cursor : cursor,
913
- fromCursor: firstPage ? params.fromCursor : undefined,
914
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
915
- });
916
- for (const event of envelope.events) {
917
- if (params.signal?.aborted)
918
- return;
919
- yield event;
920
- }
921
- const nextCursor = envelope.next_cursor;
922
- if (!nextCursor || nextCursor === cursor || envelope.events.length < batchSize) {
923
- return;
924
- }
925
- cursor = nextCursor;
926
- firstPage = false;
927
- }
885
+ walkEvents(params) {
886
+ return this.keysetWalk(params, (page) => this.listEvents({ ...params, ...page }), (e) => e.events);
928
887
  }
929
888
  async listContractCalls(params = {}) {
930
889
  return this.request("GET", `/v1/index/contract-calls${buildQuery({
@@ -939,30 +898,8 @@ class Index extends BaseClient {
939
898
  trait: params.trait
940
899
  })}`);
941
900
  }
942
- async* walkContractCalls(params = {}) {
943
- const batchSize = params.batchSize ?? 200;
944
- let cursor = params.cursor ?? params.fromCursor ?? null;
945
- let firstPage = true;
946
- while (!params.signal?.aborted) {
947
- const envelope = await this.listContractCalls({
948
- ...params,
949
- limit: batchSize,
950
- cursor: firstPage ? params.cursor : cursor,
951
- fromCursor: firstPage ? params.fromCursor : undefined,
952
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
953
- });
954
- for (const call of envelope.contract_calls) {
955
- if (params.signal?.aborted)
956
- return;
957
- yield call;
958
- }
959
- const nextCursor = envelope.next_cursor;
960
- if (!nextCursor || nextCursor === cursor || envelope.contract_calls.length < batchSize) {
961
- return;
962
- }
963
- cursor = nextCursor;
964
- firstPage = false;
965
- }
901
+ walkContractCalls(params = {}) {
902
+ return this.keysetWalk(params, (page) => this.listContractCalls({ ...params, ...page }), (e) => e.contract_calls);
966
903
  }
967
904
  async listCanonical(params = {}) {
968
905
  return this.request("GET", `/v1/index/canonical${buildQuery({
@@ -973,30 +910,8 @@ class Index extends BaseClient {
973
910
  to_height: params.toHeight
974
911
  })}`);
975
912
  }
976
- async* walkCanonical(params = {}) {
977
- const batchSize = params.batchSize ?? 200;
978
- let cursor = params.cursor ?? params.fromCursor ?? null;
979
- let firstPage = true;
980
- while (!params.signal?.aborted) {
981
- const envelope = await this.listCanonical({
982
- ...params,
983
- limit: batchSize,
984
- cursor: firstPage ? params.cursor : cursor,
985
- fromCursor: firstPage ? params.fromCursor : undefined,
986
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
987
- });
988
- for (const block of envelope.canonical) {
989
- if (params.signal?.aborted)
990
- return;
991
- yield block;
992
- }
993
- const nextCursor = envelope.next_cursor;
994
- if (!nextCursor || nextCursor === cursor || envelope.canonical.length < batchSize) {
995
- return;
996
- }
997
- cursor = nextCursor;
998
- firstPage = false;
999
- }
913
+ walkCanonical(params = {}) {
914
+ return this.keysetWalk(params, (page) => this.listCanonical({ ...params, ...page }), (e) => e.canonical);
1000
915
  }
1001
916
  async listBlocks(params = {}) {
1002
917
  return this.request("GET", `/v1/index/blocks${buildQuery({
@@ -1010,30 +925,8 @@ class Index extends BaseClient {
1010
925
  async getBlock(ref) {
1011
926
  return this.requestOrNull("GET", `/v1/index/blocks/${encodeURIComponent(String(ref))}`);
1012
927
  }
1013
- async* walkBlocks(params = {}) {
1014
- const batchSize = params.batchSize ?? 200;
1015
- let cursor = params.cursor ?? params.fromCursor ?? null;
1016
- let firstPage = true;
1017
- while (!params.signal?.aborted) {
1018
- const envelope = await this.listBlocks({
1019
- ...params,
1020
- limit: batchSize,
1021
- cursor: firstPage ? params.cursor : cursor,
1022
- fromCursor: firstPage ? params.fromCursor : undefined,
1023
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
1024
- });
1025
- for (const block of envelope.blocks) {
1026
- if (params.signal?.aborted)
1027
- return;
1028
- yield block;
1029
- }
1030
- const nextCursor = envelope.next_cursor;
1031
- if (!nextCursor || nextCursor === cursor || envelope.blocks.length < batchSize) {
1032
- return;
1033
- }
1034
- cursor = nextCursor;
1035
- firstPage = false;
1036
- }
928
+ walkBlocks(params = {}) {
929
+ return this.keysetWalk(params, (page) => this.listBlocks({ ...params, ...page }), (e) => e.blocks);
1037
930
  }
1038
931
  async listTransactions(params = {}) {
1039
932
  return this.request("GET", `/v1/index/transactions${buildQuery({
@@ -1053,30 +946,8 @@ class Index extends BaseClient {
1053
946
  async getTransactionProof(txId) {
1054
947
  return this.requestOrNull("GET", `/v1/index/transactions/${encodeURIComponent(txId)}/proof`);
1055
948
  }
1056
- async* walkTransactions(params = {}) {
1057
- const batchSize = params.batchSize ?? 200;
1058
- let cursor = params.cursor ?? params.fromCursor ?? null;
1059
- let firstPage = true;
1060
- while (!params.signal?.aborted) {
1061
- const envelope = await this.listTransactions({
1062
- ...params,
1063
- limit: batchSize,
1064
- cursor: firstPage ? params.cursor : cursor,
1065
- fromCursor: firstPage ? params.fromCursor : undefined,
1066
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
1067
- });
1068
- for (const tx of envelope.transactions) {
1069
- if (params.signal?.aborted)
1070
- return;
1071
- yield tx;
1072
- }
1073
- const nextCursor = envelope.next_cursor;
1074
- if (!nextCursor || nextCursor === cursor || envelope.transactions.length < batchSize) {
1075
- return;
1076
- }
1077
- cursor = nextCursor;
1078
- firstPage = false;
1079
- }
949
+ walkTransactions(params = {}) {
950
+ return this.keysetWalk(params, (page) => this.listTransactions({ ...params, ...page }), (e) => e.transactions);
1080
951
  }
1081
952
  async listStacking(params = {}) {
1082
953
  return this.request("GET", `/v1/index/stacking${buildQuery({
@@ -1090,30 +961,8 @@ class Index extends BaseClient {
1090
961
  to_height: params.toHeight
1091
962
  })}`);
1092
963
  }
1093
- async* walkStacking(params = {}) {
1094
- const batchSize = params.batchSize ?? 200;
1095
- let cursor = params.cursor ?? params.fromCursor ?? null;
1096
- let firstPage = true;
1097
- while (!params.signal?.aborted) {
1098
- const envelope = await this.listStacking({
1099
- ...params,
1100
- limit: batchSize,
1101
- cursor: firstPage ? params.cursor : cursor,
1102
- fromCursor: firstPage ? params.fromCursor : undefined,
1103
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
1104
- });
1105
- for (const action of envelope.stacking) {
1106
- if (params.signal?.aborted)
1107
- return;
1108
- yield action;
1109
- }
1110
- const nextCursor = envelope.next_cursor;
1111
- if (!nextCursor || nextCursor === cursor || envelope.stacking.length < batchSize) {
1112
- return;
1113
- }
1114
- cursor = nextCursor;
1115
- firstPage = false;
1116
- }
964
+ walkStacking(params = {}) {
965
+ return this.keysetWalk(params, (page) => this.listStacking({ ...params, ...page }), (e) => e.stacking);
1117
966
  }
1118
967
  async listMempool(params = {}) {
1119
968
  return this.request("GET", `/v1/index/mempool${buildQuery({
@@ -1128,29 +977,8 @@ class Index extends BaseClient {
1128
977
  async getMempoolTx(txId) {
1129
978
  return this.requestOrNull("GET", `/v1/index/mempool/${encodeURIComponent(txId)}`);
1130
979
  }
1131
- async* walkMempool(params = {}) {
1132
- const batchSize = params.batchSize ?? 200;
1133
- let cursor = params.cursor ?? params.fromCursor ?? null;
1134
- let firstPage = true;
1135
- while (!params.signal?.aborted) {
1136
- const envelope = await this.listMempool({
1137
- ...params,
1138
- limit: batchSize,
1139
- cursor: firstPage ? params.cursor : cursor,
1140
- fromCursor: firstPage ? params.fromCursor : undefined
1141
- });
1142
- for (const tx of envelope.mempool) {
1143
- if (params.signal?.aborted)
1144
- return;
1145
- yield tx;
1146
- }
1147
- const nextCursor = envelope.next_cursor;
1148
- if (!nextCursor || nextCursor === cursor || envelope.mempool.length < batchSize) {
1149
- return;
1150
- }
1151
- cursor = nextCursor;
1152
- firstPage = false;
1153
- }
980
+ walkMempool(params = {}) {
981
+ return this.keysetWalk(params, (page) => this.listMempool({ ...params, ...page }), (e) => e.mempool);
1154
982
  }
1155
983
  async listSbtcDeposits(params = {}) {
1156
984
  return this.request("GET", `/v1/index/sbtc/deposits${buildQuery({
@@ -1164,30 +992,8 @@ class Index extends BaseClient {
1164
992
  to_height: params.toHeight
1165
993
  })}`);
1166
994
  }
1167
- async* walkSbtcDeposits(params = {}) {
1168
- const batchSize = params.batchSize ?? 200;
1169
- let cursor = params.cursor ?? params.fromCursor ?? null;
1170
- let firstPage = true;
1171
- while (!params.signal?.aborted) {
1172
- const envelope = await this.listSbtcDeposits({
1173
- ...params,
1174
- limit: batchSize,
1175
- cursor: firstPage ? params.cursor : cursor,
1176
- fromCursor: firstPage ? params.fromCursor : undefined,
1177
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
1178
- });
1179
- for (const deposit of envelope.deposits) {
1180
- if (params.signal?.aborted)
1181
- return;
1182
- yield deposit;
1183
- }
1184
- const nextCursor = envelope.next_cursor;
1185
- if (!nextCursor || nextCursor === cursor || envelope.deposits.length < batchSize) {
1186
- return;
1187
- }
1188
- cursor = nextCursor;
1189
- firstPage = false;
1190
- }
995
+ walkSbtcDeposits(params = {}) {
996
+ return this.keysetWalk(params, (page) => this.listSbtcDeposits({ ...params, ...page }), (e) => e.deposits);
1191
997
  }
1192
998
  async getSbtcDeposit(bitcoinTxid) {
1193
999
  return this.requestOrNull("GET", `/v1/index/sbtc/deposits/${encodeURIComponent(bitcoinTxid)}`);
@@ -1206,30 +1012,8 @@ class Index extends BaseClient {
1206
1012
  to_height: params.toHeight
1207
1013
  })}`);
1208
1014
  }
1209
- async* walkSbtcWithdrawals(params = {}) {
1210
- const batchSize = params.batchSize ?? 200;
1211
- let cursor = params.cursor ?? params.fromCursor ?? null;
1212
- let firstPage = true;
1213
- while (!params.signal?.aborted) {
1214
- const envelope = await this.listSbtcWithdrawals({
1215
- ...params,
1216
- limit: batchSize,
1217
- cursor: firstPage ? params.cursor : cursor,
1218
- fromCursor: firstPage ? params.fromCursor : undefined,
1219
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
1220
- });
1221
- for (const withdrawal of envelope.withdrawals) {
1222
- if (params.signal?.aborted)
1223
- return;
1224
- yield withdrawal;
1225
- }
1226
- const nextCursor = envelope.next_cursor;
1227
- if (!nextCursor || nextCursor === cursor || envelope.withdrawals.length < batchSize) {
1228
- return;
1229
- }
1230
- cursor = nextCursor;
1231
- firstPage = false;
1232
- }
1015
+ walkSbtcWithdrawals(params = {}) {
1016
+ return this.keysetWalk(params, (page) => this.listSbtcWithdrawals({ ...params, ...page }), (e) => e.withdrawals);
1233
1017
  }
1234
1018
  async getSbtcWithdrawal(requestId) {
1235
1019
  return this.requestOrNull("GET", `/v1/index/sbtc/withdrawals/${requestId}`);
@@ -1248,30 +1032,8 @@ class Index extends BaseClient {
1248
1032
  to_height: params.toHeight
1249
1033
  })}`);
1250
1034
  }
1251
- async* walkSbtcEvents(params = {}) {
1252
- const batchSize = params.batchSize ?? 200;
1253
- let cursor = params.cursor ?? params.fromCursor ?? null;
1254
- let firstPage = true;
1255
- while (!params.signal?.aborted) {
1256
- const envelope = await this.listSbtcEvents({
1257
- ...params,
1258
- limit: batchSize,
1259
- cursor: firstPage ? params.cursor : cursor,
1260
- fromCursor: firstPage ? params.fromCursor : undefined,
1261
- fromHeight: firstPage ? firstWalkFromHeight(params) : undefined
1262
- });
1263
- for (const event of envelope.events) {
1264
- if (params.signal?.aborted)
1265
- return;
1266
- yield event;
1267
- }
1268
- const nextCursor = envelope.next_cursor;
1269
- if (!nextCursor || nextCursor === cursor || envelope.events.length < batchSize) {
1270
- return;
1271
- }
1272
- cursor = nextCursor;
1273
- firstPage = false;
1274
- }
1035
+ walkSbtcEvents(params = {}) {
1036
+ return this.keysetWalk(params, (page) => this.listSbtcEvents({ ...params, ...page }), (e) => e.events);
1275
1037
  }
1276
1038
  async getSbtcSummary() {
1277
1039
  return this.request("GET", "/v1/index/sbtc/summary");
@@ -2635,5 +2397,5 @@ export {
2635
2397
  ApiError
2636
2398
  };
2637
2399
 
2638
- //# debugId=560ACB6602920BFB64756E2164756E21
2400
+ //# debugId=A8092EB602106E7964756E2164756E21
2639
2401
  //# sourceMappingURL=index.js.map