aftermath-ts-sdk 3.1.0 → 3.1.1-dev.7352e83
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.js +25 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15980,7 +15980,7 @@ var init_wallet = __esm({
|
|
|
15980
15980
|
});
|
|
15981
15981
|
|
|
15982
15982
|
// src/packages/coin/api/coinApi.ts
|
|
15983
|
-
var _CoinApi, CoinApi;
|
|
15983
|
+
var MAX_COIN_FETCH_PAGES, _CoinApi, CoinApi;
|
|
15984
15984
|
var init_coinApi = __esm({
|
|
15985
15985
|
"src/packages/coin/api/coinApi.ts"() {
|
|
15986
15986
|
"use strict";
|
|
@@ -15988,6 +15988,7 @@ var init_coinApi = __esm({
|
|
|
15988
15988
|
init_grpcCasting();
|
|
15989
15989
|
init_helpers();
|
|
15990
15990
|
init_coin();
|
|
15991
|
+
MAX_COIN_FETCH_PAGES = 50;
|
|
15991
15992
|
_CoinApi = class _CoinApi {
|
|
15992
15993
|
// =========================================================================
|
|
15993
15994
|
// Constructor
|
|
@@ -16035,39 +16036,43 @@ var init_coinApi = __esm({
|
|
|
16035
16036
|
return coinArgs;
|
|
16036
16037
|
};
|
|
16037
16038
|
this.fetchCoinsWithAtLeastAmount = async (inputs) => {
|
|
16038
|
-
|
|
16039
|
+
const allCoinData = [];
|
|
16039
16040
|
let cursor;
|
|
16041
|
+
let pages = 0;
|
|
16040
16042
|
do {
|
|
16041
16043
|
const paginatedCoins = await this.api.client.listCoins({
|
|
16042
16044
|
coinType: inputs.coinType,
|
|
16043
16045
|
owner: inputs.walletAddress,
|
|
16044
16046
|
cursor
|
|
16045
16047
|
});
|
|
16046
|
-
|
|
16047
|
-
|
|
16048
|
+
pages += 1;
|
|
16049
|
+
allCoinData.push(
|
|
16050
|
+
...paginatedCoins.objects.map(GrpcCasting.coinStructFromGrpcCoin)
|
|
16048
16051
|
);
|
|
16049
|
-
allCoinData
|
|
16050
|
-
|
|
16051
|
-
|
|
16052
|
-
|
|
16053
|
-
);
|
|
16054
|
-
|
|
16055
|
-
|
|
16056
|
-
|
|
16057
|
-
coinDatas.push(coinData2);
|
|
16058
|
-
sum += BigInt(coinData2.balance);
|
|
16059
|
-
if (sum >= inputs.coinAmount) {
|
|
16060
|
-
return coinDatas;
|
|
16061
|
-
}
|
|
16052
|
+
allCoinData.sort((b, a) => Number(BigInt(a.balance) - BigInt(b.balance)));
|
|
16053
|
+
const selectedCoins = [];
|
|
16054
|
+
let sum = BigInt(0);
|
|
16055
|
+
for (const coinData of allCoinData) {
|
|
16056
|
+
selectedCoins.push(coinData);
|
|
16057
|
+
sum += BigInt(coinData.balance);
|
|
16058
|
+
if (sum >= inputs.coinAmount) {
|
|
16059
|
+
return selectedCoins;
|
|
16062
16060
|
}
|
|
16061
|
+
}
|
|
16062
|
+
if (paginatedCoins.objects.length === 0 || !paginatedCoins.hasNextPage || !paginatedCoins.cursor) {
|
|
16063
16063
|
throw new Error("wallet does not have coins of sufficient balance");
|
|
16064
16064
|
}
|
|
16065
|
+
if (pages >= MAX_COIN_FETCH_PAGES) {
|
|
16066
|
+
throw new Error(
|
|
16067
|
+
"wallet balance is spread across too many coin objects"
|
|
16068
|
+
);
|
|
16069
|
+
}
|
|
16065
16070
|
cursor = paginatedCoins.cursor;
|
|
16066
16071
|
} while (true);
|
|
16067
16072
|
};
|
|
16068
16073
|
// fetchCoinsUntilAmountReachedOrEnd
|
|
16069
16074
|
this.fetchAllCoins = async (inputs) => {
|
|
16070
|
-
|
|
16075
|
+
const allCoinData = [];
|
|
16071
16076
|
let cursor;
|
|
16072
16077
|
do {
|
|
16073
16078
|
const paginatedCoins = await this.api.client.listCoins({
|
|
@@ -16075,10 +16080,9 @@ var init_coinApi = __esm({
|
|
|
16075
16080
|
owner: inputs.walletAddress,
|
|
16076
16081
|
cursor
|
|
16077
16082
|
});
|
|
16078
|
-
|
|
16079
|
-
GrpcCasting.coinStructFromGrpcCoin
|
|
16083
|
+
allCoinData.push(
|
|
16084
|
+
...paginatedCoins.objects.map(GrpcCasting.coinStructFromGrpcCoin)
|
|
16080
16085
|
);
|
|
16081
|
-
allCoinData = [...allCoinData, ...coinData];
|
|
16082
16086
|
if (paginatedCoins.objects.length === 0 || !paginatedCoins.hasNextPage || !paginatedCoins.cursor) {
|
|
16083
16087
|
return allCoinData.sort(
|
|
16084
16088
|
(b, a) => Number(BigInt(b.coinObjectId) - BigInt(a.coinObjectId))
|