@alephium/web3 0.14.2 → 0.14.3
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/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/explorer-provider.js +1 -2
- package/dist/src/api/node-provider.js +14 -15
- package/dist/src/api/utils.d.ts +0 -5
- package/dist/src/api/utils.js +1 -30
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.js +2 -1
- package/package.json +1 -2
- package/src/api/explorer-provider.ts +1 -2
- package/src/api/node-provider.ts +1 -2
- package/src/api/utils.ts +0 -29
- package/src/constants.ts +1 -0
|
@@ -20,13 +20,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.ExplorerProvider = void 0;
|
|
21
21
|
const types_1 = require("./types");
|
|
22
22
|
const api_explorer_1 = require("./api-explorer");
|
|
23
|
-
const utils_1 = require("./utils");
|
|
24
23
|
function initializeExplorerApi(baseUrl, apiKey, customFetch) {
|
|
25
24
|
const explorerApi = new api_explorer_1.Api({
|
|
26
25
|
baseUrl: baseUrl,
|
|
27
26
|
baseApiParams: { secure: true },
|
|
28
27
|
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {}),
|
|
29
|
-
customFetch: customFetch ??
|
|
28
|
+
customFetch: customFetch ?? fetch
|
|
30
29
|
});
|
|
31
30
|
explorerApi.setSecurityData(apiKey ?? null);
|
|
32
31
|
return explorerApi;
|
|
@@ -20,14 +20,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.NodeProvider = void 0;
|
|
21
21
|
const types_1 = require("./types");
|
|
22
22
|
const api_alephium_1 = require("./api-alephium");
|
|
23
|
-
const utils_1 = require("
|
|
24
|
-
const utils_2 = require("../utils");
|
|
23
|
+
const utils_1 = require("../utils");
|
|
25
24
|
function initializeNodeApi(baseUrl, apiKey, customFetch) {
|
|
26
25
|
const nodeApi = new api_alephium_1.Api({
|
|
27
26
|
baseUrl: baseUrl,
|
|
28
27
|
baseApiParams: { secure: true },
|
|
29
28
|
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {}),
|
|
30
|
-
customFetch: customFetch ??
|
|
29
|
+
customFetch: customFetch ?? fetch
|
|
31
30
|
});
|
|
32
31
|
nodeApi.setSecurityData(apiKey ?? null);
|
|
33
32
|
return nodeApi;
|
|
@@ -39,8 +38,8 @@ class NodeProvider {
|
|
|
39
38
|
};
|
|
40
39
|
// Only use this when the token follows the fungible token interface, check `guessTokenType` first
|
|
41
40
|
this.fetchFungibleTokenMetaData = async (tokenId) => {
|
|
42
|
-
const address = (0,
|
|
43
|
-
const group = (0,
|
|
41
|
+
const address = (0, utils_1.addressFromTokenId)(tokenId);
|
|
42
|
+
const group = (0, utils_1.groupOfAddress)(address);
|
|
44
43
|
const calls = Array.from([0, 1, 2, 3], (index) => ({ methodIndex: index, group: group, address: address }));
|
|
45
44
|
const result = await this.contracts.postContractsMulticallContract({
|
|
46
45
|
calls: calls
|
|
@@ -54,32 +53,32 @@ class NodeProvider {
|
|
|
54
53
|
};
|
|
55
54
|
// Only use this when the token follows the non-fungile token interface, check `guessTokenType` first
|
|
56
55
|
this.fetchNFTMetaData = async (tokenId) => {
|
|
57
|
-
const address = (0,
|
|
58
|
-
const group = (0,
|
|
56
|
+
const address = (0, utils_1.addressFromTokenId)(tokenId);
|
|
57
|
+
const group = (0, utils_1.groupOfAddress)(address);
|
|
59
58
|
const calls = Array.from([0, 1], (index) => ({ methodIndex: index, group: group, address: address }));
|
|
60
59
|
const result = await this.contracts.postContractsMulticallContract({
|
|
61
60
|
calls: calls
|
|
62
61
|
});
|
|
63
62
|
return {
|
|
64
|
-
tokenUri: (0,
|
|
65
|
-
collectionAddress: (0,
|
|
63
|
+
tokenUri: (0, utils_1.hexToString)(result.results[0].returns[0].value),
|
|
64
|
+
collectionAddress: (0, utils_1.addressFromContractId)(result.results[1].returns[0].value)
|
|
66
65
|
};
|
|
67
66
|
};
|
|
68
67
|
// Only use this when the contract follows the NFT collection interface, check `guessFollowsNFTCollectionStd` first
|
|
69
68
|
this.fetchNFTCollectionMetaData = async (contractId) => {
|
|
70
|
-
const address = (0,
|
|
71
|
-
const group = (0,
|
|
69
|
+
const address = (0, utils_1.addressFromContractId)(contractId);
|
|
70
|
+
const group = (0, utils_1.groupOfAddress)(address);
|
|
72
71
|
const calls = Array.from([0, 1], (index) => ({ methodIndex: index, group: group, address: address }));
|
|
73
72
|
const result = await this.contracts.postContractsMulticallContract({ calls });
|
|
74
73
|
return {
|
|
75
|
-
collectionUri: (0,
|
|
74
|
+
collectionUri: (0, utils_1.hexToString)(result.results[0].returns[0].value),
|
|
76
75
|
totalSupply: BigInt(result.results[1].returns[0].value)
|
|
77
76
|
};
|
|
78
77
|
};
|
|
79
78
|
this.guessStdInterfaceId = async (tokenId) => {
|
|
80
|
-
const address = (0,
|
|
81
|
-
const group = (0,
|
|
82
|
-
const rawState = await this.contracts.getContractsAddressState((0,
|
|
79
|
+
const address = (0, utils_1.addressFromTokenId)(tokenId);
|
|
80
|
+
const group = (0, utils_1.groupOfAddress)(address);
|
|
81
|
+
const rawState = await this.contracts.getContractsAddressState((0, utils_1.addressFromTokenId)(tokenId), { group });
|
|
83
82
|
const lastImmField = rawState.immFields.slice(-1).pop()?.value;
|
|
84
83
|
const interfaceIdPrefix = '414c5048'; // the hex of 'ALPH'
|
|
85
84
|
if (typeof lastImmField === 'string' && lastImmField.startsWith(interfaceIdPrefix)) {
|
package/dist/src/api/utils.d.ts
CHANGED
|
@@ -6,8 +6,3 @@ export declare function convertHttpResponse<T>(response: {
|
|
|
6
6
|
detail: string;
|
|
7
7
|
};
|
|
8
8
|
}): T;
|
|
9
|
-
export declare function retryFetch(...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
10
|
-
export declare function throttledFetch(ratePerSec: number): typeof fetch;
|
|
11
|
-
export declare const RETRY_LIMIT_WHEN_429 = 3;
|
|
12
|
-
export declare const DEFAULT_RATE_LIMIT = 3;
|
|
13
|
-
export declare const DEFAULT_THROTTLE_FETCH: typeof fetch;
|
package/dist/src/api/utils.js
CHANGED
|
@@ -17,10 +17,8 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
20
|
+
exports.convertHttpResponse = void 0;
|
|
21
21
|
require("cross-fetch/polyfill");
|
|
22
|
-
const utils_1 = require("../utils");
|
|
23
|
-
const async_sema_1 = require("async-sema");
|
|
24
22
|
function convertHttpResponse(response) {
|
|
25
23
|
if (response.error) {
|
|
26
24
|
const errorMessage = response.error.detail ?? `status code: ${response.status}`;
|
|
@@ -31,30 +29,3 @@ function convertHttpResponse(response) {
|
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
exports.convertHttpResponse = convertHttpResponse;
|
|
34
|
-
async function retryFetch(...fetchParams) {
|
|
35
|
-
const retry = async (retryCount) => {
|
|
36
|
-
const response = await fetch(...fetchParams);
|
|
37
|
-
if (response.status === 429 && retryCount < exports.RETRY_LIMIT_WHEN_429) {
|
|
38
|
-
const nextCount = retryCount + 1;
|
|
39
|
-
await (0, utils_1.sleep)(nextCount * 500);
|
|
40
|
-
return await retry(nextCount);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return response;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
return retry(0);
|
|
47
|
-
}
|
|
48
|
-
exports.retryFetch = retryFetch;
|
|
49
|
-
function throttledFetch(ratePerSec) {
|
|
50
|
-
const limit = (0, async_sema_1.RateLimit)(ratePerSec);
|
|
51
|
-
const customFetch = async (...fetchParams) => {
|
|
52
|
-
await limit();
|
|
53
|
-
return retryFetch(...fetchParams);
|
|
54
|
-
};
|
|
55
|
-
return customFetch;
|
|
56
|
-
}
|
|
57
|
-
exports.throttledFetch = throttledFetch;
|
|
58
|
-
exports.RETRY_LIMIT_WHEN_429 = 3;
|
|
59
|
-
exports.DEFAULT_RATE_LIMIT = 3;
|
|
60
|
-
exports.DEFAULT_THROTTLE_FETCH = throttledFetch(exports.DEFAULT_RATE_LIMIT);
|
package/dist/src/constants.d.ts
CHANGED
package/dist/src/constants.js
CHANGED
|
@@ -17,10 +17,11 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
20
|
+
exports.ZERO_ADDRESS = exports.DUST_AMOUNT = exports.ONE_ALPH = exports.ALPH_TOKEN_ID = exports.MIN_UTXO_SET_AMOUNT = exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS = void 0;
|
|
21
21
|
exports.TOTAL_NUMBER_OF_GROUPS = 4;
|
|
22
22
|
exports.TOTAL_NUMBER_OF_CHAINS = exports.TOTAL_NUMBER_OF_GROUPS * exports.TOTAL_NUMBER_OF_GROUPS;
|
|
23
23
|
exports.MIN_UTXO_SET_AMOUNT = BigInt(1000000000000);
|
|
24
24
|
exports.ALPH_TOKEN_ID = ''.padStart(64, '0');
|
|
25
25
|
exports.ONE_ALPH = 10n ** 18n;
|
|
26
26
|
exports.DUST_AMOUNT = 10n ** 15n;
|
|
27
|
+
exports.ZERO_ADDRESS = 'tgx7VNFoP9DJiFMFgXXtafQZkUvyEdDHT9ryamHJYrjq';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"type": "commonjs",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@noble/secp256k1": "1.7.1",
|
|
36
|
-
"async-sema": "^3.1.1",
|
|
37
36
|
"base-x": "4.0.0",
|
|
38
37
|
"bignumber.js": "^9.1.1",
|
|
39
38
|
"blakejs": "1.2.1",
|
|
@@ -18,14 +18,13 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
|
|
19
19
|
import { ApiRequestArguments, ApiRequestHandler, forwardRequests, request } from './types'
|
|
20
20
|
import { Api as ExplorerApi } from './api-explorer'
|
|
21
|
-
import { DEFAULT_THROTTLE_FETCH } from './utils'
|
|
22
21
|
|
|
23
22
|
function initializeExplorerApi(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): ExplorerApi<string> {
|
|
24
23
|
const explorerApi = new ExplorerApi<string>({
|
|
25
24
|
baseUrl: baseUrl,
|
|
26
25
|
baseApiParams: { secure: true },
|
|
27
26
|
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {}),
|
|
28
|
-
customFetch: customFetch ??
|
|
27
|
+
customFetch: customFetch ?? fetch
|
|
29
28
|
})
|
|
30
29
|
explorerApi.setSecurityData(apiKey ?? null)
|
|
31
30
|
return explorerApi
|
package/src/api/node-provider.ts
CHANGED
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
StdInterfaceIds
|
|
28
28
|
} from './types'
|
|
29
29
|
import { Api as NodeApi } from './api-alephium'
|
|
30
|
-
import { DEFAULT_THROTTLE_FETCH } from './utils'
|
|
31
30
|
import { HexString } from '../contract'
|
|
32
31
|
import { addressFromContractId, addressFromTokenId, groupOfAddress, hexToString } from '../utils'
|
|
33
32
|
|
|
@@ -36,7 +35,7 @@ function initializeNodeApi(baseUrl: string, apiKey?: string, customFetch?: typeo
|
|
|
36
35
|
baseUrl: baseUrl,
|
|
37
36
|
baseApiParams: { secure: true },
|
|
38
37
|
securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {}),
|
|
39
|
-
customFetch: customFetch ??
|
|
38
|
+
customFetch: customFetch ?? fetch
|
|
40
39
|
})
|
|
41
40
|
nodeApi.setSecurityData(apiKey ?? null)
|
|
42
41
|
return nodeApi
|
package/src/api/utils.ts
CHANGED
|
@@ -17,8 +17,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import 'cross-fetch/polyfill'
|
|
20
|
-
import { sleep } from '../utils'
|
|
21
|
-
import { RateLimit } from 'async-sema'
|
|
22
20
|
|
|
23
21
|
export function convertHttpResponse<T>(response: { status: number; data: T; error?: { detail: string } }): T {
|
|
24
22
|
if (response.error) {
|
|
@@ -28,30 +26,3 @@ export function convertHttpResponse<T>(response: { status: number; data: T; erro
|
|
|
28
26
|
return response.data
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
export async function retryFetch(...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch> {
|
|
33
|
-
const retry = async (retryCount: number): ReturnType<typeof fetch> => {
|
|
34
|
-
const response = await fetch(...fetchParams)
|
|
35
|
-
if (response.status === 429 && retryCount < RETRY_LIMIT_WHEN_429) {
|
|
36
|
-
const nextCount = retryCount + 1
|
|
37
|
-
await sleep(nextCount * 500)
|
|
38
|
-
return await retry(nextCount)
|
|
39
|
-
} else {
|
|
40
|
-
return response
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return retry(0)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function throttledFetch(ratePerSec: number): typeof fetch {
|
|
47
|
-
const limit = RateLimit(ratePerSec)
|
|
48
|
-
const customFetch = async (...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch> => {
|
|
49
|
-
await limit()
|
|
50
|
-
return retryFetch(...fetchParams)
|
|
51
|
-
}
|
|
52
|
-
return customFetch
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const RETRY_LIMIT_WHEN_429 = 3
|
|
56
|
-
export const DEFAULT_RATE_LIMIT = 3
|
|
57
|
-
export const DEFAULT_THROTTLE_FETCH = throttledFetch(DEFAULT_RATE_LIMIT)
|
package/src/constants.ts
CHANGED