dash-platform-sdk 1.6.0-dev.1 → 1.6.0-dev.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/README.md +33 -15
- package/bundle.min.js +1 -1
- package/index.d.ts +3 -1
- package/index.js +2 -1
- package/package.json +2 -2
- package/proto/generated/platform.d.ts +128 -2
- package/proto/generated/platform.js +266 -8
- package/src/DashPlatformSDK.d.ts +19 -1
- package/src/DashPlatformSDK.js +28 -10
- package/src/QueryExecutor.d.ts +122 -0
- package/src/QueryExecutor.js +205 -0
- package/src/constants.d.ts +6 -0
- package/src/constants.js +6 -0
- package/src/contestedResources/getContestedResourceVoteState.d.ts +2 -1
- package/src/contestedResources/getContestedResourceVoteState.js +69 -49
- package/src/contestedResources/index.d.ts +4 -1
- package/src/contestedResources/index.js +5 -2
- package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -1
- package/src/dataContracts/getDataContractByIdentifier.js +15 -27
- package/src/dataContracts/index.d.ts +4 -1
- package/src/dataContracts/index.js +5 -2
- package/src/documents/create.d.ts +1 -1
- package/src/documents/create.js +2 -2
- package/src/documents/getActionFeeAgreement.d.ts +2 -1
- package/src/documents/getActionFeeAgreement.js +3 -3
- package/src/documents/index.d.ts +14 -9
- package/src/documents/index.js +19 -15
- package/src/documents/query.d.ts +2 -1
- package/src/documents/query.js +16 -8
- package/src/documents/queryAggregate.d.ts +8 -1
- package/src/documents/queryAggregate.js +49 -15
- package/src/documents/queryJoined.d.ts +3 -2
- package/src/documents/queryJoined.js +54 -13
- package/src/documents/queryRanked.d.ts +3 -2
- package/src/documents/queryRanked.js +49 -15
- package/src/documents/v1.d.ts +25 -8
- package/src/documents/v1.js +50 -14
- package/src/grpcConnectionPool.d.ts +24 -4
- package/src/grpcConnectionPool.js +153 -37
- package/src/identities/getIdentityBalance.d.ts +2 -1
- package/src/identities/getIdentityBalance.js +13 -27
- package/src/identities/getIdentityByIdentifier.d.ts +2 -1
- package/src/identities/getIdentityByIdentifier.js +14 -28
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +2 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +49 -28
- package/src/identities/getIdentityByPublicKeyHash.d.ts +2 -1
- package/src/identities/getIdentityByPublicKeyHash.js +14 -28
- package/src/identities/getIdentityContractNonce.d.ts +2 -1
- package/src/identities/getIdentityContractNonce.js +10 -27
- package/src/identities/getIdentityNonce.d.ts +2 -1
- package/src/identities/getIdentityNonce.js +10 -27
- package/src/identities/getIdentityPublicKeys.d.ts +2 -1
- package/src/identities/getIdentityPublicKeys.js +16 -29
- package/src/identities/index.d.ts +4 -1
- package/src/identities/index.js +11 -8
- package/src/names/index.d.ts +8 -2
- package/src/names/index.js +12 -6
- package/src/names/registerName.d.ts +2 -1
- package/src/names/registerName.js +56 -36
- package/src/names/searchByIdentity.d.ts +2 -1
- package/src/names/searchByIdentity.js +2 -2
- package/src/names/searchByName.d.ts +2 -1
- package/src/names/searchByName.js +2 -2
- package/src/node/epochInfos.d.ts +2 -1
- package/src/node/epochInfos.js +27 -31
- package/src/node/finalizedEpochInfos.d.ts +4 -3
- package/src/node/finalizedEpochInfos.js +45 -39
- package/src/node/index.d.ts +4 -1
- package/src/node/index.js +7 -4
- package/src/node/totalCredits.d.ts +2 -1
- package/src/node/totalCredits.js +10 -25
- package/src/platformAddresses/getAddressInfo.d.ts +2 -1
- package/src/platformAddresses/getAddressInfo.js +17 -31
- package/src/platformAddresses/getAddressesBranchState.d.ts +2 -1
- package/src/platformAddresses/getAddressesBranchState.js +22 -8
- package/src/platformAddresses/getAddressesInfos.d.ts +2 -1
- package/src/platformAddresses/getAddressesInfos.js +18 -29
- package/src/platformAddresses/getAddressesTrunkState.d.ts +2 -1
- package/src/platformAddresses/getAddressesTrunkState.js +25 -23
- package/src/platformAddresses/getRecentAddressBalanceChanges.d.ts +2 -1
- package/src/platformAddresses/getRecentAddressBalanceChanges.js +26 -26
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.d.ts +2 -1
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +30 -26
- package/src/platformAddresses/index.d.ts +4 -1
- package/src/platformAddresses/index.js +10 -7
- package/src/quorumKeyProvider.d.ts +23 -0
- package/src/quorumKeyProvider.js +28 -0
- package/src/shielded/getMostRecentShieldedAnchor.d.ts +2 -1
- package/src/shielded/getMostRecentShieldedAnchor.js +8 -25
- package/src/shielded/getShieldedAnchors.d.ts +2 -1
- package/src/shielded/getShieldedAnchors.js +8 -25
- package/src/shielded/getShieldedEncryptedNotes.d.ts +2 -1
- package/src/shielded/getShieldedEncryptedNotes.js +16 -30
- package/src/shielded/getShieldedNotesCount.d.ts +2 -1
- package/src/shielded/getShieldedNotesCount.js +8 -25
- package/src/shielded/getShieldedNullifiers.d.ts +2 -1
- package/src/shielded/getShieldedNullifiers.js +14 -28
- package/src/shielded/getShieldedPoolState.d.ts +2 -1
- package/src/shielded/getShieldedPoolState.js +8 -25
- package/src/shielded/index.d.ts +4 -1
- package/src/shielded/index.js +10 -7
- package/src/stateTransitions/index.d.ts +4 -1
- package/src/stateTransitions/index.js +5 -2
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +2 -1
- package/src/stateTransitions/waitForStateTransitionResult.js +42 -44
- package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -1
- package/src/tokens/getIdentitiesTokenBalances.js +17 -28
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -1
- package/src/tokens/getIdentityTokensBalances.js +17 -28
- package/src/tokens/getTokenContractInfo.d.ts +2 -1
- package/src/tokens/getTokenContractInfo.js +16 -30
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -1
- package/src/tokens/getTokenDirectPurchasePrices.js +26 -28
- package/src/tokens/getTokenTotalSupply.d.ts +2 -1
- package/src/tokens/getTokenTotalSupply.js +16 -28
- package/src/tokens/index.d.ts +4 -1
- package/src/tokens/index.js +11 -8
- package/src/utils/ProofError.d.ts +9 -0
- package/src/utils/ProofError.js +10 -0
- package/src/utils/verifyTenderdashProof.js +2 -1
- package/test/unit/Document.spec.js +9 -9
- package/test/unit/DocumentActionFees.spec.js +2 -2
- package/test/unit/Names.spec.js +30 -0
- package/test/unit/Node.spec.js +11 -8
- package/test/unit/SDK.spec.js +42 -0
- package/src/utils/getQuorumPublicKey.d.ts +0 -1
- package/src/utils/getQuorumPublicKey.js +0 -19
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { DataContractWASM, IdentifierWASM, verifyContractProof } from 'pshenmic-dpp';
|
|
2
2
|
import { GetDataContractRequest } from '../../proto/generated/platform.js';
|
|
3
|
-
import
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
3
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
6
4
|
import { DPNS_DATA_CONTRACT_BYTES, DPNS_DATA_CONTRACT_ID, LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getByIdentifier(grpcPool, identifier) {
|
|
5
|
+
export default async function getByIdentifier(grpcPool, quorumKeyProvider, identifier) {
|
|
8
6
|
const id = new IdentifierWASM(identifier);
|
|
9
7
|
if (id.base58() === DPNS_DATA_CONTRACT_ID) {
|
|
10
8
|
return DataContractWASM.fromBase64(DPNS_DATA_CONTRACT_BYTES, true, 9);
|
|
@@ -18,27 +16,17 @@ export default async function getByIdentifier(grpcPool, identifier) {
|
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { rootHash, dataContract } = verifyContractProof(proof.grovedbProof, undefined, false, false, id.bytes(), LATEST_PLATFORM_VERSION);
|
|
35
|
-
if (dataContract == null) {
|
|
36
|
-
throw new Error(`Data Contract with identifier ${id.base58()} not found`);
|
|
37
|
-
}
|
|
38
|
-
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
39
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
40
|
-
if (!verify) {
|
|
41
|
-
throw new Error('Failed to verify query');
|
|
42
|
-
}
|
|
43
|
-
return dataContract;
|
|
19
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
20
|
+
.setGrpcRequest('getDataContract', getDataContractRequest)
|
|
21
|
+
.setProofVerifier(verifyContractProof, undefined, false, false, id.bytes(), LATEST_PLATFORM_VERSION)
|
|
22
|
+
.mapResponse(data => {
|
|
23
|
+
const dataContract = data.proved
|
|
24
|
+
? data.verified.dataContract
|
|
25
|
+
: DataContractWASM.fromBytes(data.result.dataContract, false, LATEST_PLATFORM_VERSION);
|
|
26
|
+
if (dataContract == null) {
|
|
27
|
+
throw new Error(`Data Contract with identifier ${id.base58()} not found`);
|
|
28
|
+
}
|
|
29
|
+
return dataContract;
|
|
30
|
+
})
|
|
31
|
+
.execute();
|
|
44
32
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataContractTokens, DataContractWASM, IdentifierLike, PlatformVersionWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
4
|
import { DataContractConfig } from '../../types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Collection of methods necessary to work with Data Contracts in the network,
|
|
@@ -10,7 +11,9 @@ import { DataContractConfig } from '../../types.js';
|
|
|
10
11
|
export declare class DataContractsController {
|
|
11
12
|
/** @ignore */
|
|
12
13
|
grpcPool: GRPCPool;
|
|
13
|
-
|
|
14
|
+
/** @ignore */
|
|
15
|
+
quorumKeyProvider: QuorumKeyProvider;
|
|
16
|
+
constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
|
|
14
17
|
/**
|
|
15
18
|
* Creates an instance of {DataContractWASM} that can be used to
|
|
16
19
|
* register a data contract in the network.
|
|
@@ -10,8 +10,11 @@ import createStateTransition from './createStateTransition.js';
|
|
|
10
10
|
export class DataContractsController {
|
|
11
11
|
/** @ignore */
|
|
12
12
|
grpcPool;
|
|
13
|
-
|
|
13
|
+
/** @ignore */
|
|
14
|
+
quorumKeyProvider;
|
|
15
|
+
constructor(grpcPool, quorumKeyProvider) {
|
|
14
16
|
this.grpcPool = grpcPool;
|
|
17
|
+
this.quorumKeyProvider = quorumKeyProvider;
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
17
20
|
* Creates an instance of {DataContractWASM} that can be used to
|
|
@@ -38,7 +41,7 @@ export class DataContractsController {
|
|
|
38
41
|
* @return {Promise<DataContractWASM>}
|
|
39
42
|
*/
|
|
40
43
|
async getDataContractByIdentifier(identifier) {
|
|
41
|
-
return await getDataContractByIdentifier(this.grpcPool, identifier);
|
|
44
|
+
return await getDataContractByIdentifier(this.grpcPool, this.quorumKeyProvider, identifier);
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Helper function to create a state transition from a {DataContractWASM} instance
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { DocumentWASM, IdentifierLike } from 'pshenmic-dpp';
|
|
2
|
-
export default function createDocument(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, revision?: bigint, documentId?: IdentifierLike): DocumentWASM;
|
|
2
|
+
export default function createDocument(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, identityContractNonce: bigint, revision?: bigint, documentId?: IdentifierLike): DocumentWASM;
|
package/src/documents/create.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { DocumentWASM } from 'pshenmic-dpp';
|
|
2
|
-
export default function createDocument(dataContractId, documentType, data, owner, revision, documentId) {
|
|
3
|
-
return new DocumentWASM(data, documentType, revision ?? BigInt(1), dataContractId, owner, documentId, owner);
|
|
2
|
+
export default function createDocument(dataContractId, documentType, data, owner, identityContractNonce, revision, documentId) {
|
|
3
|
+
return new DocumentWASM(data, documentType, revision ?? BigInt(1), dataContractId, owner, documentId, owner, identityContractNonce);
|
|
4
4
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentActionFeeAgreementWASM, IdentifierLike } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
4
|
import { DocumentTransitionType } from '../../types.js';
|
|
4
|
-
export default function getActionFeeAgreement(grpcPool: GRPCPool, dataContractId: IdentifierLike, documentTypeName: string, action: DocumentTransitionType, increaseTolerancePercent: number): Promise<DocumentActionFeeAgreementWASM | undefined>;
|
|
5
|
+
export default function getActionFeeAgreement(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, documentTypeName: string, action: DocumentTransitionType, increaseTolerancePercent: number): Promise<DocumentActionFeeAgreementWASM | undefined>;
|
|
@@ -9,10 +9,10 @@ const BATCH_TYPES = {
|
|
|
9
9
|
transfer: 'Transfer',
|
|
10
10
|
purchase: 'Purchase'
|
|
11
11
|
};
|
|
12
|
-
export default async function getActionFeeAgreement(grpcPool, dataContractId, documentTypeName, action, increaseTolerancePercent) {
|
|
13
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
12
|
+
export default async function getActionFeeAgreement(grpcPool, quorumKeyProvider, dataContractId, documentTypeName, action, increaseTolerancePercent) {
|
|
13
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
14
14
|
// the current epoch: descending from the latest one
|
|
15
|
-
const [currentEpoch] = await getEpochsInfo(grpcPool, 1, false);
|
|
15
|
+
const [currentEpoch] = await getEpochsInfo(grpcPool, quorumKeyProvider, 1, false);
|
|
16
16
|
if (currentEpoch == null) {
|
|
17
17
|
throw new Error('Current epoch not found');
|
|
18
18
|
}
|
package/src/documents/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DocumentTransitionParams, DocumentTransitionType } from '../../types.js';
|
|
2
|
-
import { AggregateDocumentsQuery, AggregateProofQuery, CompositeSubQuery, DocumentActionFeeAgreementWASM, DocumentsQuery, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM,
|
|
2
|
+
import { AggregateDocumentsQuery, AggregateProofQuery, CompositeSubQuery, DocumentActionFeeAgreementWASM, DocumentsQuery, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM, ProvenRankedEntry, ProvenRankedPage, StateTransitionWASM, WhereClause } from 'pshenmic-dpp';
|
|
3
3
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
4
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
5
|
+
import { DocumentsAggregate } from './queryAggregate.js';
|
|
4
6
|
import { ChainedDocuments, CompositeDocuments } from './queryJoined.js';
|
|
5
7
|
/**
|
|
6
8
|
* Collection of methods to work with documents like creation, querying or preparing a transition action
|
|
@@ -10,7 +12,9 @@ import { ChainedDocuments, CompositeDocuments } from './queryJoined.js';
|
|
|
10
12
|
export declare class DocumentsController {
|
|
11
13
|
/** @ignore **/
|
|
12
14
|
grpcPool: GRPCPool;
|
|
13
|
-
|
|
15
|
+
/** @ignore **/
|
|
16
|
+
quorumKeyProvider: QuorumKeyProvider;
|
|
17
|
+
constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
|
|
14
18
|
/**
|
|
15
19
|
* Creates a {DocumentWASM} instance that can be used to submit a document in the network.
|
|
16
20
|
*
|
|
@@ -18,11 +22,12 @@ export declare class DocumentsController {
|
|
|
18
22
|
* @param documentType {string} Document type as string
|
|
19
23
|
* @param data {object} Data as JSON object
|
|
20
24
|
* @param owner {IdentifierLike} Identifier of the document's owner
|
|
25
|
+
* @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
|
|
21
26
|
* @param revision {bigint=} revision (optional)
|
|
22
27
|
*
|
|
23
28
|
* @return {DataContractWASM}
|
|
24
29
|
*/
|
|
25
|
-
create(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, revision?: bigint): DocumentWASM;
|
|
30
|
+
create(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, identityContractNonce: bigint, revision?: bigint): DocumentWASM;
|
|
26
31
|
/**
|
|
27
32
|
* Make a query for documents retrieval from the network.
|
|
28
33
|
*
|
|
@@ -42,9 +47,9 @@ export declare class DocumentsController {
|
|
|
42
47
|
* @param dataContractId {IdentifierLike} Identifier of the Data Contract
|
|
43
48
|
* @param query {AggregateProofQuery} documentTypeName, where, orderBy, groupBy and limit of the query
|
|
44
49
|
*
|
|
45
|
-
* @return {Promise<
|
|
50
|
+
* @return {Promise<DocumentsAggregate>}
|
|
46
51
|
*/
|
|
47
|
-
count(dataContractId: IdentifierLike, query: AggregateProofQuery): Promise<
|
|
52
|
+
count(dataContractId: IdentifierLike, query: AggregateProofQuery): Promise<DocumentsAggregate>;
|
|
48
53
|
/**
|
|
49
54
|
* Sums a field over documents matching a query. Without `groupBy` returns one entry with the total,
|
|
50
55
|
* with `groupBy` one entry per group
|
|
@@ -53,9 +58,9 @@ export declare class DocumentsController {
|
|
|
53
58
|
* @param query {AggregateProofQuery} documentTypeName, where, orderBy, groupBy and limit of the query
|
|
54
59
|
* @param field {string} Integer field to sum
|
|
55
60
|
*
|
|
56
|
-
* @return {Promise<
|
|
61
|
+
* @return {Promise<DocumentsAggregate>}
|
|
57
62
|
*/
|
|
58
|
-
sum(dataContractId: IdentifierLike, query: AggregateProofQuery, field: string): Promise<
|
|
63
|
+
sum(dataContractId: IdentifierLike, query: AggregateProofQuery, field: string): Promise<DocumentsAggregate>;
|
|
59
64
|
/**
|
|
60
65
|
* Averages a field over documents matching a query. Entries carry `count` and `sum`, the average is `sum / count`.
|
|
61
66
|
* Without `groupBy` returns one entry with the total, with `groupBy` one entry per group
|
|
@@ -64,9 +69,9 @@ export declare class DocumentsController {
|
|
|
64
69
|
* @param query {AggregateProofQuery} documentTypeName, where, orderBy, groupBy and limit of the query
|
|
65
70
|
* @param field {string} Integer field to average
|
|
66
71
|
*
|
|
67
|
-
* @return {Promise<
|
|
72
|
+
* @return {Promise<DocumentsAggregate>}
|
|
68
73
|
*/
|
|
69
|
-
average(dataContractId: IdentifierLike, query: AggregateProofQuery, field: string): Promise<
|
|
74
|
+
average(dataContractId: IdentifierLike, query: AggregateProofQuery, field: string): Promise<DocumentsAggregate>;
|
|
70
75
|
/**
|
|
71
76
|
* Top-K query: groups of `groupBy` ranked by the selected aggregate. Order by the selected field,
|
|
72
77
|
* or by `$count` for count, e.g. `orderBy: [['$count', 'desc']]`. Supports `limit` and `offset`
|
package/src/documents/index.js
CHANGED
|
@@ -14,8 +14,11 @@ import { queryChained, queryComposite } from './queryJoined.js';
|
|
|
14
14
|
export class DocumentsController {
|
|
15
15
|
/** @ignore **/
|
|
16
16
|
grpcPool;
|
|
17
|
-
|
|
17
|
+
/** @ignore **/
|
|
18
|
+
quorumKeyProvider;
|
|
19
|
+
constructor(grpcPool, quorumKeyProvider) {
|
|
18
20
|
this.grpcPool = grpcPool;
|
|
21
|
+
this.quorumKeyProvider = quorumKeyProvider;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Creates a {DocumentWASM} instance that can be used to submit a document in the network.
|
|
@@ -24,12 +27,13 @@ export class DocumentsController {
|
|
|
24
27
|
* @param documentType {string} Document type as string
|
|
25
28
|
* @param data {object} Data as JSON object
|
|
26
29
|
* @param owner {IdentifierLike} Identifier of the document's owner
|
|
30
|
+
* @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
|
|
27
31
|
* @param revision {bigint=} revision (optional)
|
|
28
32
|
*
|
|
29
33
|
* @return {DataContractWASM}
|
|
30
34
|
*/
|
|
31
|
-
create(dataContractId, documentType, data, owner, revision) {
|
|
32
|
-
return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), revision);
|
|
35
|
+
create(dataContractId, documentType, data, owner, identityContractNonce, revision) {
|
|
36
|
+
return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), identityContractNonce, revision);
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* Make a query for documents retrieval from the network.
|
|
@@ -46,7 +50,7 @@ export class DocumentsController {
|
|
|
46
50
|
if (startAfter != null && startAt != null) {
|
|
47
51
|
throw new Error('You may only set either startAfter or startAt at once');
|
|
48
52
|
}
|
|
49
|
-
return await query(this.grpcPool, new IdentifierWASM(dataContractId), documentType, where, orderBy, limit ?? 100, startAt, startAfter);
|
|
53
|
+
return await query(this.grpcPool, this.quorumKeyProvider, new IdentifierWASM(dataContractId), documentType, where, orderBy, limit ?? 100, startAt, startAfter);
|
|
50
54
|
}
|
|
51
55
|
/**
|
|
52
56
|
* Counts documents matching a query. Without `groupBy` returns one entry with the total,
|
|
@@ -55,10 +59,10 @@ export class DocumentsController {
|
|
|
55
59
|
* @param dataContractId {IdentifierLike} Identifier of the Data Contract
|
|
56
60
|
* @param query {AggregateProofQuery} documentTypeName, where, orderBy, groupBy and limit of the query
|
|
57
61
|
*
|
|
58
|
-
* @return {Promise<
|
|
62
|
+
* @return {Promise<DocumentsAggregate>}
|
|
59
63
|
*/
|
|
60
64
|
async count(dataContractId, query) {
|
|
61
|
-
return await queryAggregate(this.grpcPool, dataContractId, 'count', query);
|
|
65
|
+
return await queryAggregate(this.grpcPool, this.quorumKeyProvider, dataContractId, 'count', query);
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
68
|
* Sums a field over documents matching a query. Without `groupBy` returns one entry with the total,
|
|
@@ -68,10 +72,10 @@ export class DocumentsController {
|
|
|
68
72
|
* @param query {AggregateProofQuery} documentTypeName, where, orderBy, groupBy and limit of the query
|
|
69
73
|
* @param field {string} Integer field to sum
|
|
70
74
|
*
|
|
71
|
-
* @return {Promise<
|
|
75
|
+
* @return {Promise<DocumentsAggregate>}
|
|
72
76
|
*/
|
|
73
77
|
async sum(dataContractId, query, field) {
|
|
74
|
-
return await queryAggregate(this.grpcPool, dataContractId, 'sum', query, field);
|
|
78
|
+
return await queryAggregate(this.grpcPool, this.quorumKeyProvider, dataContractId, 'sum', query, field);
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
81
|
* Averages a field over documents matching a query. Entries carry `count` and `sum`, the average is `sum / count`.
|
|
@@ -81,10 +85,10 @@ export class DocumentsController {
|
|
|
81
85
|
* @param query {AggregateProofQuery} documentTypeName, where, orderBy, groupBy and limit of the query
|
|
82
86
|
* @param field {string} Integer field to average
|
|
83
87
|
*
|
|
84
|
-
* @return {Promise<
|
|
88
|
+
* @return {Promise<DocumentsAggregate>}
|
|
85
89
|
*/
|
|
86
90
|
async average(dataContractId, query, field) {
|
|
87
|
-
return await queryAggregate(this.grpcPool, dataContractId, 'avg', query, field);
|
|
91
|
+
return await queryAggregate(this.grpcPool, this.quorumKeyProvider, dataContractId, 'avg', query, field);
|
|
88
92
|
}
|
|
89
93
|
/**
|
|
90
94
|
* Top-K query: groups of `groupBy` ranked by the selected aggregate. Order by the selected field,
|
|
@@ -96,7 +100,7 @@ export class DocumentsController {
|
|
|
96
100
|
* @return {Promise<ProvenRankedPage>}
|
|
97
101
|
*/
|
|
98
102
|
async ranked(dataContractId, query) {
|
|
99
|
-
return await queryRanked(this.grpcPool, dataContractId, query);
|
|
103
|
+
return await queryRanked(this.grpcPool, this.quorumKeyProvider, dataContractId, query);
|
|
100
104
|
}
|
|
101
105
|
/**
|
|
102
106
|
* Having query: groups of `groupBy` whose aggregate falls within the `having` bounds
|
|
@@ -107,7 +111,7 @@ export class DocumentsController {
|
|
|
107
111
|
* @return {Promise<ProvenRankedEntry[]>}
|
|
108
112
|
*/
|
|
109
113
|
async having(dataContractId, query) {
|
|
110
|
-
return await queryHaving(this.grpcPool, dataContractId, query);
|
|
114
|
+
return await queryHaving(this.grpcPool, this.quorumKeyProvider, dataContractId, query);
|
|
111
115
|
}
|
|
112
116
|
/**
|
|
113
117
|
* Chained join: documents of the query, then the documents of `outerDocumentType`
|
|
@@ -121,7 +125,7 @@ export class DocumentsController {
|
|
|
121
125
|
* @return {Promise<ChainedDocuments>}
|
|
122
126
|
*/
|
|
123
127
|
async chained(dataContractId, query, joinProperty, outerDocumentType) {
|
|
124
|
-
return await queryChained(this.grpcPool, dataContractId, query, joinProperty, outerDocumentType);
|
|
128
|
+
return await queryChained(this.grpcPool, this.quorumKeyProvider, dataContractId, query, joinProperty, outerDocumentType);
|
|
125
129
|
}
|
|
126
130
|
/**
|
|
127
131
|
* Composite query: a page of documents plus up to 10 sub-queries, each optionally bound
|
|
@@ -134,7 +138,7 @@ export class DocumentsController {
|
|
|
134
138
|
* @return {Promise<CompositeDocuments>}
|
|
135
139
|
*/
|
|
136
140
|
async composite(dataContractId, query, subQueries) {
|
|
137
|
-
return await queryComposite(this.grpcPool, dataContractId, query, subQueries);
|
|
141
|
+
return await queryComposite(this.grpcPool, this.quorumKeyProvider, dataContractId, query, subQueries);
|
|
138
142
|
}
|
|
139
143
|
/**
|
|
140
144
|
* Helper function for creating {StateTransitionWASM} from documents. It may be used to create any of 6 Document Transition actions:
|
|
@@ -191,6 +195,6 @@ export class DocumentsController {
|
|
|
191
195
|
* @return {Promise<DocumentActionFeeAgreementWASM | undefined>}
|
|
192
196
|
*/
|
|
193
197
|
async getActionFeeAgreement(dataContractId, documentType, action, increaseTolerancePercent) {
|
|
194
|
-
return await getActionFeeAgreement(this.grpcPool, dataContractId, documentType, action, increaseTolerancePercent ?? 0);
|
|
198
|
+
return await getActionFeeAgreement(this.grpcPool, this.quorumKeyProvider, dataContractId, documentType, action, increaseTolerancePercent ?? 0);
|
|
195
199
|
}
|
|
196
200
|
}
|
package/src/documents/query.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { DocumentWASM, IdentifierLike, IdentifierWASM, WhereClause } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
-
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
4
|
+
export default function query(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, documentTypeName: string, where?: WhereClause[], orderBy?: string[][], limit?: number | undefined, startAt?: IdentifierWASM, startAfter?: IdentifierWASM): Promise<DocumentWASM[]>;
|
package/src/documents/query.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyDocumentsProof } from 'pshenmic-dpp';
|
|
2
2
|
import { DAPI_DEFAULT_LIMIT, LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
3
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toDocuments, toOrderClauses, toStart, toWhereClauses } from './v1.js';
|
|
6
|
+
export default async function query(grpcPool, quorumKeyProvider, dataContractId, documentTypeName, where, orderBy, limit = 100, startAt, startAfter) {
|
|
7
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
7
8
|
const startIdentifier = startAt ?? startAfter;
|
|
8
9
|
const startAtIncluded = startAt != null;
|
|
9
|
-
const
|
|
10
|
+
const request = createDocumentsV1Request({
|
|
10
11
|
dataContractId: (new IdentifierWASM(dataContractId)).bytes(),
|
|
11
12
|
documentType: documentTypeName,
|
|
12
13
|
whereClauses: toWhereClauses(where),
|
|
@@ -14,8 +15,15 @@ export default async function query(grpcPool, dataContractId, documentTypeName,
|
|
|
14
15
|
limit: limit ?? DAPI_DEFAULT_LIMIT,
|
|
15
16
|
start: toStart(startIdentifier, startAtIncluded)
|
|
16
17
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
|
+
.setGrpcRequest('getDocuments', request)
|
|
20
|
+
.mapProof(getDocumentsV1Proof)
|
|
21
|
+
.setProofVerifier(verifyDocumentsProof, ({ metadata }) => {
|
|
22
|
+
const metadataTimeMs = BigInt(metadata.timeMs);
|
|
23
|
+
return [dataContract, documentTypeName, where, orderBy, limit, startIdentifier?.bytes(), startAtIncluded, metadataTimeMs, LATEST_PLATFORM_VERSION, metadataTimeMs];
|
|
24
|
+
})
|
|
25
|
+
.mapResponse(data => data.proved
|
|
26
|
+
? data.verified.documents ?? []
|
|
27
|
+
: toDocuments(getDocumentsV1Data(data.result, 'documents').documents, dataContract, documentTypeName))
|
|
28
|
+
.execute();
|
|
21
29
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { AggregateProofQuery, IdentifierLike, ProvenAggregate } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
4
|
export type DocumentsAggregateFunction = 'count' | 'sum' | 'avg';
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Aggregate of the documents, `mode` (the shape of the proof) is known only with proof
|
|
7
|
+
*/
|
|
8
|
+
export type DocumentsAggregate = Omit<ProvenAggregate, 'mode'> & {
|
|
9
|
+
mode?: ProvenAggregate['mode'];
|
|
10
|
+
};
|
|
11
|
+
export default function queryAggregate(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, aggregateFunction: DocumentsAggregateFunction, query: AggregateProofQuery, field?: string): Promise<DocumentsAggregate>;
|
|
@@ -1,13 +1,46 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyDocumentsAverageProof, verifyDocumentsCountProof, verifyDocumentsSumProof } from 'pshenmic-dpp';
|
|
2
2
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
3
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toOrderClauses, toSelect, toWhereClauses } from './v1.js';
|
|
6
|
+
/**
|
|
7
|
+
* Converts the aggregate of a response requested without proof to the one of the proof verification.
|
|
8
|
+
* Aggregate without grouping is returned as a single entry with an empty key, groups without documents
|
|
9
|
+
* are skipped like in the proof. The `in` value of a carrier aggregate (`inKey`) is not returned without proof
|
|
10
|
+
*/
|
|
11
|
+
function toDocumentsAggregate(result, aggregateFunction) {
|
|
12
|
+
const toEntry = ({ inKey, key, count, sum }) => ({
|
|
13
|
+
inKey: inKey ?? null,
|
|
14
|
+
key: key ?? new Uint8Array(),
|
|
15
|
+
count: count != null ? BigInt(count) : undefined,
|
|
16
|
+
sum: sum != null ? BigInt(sum) : undefined
|
|
17
|
+
});
|
|
18
|
+
if (aggregateFunction === 'count') {
|
|
19
|
+
const { variant } = getDocumentsV1Data(result, 'counts');
|
|
20
|
+
if (variant.oneofKind === 'aggregateCount') {
|
|
21
|
+
return { entries: [toEntry({ count: variant.aggregateCount })] };
|
|
22
|
+
}
|
|
23
|
+
return { entries: variant.oneofKind === 'entries' ? variant.entries.entries.filter(({ count }) => count !== '0').map(toEntry) : [] };
|
|
24
|
+
}
|
|
25
|
+
if (aggregateFunction === 'sum') {
|
|
26
|
+
const { variant } = getDocumentsV1Data(result, 'sums');
|
|
27
|
+
if (variant.oneofKind === 'aggregateSum') {
|
|
28
|
+
return { entries: [toEntry({ sum: variant.aggregateSum })] };
|
|
29
|
+
}
|
|
30
|
+
return { entries: variant.oneofKind === 'entries' ? variant.entries.entries.map(toEntry) : [] };
|
|
31
|
+
}
|
|
32
|
+
const { variant } = getDocumentsV1Data(result, 'averages');
|
|
33
|
+
if (variant.oneofKind === 'aggregateAverage') {
|
|
34
|
+
return { entries: [toEntry(variant.aggregateAverage)] };
|
|
35
|
+
}
|
|
36
|
+
return { entries: variant.oneofKind === 'entries' ? variant.entries.entries.filter(({ count }) => count !== '0').map(toEntry) : [] };
|
|
37
|
+
}
|
|
38
|
+
export default async function queryAggregate(grpcPool, quorumKeyProvider, dataContractId, aggregateFunction, query, field) {
|
|
6
39
|
if (aggregateFunction !== 'count' && field == null) {
|
|
7
40
|
throw new Error(`Field is required for ${aggregateFunction} query`);
|
|
8
41
|
}
|
|
9
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
10
|
-
const
|
|
42
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
43
|
+
const request = createDocumentsV1Request({
|
|
11
44
|
dataContractId: (new IdentifierWASM(dataContractId)).bytes(),
|
|
12
45
|
documentType: query.documentTypeName,
|
|
13
46
|
whereClauses: toWhereClauses(query.where),
|
|
@@ -16,17 +49,18 @@ export default async function queryAggregate(grpcPool, dataContractId, aggregate
|
|
|
16
49
|
selects: toSelect({ function: aggregateFunction, field }),
|
|
17
50
|
groupBy: query.groupBy ?? []
|
|
18
51
|
});
|
|
19
|
-
const
|
|
20
|
-
|
|
52
|
+
const executor = QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
53
|
+
.setGrpcRequest('getDocuments', request)
|
|
54
|
+
.mapProof(getDocumentsV1Proof);
|
|
21
55
|
if (aggregateFunction === 'count') {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
verified = verifyDocumentsAverageProof(proof.grovedbProof, dataContract, query, field, LATEST_PLATFORM_VERSION, metadataTimeMs);
|
|
56
|
+
return await executor
|
|
57
|
+
.setProofVerifier(verifyDocumentsCountProof, ({ metadata }) => [dataContract, query, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
|
|
58
|
+
.mapResponse(data => data.proved ? data.verified.value : toDocumentsAggregate(data.result, aggregateFunction))
|
|
59
|
+
.execute();
|
|
29
60
|
}
|
|
30
|
-
|
|
31
|
-
return
|
|
61
|
+
const verify = aggregateFunction === 'sum' ? verifyDocumentsSumProof : verifyDocumentsAverageProof;
|
|
62
|
+
return await executor
|
|
63
|
+
.setProofVerifier(verify, ({ metadata }) => [dataContract, query, field, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
|
|
64
|
+
.mapResponse(data => data.proved ? data.verified.value : toDocumentsAggregate(data.result, aggregateFunction))
|
|
65
|
+
.execute();
|
|
32
66
|
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { CompositeSubQuery, DocumentsQuery, IdentifierLike, VerifiedChainedDocuments, VerifiedCompositeDocuments } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
4
|
export type ChainedDocuments = Omit<VerifiedChainedDocuments, 'rootHash'>;
|
|
4
5
|
export type CompositeDocuments = Omit<VerifiedCompositeDocuments, 'rootHash'>;
|
|
5
6
|
/**
|
|
6
7
|
* Chained join: documents of `query`, then the documents of `outerDocumentTypeName`
|
|
7
8
|
* their `joinProperty` refers to
|
|
8
9
|
*/
|
|
9
|
-
export declare function queryChained(grpcPool: GRPCPool, dataContractId: IdentifierLike, query: DocumentsQuery, joinProperty: string, outerDocumentTypeName: string): Promise<ChainedDocuments>;
|
|
10
|
+
export declare function queryChained(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, query: DocumentsQuery, joinProperty: string, outerDocumentTypeName: string): Promise<ChainedDocuments>;
|
|
10
11
|
/**
|
|
11
12
|
* Composite query: a page of documents plus up to 10 sub-queries, each optionally bound
|
|
12
13
|
* to values the page or an earlier sub-query proved
|
|
13
14
|
*/
|
|
14
|
-
export declare function queryComposite(grpcPool: GRPCPool, dataContractId: IdentifierLike, query: DocumentsQuery & {
|
|
15
|
+
export declare function queryComposite(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, query: DocumentsQuery & {
|
|
15
16
|
offset?: number;
|
|
16
17
|
}, subQueries: CompositeSubQuery[]): Promise<CompositeDocuments>;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyChainedDocumentsProof, verifyCompositeDocumentsProof } from 'pshenmic-dpp';
|
|
2
2
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
3
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
|
-
import
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toDocumentRemovalEntry, toDocuments, toOrderClauses, toStart, toSubQueries, toWhereClauses } from './v1.js';
|
|
5
6
|
/**
|
|
6
7
|
* Chained join: documents of `query`, then the documents of `outerDocumentTypeName`
|
|
7
8
|
* their `joinProperty` refers to
|
|
8
9
|
*/
|
|
9
|
-
export async function queryChained(grpcPool, dataContractId, query, joinProperty, outerDocumentTypeName) {
|
|
10
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
11
|
-
const
|
|
10
|
+
export async function queryChained(grpcPool, quorumKeyProvider, dataContractId, query, joinProperty, outerDocumentTypeName) {
|
|
11
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
12
|
+
const request = createDocumentsV1Request({
|
|
12
13
|
dataContractId: (new IdentifierWASM(dataContractId)).bytes(),
|
|
13
14
|
documentType: query.documentTypeName,
|
|
14
15
|
whereClauses: toWhereClauses(query.where),
|
|
@@ -17,18 +18,33 @@ export async function queryChained(grpcPool, dataContractId, query, joinProperty
|
|
|
17
18
|
start: toStart(query.startAt, query.startAtIncluded),
|
|
18
19
|
chained: { joinProperty, outerDocumentType: outerDocumentTypeName }
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
22
|
+
.setGrpcRequest('getDocuments', request)
|
|
23
|
+
.mapProof(getDocumentsV1Proof)
|
|
24
|
+
.setProofVerifier(verifyChainedDocumentsProof, dataContract, query, joinProperty, outerDocumentTypeName, LATEST_PLATFORM_VERSION)
|
|
25
|
+
.mapResponse(data => {
|
|
26
|
+
if (data.proved) {
|
|
27
|
+
const { rootHash, ...result } = data.verified;
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
const { innerDocuments, outerDocuments, missingOuterIds, removedOuterDocuments } = getDocumentsV1Data(data.result, 'chained');
|
|
31
|
+
return {
|
|
32
|
+
innerDocuments: toDocuments(innerDocuments, dataContract, query.documentTypeName),
|
|
33
|
+
outerDocuments: toDocuments(outerDocuments, dataContract, outerDocumentTypeName),
|
|
34
|
+
missingOuterIds: missingOuterIds.map(id => new IdentifierWASM(id)),
|
|
35
|
+
removedOuterDocuments: removedOuterDocuments.map(toDocumentRemovalEntry)
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.execute();
|
|
23
39
|
}
|
|
24
40
|
/**
|
|
25
41
|
* Composite query: a page of documents plus up to 10 sub-queries, each optionally bound
|
|
26
42
|
* to values the page or an earlier sub-query proved
|
|
27
43
|
*/
|
|
28
|
-
export async function queryComposite(grpcPool, dataContractId, query, subQueries) {
|
|
29
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
44
|
+
export async function queryComposite(grpcPool, quorumKeyProvider, dataContractId, query, subQueries) {
|
|
45
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
30
46
|
const identifier = new IdentifierWASM(dataContractId);
|
|
31
|
-
const
|
|
47
|
+
const request = createDocumentsV1Request({
|
|
32
48
|
dataContractId: identifier.bytes(),
|
|
33
49
|
documentType: query.documentTypeName,
|
|
34
50
|
whereClauses: toWhereClauses(query.where),
|
|
@@ -38,7 +54,32 @@ export async function queryComposite(grpcPool, dataContractId, query, subQueries
|
|
|
38
54
|
start: toStart(query.startAt, query.startAtIncluded),
|
|
39
55
|
subQueries: toSubQueries(subQueries, identifier)
|
|
40
56
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
58
|
+
.setGrpcRequest('getDocuments', request)
|
|
59
|
+
.mapProof(getDocumentsV1Proof)
|
|
60
|
+
.setProofVerifier(verifyCompositeDocumentsProof, dataContract, query, subQueries, LATEST_PLATFORM_VERSION)
|
|
61
|
+
.mapResponse(data => {
|
|
62
|
+
if (data.proved) {
|
|
63
|
+
const { rootHash, ...result } = data.verified;
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
const { pageDocuments, subResults } = getDocumentsV1Data(data.result, 'composite');
|
|
67
|
+
return {
|
|
68
|
+
pageDocuments: toDocuments(pageDocuments, dataContract, query.documentTypeName),
|
|
69
|
+
subResults: subResults.map(({ result, missingIds, removed }, index) => {
|
|
70
|
+
const subQuery = subQueries[index];
|
|
71
|
+
return {
|
|
72
|
+
documents: result.oneofKind === 'documents'
|
|
73
|
+
? toDocuments(result.documents.documents, subQuery.dataContract ?? dataContract, subQuery.documentTypeName)
|
|
74
|
+
: undefined,
|
|
75
|
+
counts: result.oneofKind === 'counts'
|
|
76
|
+
? result.counts.entries.map(({ inKey, key, count }) => ({ inKey: inKey ?? null, key, count: BigInt(count) }))
|
|
77
|
+
: undefined,
|
|
78
|
+
missingIds: missingIds.map(id => new IdentifierWASM(id)),
|
|
79
|
+
removals: removed.map(toDocumentRemovalEntry)
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
})
|
|
84
|
+
.execute();
|
|
44
85
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AggregateDocumentsQuery, HavingClause, IdentifierLike, ProvenRankedEntry, ProvenRankedPage } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
4
|
/**
|
|
4
5
|
* Top-K query: groups of `groupBy` ranked by the selected aggregate in the order `orderBy` names
|
|
5
6
|
*/
|
|
6
|
-
export declare function queryRanked(grpcPool: GRPCPool, dataContractId: IdentifierLike, query: AggregateDocumentsQuery): Promise<ProvenRankedPage>;
|
|
7
|
+
export declare function queryRanked(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, query: AggregateDocumentsQuery): Promise<ProvenRankedPage>;
|
|
7
8
|
/**
|
|
8
9
|
* Having query: groups of `groupBy` whose aggregate falls within the `having` bounds
|
|
9
10
|
*/
|
|
10
|
-
export declare function queryHaving(grpcPool: GRPCPool, dataContractId: IdentifierLike, query: AggregateDocumentsQuery & {
|
|
11
|
+
export declare function queryHaving(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, query: AggregateDocumentsQuery & {
|
|
11
12
|
having: HavingClause[];
|
|
12
13
|
}): Promise<ProvenRankedEntry[]>;
|