dash-platform-sdk 1.5.0 → 1.5.2
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/README.md +15 -15
- package/bundle.min.js +1 -1
- package/index.d.ts +4 -1
- package/index.js +3 -1
- package/package.json +1 -1
- package/proto/generated/platform.client.d.ts +10 -0
- package/proto/generated/platform.client.js +25 -18
- package/proto/generated/platform.d.ts +162 -0
- package/proto/generated/platform.js +351 -0
- package/src/DashPlatformSDK.d.ts +19 -7
- package/src/DashPlatformSDK.js +33 -3
- package/src/contestedResources/getContestedResourceVoteState.d.ts +2 -2
- package/src/contestedResources/index.d.ts +3 -3
- package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -2
- package/src/dataContracts/index.d.ts +3 -3
- package/src/documents/index.d.ts +3 -3
- package/src/documents/query.d.ts +2 -2
- package/src/grpcConnectionPool.d.ts +19 -2
- package/src/grpcConnectionPool.js +44 -16
- package/src/identities/getIdentityBalance.d.ts +2 -2
- package/src/identities/getIdentityByIdentifier.d.ts +2 -2
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +2 -2
- package/src/identities/getIdentityByPublicKeyHash.d.ts +2 -2
- package/src/identities/getIdentityContractNonce.d.ts +2 -2
- package/src/identities/getIdentityNonce.d.ts +2 -2
- package/src/identities/getIdentityPublicKeys.d.ts +2 -2
- package/src/identities/index.d.ts +3 -3
- package/src/names/index.d.ts +3 -3
- package/src/names/registerName.d.ts +2 -2
- package/src/names/searchByIdentity.d.ts +2 -2
- package/src/names/searchByName.d.ts +2 -2
- package/src/node/epochInfos.d.ts +2 -2
- package/src/node/finalizedEpochInfos.d.ts +2 -2
- package/src/node/getCurrentQuorumsInfo.d.ts +19 -0
- package/src/node/getCurrentQuorumsInfo.js +31 -0
- package/src/node/index.d.ts +11 -3
- package/src/node/index.js +10 -0
- package/src/node/status.d.ts +2 -2
- package/src/node/totalCredits.d.ts +2 -2
- package/src/platformAddresses/getAddressInfo.d.ts +2 -2
- package/src/platformAddresses/getAddressesBranchState.d.ts +2 -2
- package/src/platformAddresses/getAddressesInfos.d.ts +2 -2
- package/src/platformAddresses/getAddressesTrunkState.d.ts +2 -2
- package/src/platformAddresses/getRecentAddressBalanceChanges.d.ts +2 -2
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.d.ts +2 -2
- package/src/platformAddresses/index.d.ts +3 -3
- package/src/shielded/getMostRecentShieldedAnchor.d.ts +2 -2
- package/src/shielded/getShieldedAnchors.d.ts +2 -2
- package/src/shielded/getShieldedEncryptedNotes.d.ts +2 -2
- package/src/shielded/getShieldedNotesCount.d.ts +2 -2
- package/src/shielded/getShieldedNullifiers.d.ts +2 -2
- package/src/shielded/getShieldedPoolState.d.ts +2 -2
- package/src/shielded/index.d.ts +3 -3
- package/src/stateTransitions/broadcast.d.ts +2 -2
- package/src/stateTransitions/index.d.ts +3 -3
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +2 -2
- package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -2
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -2
- package/src/tokens/getTokenContractInfo.d.ts +2 -2
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -2
- package/src/tokens/getTokenTotalSupply.d.ts +2 -2
- package/src/tokens/index.d.ts +3 -3
- package/src/utils/fetchWithDetails.d.ts +24 -0
- package/src/utils/fetchWithDetails.js +71 -0
- package/src/utils/getQuorumPublicKey.js +2 -1
- package/test/unit/ContestedResources.spec.js +2 -1
- package/test/unit/DataContract.spec.js +2 -1
- package/test/unit/Document.spec.js +2 -1
- package/test/unit/Identity.spec.js +2 -1
- package/test/unit/Names.spec.js +2 -1
- package/test/unit/Node.spec.js +20 -1
- package/test/unit/PlatformAddress.spec.js +2 -1
- package/test/unit/Shielded.spec.js +1 -0
- package/test/unit/Tokens.spec.js +2 -1
- package/src/utils/getEvonodeList.d.ts +0 -2
- package/src/utils/getEvonodeList.js +0 -12
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collects human-readable details from a fetch error and its nested causes.
|
|
3
|
+
* Node.js (undici) throws a generic `TypeError: fetch failed` and puts the real
|
|
4
|
+
* reason (ECONNREFUSED, ENOTFOUND, certificate errors, timeouts...) in `error.cause`,
|
|
5
|
+
* which may itself be nested or an AggregateError
|
|
6
|
+
*
|
|
7
|
+
* @param error {unknown}
|
|
8
|
+
* @return {string[]}
|
|
9
|
+
*/
|
|
10
|
+
export function decodeFetchErrorDetails(error) {
|
|
11
|
+
const details = [];
|
|
12
|
+
const seen = new Set();
|
|
13
|
+
const visit = (err) => {
|
|
14
|
+
if (err == null || seen.has(err)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
seen.add(err);
|
|
18
|
+
if (typeof err !== 'object') {
|
|
19
|
+
details.push(String(err));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const { code, message, cause, errors } = err;
|
|
23
|
+
const detail = [code, message]
|
|
24
|
+
.filter(e => e != null && e !== '')
|
|
25
|
+
.map(String)
|
|
26
|
+
.filter((e, i, arr) => arr.indexOf(e) === i)
|
|
27
|
+
.join(': ');
|
|
28
|
+
if (detail !== '' && !details.includes(detail)) {
|
|
29
|
+
details.push(detail);
|
|
30
|
+
}
|
|
31
|
+
if (Array.isArray(errors)) {
|
|
32
|
+
errors.forEach(visit);
|
|
33
|
+
}
|
|
34
|
+
visit(cause);
|
|
35
|
+
};
|
|
36
|
+
visit(error);
|
|
37
|
+
return details;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Wraps an error thrown by fetch into a new Error that includes the
|
|
41
|
+
* request url and all nested causes in its message, keeping the original as `cause`
|
|
42
|
+
*
|
|
43
|
+
* @param error {unknown}
|
|
44
|
+
* @param url {string}
|
|
45
|
+
* @return {Error}
|
|
46
|
+
*/
|
|
47
|
+
export function decodeFetchError(error, url) {
|
|
48
|
+
const [message, ...causes] = decodeFetchErrorDetails(error);
|
|
49
|
+
const decoded = new Error(`${message ?? 'fetch failed'} (${url})${causes.length > 0 ? `: ${causes.join(' <- ')}` : ''}`, { cause: error });
|
|
50
|
+
if (error instanceof Error) {
|
|
51
|
+
decoded.name = error.name;
|
|
52
|
+
}
|
|
53
|
+
return decoded;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Drop-in replacement for global fetch that rethrows network errors
|
|
57
|
+
* with decoded details instead of opaque `fetch failed`
|
|
58
|
+
*/
|
|
59
|
+
export const fetchWithDetails = async (input, init) => {
|
|
60
|
+
try {
|
|
61
|
+
return await globalThis.fetch(input, init);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
// keep abort errors untouched so callers can detect cancellation
|
|
65
|
+
if (e instanceof Error && e.name === 'AbortError') {
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
68
|
+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
69
|
+
throw decodeFetchError(e, url);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fetchWithDetails } from './fetchWithDetails.js';
|
|
1
2
|
const cache = {};
|
|
2
3
|
export async function getQuorumPublicKey(network, quorumType, quorumHash) {
|
|
3
4
|
const cached = cache[`${quorumType}_${quorumHash}`];
|
|
@@ -5,7 +6,7 @@ export async function getQuorumPublicKey(network, quorumType, quorumHash) {
|
|
|
5
6
|
return cached;
|
|
6
7
|
}
|
|
7
8
|
const url = `https://${network === 'mainnet' ? '' : 'testnet.'}platform-explorer.pshenmic.dev/quorum/info?quorumType=${quorumType}&quorumHash=${quorumHash}`;
|
|
8
|
-
const resp = await
|
|
9
|
+
const resp = await fetchWithDetails(url, {
|
|
9
10
|
method: 'GET'
|
|
10
11
|
});
|
|
11
12
|
if (resp.status !== 200) {
|
|
@@ -5,8 +5,9 @@ import { LATEST_PLATFORM_VERSION } from '../../src/constants.js';
|
|
|
5
5
|
let sdk;
|
|
6
6
|
let contract;
|
|
7
7
|
describe('Contested Resources', () => {
|
|
8
|
-
beforeAll(() => {
|
|
8
|
+
beforeAll(async () => {
|
|
9
9
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
10
|
+
await sdk.waitForInit();
|
|
10
11
|
contract = new DataContractWASM('11111111111111111111111111111111', BigInt(1), {
|
|
11
12
|
domain: {
|
|
12
13
|
type: 'object',
|
|
@@ -6,8 +6,9 @@ let identityNonce;
|
|
|
6
6
|
let config;
|
|
7
7
|
let schema;
|
|
8
8
|
describe('DataContract', () => {
|
|
9
|
-
beforeAll(() => {
|
|
9
|
+
beforeAll(async () => {
|
|
10
10
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
11
|
+
await sdk.waitForInit();
|
|
11
12
|
ownerIdentifier = 'GARSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
12
13
|
identityNonce = BigInt(11);
|
|
13
14
|
config = {
|
|
@@ -7,8 +7,9 @@ let documentType;
|
|
|
7
7
|
let revision;
|
|
8
8
|
let data;
|
|
9
9
|
describe('Document', () => {
|
|
10
|
-
beforeAll(() => {
|
|
10
|
+
beforeAll(async () => {
|
|
11
11
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
12
|
+
await sdk.waitForInit();
|
|
12
13
|
dataContract = '6QMfQTdKpC3Y9uWBcTwXeY3KdzRLDqASUsDnQ4MEc9XC';
|
|
13
14
|
identity = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
14
15
|
revision = BigInt(1);
|
|
@@ -3,8 +3,9 @@ import { DashPlatformSDK } from '../../types.js';
|
|
|
3
3
|
import { base58 } from '@scure/base';
|
|
4
4
|
let sdk;
|
|
5
5
|
describe('Identity', () => {
|
|
6
|
-
beforeAll(() => {
|
|
6
|
+
beforeAll(async () => {
|
|
7
7
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
8
|
+
await sdk.waitForInit();
|
|
8
9
|
});
|
|
9
10
|
test('should be able to get identity by identifier', async () => {
|
|
10
11
|
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
package/test/unit/Names.spec.js
CHANGED
|
@@ -7,8 +7,9 @@ jest.mock('../../src/stateTransitions/broadcast');
|
|
|
7
7
|
jest.mock('../../src/utils/sleep');
|
|
8
8
|
let sdk;
|
|
9
9
|
describe('DPNS names', () => {
|
|
10
|
-
beforeAll(() => {
|
|
10
|
+
beforeAll(async () => {
|
|
11
11
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
12
|
+
await sdk.waitForInit();
|
|
12
13
|
// @ts-expect-error
|
|
13
14
|
sleep.mockReturnValue(Promise.resolve());
|
|
14
15
|
sdk.stateTransitions.broadcast = jest.fn();
|
package/test/unit/Node.spec.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
2
2
|
let sdk;
|
|
3
3
|
describe('Node', () => {
|
|
4
|
-
beforeAll(() => {
|
|
4
|
+
beforeAll(async () => {
|
|
5
5
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
6
|
+
await sdk.waitForInit();
|
|
6
7
|
});
|
|
7
8
|
test('should be able to call getStatus', async () => {
|
|
8
9
|
const status = await sdk.node.status();
|
|
@@ -61,4 +62,22 @@ describe('Node', () => {
|
|
|
61
62
|
const totalCredits = await sdk.node.totalCredits();
|
|
62
63
|
expect(Number(totalCredits)).toBeGreaterThan(0);
|
|
63
64
|
});
|
|
65
|
+
test('should be able to call getCurrentQuorumsInfo', async () => {
|
|
66
|
+
const quorumsInfo = await sdk.node.getCurrentQuorumsInfo();
|
|
67
|
+
expect(quorumsInfo.quorumHashes.length).toBeGreaterThan(0);
|
|
68
|
+
expect(quorumsInfo.currentQuorumHash).toMatch(/^[0-9a-f]{64}$/);
|
|
69
|
+
expect(quorumsInfo.lastBlockProposer).toMatch(/^[0-9a-f]{64}$/);
|
|
70
|
+
expect(quorumsInfo.validatorSets.length).toBeGreaterThan(0);
|
|
71
|
+
for (const validatorSet of quorumsInfo.validatorSets) {
|
|
72
|
+
expect(validatorSet.quorumHash).toMatch(/^[0-9a-f]{64}$/);
|
|
73
|
+
expect(validatorSet.coreHeight).toBeGreaterThan(0);
|
|
74
|
+
expect(validatorSet.thresholdPublicKey).toMatch(/^[0-9a-f]{96}$/);
|
|
75
|
+
expect(validatorSet.members.length).toBeGreaterThan(0);
|
|
76
|
+
for (const member of validatorSet.members) {
|
|
77
|
+
expect(member.proTxHash).toMatch(/^[0-9a-f]{64}$/);
|
|
78
|
+
expect(member.nodeIp).toEqual(expect.any(String));
|
|
79
|
+
expect(member.isBanned).toEqual(expect.any(Boolean));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
64
83
|
});
|
|
@@ -3,8 +3,9 @@ import { base58 } from '@scure/base';
|
|
|
3
3
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
4
4
|
let sdk;
|
|
5
5
|
describe('PlatformAddress', () => {
|
|
6
|
-
beforeAll(() => {
|
|
6
|
+
beforeAll(async () => {
|
|
7
7
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
8
|
+
await sdk.waitForInit();
|
|
8
9
|
});
|
|
9
10
|
test('getAddressInfo', async () => {
|
|
10
11
|
const info = await sdk.platformAddresses.getAddressInfo('tdash1kzg5azscav69z7m6dfzr9ner0a5vt7pn9ca4sz8d');
|
|
@@ -37,6 +37,7 @@ function makeSpendableNote(seed, value) {
|
|
|
37
37
|
describe('Shielded', () => {
|
|
38
38
|
beforeAll(async () => {
|
|
39
39
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
40
|
+
await sdk.waitForInit();
|
|
40
41
|
await sdk.shielded.init();
|
|
41
42
|
}, 60000);
|
|
42
43
|
test('getShieldedNotesCount', async () => {
|
package/test/unit/Tokens.spec.js
CHANGED
|
@@ -2,8 +2,9 @@ import { StateTransitionWASM, TokenBaseTransitionWASM, TokenEmergencyActionWASM
|
|
|
2
2
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
3
3
|
let sdk;
|
|
4
4
|
describe('Tokens', () => {
|
|
5
|
-
beforeAll(() => {
|
|
5
|
+
beforeAll(async () => {
|
|
6
6
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
7
|
+
await sdk.waitForInit();
|
|
7
8
|
});
|
|
8
9
|
test('should be able to get token total supply', async () => {
|
|
9
10
|
const tokenTotalSupply = await sdk.tokens.getTokenTotalSupply('9YxdbQUjJmQsmVPen95HjAU3Esj7tVkWSY2EQWT84ZQP');
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export default async function getDAPINodeList(network) {
|
|
2
|
-
const url = `https://${network === 'mainnet' ? '' : 'testnet.'}platform-explorer.pshenmic.dev/validators?isActive=true`;
|
|
3
|
-
const resp = await fetch(url);
|
|
4
|
-
if (resp.status !== 200) {
|
|
5
|
-
throw new Error('Failed to query Platform Explorer for active validators');
|
|
6
|
-
}
|
|
7
|
-
const { resultSet } = await resp.json();
|
|
8
|
-
return resultSet
|
|
9
|
-
// eslint-disable-next-line
|
|
10
|
-
.map((validator) => validator?.proTxInfo?.state?.service ? `https://${validator.proTxInfo.state.service.split(':')[0]}${network === 'mainnet' ? '' : ':1443'}` : undefined)
|
|
11
|
-
.filter(e => e != null);
|
|
12
|
-
}
|