dash-platform-sdk 1.6.0-dev.7 → 1.6.0-dev.9
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 +14 -14
- package/bundle.min.js +1 -1
- package/package.json +2 -2
- package/proto/generated/platform.client.d.ts +10 -0
- package/proto/generated/platform.client.js +7 -0
- package/proto/generated/platform.d.ts +137 -0
- package/proto/generated/platform.js +279 -1
- package/src/QueryExecutor.d.ts +40 -4
- package/src/QueryExecutor.js +61 -8
- package/src/constants.d.ts +7 -1
- package/src/constants.js +9 -2
- package/src/contestedResources/getContestedResourceVoteState.js +14 -6
- package/src/contestedResources/getVotePollsByEndDate.js +7 -2
- package/src/dataContracts/getDataContractByIdentifier.js +3 -3
- package/src/documents/index.d.ts +4 -1
- package/src/documents/index.js +6 -2
- package/src/documents/query.js +4 -4
- package/src/documents/queryAggregate.js +2 -3
- package/src/documents/queryJoined.js +6 -7
- package/src/documents/queryRanked.js +2 -3
- package/src/documents/v1.d.ts +2 -2
- package/src/documents/v1.js +2 -3
- package/src/grpcConnectionPool.d.ts +9 -2
- package/src/grpcConnectionPool.js +7 -8
- package/src/identities/getIdentityBalance.js +1 -2
- package/src/identities/getIdentityByIdentifier.js +1 -2
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +2 -3
- package/src/identities/getIdentityByPublicKeyHash.js +1 -2
- package/src/identities/getIdentityContractNonce.js +1 -2
- package/src/identities/getIdentityNonce.js +1 -2
- package/src/identities/getIdentityPublicKeys.js +1 -2
- package/src/names/index.d.ts +1 -1
- package/src/names/index.js +1 -1
- package/src/names/registerName.js +5 -2
- package/src/node/epochInfos.js +1 -2
- package/src/node/finalizedEpochInfos.js +1 -2
- package/src/node/getPathElements.d.ts +4 -0
- package/src/node/getPathElements.js +27 -0
- package/src/node/getProtocolVersion.d.ts +9 -0
- package/src/node/getProtocolVersion.js +29 -0
- package/src/node/index.d.ts +20 -0
- package/src/node/index.js +25 -0
- package/src/node/totalCredits.js +3 -3
- package/src/platformAddresses/getAddressInfo.js +1 -2
- package/src/platformAddresses/getAddressesBranchState.js +1 -2
- package/src/platformAddresses/getAddressesInfos.js +1 -2
- package/src/platformAddresses/getAddressesTrunkState.js +1 -2
- package/src/platformAddresses/getRecentAddressBalanceChanges.js +2 -2
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +2 -2
- package/src/shielded/getMostRecentShieldedAnchor.js +1 -2
- package/src/shielded/getShieldedAnchors.js +1 -2
- package/src/shielded/getShieldedEncryptedNotes.js +2 -2
- package/src/shielded/getShieldedNotesCount.js +1 -2
- package/src/shielded/getShieldedNullifiers.js +1 -2
- package/src/shielded/getShieldedPoolState.js +1 -2
- package/src/stateTransitions/waitForStateTransitionResult.js +13 -11
- package/src/tokens/getIdentitiesTokenBalances.js +1 -2
- package/src/tokens/getIdentityTokensBalances.js +1 -2
- package/src/tokens/getTokenContractInfo.js +1 -2
- package/src/tokens/getTokenDirectPurchasePrices.js +1 -2
- package/src/tokens/getTokenTotalSupply.js +1 -2
- package/test/integration/MainnetCompatibility.spec.d.ts +1 -0
- package/test/integration/MainnetCompatibility.spec.js +373 -0
- package/test/unit/Node.spec.js +17 -0
- package/test/unit/SDK.spec.js +38 -0
package/src/QueryExecutor.js
CHANGED
|
@@ -2,6 +2,7 @@ import bytesToHex from './utils/bytesToHex.js';
|
|
|
2
2
|
import verifyTenderdashProof from './utils/verifyTenderdashProof.js';
|
|
3
3
|
import ProofError from './utils/ProofError.js';
|
|
4
4
|
import sleep from './utils/sleep.js';
|
|
5
|
+
import { LATEST_PLATFORM_VERSION, MIN_PROTOCOL_VERSION } from './constants.js';
|
|
5
6
|
const RETRY_DELAY_MS = 10;
|
|
6
7
|
/**
|
|
7
8
|
* Returns the versioned body of a request or a response (e.g. `version.v0`)
|
|
@@ -13,6 +14,42 @@ function getVersionBody(message) {
|
|
|
13
14
|
}
|
|
14
15
|
return version[version.oneofKind];
|
|
15
16
|
}
|
|
17
|
+
// highest protocol version of the verified responses of the pool, unlike `grpcPool.protocolVersion` it is never seeded
|
|
18
|
+
const verifiedProtocolVersions = new WeakMap();
|
|
19
|
+
/**
|
|
20
|
+
* Returns the highest protocol version of the responses of the pool whose proof and quorum signature were verified,
|
|
21
|
+
* or undefined if no response was verified yet
|
|
22
|
+
*/
|
|
23
|
+
export function getVerifiedProtocolVersion(grpcPool) {
|
|
24
|
+
return verifiedProtocolVersions.get(grpcPool);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the protocol version of the pool, the lowest version the network runs if it was not learned yet
|
|
28
|
+
*/
|
|
29
|
+
export function getPoolProtocolVersion(grpcPool) {
|
|
30
|
+
return Math.min(grpcPool.protocolVersion ?? MIN_PROTOCOL_VERSION[grpcPool.network], LATEST_PLATFORM_VERSION);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the platform version to verify a response signed with the given protocol version.
|
|
34
|
+
* A newer signed version is used (up to the latest version known to the SDK), an older one is not,
|
|
35
|
+
* so a node behind the network fails the verification and the request is sent to another node.
|
|
36
|
+
*
|
|
37
|
+
* Choosing the version before the quorum signature is verified is safe:
|
|
38
|
+
* the signature covers the protocol version, so a false version fails the verification
|
|
39
|
+
*/
|
|
40
|
+
export function getVerifierVersion(protocolVersion, signedProtocolVersion) {
|
|
41
|
+
return Math.min(Math.max(protocolVersion, signedProtocolVersion), LATEST_PLATFORM_VERSION);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Raises the protocol version of the pool to the one of a response whose proof and quorum signature were verified.
|
|
45
|
+
* The version is never lowered, versions unknown to the SDK are ignored
|
|
46
|
+
*/
|
|
47
|
+
function updateProtocolVersion(grpcPool, signedProtocolVersion) {
|
|
48
|
+
verifiedProtocolVersions.set(grpcPool, Math.max(verifiedProtocolVersions.get(grpcPool) ?? 0, signedProtocolVersion));
|
|
49
|
+
if (signedProtocolVersion > getPoolProtocolVersion(grpcPool) && signedProtocolVersion <= LATEST_PLATFORM_VERSION) {
|
|
50
|
+
grpcPool.protocolVersion = signedProtocolVersion;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
16
53
|
/**
|
|
17
54
|
* Returns the proof and the metadata of a v0 response, requested with `prove: true`
|
|
18
55
|
*/
|
|
@@ -34,9 +71,12 @@ export function getResponseProof(response) {
|
|
|
34
71
|
* Sends a GRPC request to a node from the pool and returns the mapped result of the response.
|
|
35
72
|
*
|
|
36
73
|
* Queries are requested with proofs, unless proofs are disabled in the pool (`grpcPool.proofs === false`):
|
|
37
|
-
* - with proofs: request (`prove: true`) -> proof mapping -> GroveDB proof verification -> quorum signature verification -> mapping
|
|
74
|
+
* - with proofs: request (`prove: true`) -> proof mapping -> GroveDB proof verification -> quorum signature verification -> protocol version update -> mapping
|
|
38
75
|
* - without proofs: request (`prove: false`) -> mapping of the response result
|
|
39
76
|
*
|
|
77
|
+
* The protocol version of the pool is raised to the protocol version of the verified responses,
|
|
78
|
+
* the platform version to verify the proof with is passed to the args callback of the proof verifier, see {getVerifierVersion}
|
|
79
|
+
*
|
|
40
80
|
* `mapResponse` handles both cases, the verified data or the response result, see {QueryData}.
|
|
41
81
|
* Requests without the `prove` field are always proved
|
|
42
82
|
*
|
|
@@ -46,7 +86,7 @@ export function getResponseProof(response) {
|
|
|
46
86
|
* @example
|
|
47
87
|
* const balance = await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
48
88
|
* .setGrpcRequest('getIdentityBalance', request)
|
|
49
|
-
* .setProofVerifier(verifyIdentityBalanceProof, id.bytes(), true,
|
|
89
|
+
* .setProofVerifier(verifyIdentityBalanceProof, (_, platformVersion) => [id.bytes(), true, platformVersion])
|
|
50
90
|
* .mapResponse(data => data.proved ? data.verified.balance : BigInt(data.result.balance))
|
|
51
91
|
* .execute()
|
|
52
92
|
*/
|
|
@@ -59,6 +99,7 @@ export default class QueryExecutor {
|
|
|
59
99
|
#verifyProof;
|
|
60
100
|
#mapResponse;
|
|
61
101
|
#validateProof = true;
|
|
102
|
+
#requireProof = false;
|
|
62
103
|
constructor(grpcPool, quorumKeyProvider) {
|
|
63
104
|
this.#grpcPool = grpcPool;
|
|
64
105
|
this.#quorumKeyProvider = quorumKeyProvider;
|
|
@@ -93,9 +134,9 @@ export default class QueryExecutor {
|
|
|
93
134
|
const getArgs = args.length === 1 && typeof args[0] === 'function'
|
|
94
135
|
? args[0]
|
|
95
136
|
: () => args;
|
|
96
|
-
executor.#verifyProof = (responseProof) => {
|
|
137
|
+
executor.#verifyProof = (responseProof, platformVersion) => {
|
|
97
138
|
try {
|
|
98
|
-
return verify(responseProof.proof.grovedbProof, ...getArgs(responseProof));
|
|
139
|
+
return verify(responseProof.proof.grovedbProof, ...getArgs(responseProof, platformVersion));
|
|
99
140
|
}
|
|
100
141
|
catch (e) {
|
|
101
142
|
throw new ProofError(`Failed to verify GroveDB proof: ${String(e)}`, { cause: e });
|
|
@@ -120,6 +161,14 @@ export default class QueryExecutor {
|
|
|
120
161
|
this.#validateProof = validateProof;
|
|
121
162
|
return this;
|
|
122
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Requests and verifies the proof even if proofs are disabled in the pool,
|
|
166
|
+
* e.g. to learn the protocol version of the network from a verified response
|
|
167
|
+
*/
|
|
168
|
+
setRequireProof(requireProof) {
|
|
169
|
+
this.#requireProof = requireProof;
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
123
172
|
async execute() {
|
|
124
173
|
const request = this.#request;
|
|
125
174
|
const mapResponse = this.#mapResponse;
|
|
@@ -134,7 +183,7 @@ export default class QueryExecutor {
|
|
|
134
183
|
}
|
|
135
184
|
const requestBody = getVersionBody(this.#requestMessage);
|
|
136
185
|
const canSkipProof = requestBody != null && 'prove' in requestBody;
|
|
137
|
-
const prove = this.#grpcPool.proofs !== false || !canSkipProof;
|
|
186
|
+
const prove = this.#requireProof || this.#grpcPool.proofs !== false || !canSkipProof;
|
|
138
187
|
if (canSkipProof) {
|
|
139
188
|
requestBody.prove = prove;
|
|
140
189
|
}
|
|
@@ -152,7 +201,7 @@ export default class QueryExecutor {
|
|
|
152
201
|
if (metadata == null) {
|
|
153
202
|
throw new Error('Metadata not found');
|
|
154
203
|
}
|
|
155
|
-
return { proved: false, result: result, metadata };
|
|
204
|
+
return { proved: false, result: result, metadata, platformVersion: getVerifierVersion(getPoolProtocolVersion(this.#grpcPool), metadata.protocolVersion) };
|
|
156
205
|
}
|
|
157
206
|
async #executeWithProof(request) {
|
|
158
207
|
const verifyProof = this.#verifyProof;
|
|
@@ -172,12 +221,16 @@ export default class QueryExecutor {
|
|
|
172
221
|
try {
|
|
173
222
|
const { response } = await request(client);
|
|
174
223
|
const responseProof = this.#mapProof(response);
|
|
175
|
-
const
|
|
224
|
+
const { metadata } = responseProof;
|
|
225
|
+
const platformVersion = getVerifierVersion(getPoolProtocolVersion(grpcPool), metadata.protocolVersion);
|
|
226
|
+
const verified = verifyProof(responseProof, platformVersion);
|
|
176
227
|
if (this.#validateProof) {
|
|
177
228
|
await this.#verifySignature(responseProof, verified.rootHash);
|
|
229
|
+
// protocol version is learned only from the responses with verified quorum signature
|
|
230
|
+
updateProtocolVersion(grpcPool, metadata.protocolVersion);
|
|
178
231
|
grpcPool.unbanNode?.(client);
|
|
179
232
|
}
|
|
180
|
-
return { proved: true, verified, metadata
|
|
233
|
+
return { proved: true, verified, metadata, platformVersion };
|
|
181
234
|
}
|
|
182
235
|
catch (e) {
|
|
183
236
|
if (!(e instanceof ProofError)) {
|
package/src/constants.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PlatformVersionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { Network } from '../types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Default amount of documents to retrieve from DAPI
|
|
4
5
|
*/
|
|
@@ -15,6 +16,11 @@ export declare const GRPC_DEFAULT_POOL_LIMIT = 5;
|
|
|
15
16
|
export declare const RECENT_ADDRESS_BALANCE_CHANGES_LIMIT = 100;
|
|
16
17
|
export declare const RECENT_COMPACTED_ADDRESS_BALANCE_CHANGES_LIMIT = 25;
|
|
17
18
|
export declare const DPNS_DATA_CONTRACT_ID = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec";
|
|
19
|
+
export declare const WITHDRAWALS_DATA_CONTRACT_ID = "4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6";
|
|
18
20
|
export declare const DPNS_DATA_CONTRACT_BYTES = "AeZoxlmvZq7h5ywYbd57W34KHXEqCcQNVyH2Ir9TxTFVAAAAAAABAQAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIGZG9tYWluFgsSEGRvY3VtZW50c011dGFibGUTABIMY2FuQmVEZWxldGVkEwESDHRyYW5zZmVyYWJsZQIBEgl0cmFkZU1vZGUCARIEdHlwZRIGb2JqZWN0EgdpbmRpY2VzFQIWBBIEbmFtZRIScGFyZW50TmFtZUFuZExhYmVsEgpwcm9wZXJ0aWVzFQIWARIabm9ybWFsaXplZFBhcmVudERvbWFpbk5hbWUSA2FzYxYBEg9ub3JtYWxpemVkTGFiZWwSA2FzYxIGdW5pcXVlEwESCWNvbnRlc3RlZBYDEgxmaWVsZE1hdGNoZXMVARYCEgVmaWVsZBIPbm9ybWFsaXplZExhYmVsEgxyZWdleFBhdHRlcm4SE15bYS16QS1aMDEtXXszLDE5fSQSCnJlc29sdXRpb24CABILZGVzY3JpcHRpb24SqklmIHRoZSBub3JtYWxpemVkIGxhYmVsIHBhcnQgb2YgdGhpcyBpbmRleCBpcyBsZXNzIHRoYW4gMjAgY2hhcmFjdGVycyAoYWxsIGFscGhhYmV0IGEteiwgQS1aLCAwLCAxLCBhbmQgLSkgdGhlbiBhIG1hc3Rlcm5vZGUgdm90ZSBjb250ZXN0IHRha2VzIHBsYWNlIHRvIGdpdmUgb3V0IHRoZSBuYW1lFgMSBG5hbWUSCmlkZW50aXR5SWQSDm51bGxTZWFyY2hhYmxlEwASCnByb3BlcnRpZXMVARYBEhBy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14;
|
|
20
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Protocol version the SDK starts with before it learns the protocol version of the network,
|
|
24
|
+
* the lowest version the network still runs. It is raised by the verified responses, see {GRPCPool.protocolVersion}
|
|
25
|
+
*/
|
|
26
|
+
export declare const MIN_PROTOCOL_VERSION: Record<Network, PlatformVersionWASM>;
|
package/src/constants.js
CHANGED
|
@@ -15,7 +15,14 @@ export const GRPC_DEFAULT_POOL_LIMIT = 5;
|
|
|
15
15
|
export const RECENT_ADDRESS_BALANCE_CHANGES_LIMIT = 100;
|
|
16
16
|
export const RECENT_COMPACTED_ADDRESS_BALANCE_CHANGES_LIMIT = 25;
|
|
17
17
|
export const DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
18
|
+
export const WITHDRAWALS_DATA_CONTRACT_ID = '4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6';
|
|
18
19
|
export const DPNS_DATA_CONTRACT_BYTES = 'AeZoxlmvZq7h5ywYbd57W34KHXEqCcQNVyH2Ir9TxTFVAAAAAAABAQAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIGZG9tYWluFgsSEGRvY3VtZW50c011dGFibGUTABIMY2FuQmVEZWxldGVkEwESDHRyYW5zZmVyYWJsZQIBEgl0cmFkZU1vZGUCARIEdHlwZRIGb2JqZWN0EgdpbmRpY2VzFQIWBBIEbmFtZRIScGFyZW50TmFtZUFuZExhYmVsEgpwcm9wZXJ0aWVzFQIWARIabm9ybWFsaXplZFBhcmVudERvbWFpbk5hbWUSA2FzYxYBEg9ub3JtYWxpemVkTGFiZWwSA2FzYxIGdW5pcXVlEwESCWNvbnRlc3RlZBYDEgxmaWVsZE1hdGNoZXMVARYCEgVmaWVsZBIPbm9ybWFsaXplZExhYmVsEgxyZWdleFBhdHRlcm4SE15bYS16QS1aMDEtXXszLDE5fSQSCnJlc29sdXRpb24C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hIDMyIGJ5dGUgcmFuZG9tIHNhbHQgYW5kIGEgbm9ybWFsaXplZCBkb21haW4gbmFtZRIIcmVxdWlyZWQVARIQc2FsdGVkRG9tYWluSGFzaBIUYWRkaXRpb25hbFByb3BlcnRpZXMTABIIJGNvbW1lbnQSSlByZW9yZGVyIGRvY3VtZW50cyBhcmUgaW1tdXRhYmxlOiBtb2RpZmljYXRpb24gYW5kIGRlbGV0aW9uIGFyZSByZXN0cmljdGVkAAAAAAAAAAAAAA==';
|
|
19
20
|
export const LATEST_PLATFORM_VERSION = PlatformVersionWASM.PLATFORM_V14;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Protocol version the SDK starts with before it learns the protocol version of the network,
|
|
23
|
+
* the lowest version the network still runs. It is raised by the verified responses, see {GRPCPool.protocolVersion}
|
|
24
|
+
*/
|
|
25
|
+
export const MIN_PROTOCOL_VERSION = {
|
|
26
|
+
mainnet: PlatformVersionWASM.PLATFORM_V13,
|
|
27
|
+
testnet: PlatformVersionWASM.PLATFORM_V13
|
|
28
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GetContestedResourceVoteStateRequest, GetContestedResourceVoteStateResponse_GetContestedResourceVoteStateResponseV0_FinishedVoteInfo_FinishedVoteOutcome as FinishedVoteOutcome } from '../../proto/generated/platform.js';
|
|
2
2
|
import { DocumentWASM, IdentifierWASM, verifyVotePollVoteStateProof } from 'pshenmic-dpp';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
// winner types of the proof verification by finished vote outcome of the response
|
|
6
5
|
const FINISHED_VOTE_OUTCOMES = {
|
|
7
6
|
[FinishedVoteOutcome.TOWARDS_IDENTITY]: 'WonByIdentity',
|
|
@@ -33,12 +32,21 @@ export default async function getContestedResourceVoteState(grpcPool, quorumKeyP
|
|
|
33
32
|
});
|
|
34
33
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
35
34
|
.setGrpcRequest('getContestedResourceVoteState', getContestedResourceVoteStateRequest)
|
|
36
|
-
.setProofVerifier(verifyVotePollVoteStateProof,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
.setProofVerifier(verifyVotePollVoteStateProof, (_, platformVersion) => [
|
|
36
|
+
contract,
|
|
37
|
+
documentTypeName,
|
|
38
|
+
indexName,
|
|
39
|
+
indexValues,
|
|
40
|
+
// same enums
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
resultType,
|
|
43
|
+
allowIncludeLockedAndAbstainingVoteTally,
|
|
44
|
+
count,
|
|
45
|
+
startAtIdentifierInfo,
|
|
46
|
+
platformVersion
|
|
47
|
+
])
|
|
40
48
|
.mapResponse(data => {
|
|
41
|
-
const toDocument = (bytes) => bytes != null ? DocumentWASM.fromBytes(bytes, contract, documentTypeName,
|
|
49
|
+
const toDocument = (bytes) => bytes != null ? DocumentWASM.fromBytes(bytes, contract, documentTypeName, data.platformVersion) : undefined;
|
|
42
50
|
if (data.proved) {
|
|
43
51
|
const { result: voteState } = data.verified;
|
|
44
52
|
const { contenders } = voteState ?? { contenders: [] };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { VotePollWASM, verifyVotePollsByEndDateProof } from 'pshenmic-dpp';
|
|
2
2
|
import { GetVotePollsByEndDateRequest } from '../../proto/generated/platform.js';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
export default async function getVotePollsByEndDate(grpcPool, quorumKeyProvider, startTime, endTime, limit, ascending = true) {
|
|
6
5
|
const getVotePollsByEndDateRequest = GetVotePollsByEndDateRequest.create({
|
|
7
6
|
version: {
|
|
@@ -21,7 +20,13 @@ export default async function getVotePollsByEndDate(grpcPool, quorumKeyProvider,
|
|
|
21
20
|
});
|
|
22
21
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
23
22
|
.setGrpcRequest('getVotePollsByEndDate', getVotePollsByEndDateRequest)
|
|
24
|
-
.setProofVerifier(verifyVotePollsByEndDateProof,
|
|
23
|
+
.setProofVerifier(verifyVotePollsByEndDateProof, (_, platformVersion) => [
|
|
24
|
+
startTime,
|
|
25
|
+
endTime,
|
|
26
|
+
limit,
|
|
27
|
+
ascending,
|
|
28
|
+
platformVersion
|
|
29
|
+
])
|
|
25
30
|
.mapResponse(data => {
|
|
26
31
|
if (data.proved) {
|
|
27
32
|
return data.verified.votePolls;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DataContractWASM, IdentifierWASM, verifyContractProof } from 'pshenmic-dpp';
|
|
2
2
|
import { GetDataContractRequest } from '../../proto/generated/platform.js';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { DPNS_DATA_CONTRACT_BYTES, DPNS_DATA_CONTRACT_ID
|
|
4
|
+
import { DPNS_DATA_CONTRACT_BYTES, DPNS_DATA_CONTRACT_ID } from '../constants.js';
|
|
5
5
|
export default async function getByIdentifier(grpcPool, quorumKeyProvider, identifier) {
|
|
6
6
|
const id = new IdentifierWASM(identifier);
|
|
7
7
|
if (id.base58() === DPNS_DATA_CONTRACT_ID) {
|
|
@@ -18,11 +18,11 @@ export default async function getByIdentifier(grpcPool, quorumKeyProvider, ident
|
|
|
18
18
|
});
|
|
19
19
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
20
20
|
.setGrpcRequest('getDataContract', getDataContractRequest)
|
|
21
|
-
.setProofVerifier(verifyContractProof, undefined, false, false, id.bytes(),
|
|
21
|
+
.setProofVerifier(verifyContractProof, (_, platformVersion) => [undefined, false, false, id.bytes(), platformVersion])
|
|
22
22
|
.mapResponse(data => {
|
|
23
23
|
const dataContract = data.proved
|
|
24
24
|
? data.verified.dataContract
|
|
25
|
-
: DataContractWASM.fromBytes(data.result.dataContract, false,
|
|
25
|
+
: DataContractWASM.fromBytes(data.result.dataContract, false, data.platformVersion);
|
|
26
26
|
if (dataContract == null) {
|
|
27
27
|
throw new Error(`Data Contract with identifier ${id.base58()} not found`);
|
|
28
28
|
}
|
package/src/documents/index.d.ts
CHANGED
|
@@ -24,7 +24,10 @@ export declare class DocumentsController {
|
|
|
24
24
|
* @param owner {IdentifierLike} Identifier of the document's owner
|
|
25
25
|
* @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
|
|
26
26
|
* @param revision {bigint=} revision (optional)
|
|
27
|
-
* @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional
|
|
27
|
+
* @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional).
|
|
28
|
+
* By default, the protocol version of the network learned from the verified responses is used, it determines
|
|
29
|
+
* the document id generation (v13 and v14 generate different ids). If no response was verified yet,
|
|
30
|
+
* call {NodeController.getProtocolVersion} first
|
|
28
31
|
*
|
|
29
32
|
* @return {DataContractWASM}
|
|
30
33
|
*/
|
package/src/documents/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import createDocument from './create.js';
|
|
|
2
2
|
import { AgreedFeeMultiplierWASM, DocumentActionFeeAgreementWASM, IdentifierWASM, PrefundedVotingBalanceWASM, TokenPaymentInfoWASM } from 'pshenmic-dpp';
|
|
3
3
|
import createStateTransition from './createStateTransition.js';
|
|
4
4
|
import query from './query.js';
|
|
5
|
+
import { getPoolProtocolVersion } from '../QueryExecutor.js';
|
|
5
6
|
import getActionFeeAgreement from './getActionFeeAgreement.js';
|
|
6
7
|
import queryAggregate from './queryAggregate.js';
|
|
7
8
|
import { queryHaving, queryRanked } from './queryRanked.js';
|
|
@@ -29,12 +30,15 @@ export class DocumentsController {
|
|
|
29
30
|
* @param owner {IdentifierLike} Identifier of the document's owner
|
|
30
31
|
* @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
|
|
31
32
|
* @param revision {bigint=} revision (optional)
|
|
32
|
-
* @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional
|
|
33
|
+
* @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional).
|
|
34
|
+
* By default, the protocol version of the network learned from the verified responses is used, it determines
|
|
35
|
+
* the document id generation (v13 and v14 generate different ids). If no response was verified yet,
|
|
36
|
+
* call {NodeController.getProtocolVersion} first
|
|
33
37
|
*
|
|
34
38
|
* @return {DataContractWASM}
|
|
35
39
|
*/
|
|
36
40
|
create(dataContractId, documentType, data, owner, identityContractNonce, revision, platformVersion) {
|
|
37
|
-
return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), identityContractNonce, revision, undefined, platformVersion);
|
|
41
|
+
return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), identityContractNonce, revision, undefined, platformVersion ?? getPoolProtocolVersion(this.grpcPool));
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
44
|
* Make a query for documents retrieval from the network.
|
package/src/documents/query.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyDocumentsProof } from 'pshenmic-dpp';
|
|
2
|
-
import { DAPI_DEFAULT_LIMIT
|
|
2
|
+
import { DAPI_DEFAULT_LIMIT } from '../constants.js';
|
|
3
3
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
4
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
5
|
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toDocuments, toOrderClauses, toStart, toWhereClauses } from './v1.js';
|
|
@@ -18,12 +18,12 @@ export default async function query(grpcPool, quorumKeyProvider, dataContractId,
|
|
|
18
18
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
19
|
.setGrpcRequest('getDocuments', request)
|
|
20
20
|
.mapProof(getDocumentsV1Proof)
|
|
21
|
-
.setProofVerifier(verifyDocumentsProof, ({ metadata }) => {
|
|
21
|
+
.setProofVerifier(verifyDocumentsProof, ({ metadata }, platformVersion) => {
|
|
22
22
|
const metadataTimeMs = BigInt(metadata.timeMs);
|
|
23
|
-
return [dataContract, documentTypeName, where, orderBy, limit, startIdentifier?.bytes(), startAtIncluded, metadataTimeMs,
|
|
23
|
+
return [dataContract, documentTypeName, where, orderBy, limit, startIdentifier?.bytes(), startAtIncluded, metadataTimeMs, platformVersion, metadataTimeMs];
|
|
24
24
|
})
|
|
25
25
|
.mapResponse(data => data.proved
|
|
26
26
|
? data.verified.documents ?? []
|
|
27
|
-
: toDocuments(getDocumentsV1Data(data.result, 'documents').documents, dataContract, documentTypeName))
|
|
27
|
+
: toDocuments(getDocumentsV1Data(data.result, 'documents').documents, dataContract, documentTypeName, data.platformVersion))
|
|
28
28
|
.execute();
|
|
29
29
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyDocumentsAverageProof, verifyDocumentsCountProof, verifyDocumentsSumProof } from 'pshenmic-dpp';
|
|
2
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
2
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
4
|
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toOrderClauses, toSelect, toWhereClauses } from './v1.js';
|
|
@@ -54,13 +53,13 @@ export default async function queryAggregate(grpcPool, quorumKeyProvider, dataCo
|
|
|
54
53
|
.mapProof(getDocumentsV1Proof);
|
|
55
54
|
if (aggregateFunction === 'count') {
|
|
56
55
|
return await executor
|
|
57
|
-
.setProofVerifier(verifyDocumentsCountProof, ({ metadata }) => [dataContract, query,
|
|
56
|
+
.setProofVerifier(verifyDocumentsCountProof, ({ metadata }, platformVersion) => [dataContract, query, platformVersion, BigInt(metadata.timeMs)])
|
|
58
57
|
.mapResponse(data => data.proved ? data.verified.value : toDocumentsAggregate(data.result, aggregateFunction))
|
|
59
58
|
.execute();
|
|
60
59
|
}
|
|
61
60
|
const verify = aggregateFunction === 'sum' ? verifyDocumentsSumProof : verifyDocumentsAverageProof;
|
|
62
61
|
return await executor
|
|
63
|
-
.setProofVerifier(verify, ({ metadata }) => [dataContract, query, field,
|
|
62
|
+
.setProofVerifier(verify, ({ metadata }, platformVersion) => [dataContract, query, field, platformVersion, BigInt(metadata.timeMs)])
|
|
64
63
|
.mapResponse(data => data.proved ? data.verified.value : toDocumentsAggregate(data.result, aggregateFunction))
|
|
65
64
|
.execute();
|
|
66
65
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyChainedDocumentsProof, verifyCompositeDocumentsProof } from 'pshenmic-dpp';
|
|
2
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
2
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
4
|
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toDocumentRemovalEntry, toDocuments, toOrderClauses, toStart, toSubQueries, toWhereClauses } from './v1.js';
|
|
@@ -21,7 +20,7 @@ export async function queryChained(grpcPool, quorumKeyProvider, dataContractId,
|
|
|
21
20
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
22
21
|
.setGrpcRequest('getDocuments', request)
|
|
23
22
|
.mapProof(getDocumentsV1Proof)
|
|
24
|
-
.setProofVerifier(verifyChainedDocumentsProof, dataContract, query, joinProperty, outerDocumentTypeName,
|
|
23
|
+
.setProofVerifier(verifyChainedDocumentsProof, (_, platformVersion) => [dataContract, query, joinProperty, outerDocumentTypeName, platformVersion])
|
|
25
24
|
.mapResponse(data => {
|
|
26
25
|
if (data.proved) {
|
|
27
26
|
const { rootHash, ...result } = data.verified;
|
|
@@ -29,8 +28,8 @@ export async function queryChained(grpcPool, quorumKeyProvider, dataContractId,
|
|
|
29
28
|
}
|
|
30
29
|
const { innerDocuments, outerDocuments, missingOuterIds, removedOuterDocuments } = getDocumentsV1Data(data.result, 'chained');
|
|
31
30
|
return {
|
|
32
|
-
innerDocuments: toDocuments(innerDocuments, dataContract, query.documentTypeName),
|
|
33
|
-
outerDocuments: toDocuments(outerDocuments, dataContract, outerDocumentTypeName),
|
|
31
|
+
innerDocuments: toDocuments(innerDocuments, dataContract, query.documentTypeName, data.platformVersion),
|
|
32
|
+
outerDocuments: toDocuments(outerDocuments, dataContract, outerDocumentTypeName, data.platformVersion),
|
|
34
33
|
missingOuterIds: missingOuterIds.map(id => new IdentifierWASM(id)),
|
|
35
34
|
removedOuterDocuments: removedOuterDocuments.map(toDocumentRemovalEntry)
|
|
36
35
|
};
|
|
@@ -57,7 +56,7 @@ export async function queryComposite(grpcPool, quorumKeyProvider, dataContractId
|
|
|
57
56
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
58
57
|
.setGrpcRequest('getDocuments', request)
|
|
59
58
|
.mapProof(getDocumentsV1Proof)
|
|
60
|
-
.setProofVerifier(verifyCompositeDocumentsProof, dataContract, query, subQueries,
|
|
59
|
+
.setProofVerifier(verifyCompositeDocumentsProof, (_, platformVersion) => [dataContract, query, subQueries, platformVersion])
|
|
61
60
|
.mapResponse(data => {
|
|
62
61
|
if (data.proved) {
|
|
63
62
|
const { rootHash, ...result } = data.verified;
|
|
@@ -65,12 +64,12 @@ export async function queryComposite(grpcPool, quorumKeyProvider, dataContractId
|
|
|
65
64
|
}
|
|
66
65
|
const { pageDocuments, subResults } = getDocumentsV1Data(data.result, 'composite');
|
|
67
66
|
return {
|
|
68
|
-
pageDocuments: toDocuments(pageDocuments, dataContract, query.documentTypeName),
|
|
67
|
+
pageDocuments: toDocuments(pageDocuments, dataContract, query.documentTypeName, data.platformVersion),
|
|
69
68
|
subResults: subResults.map(({ result, missingIds, removed }, index) => {
|
|
70
69
|
const subQuery = subQueries[index];
|
|
71
70
|
return {
|
|
72
71
|
documents: result.oneofKind === 'documents'
|
|
73
|
-
? toDocuments(result.documents.documents, subQuery.dataContract ?? dataContract, subQuery.documentTypeName)
|
|
72
|
+
? toDocuments(result.documents.documents, subQuery.dataContract ?? dataContract, subQuery.documentTypeName, data.platformVersion)
|
|
74
73
|
: undefined,
|
|
75
74
|
counts: result.oneofKind === 'counts'
|
|
76
75
|
? result.counts.entries.map(({ inKey, key, count }) => ({ inKey: inKey ?? null, key, count: BigInt(count) }))
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyHavingDocumentsProof, verifyRankedDocumentsProof } from 'pshenmic-dpp';
|
|
2
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
2
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
4
|
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toHavingClauses, toOrderClauses, toSelect, toWhereClauses } from './v1.js';
|
|
@@ -46,7 +45,7 @@ export async function queryRanked(grpcPool, quorumKeyProvider, dataContractId, q
|
|
|
46
45
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
47
46
|
.setGrpcRequest('getDocuments', request)
|
|
48
47
|
.mapProof(getDocumentsV1Proof)
|
|
49
|
-
.setProofVerifier(verifyRankedDocumentsProof, ({ metadata }) => [dataContract, query,
|
|
48
|
+
.setProofVerifier(verifyRankedDocumentsProof, ({ metadata }, platformVersion) => [dataContract, query, platformVersion, BigInt(metadata.timeMs)])
|
|
50
49
|
.mapResponse(data => {
|
|
51
50
|
if (data.proved) {
|
|
52
51
|
return data.verified.value;
|
|
@@ -65,7 +64,7 @@ export async function queryHaving(grpcPool, quorumKeyProvider, dataContractId, q
|
|
|
65
64
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
66
65
|
.setGrpcRequest('getDocuments', request)
|
|
67
66
|
.mapProof(getDocumentsV1Proof)
|
|
68
|
-
.setProofVerifier(verifyHavingDocumentsProof, ({ metadata }) => [dataContract, query,
|
|
67
|
+
.setProofVerifier(verifyHavingDocumentsProof, ({ metadata }, platformVersion) => [dataContract, query, platformVersion, BigInt(metadata.timeMs)])
|
|
69
68
|
.mapResponse(data => data.proved ? data.verified.value : toRankedEntries(getDocumentsV1Data(data.result, 'ranked').entries))
|
|
70
69
|
.execute();
|
|
71
70
|
}
|
package/src/documents/v1.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GetDocumentsRequest, GetDocumentsRequest_DocumentFieldValue, GetDocumentsRequest_GetDocumentsRequestV1, GetDocumentsRequest_GetDocumentsRequestV1_SubQuery, GetDocumentsRequest_HavingClause, GetDocumentsRequest_OrderClause, GetDocumentsRequest_WhereClause, GetContractDocumentRemovalsResponse_ContractDocumentRemoval, GetDocumentsResponse, GetDocumentsResponse_GetDocumentsResponseV1_ResultData, Proof, ResponseMetadata } from '../../proto/generated/platform.js';
|
|
2
|
-
import { AggregateSelect, CompositeSubQuery, DataContractWASM, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM, ProvenDocumentRemovalEntry, WhereClause } from 'pshenmic-dpp';
|
|
2
|
+
import { AggregateSelect, CompositeSubQuery, DataContractWASM, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM, PlatformVersionWASM, ProvenDocumentRemovalEntry, WhereClause } from 'pshenmic-dpp';
|
|
3
3
|
import { ResponseResult } from '../QueryExecutor.js';
|
|
4
4
|
type DocumentFieldValue = GetDocumentsRequest_DocumentFieldValue;
|
|
5
5
|
/**
|
|
@@ -42,7 +42,7 @@ export declare function getDocumentsV1Data<K extends DocumentsV1Kind>(result: Re
|
|
|
42
42
|
/**
|
|
43
43
|
* Deserializes the documents of a getDocuments response requested without proof
|
|
44
44
|
*/
|
|
45
|
-
export declare function toDocuments(documents: Uint8Array[], dataContract: DataContractWASM, documentTypeName: string): DocumentWASM[];
|
|
45
|
+
export declare function toDocuments(documents: Uint8Array[], dataContract: DataContractWASM, documentTypeName: string, platformVersion: PlatformVersionWASM): DocumentWASM[];
|
|
46
46
|
/**
|
|
47
47
|
* Converts the document removal of a getDocuments response requested without proof to the one of the proof verification
|
|
48
48
|
*/
|
package/src/documents/v1.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GetDocumentsRequest, GetDocumentsRequest_GetDocumentsRequestV1, GetDocumentsRequest_GetDocumentsRequestV1_Select_Function, GetDocumentsRequest_GetDocumentsRequestV1_SubQuery_Kind, GetDocumentsRequest_HavingAggregate_Function, GetDocumentsRequest_HavingClause_Operator, GetDocumentsRequest_IntegerRangeSelection, GetDocumentsRequest_TimeRangeSelection, GetDocumentsRequest_TimeRangeSelection_Selector, GetDocumentsRequest_WhereClause, GetDocumentsRequest_WhereOperator } from '../../proto/generated/platform.js';
|
|
2
2
|
import { DocumentWASM, IdentifierWASM } from 'pshenmic-dpp';
|
|
3
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
3
|
const WHERE_OPERATORS = {
|
|
5
4
|
'=': GetDocumentsRequest_WhereOperator.EQUAL,
|
|
6
5
|
'==': GetDocumentsRequest_WhereOperator.EQUAL,
|
|
@@ -239,8 +238,8 @@ export function getDocumentsV1Data(result, kind) {
|
|
|
239
238
|
/**
|
|
240
239
|
* Deserializes the documents of a getDocuments response requested without proof
|
|
241
240
|
*/
|
|
242
|
-
export function toDocuments(documents, dataContract, documentTypeName) {
|
|
243
|
-
return documents.map(bytes => DocumentWASM.fromBytes(bytes, dataContract, documentTypeName,
|
|
241
|
+
export function toDocuments(documents, dataContract, documentTypeName, platformVersion) {
|
|
242
|
+
return documents.map(bytes => DocumentWASM.fromBytes(bytes, dataContract, documentTypeName, platformVersion));
|
|
244
243
|
}
|
|
245
244
|
/**
|
|
246
245
|
* Converts the document removal of a getDocuments response requested without proof to the one of the proof verification
|
|
@@ -6,8 +6,8 @@ export interface GRPCOptions {
|
|
|
6
6
|
retries?: number;
|
|
7
7
|
/**
|
|
8
8
|
* Minimal protocol version of the nodes, nodes with the protocol version from `minProtocolVersion` up to the latest
|
|
9
|
-
* version supported by the SDK are used. By default,
|
|
10
|
-
*
|
|
9
|
+
* version supported by the SDK are used. By default, nodes with any protocol version up to the latest one are used.
|
|
10
|
+
* The SDK starts with the higher of it and the lowest version the network runs, see {GRPCPool.protocolVersion}
|
|
11
11
|
*/
|
|
12
12
|
minProtocolVersion?: number;
|
|
13
13
|
/** Custom connection pool, if set, `poolLimit`, `dapiUrl` and `retries` are ignored **/
|
|
@@ -28,6 +28,12 @@ export interface GRPCPool {
|
|
|
28
28
|
unbanNode?: (client: PlatformClient) => void;
|
|
29
29
|
/** Requests and verifies proofs of the queries, `true` if not set **/
|
|
30
30
|
proofs?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Protocol version used to verify proofs and to parse responses, the lowest version the network runs if not set.
|
|
33
|
+
* Raised by the SDK to the protocol version of the responses whose proof and quorum signature were verified,
|
|
34
|
+
* it is never lowered and versions unknown to the SDK are ignored
|
|
35
|
+
*/
|
|
36
|
+
protocolVersion?: number;
|
|
31
37
|
}
|
|
32
38
|
export interface MasternodeInfo {
|
|
33
39
|
proTxHash: string;
|
|
@@ -54,6 +60,7 @@ export default class GRPCConnectionPool implements GRPCPool {
|
|
|
54
60
|
network: Network;
|
|
55
61
|
readonly retries: number;
|
|
56
62
|
proofs?: boolean;
|
|
63
|
+
protocolVersion: number;
|
|
57
64
|
constructor(network: Network, grpcOptions?: GRPCOptions);
|
|
58
65
|
/**
|
|
59
66
|
* Waits for the pool initialization and returns a client connected to the next healthy node (round-robin)
|
|
@@ -3,7 +3,7 @@ import { PlatformClient } from '../proto/generated/platform.client.js';
|
|
|
3
3
|
import { GetStatusRequest } from '../proto/generated/platform.js';
|
|
4
4
|
import getCurrentQuorumsInfo from './node/getCurrentQuorumsInfo.js';
|
|
5
5
|
import { fetchWithDetails } from './utils/fetchWithDetails.js';
|
|
6
|
-
import { LATEST_PLATFORM_VERSION } from './constants.js';
|
|
6
|
+
import { LATEST_PLATFORM_VERSION, MIN_PROTOCOL_VERSION } from './constants.js';
|
|
7
7
|
import sleep from './utils/sleep.js';
|
|
8
8
|
const GRPC_DEFAULT_POOL_LIMIT = 15;
|
|
9
9
|
const GRPC_DEFAULT_CONNECT_RETRIES = 5;
|
|
@@ -106,12 +106,8 @@ const isNodeHealthy = async (url, minProtocolVersion) => {
|
|
|
106
106
|
if (protocol == null) {
|
|
107
107
|
return false;
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else if (protocol.current < minProtocolVersion || protocol.current > Number(LATEST_PLATFORM_VERSION)) {
|
|
109
|
+
// the protocol version of the network is learned from the verified responses, so nodes of any supported version are used
|
|
110
|
+
if (protocol.current < (minProtocolVersion ?? 1) || protocol.current > Number(LATEST_PLATFORM_VERSION)) {
|
|
115
111
|
return false;
|
|
116
112
|
}
|
|
117
113
|
// chain is stalled, last block is too old relative to the node's own clock
|
|
@@ -143,6 +139,7 @@ export default class GRPCConnectionPool {
|
|
|
143
139
|
#minProtocolVersion;
|
|
144
140
|
retries;
|
|
145
141
|
proofs;
|
|
142
|
+
protocolVersion;
|
|
146
143
|
#nodeIndex = 0;
|
|
147
144
|
#initialization;
|
|
148
145
|
// ban state of nodes that failed with a retryable error, banned nodes are skipped on node selection
|
|
@@ -159,6 +156,8 @@ export default class GRPCConnectionPool {
|
|
|
159
156
|
throw new Error(`GRPC minProtocolVersion must be an integer from 1 to ${Number(LATEST_PLATFORM_VERSION)}, got ${String(minProtocolVersion)}`);
|
|
160
157
|
}
|
|
161
158
|
this.#minProtocolVersion = minProtocolVersion;
|
|
159
|
+
// nodes run at least `minProtocolVersion`, but the SDK never starts below the lowest version the network runs
|
|
160
|
+
this.protocolVersion = Math.max(minProtocolVersion ?? 0, MIN_PROTOCOL_VERSION[network]);
|
|
162
161
|
this.network = network;
|
|
163
162
|
this.#poolLimit = grpcOptions?.poolLimit ?? GRPC_DEFAULT_POOL_LIMIT;
|
|
164
163
|
this.#dapiUrl = grpcOptions?.dapiUrl;
|
|
@@ -209,7 +208,7 @@ export default class GRPCConnectionPool {
|
|
|
209
208
|
// fail the initialization, so it is retried on the next request
|
|
210
209
|
if (dapiUrls.length === 0) {
|
|
211
210
|
throw new Error(`None of the ${network} evonodes are available (${networkDAPIUrls.length} checked, ` +
|
|
212
|
-
`nodes must be synced and run protocol version ${this.#minProtocolVersion
|
|
211
|
+
`nodes must be synced and run protocol version ${this.#minProtocolVersion ?? 1}-${Number(LATEST_PLATFORM_VERSION)})`);
|
|
213
212
|
}
|
|
214
213
|
this.dapiUrls = dapiUrls.slice(0, this.#poolLimit);
|
|
215
214
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GetIdentityBalanceRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyIdentityBalanceProof } from 'pshenmic-dpp';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
export default async function getIdentityBalance(grpcPool, quorumKeyProvider, identifier) {
|
|
6
5
|
const id = new IdentifierWASM(identifier);
|
|
7
6
|
const getIdentityBalanceRequest = GetIdentityBalanceRequest.create({
|
|
@@ -15,7 +14,7 @@ export default async function getIdentityBalance(grpcPool, quorumKeyProvider, id
|
|
|
15
14
|
});
|
|
16
15
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
16
|
.setGrpcRequest('getIdentityBalance', getIdentityBalanceRequest)
|
|
18
|
-
.setProofVerifier(verifyIdentityBalanceProof, id.bytes(), true,
|
|
17
|
+
.setProofVerifier(verifyIdentityBalanceProof, (_, platformVersion) => [id.bytes(), true, platformVersion])
|
|
19
18
|
.mapResponse(data => {
|
|
20
19
|
const balance = data.proved ? data.verified.balance : BigInt(data.result.balance);
|
|
21
20
|
if (balance == null) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GetIdentityRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, IdentityWASM, verifyIdentityByIdentifierProof } from 'pshenmic-dpp';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
export default async function getIdentityByIdentifier(grpcPool, quorumKeyProvider, identifier) {
|
|
6
5
|
const id = new IdentifierWASM(identifier);
|
|
7
6
|
const getIdentityRequest = GetIdentityRequest.create({
|
|
@@ -15,7 +14,7 @@ export default async function getIdentityByIdentifier(grpcPool, quorumKeyProvide
|
|
|
15
14
|
});
|
|
16
15
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
16
|
.setGrpcRequest('getIdentity', getIdentityRequest)
|
|
18
|
-
.setProofVerifier(verifyIdentityByIdentifierProof, id, true,
|
|
17
|
+
.setProofVerifier(verifyIdentityByIdentifierProof, (_, platformVersion) => [id, true, platformVersion])
|
|
19
18
|
.mapResponse(data => {
|
|
20
19
|
const identity = data.proved ? data.verified.identity : IdentityWASM.fromBytes(data.result.identity);
|
|
21
20
|
if (identity == null) {
|
|
@@ -2,7 +2,6 @@ import { GetIdentityByNonUniquePublicKeyHashRequest } from '../../proto/generate
|
|
|
2
2
|
import { IdentityWASM, verifyFullIdentityByNonUniquePublicKeyHashProof, verifyFullIdentityByNonUniquePublicKeyHashTwoProofs } from 'pshenmic-dpp';
|
|
3
3
|
import hexToBytes from '../utils/hexToBytes.js';
|
|
4
4
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
6
5
|
function getNonUniquePublicKeyHashProof({ version }) {
|
|
7
6
|
if (version.oneofKind !== 'v0') {
|
|
8
7
|
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
@@ -39,12 +38,12 @@ export default async function getIdentityByNonUniquePublicKeyHash(grpcPool, quor
|
|
|
39
38
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
40
39
|
.setGrpcRequest('getIdentityByNonUniquePublicKeyHash', getIdentityByNonUniquePublicKeyHashRequest)
|
|
41
40
|
.mapProof(getNonUniquePublicKeyHashProof)
|
|
42
|
-
.setProofVerifier(verifyNonUniquePublicKeyHashProof, ({ metadata, identityProof, twoProofs }) => [
|
|
41
|
+
.setProofVerifier(verifyNonUniquePublicKeyHashProof, ({ metadata, identityProof, twoProofs }, platformVersion) => [
|
|
43
42
|
identityProof,
|
|
44
43
|
twoProofs,
|
|
45
44
|
hexToBytes(hex),
|
|
46
45
|
metadata.protocolVersion,
|
|
47
|
-
|
|
46
|
+
platformVersion
|
|
48
47
|
])
|
|
49
48
|
.mapResponse(data => {
|
|
50
49
|
if (data.proved) {
|