dash-platform-sdk 1.6.0-dev.2 → 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/getActionFeeAgreement.d.ts +2 -1
- package/src/documents/getActionFeeAgreement.js +3 -3
- package/src/documents/index.d.ts +12 -8
- package/src/documents/index.js +16 -13
- 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 +4 -1
- package/src/names/index.js +8 -5
- package/src/names/registerName.d.ts +2 -1
- package/src/names/registerName.js +4 -4
- 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/SDK.spec.js +42 -0
- package/src/utils/getQuorumPublicKey.d.ts +0 -1
- package/src/utils/getQuorumPublicKey.js +0 -19
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import convertToHomographSafeChars from '../utils/convertToHomographSafeChars.js';
|
|
2
2
|
import query from '../documents/query.js';
|
|
3
3
|
const DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
4
|
-
export default async function search(grpcPool, name) {
|
|
4
|
+
export default async function search(grpcPool, quorumKeyProvider, name) {
|
|
5
5
|
const [label, parentDomainName] = name.split('.');
|
|
6
6
|
const normalizedParentDomainName = convertToHomographSafeChars(parentDomainName);
|
|
7
7
|
const normalizedLabelPrefix = convertToHomographSafeChars(label);
|
|
@@ -12,5 +12,5 @@ export default async function search(grpcPool, name) {
|
|
|
12
12
|
const orderBy = [
|
|
13
13
|
['normalizedLabel', 'asc']
|
|
14
14
|
];
|
|
15
|
-
return await query(grpcPool, DPNS_DATA_CONTRACT_ID, 'domain', where, orderBy);
|
|
15
|
+
return await query(grpcPool, quorumKeyProvider, DPNS_DATA_CONTRACT_ID, 'domain', where, orderBy);
|
|
16
16
|
}
|
package/src/node/epochInfos.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
export interface EpochInfo {
|
|
3
4
|
number: number;
|
|
4
5
|
firstBlockHeight: number;
|
|
@@ -7,4 +8,4 @@ export interface EpochInfo {
|
|
|
7
8
|
feeMultiplier: bigint;
|
|
8
9
|
protocolVersion: 9;
|
|
9
10
|
}
|
|
10
|
-
export default function epochInfos(grpcPool: GRPCPool, count: number, ascending: boolean, start?: number): Promise<EpochInfo[]>;
|
|
11
|
+
export default function epochInfos(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, count: number, ascending: boolean, start?: number): Promise<EpochInfo[]>;
|
package/src/node/epochInfos.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { GetEpochsInfoRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { verifyEpochsInfoProof } from 'pshenmic-dpp';
|
|
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 { UInt32Value } from '../../proto/generated/google/protobuf/wrappers.js';
|
|
7
5
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
8
|
-
export default async function epochInfos(grpcPool, count, ascending, start) {
|
|
6
|
+
export default async function epochInfos(grpcPool, quorumKeyProvider, count, ascending, start) {
|
|
9
7
|
const getEpochsInfoRequest = GetEpochsInfoRequest.create({
|
|
10
8
|
version: {
|
|
11
9
|
oneofKind: 'v0',
|
|
@@ -17,31 +15,29 @@ export default async function epochInfos(grpcPool, count, ascending, start) {
|
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
protocolVersion: info.protocolVersion
|
|
46
|
-
}));
|
|
18
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
|
+
.setGrpcRequest('getEpochsInfo', getEpochsInfoRequest)
|
|
20
|
+
.setProofVerifier(verifyEpochsInfoProof, ({ metadata }) => [metadata.epoch, start, count, ascending, LATEST_PLATFORM_VERSION])
|
|
21
|
+
.mapResponse(data => {
|
|
22
|
+
if (data.proved) {
|
|
23
|
+
return data.verified.epochsInfo.map(info => ({
|
|
24
|
+
number: info.index,
|
|
25
|
+
firstBlockHeight: info.firstBlockHeight,
|
|
26
|
+
firstCoreBlockHeight: info.firstCoreBlockHeight,
|
|
27
|
+
startTime: info.firstBlockTime,
|
|
28
|
+
feeMultiplier: info.feeMultiplierPermille,
|
|
29
|
+
protocolVersion: info.protocolVersion
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
return data.result.epochs.epochInfos.map(info => ({
|
|
33
|
+
number: info.number,
|
|
34
|
+
firstBlockHeight: BigInt(info.firstBlockHeight),
|
|
35
|
+
firstCoreBlockHeight: info.firstCoreBlockHeight,
|
|
36
|
+
startTime: BigInt(info.startTime),
|
|
37
|
+
// returned as a fraction, e.g. 1.5 for 1500 permille
|
|
38
|
+
feeMultiplier: BigInt(Math.round(info.feeMultiplier * 1000)),
|
|
39
|
+
protocolVersion: info.protocolVersion
|
|
40
|
+
}));
|
|
41
|
+
})
|
|
42
|
+
.execute();
|
|
47
43
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
3
4
|
export interface FinalizedEpochInfo {
|
|
4
5
|
epochIndex: number;
|
|
@@ -11,11 +12,11 @@ export interface FinalizedEpochInfo {
|
|
|
11
12
|
totalDistributedStorageFees: bigint;
|
|
12
13
|
totalCreatedStorageFees: bigint;
|
|
13
14
|
coreBlockRewards: bigint;
|
|
14
|
-
blockProposers: {
|
|
15
|
+
blockProposers: Array<{
|
|
15
16
|
proposer: IdentifierWASM;
|
|
16
17
|
count: bigint;
|
|
17
|
-
}
|
|
18
|
+
}>;
|
|
18
19
|
feeMultiplier: bigint;
|
|
19
20
|
protocolVersion: number;
|
|
20
21
|
}
|
|
21
|
-
export default function getFinalizedEpochsInfo(grpcPool: GRPCPool, startEpochIndex: number, startEpochIndexIncluded: boolean, endEpochIndex: number, endEpochIndexIncluded: boolean): Promise<FinalizedEpochInfo[]>;
|
|
22
|
+
export default function getFinalizedEpochsInfo(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, startEpochIndex: number, startEpochIndexIncluded: boolean, endEpochIndex: number, endEpochIndexIncluded: boolean): Promise<FinalizedEpochInfo[]>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetFinalizedEpochInfosRequest } from '../../proto/generated/platform.js';
|
|
2
|
-
import { verifyFinalizedEpochInfosProof } from 'pshenmic-dpp';
|
|
3
|
-
import
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
2
|
+
import { IdentifierWASM, verifyFinalizedEpochInfosProof } from 'pshenmic-dpp';
|
|
3
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
6
4
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getFinalizedEpochsInfo(grpcPool, startEpochIndex, startEpochIndexIncluded, endEpochIndex, endEpochIndexIncluded) {
|
|
5
|
+
export default async function getFinalizedEpochsInfo(grpcPool, quorumKeyProvider, startEpochIndex, startEpochIndexIncluded, endEpochIndex, endEpochIndexIncluded) {
|
|
8
6
|
const getEpochsInfoRequest = GetFinalizedEpochInfosRequest.create({
|
|
9
7
|
version: {
|
|
10
8
|
oneofKind: 'v0',
|
|
@@ -17,38 +15,46 @@ export default async function getFinalizedEpochsInfo(grpcPool, startEpochIndex,
|
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
18
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
|
+
.setGrpcRequest('getFinalizedEpochInfos', getEpochsInfoRequest)
|
|
20
|
+
.setProofVerifier(verifyFinalizedEpochInfosProof, startEpochIndex, startEpochIndexIncluded, endEpochIndex, endEpochIndexIncluded, LATEST_PLATFORM_VERSION)
|
|
21
|
+
.mapResponse(data => {
|
|
22
|
+
if (data.proved) {
|
|
23
|
+
return data.verified.epochInfos.map(info => ({
|
|
24
|
+
epochIndex: info.epochIndex,
|
|
25
|
+
firstBlockTime: info.firstBlockTime,
|
|
26
|
+
firstBlockHeight: info.firstBlockHeight,
|
|
27
|
+
totalBlocksInEpoch: info.totalBlocksInEpoch,
|
|
28
|
+
firstCoreBlockHeight: info.firstCoreBlockHeight,
|
|
29
|
+
nextEpochStartCoreBlockHeight: info.nextEpochStartCoreBlockHeight,
|
|
30
|
+
totalProcessingFees: info.totalProcessingFees,
|
|
31
|
+
totalDistributedStorageFees: info.totalDistributedStorageFees,
|
|
32
|
+
totalCreatedStorageFees: info.totalCreatedStorageFees,
|
|
33
|
+
coreBlockRewards: info.coreBlockRewards,
|
|
34
|
+
blockProposers: info.blockProposers,
|
|
35
|
+
feeMultiplier: info.feeMultiplierPermille,
|
|
36
|
+
protocolVersion: info.protocolVersion
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
return data.result.epochs.finalizedEpochInfos.map(info => ({
|
|
40
|
+
epochIndex: info.number,
|
|
41
|
+
firstBlockTime: new Date(Number(info.firstBlockTime)),
|
|
42
|
+
firstBlockHeight: BigInt(info.firstBlockHeight),
|
|
43
|
+
totalBlocksInEpoch: BigInt(info.totalBlocksInEpoch),
|
|
44
|
+
firstCoreBlockHeight: info.firstCoreBlockHeight,
|
|
45
|
+
nextEpochStartCoreBlockHeight: info.nextEpochStartCoreBlockHeight,
|
|
46
|
+
totalProcessingFees: BigInt(info.totalProcessingFees),
|
|
47
|
+
totalDistributedStorageFees: BigInt(info.totalDistributedStorageFees),
|
|
48
|
+
totalCreatedStorageFees: BigInt(info.totalCreatedStorageFees),
|
|
49
|
+
coreBlockRewards: BigInt(info.coreBlockRewards),
|
|
50
|
+
blockProposers: info.blockProposers.map(({ proposerId, blockCount }) => ({
|
|
51
|
+
proposer: new IdentifierWASM(proposerId),
|
|
52
|
+
count: BigInt(blockCount)
|
|
53
|
+
})),
|
|
54
|
+
// returned as a fraction, e.g. 1.5 for 1500 permille
|
|
55
|
+
feeMultiplier: BigInt(Math.round(info.feeMultiplier * 1000)),
|
|
56
|
+
protocolVersion: info.protocolVersion
|
|
57
|
+
}));
|
|
58
|
+
})
|
|
59
|
+
.execute();
|
|
54
60
|
}
|
package/src/node/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { NodeStatus } from '../../types.js';
|
|
3
4
|
import { EpochInfo } from './epochInfos.js';
|
|
4
5
|
import { FinalizedEpochInfo } from './finalizedEpochInfos.js';
|
|
@@ -11,7 +12,9 @@ import { CurrentQuorumsInfo } from './getCurrentQuorumsInfo.js';
|
|
|
11
12
|
export declare class NodeController {
|
|
12
13
|
/** @ignore **/
|
|
13
14
|
grpcPool: GRPCPool;
|
|
14
|
-
|
|
15
|
+
/** @ignore **/
|
|
16
|
+
quorumKeyProvider: QuorumKeyProvider;
|
|
17
|
+
constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
|
|
15
18
|
/**
|
|
16
19
|
* Retrieves an info about node
|
|
17
20
|
* Includes information about genesis, chain, software versions
|
package/src/node/index.js
CHANGED
|
@@ -11,8 +11,11 @@ import getCurrentQuorumsInfo from './getCurrentQuorumsInfo.js';
|
|
|
11
11
|
export class NodeController {
|
|
12
12
|
/** @ignore **/
|
|
13
13
|
grpcPool;
|
|
14
|
-
|
|
14
|
+
/** @ignore **/
|
|
15
|
+
quorumKeyProvider;
|
|
16
|
+
constructor(grpcPool, quorumKeyProvider) {
|
|
15
17
|
this.grpcPool = grpcPool;
|
|
18
|
+
this.quorumKeyProvider = quorumKeyProvider;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* Retrieves an info about node
|
|
@@ -29,7 +32,7 @@ export class NodeController {
|
|
|
29
32
|
* @return {Promise<bigint>}
|
|
30
33
|
*/
|
|
31
34
|
async totalCredits() {
|
|
32
|
-
return await getTotalCredits(this.grpcPool);
|
|
35
|
+
return await getTotalCredits(this.grpcPool, this.quorumKeyProvider);
|
|
33
36
|
}
|
|
34
37
|
/**
|
|
35
38
|
* Retrieves an info about epochs
|
|
@@ -38,7 +41,7 @@ export class NodeController {
|
|
|
38
41
|
* @return {Promise<EpochInfo[]>}
|
|
39
42
|
*/
|
|
40
43
|
async getEpochsInfo(count, ascending, start) {
|
|
41
|
-
return await getEpochsInfo(this.grpcPool, count, ascending, start);
|
|
44
|
+
return await getEpochsInfo(this.grpcPool, this.quorumKeyProvider, count, ascending, start);
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Retrieves an finalized info about epochs
|
|
@@ -47,7 +50,7 @@ export class NodeController {
|
|
|
47
50
|
* @return {Promise<FinalizedEpochInfo[]>}
|
|
48
51
|
*/
|
|
49
52
|
async getFinalizedEpochsInfo(startEpochIndex, startEpochIndexIncluded, endEpochIndex, endEpochIndexIncluded) {
|
|
50
|
-
return await getFinalizedEpochsInfo(this.grpcPool, startEpochIndex, startEpochIndexIncluded, endEpochIndex, endEpochIndexIncluded);
|
|
53
|
+
return await getFinalizedEpochsInfo(this.grpcPool, this.quorumKeyProvider, startEpochIndex, startEpochIndexIncluded, endEpochIndex, endEpochIndexIncluded);
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
53
56
|
* Retrieves an info about current validator sets (quorums)
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
-
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
|
+
export default function totalCredits(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider): Promise<bigint>;
|
package/src/node/totalCredits.js
CHANGED
|
@@ -1,35 +1,20 @@
|
|
|
1
1
|
import { GetTotalCreditsInPlatformRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { HALVING_INTERVAL, LATEST_PLATFORM_VERSION, MAINNET_ACTIVATION_HEIGHT, TESTNET_ACTIVATION_HEIGHT } from '../constants.js';
|
|
3
3
|
import { verifyTotalCreditsProof } from 'pshenmic-dpp';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
-
export default async function totalCredits(grpcPool) {
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export default async function totalCredits(grpcPool, quorumKeyProvider) {
|
|
8
6
|
const getTotalCreditsInPlatformRequest = GetTotalCreditsInPlatformRequest.create({
|
|
9
7
|
version: {
|
|
10
8
|
oneofKind: 'v0',
|
|
11
9
|
v0: { prove: true }
|
|
12
10
|
}
|
|
13
11
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
const { result: { proof }, metadata } = v0;
|
|
24
|
-
if (metadata == null) {
|
|
25
|
-
throw new Error('Metadata not found');
|
|
26
|
-
}
|
|
27
|
-
const activationHeight = grpcPool.network === 'testnet' ? TESTNET_ACTIVATION_HEIGHT : MAINNET_ACTIVATION_HEIGHT;
|
|
28
|
-
const { rootHash, totalCredits } = verifyTotalCreditsProof(proof.grovedbProof, HALVING_INTERVAL, activationHeight, Number(metadata.height), LATEST_PLATFORM_VERSION);
|
|
29
|
-
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
30
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
31
|
-
if (!verify) {
|
|
32
|
-
throw new Error('Failed to verify query');
|
|
33
|
-
}
|
|
34
|
-
return totalCredits;
|
|
12
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
13
|
+
.setGrpcRequest('getTotalCreditsInPlatform', getTotalCreditsInPlatformRequest)
|
|
14
|
+
.setProofVerifier(verifyTotalCreditsProof, ({ metadata }) => {
|
|
15
|
+
const activationHeight = grpcPool.network === 'testnet' ? TESTNET_ACTIVATION_HEIGHT : MAINNET_ACTIVATION_HEIGHT;
|
|
16
|
+
return [HALVING_INTERVAL, activationHeight, metadata.coreChainLockedHeight, LATEST_PLATFORM_VERSION];
|
|
17
|
+
})
|
|
18
|
+
.mapResponse(data => data.proved ? data.verified.totalCredits : BigInt(data.result.credits))
|
|
19
|
+
.execute();
|
|
35
20
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { PlatformAddressLike } from 'pshenmic-dpp';
|
|
3
4
|
import { PlatformAddressInfo } from '../../types.js';
|
|
4
|
-
export declare function getAddressInfo(grpcPool: GRPCPool, platformAddress: PlatformAddressLike): Promise<PlatformAddressInfo>;
|
|
5
|
+
export declare function getAddressInfo(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, platformAddress: PlatformAddressLike): Promise<PlatformAddressInfo>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { PlatformAddressWASM, verifyPlatformAddressInfo } from 'pshenmic-dpp';
|
|
2
2
|
import { GetAddressInfoRequest } from '../../proto/generated/platform.js';
|
|
3
3
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
-
export async function getAddressInfo(grpcPool, platformAddress) {
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export async function getAddressInfo(grpcPool, quorumKeyProvider, platformAddress) {
|
|
8
6
|
const platformAddressWASM = new PlatformAddressWASM(platformAddress);
|
|
9
7
|
const getAddressInfoRequest = GetAddressInfoRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,31 +13,19 @@ export async function getAddressInfo(grpcPool, platformAddress) {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw new Error(`Failed to fetch info for address ${platformAddressWASM.toBech32m(grpcPool.network)}`);
|
|
34
|
-
}
|
|
35
|
-
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
36
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
37
|
-
if (!verify) {
|
|
38
|
-
throw new Error('Failed to verify query');
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
address,
|
|
42
|
-
nonce,
|
|
43
|
-
balance
|
|
44
|
-
};
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getAddressInfo', getAddressInfoRequest)
|
|
18
|
+
.setProofVerifier(verifyPlatformAddressInfo, platformAddressWASM, true, LATEST_PLATFORM_VERSION)
|
|
19
|
+
.mapResponse(data => {
|
|
20
|
+
const balanceAndNonce = data.proved ? data.verified : data.result.addressInfoEntry.balanceAndNonce;
|
|
21
|
+
if (balanceAndNonce?.nonce == null || balanceAndNonce.balance == null) {
|
|
22
|
+
throw new Error(`Failed to fetch info for address ${platformAddressWASM.toBech32m(grpcPool.network)}`);
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
address: platformAddressWASM,
|
|
26
|
+
nonce: balanceAndNonce.nonce,
|
|
27
|
+
balance: BigInt(balanceAndNonce.balance)
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.execute();
|
|
45
31
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { VerifiedAddressesBranchState } from 'pshenmic-dpp';
|
|
3
|
-
export declare function getAddressesBranchState(grpcPool: GRPCPool, key: Uint8Array, depth: number, checkpointHeight: bigint, expectedRootHash: Uint8Array): Promise<VerifiedAddressesBranchState>;
|
|
4
|
+
export declare function getAddressesBranchState(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, key: Uint8Array, depth: number, checkpointHeight: bigint, expectedRootHash: Uint8Array): Promise<VerifiedAddressesBranchState>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { verifyAddressesBranchState } from 'pshenmic-dpp';
|
|
2
|
-
import { GetAddressesBranchStateRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { GetAddressesBranchStateRequest, Proof, ResponseMetadata } from '../../proto/generated/platform.js';
|
|
3
3
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
-
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export async function getAddressesBranchState(grpcPool, quorumKeyProvider, key, depth, checkpointHeight, expectedRootHash) {
|
|
5
6
|
const getAddressesBranchStateRequest = GetAddressesBranchStateRequest.create({
|
|
6
7
|
version: {
|
|
7
8
|
oneofKind: 'v0',
|
|
@@ -12,10 +13,23 @@ export async function getAddressesBranchState(grpcPool, key, depth, checkpointHe
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
// the proof is verified against the root hash of the already verified trunk state, so it has no quorum signature
|
|
17
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
18
|
+
.setGrpcRequest('getAddressesBranchState', getAddressesBranchStateRequest)
|
|
19
|
+
// the response has no proof message, only the merk proof
|
|
20
|
+
.mapProof(({ version }) => {
|
|
21
|
+
if (version.oneofKind !== 'v0') {
|
|
22
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
23
|
+
}
|
|
24
|
+
return { proof: Proof.create({ grovedbProof: version.v0.merkProof }), metadata: ResponseMetadata.create() };
|
|
25
|
+
})
|
|
26
|
+
.setProofVerifier(verifyAddressesBranchState, key, depth, expectedRootHash, LATEST_PLATFORM_VERSION)
|
|
27
|
+
.mapResponse(data => {
|
|
28
|
+
if (!data.proved) {
|
|
29
|
+
throw new Error('Addresses branch state can only be requested with proof');
|
|
30
|
+
}
|
|
31
|
+
return data.verified;
|
|
32
|
+
})
|
|
33
|
+
.setValidateProof(false)
|
|
34
|
+
.execute();
|
|
21
35
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { PlatformAddressLike } from 'pshenmic-dpp';
|
|
3
4
|
import { PlatformAddressInfo } from '../../types.js';
|
|
4
|
-
export declare function getAddressesInfos(grpcPool: GRPCPool, platformAddresses: PlatformAddressLike[]): Promise<PlatformAddressInfo[]>;
|
|
5
|
+
export declare function getAddressesInfos(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, platformAddresses: PlatformAddressLike[]): Promise<PlatformAddressInfo[]>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { PlatformAddressWASM, verifyPlatformAddressesInfos } from 'pshenmic-dpp';
|
|
2
2
|
import { GetAddressesInfosRequest } from '../../proto/generated/platform.js';
|
|
3
3
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
-
export async function getAddressesInfos(grpcPool, platformAddresses) {
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export async function getAddressesInfos(grpcPool, quorumKeyProvider, platformAddresses) {
|
|
8
6
|
const platformAddressesWASM = platformAddresses.map(addr => new PlatformAddressWASM(addr));
|
|
9
7
|
const getAddressInfoRequest = GetAddressesInfosRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,29 +13,20 @@ export async function getAddressesInfos(grpcPool, platformAddresses) {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (!verify) {
|
|
35
|
-
throw new Error('Failed to verify query');
|
|
36
|
-
}
|
|
37
|
-
return infos
|
|
38
|
-
.map(info => ({
|
|
39
|
-
address: info.address,
|
|
40
|
-
nonce: info.nonce ?? 0,
|
|
41
|
-
balance: BigInt(info.balance ?? 0)
|
|
42
|
-
}));
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getAddressesInfos', getAddressInfoRequest)
|
|
18
|
+
.setProofVerifier(verifyPlatformAddressesInfos, platformAddressesWASM, true, LATEST_PLATFORM_VERSION)
|
|
19
|
+
.mapResponse(data => {
|
|
20
|
+
const infos = data.proved
|
|
21
|
+
? data.verified.infos
|
|
22
|
+
: data.result.addressInfoEntries.addressInfoEntries
|
|
23
|
+
.map(({ address, balanceAndNonce }) => ({ address: PlatformAddressWASM.fromBytes(address), ...balanceAndNonce }));
|
|
24
|
+
return infos
|
|
25
|
+
.map(info => ({
|
|
26
|
+
address: info.address,
|
|
27
|
+
nonce: info.nonce ?? 0,
|
|
28
|
+
balance: BigInt(info.balance ?? 0)
|
|
29
|
+
}));
|
|
30
|
+
})
|
|
31
|
+
.execute();
|
|
43
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { PlatformAddressesTrunkState } from '../../types.js';
|
|
3
|
-
export declare function getAddressesTrunkState(grpcPool: GRPCPool): Promise<PlatformAddressesTrunkState>;
|
|
4
|
+
export declare function getAddressesTrunkState(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider): Promise<PlatformAddressesTrunkState>;
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
import { verifyAddressesTrunkState } from 'pshenmic-dpp';
|
|
2
2
|
import { GetAddressesTrunkStateRequest } from '../../proto/generated/platform.js';
|
|
3
3
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
-
export async function getAddressesTrunkState(grpcPool) {
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export async function getAddressesTrunkState(grpcPool, quorumKeyProvider) {
|
|
8
6
|
const getAddressesTrunkStateRequest = GetAddressesTrunkStateRequest.create({
|
|
9
7
|
version: {
|
|
10
8
|
oneofKind: 'v0',
|
|
11
9
|
v0: {}
|
|
12
10
|
}
|
|
13
11
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
13
|
+
.setGrpcRequest('getAddressesTrunkState', getAddressesTrunkStateRequest)
|
|
14
|
+
.mapProof(({ version }) => {
|
|
15
|
+
if (version.oneofKind !== 'v0') {
|
|
16
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
17
|
+
}
|
|
18
|
+
const { v0: { proof, metadata } } = version;
|
|
19
|
+
if (proof == null) {
|
|
20
|
+
throw new Error('Proof not found');
|
|
21
|
+
}
|
|
22
|
+
if (metadata == null) {
|
|
23
|
+
throw new Error('Metadata not found');
|
|
24
|
+
}
|
|
25
|
+
return { proof, metadata };
|
|
26
|
+
})
|
|
27
|
+
.setProofVerifier(verifyAddressesTrunkState, LATEST_PLATFORM_VERSION)
|
|
28
|
+
.mapResponse(data => {
|
|
29
|
+
if (!data.proved) {
|
|
30
|
+
throw new Error('Addresses trunk state can only be requested with proof');
|
|
31
|
+
}
|
|
32
|
+
return { trunk: data.verified, metadata: data.metadata };
|
|
33
|
+
})
|
|
34
|
+
.execute();
|
|
33
35
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { BlockAddressBalanceChanges } from 'pshenmic-dpp';
|
|
3
|
-
export declare function getRecentAddressBalanceChanges(grpcPool: GRPCPool, startHeight: bigint, startHeightExclusive?: boolean): Promise<BlockAddressBalanceChanges[]>;
|
|
4
|
+
export declare function getRecentAddressBalanceChanges(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, startHeight: bigint, startHeightExclusive?: boolean): Promise<BlockAddressBalanceChanges[]>;
|