dash-platform-sdk 1.1.3 → 1.1.5
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/bundle.min.js +1 -1
- package/package.json +2 -2
- package/src/contestedResources/getContestedResourceVoteState.js +1 -1
- package/src/dataContracts/getDataContractByIdentifier.js +1 -1
- package/src/documents/query.js +1 -1
- package/src/grpcConnectionPool.d.ts +1 -0
- package/src/grpcConnectionPool.js +5 -4
- package/src/identities/getIdentityBalance.js +1 -1
- package/src/identities/getIdentityByIdentifier.js +1 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +1 -1
- package/src/identities/getIdentityByPublicKeyHash.js +1 -1
- package/src/identities/getIdentityContractNonce.js +1 -1
- package/src/identities/getIdentityNonce.js +1 -1
- package/src/identities/getIdentityPublicKeys.js +1 -1
- package/src/node/epochs.js +1 -1
- package/src/node/totalCredits.js +1 -1
- package/src/tokens/createStateTransition.d.ts +3 -0
- package/src/tokens/createStateTransition.js +79 -0
- package/src/tokens/getIdentitiesTokenBalances.js +1 -1
- package/src/tokens/getIdentityTokensBalances.js +1 -1
- package/src/tokens/getTokenContractInfo.d.ts +1 -1
- package/src/tokens/getTokenContractInfo.js +2 -2
- package/src/tokens/getTokenTotalSupply.js +1 -1
- package/src/tokens/index.d.ts +25 -1
- package/src/tokens/index.js +50 -0
- package/src/types.d.ts +12 -1
- package/src/utils/getEvonodeList.d.ts +1 -1
- package/src/utils/getEvonodeList.js +13 -28
- package/src/utils/getQuorumPublicKey.d.ts +1 -1
- package/src/utils/getQuorumPublicKey.js +8 -21
- package/test/unit/Tokens.spec.js +172 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dash-platform-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Lightweight SDK for accessing Dash Platform blockchain",
|
|
6
6
|
"ts-standard": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"grpc-web": "^1.5.0",
|
|
59
59
|
"hash.js": "^1.1.7",
|
|
60
60
|
"nice-grpc-web": "^3.3.6",
|
|
61
|
-
"pshenmic-dpp": "1.0.
|
|
61
|
+
"pshenmic-dpp": "1.0.19",
|
|
62
62
|
"rfc4648": "^1.5.4",
|
|
63
63
|
"wasm-drive-verify": "github:owl352/wasm-drive-verify#9c572d86992d205d994cd7e0630a4bd14d284f8a"
|
|
64
64
|
}
|
|
@@ -91,7 +91,7 @@ function getContestedResourceVoteState(grpcPool, contract, documentTypeName, ind
|
|
|
91
91
|
throw new Error('Metadata not found');
|
|
92
92
|
}
|
|
93
93
|
_b = (0, wasm_drive_verify_1.verifyVotePollVoteStateProof)(proof.grovedbProof, contract.bytes(pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, count, startAtIdentifierInfo, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, result = _b.result;
|
|
94
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
94
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
95
95
|
case 2:
|
|
96
96
|
quorumPublicKey = _e.sent();
|
|
97
97
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -70,7 +70,7 @@ function getByIdentifier(grpcPool, identifier) {
|
|
|
70
70
|
if (contract == null) {
|
|
71
71
|
throw new Error("Data Contract with identifier ".concat(id.base58(), " not found"));
|
|
72
72
|
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
74
|
case 2:
|
|
75
75
|
quorumPublicKey = _c.sent();
|
|
76
76
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
package/src/documents/query.js
CHANGED
|
@@ -81,7 +81,7 @@ function query(grpcPool_1, dataContractId_1, documentTypeName_1, where_1, orderB
|
|
|
81
81
|
}
|
|
82
82
|
startAtIncluded = ((_c = getDocumentsRequest.v0) === null || _c === void 0 ? void 0 : _c.startAfter) == null;
|
|
83
83
|
_b = (0, wasm_drive_verify_1.verifyDocumentProof)(proof.grovedbProof, dataContract.bytes(pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), documentTypeName, where, orderBy, limit, (_d = getDocumentsRequest.v0) === null || _d === void 0 ? void 0 : _d.startAt, startAtIncluded, BigInt(metadata === null || metadata === void 0 ? void 0 : metadata.timeMs), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, documents = _b.documents;
|
|
84
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
84
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
85
85
|
case 3:
|
|
86
86
|
quorumPublicKey = _f.sent();
|
|
87
87
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -3,6 +3,7 @@ import { PlatformDefinition } from '../proto/generated/platform';
|
|
|
3
3
|
import { GRPCOptions } from './DashPlatformSDK';
|
|
4
4
|
export default class GRPCConnectionPool {
|
|
5
5
|
channels: Channel[];
|
|
6
|
+
network: string;
|
|
6
7
|
constructor(network: 'testnet' | 'mainnet', grpcOptions?: GRPCOptions);
|
|
7
8
|
_initialize(network: 'testnet' | 'mainnet', poolLimit: number, dapiUrl?: string | string[]): Promise<void>;
|
|
8
9
|
getClient(): Client<PlatformDefinition>;
|
|
@@ -48,17 +48,18 @@ var seedNodes = {
|
|
|
48
48
|
],
|
|
49
49
|
mainnet: [
|
|
50
50
|
// seed-1.pshenmic.dev
|
|
51
|
-
'https://158.160.14.115:443'
|
|
51
|
+
'https://158.160.14.115:443'
|
|
52
52
|
// mainnet dcg seeds
|
|
53
|
-
'https://158.160.14.115',
|
|
54
|
-
'https://3.0.60.103',
|
|
55
|
-
'https://34.211.174.194'
|
|
53
|
+
// 'https://158.160.14.115',
|
|
54
|
+
// 'https://3.0.60.103',
|
|
55
|
+
// 'https://34.211.174.194'
|
|
56
56
|
]
|
|
57
57
|
};
|
|
58
58
|
var GRPCConnectionPool = /** @class */ (function () {
|
|
59
59
|
function GRPCConnectionPool(network, grpcOptions) {
|
|
60
60
|
var _a;
|
|
61
61
|
var grpcPoolLimit = (_a = grpcOptions === null || grpcOptions === void 0 ? void 0 : grpcOptions.poolLimit) !== null && _a !== void 0 ? _a : constants_1.GRPC_DEFAULT_POOL_LIMIT;
|
|
62
|
+
this.network = network;
|
|
62
63
|
this._initialize(network, grpcPoolLimit, grpcOptions === null || grpcOptions === void 0 ? void 0 : grpcOptions.dapiUrl).catch(console.error);
|
|
63
64
|
}
|
|
64
65
|
GRPCConnectionPool.prototype._initialize = function (network, poolLimit, dapiUrl) {
|
|
@@ -70,7 +70,7 @@ function getIdentityBalance(grpcPool, identifier) {
|
|
|
70
70
|
if (balance == null) {
|
|
71
71
|
throw new Error("Failed to fetch balance for identifier ".concat(id.base58()));
|
|
72
72
|
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
74
|
case 2:
|
|
75
75
|
quorumPublicKey = _c.sent();
|
|
76
76
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -70,7 +70,7 @@ function getIdentityByIdentifier(grpcPool, identifier) {
|
|
|
70
70
|
if (identity == null) {
|
|
71
71
|
throw new Error("Identity with identifier ".concat(id.base58(), " not found"));
|
|
72
72
|
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
74
|
case 2:
|
|
75
75
|
quorumPublicKey = _c.sent();
|
|
76
76
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -72,7 +72,7 @@ function getIdentityByNonUniquePublicKeyHash(grpcPool, hex) {
|
|
|
72
72
|
throw new Error("Identity with non unique public key hash ".concat(hex, " not found"));
|
|
73
73
|
}
|
|
74
74
|
identifier = new pshenmic_dpp_1.IdentifierWASM(identityId);
|
|
75
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.grovedbIdentityPublicKeyHashProof.quorumType, (0, bytesToHex_1.default)(proof.grovedbIdentityPublicKeyHashProof.quorumHash))];
|
|
75
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.grovedbIdentityPublicKeyHashProof.quorumType, (0, bytesToHex_1.default)(proof.grovedbIdentityPublicKeyHashProof.quorumHash))];
|
|
76
76
|
case 2:
|
|
77
77
|
quorumPublicKey = _c.sent();
|
|
78
78
|
verify = (0, verifyTenderdashProof_1.default)(proof.grovedbIdentityPublicKeyHashProof, metadata, rootHash, quorumPublicKey);
|
|
@@ -70,7 +70,7 @@ function getIdentityByPublicKeyHash(grpcPool, hex) {
|
|
|
70
70
|
if (identity == null) {
|
|
71
71
|
throw new Error("Identity with public key hash ".concat(hex, " not found"));
|
|
72
72
|
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
74
|
case 2:
|
|
75
75
|
quorumPublicKey = _c.sent();
|
|
76
76
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -73,7 +73,7 @@ function getIdentityContractNonce(grpcPool, identity, dataContract) {
|
|
|
73
73
|
if (identityContractNonce == null) {
|
|
74
74
|
return [2 /*return*/, BigInt(0)];
|
|
75
75
|
}
|
|
76
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
76
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
77
77
|
case 2:
|
|
78
78
|
quorumPublicKey = _c.sent();
|
|
79
79
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -71,7 +71,7 @@ function getIdentityNonce(grpcPool, identifier) {
|
|
|
71
71
|
if (nonce == null) {
|
|
72
72
|
return [2 /*return*/, BigInt(0)];
|
|
73
73
|
}
|
|
74
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
75
75
|
case 2:
|
|
76
76
|
quorumPublicKey = _c.sent();
|
|
77
77
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -71,7 +71,7 @@ function getIdentityPublicKeys(grpcPool, identifier) {
|
|
|
71
71
|
if (loadedIdentityKeys == null) {
|
|
72
72
|
throw new Error("Identity with identifier ".concat(id.base58(), " not found"));
|
|
73
73
|
}
|
|
74
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
75
75
|
case 2:
|
|
76
76
|
quorumPublicKey = _c.sent();
|
|
77
77
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
package/src/node/epochs.js
CHANGED
|
@@ -68,7 +68,7 @@ function epochs(grpcPool, count, ascending, start) {
|
|
|
68
68
|
throw new Error('Metadata not found');
|
|
69
69
|
}
|
|
70
70
|
_b = (0, wasm_drive_verify_1.verifyEpochInfos)(proof.grovedbProof, metadata.epoch, start, count, ascending, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, epochInfos = _b.epoch_infos;
|
|
71
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
71
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
72
72
|
case 2:
|
|
73
73
|
quorumPublicKey = _c.sent();
|
|
74
74
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
package/src/node/totalCredits.js
CHANGED
|
@@ -63,7 +63,7 @@ function totalCredits(grpcPool, network) {
|
|
|
63
63
|
}
|
|
64
64
|
activationHeight = network === 'testnet' ? constants_1.TESTNET_ACTIVATION_HEIGHT : constants_1.MAINNET_ACTIVATION_HEIGHT;
|
|
65
65
|
_b = (0, wasm_drive_verify_1.verifyTotalCreditsInSystem)(proof.grovedbProof, constants_1.HALVING_INTERVAL, activationHeight, Number(metadata.height), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, totalCredits = _b.total_credits;
|
|
66
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
66
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
67
67
|
case 2:
|
|
68
68
|
quorumPublicKey = _c.sent();
|
|
69
69
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IdentifierWASM, StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { TokenTransitionParams, TokenTransitionType } from '../types';
|
|
3
|
+
export default function createStateTransition(base: TokenBaseTransitionWASM, ownerId: IdentifierWASM, type: TokenTransitionType, params: TokenTransitionParams): StateTransitionWASM;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.default = createStateTransition;
|
|
13
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
14
|
+
var tokenTransitionsMap = {
|
|
15
|
+
burn: {
|
|
16
|
+
class: pshenmic_dpp_1.TokenBurnTransitionWASM,
|
|
17
|
+
arguments: ['amount', 'publicNote'],
|
|
18
|
+
optionalArguments: ['publicNote']
|
|
19
|
+
},
|
|
20
|
+
mint: {
|
|
21
|
+
class: pshenmic_dpp_1.TokenMintTransitionWASM,
|
|
22
|
+
arguments: ['identityId', 'amount', 'publicNote'],
|
|
23
|
+
optionalArguments: ['publicNote']
|
|
24
|
+
},
|
|
25
|
+
transfer: {
|
|
26
|
+
class: pshenmic_dpp_1.TokenTransferTransitionWASM,
|
|
27
|
+
arguments: ['identityId', 'amount', 'publicNote', 'sharedEncryptedNote', 'privateEncryptedNote'],
|
|
28
|
+
optionalArguments: ['publicNote', 'sharedEncryptedNote', 'privateEncryptedNote']
|
|
29
|
+
},
|
|
30
|
+
freeze: {
|
|
31
|
+
class: pshenmic_dpp_1.TokenFreezeTransitionWASM,
|
|
32
|
+
arguments: ['identityId', 'publicNote'],
|
|
33
|
+
optionalArguments: ['publicNote']
|
|
34
|
+
},
|
|
35
|
+
unfreeze: {
|
|
36
|
+
class: pshenmic_dpp_1.TokenUnFreezeTransitionWASM,
|
|
37
|
+
arguments: ['identityId', 'publicNote'],
|
|
38
|
+
optionalArguments: ['publicNote']
|
|
39
|
+
},
|
|
40
|
+
destroyFrozenFunds: {
|
|
41
|
+
class: pshenmic_dpp_1.TokenDestroyFrozenFundsTransitionWASM,
|
|
42
|
+
arguments: ['identityId', 'publicNote'],
|
|
43
|
+
optionalArguments: ['publicNote']
|
|
44
|
+
},
|
|
45
|
+
emergencyAction: {
|
|
46
|
+
class: pshenmic_dpp_1.TokenEmergencyActionTransitionWASM,
|
|
47
|
+
arguments: ['emergencyAction', 'publicNote'],
|
|
48
|
+
optionalArguments: ['publicNote']
|
|
49
|
+
},
|
|
50
|
+
directPurchase: {
|
|
51
|
+
class: pshenmic_dpp_1.TokenDirectPurchaseTransitionWASM,
|
|
52
|
+
arguments: ['amount', 'totalAgreedPrice'],
|
|
53
|
+
optionalArguments: []
|
|
54
|
+
},
|
|
55
|
+
setPriceForDirectPurchase: {
|
|
56
|
+
class: pshenmic_dpp_1.TokenSetPriceForDirectPurchaseTransitionWASM,
|
|
57
|
+
arguments: ['price', 'publicNote'],
|
|
58
|
+
optionalArguments: ['publicNote']
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function createStateTransition(base, ownerId, type, params) {
|
|
62
|
+
var _a = tokenTransitionsMap[type], TransitionClass = _a.class, classArguments = _a.arguments, optionalArguments = _a.optionalArguments;
|
|
63
|
+
if (TransitionClass == null) {
|
|
64
|
+
throw new Error("Unimplemented transition type: ".concat(type));
|
|
65
|
+
}
|
|
66
|
+
// check if all required params for token transition exists
|
|
67
|
+
var missingArgument = classArguments
|
|
68
|
+
.filter(function (classArgument) { return params[classArgument] == null &&
|
|
69
|
+
!optionalArguments.includes(classArgument); })[0];
|
|
70
|
+
if (missingArgument != null) {
|
|
71
|
+
throw new Error("Token transition param \"".concat(missingArgument, "\" is missing"));
|
|
72
|
+
}
|
|
73
|
+
var transitionParams = classArguments.map(function (classArgument) { return params[classArgument]; });
|
|
74
|
+
// @ts-expect-error
|
|
75
|
+
var tokenTransition = new (TransitionClass.bind.apply(TransitionClass, __spreadArray([void 0, base], transitionParams, false)))();
|
|
76
|
+
var tokenTransitionWASM = new pshenmic_dpp_1.TokenTransitionWASM(tokenTransition);
|
|
77
|
+
var batchedTransition = new pshenmic_dpp_1.BatchedTransitionWASM(tokenTransitionWASM);
|
|
78
|
+
return pshenmic_dpp_1.BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition], ownerId, 1).toStateTransition();
|
|
79
|
+
}
|
|
@@ -69,7 +69,7 @@ function getIdentitiesTokenBalances(grpcPool, identifiers, tokenIdentifier) {
|
|
|
69
69
|
throw new Error('Metadata not found');
|
|
70
70
|
}
|
|
71
71
|
_b = (0, wasm_drive_verify_1.verifyTokenBalancesForIdentityIdsVec)(proof.grovedbProof, tokenId.bytes(), true, ids.map(function (id) { return id.bytes(); }), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, balances = _b.balances;
|
|
72
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
72
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
73
|
case 2:
|
|
74
74
|
quorumPublicKey = _c.sent();
|
|
75
75
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -69,7 +69,7 @@ function getIdentityTokensBalances(grpcPool, identifier, tokenIdentifiers) {
|
|
|
69
69
|
throw new Error('Metadata not found');
|
|
70
70
|
}
|
|
71
71
|
_b = (0, wasm_drive_verify_1.verifyTokenBalancesForIdentityIdVec)(proof.grovedbProof, tokenIds.map(function (identifier) { return identifier.bytes(); }), id.bytes(), true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, balances = _b.balances;
|
|
72
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
72
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
73
|
case 2:
|
|
74
74
|
quorumPublicKey = _c.sent();
|
|
75
75
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -2,7 +2,7 @@ import GRPCConnectionPool from '../grpcConnectionPool';
|
|
|
2
2
|
import { IdentifierLike } from '../types';
|
|
3
3
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
4
4
|
export interface TokenContractInfo {
|
|
5
|
-
|
|
5
|
+
dataContractId: IdentifierWASM;
|
|
6
6
|
tokenContractPosition: number;
|
|
7
7
|
}
|
|
8
8
|
export default function getTokenContractInfo(grpcPool: GRPCConnectionPool, tokenIdentifier: IdentifierLike): Promise<TokenContractInfo>;
|
|
@@ -70,7 +70,7 @@ function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
|
70
70
|
if (contractInfo == null) {
|
|
71
71
|
throw new Error('ContractInfo not found');
|
|
72
72
|
}
|
|
73
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
73
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
74
74
|
case 2:
|
|
75
75
|
quorumPublicKey = _c.sent();
|
|
76
76
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -78,7 +78,7 @@ function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
|
78
78
|
throw new Error('Failed to verify query');
|
|
79
79
|
}
|
|
80
80
|
return [2 /*return*/, {
|
|
81
|
-
|
|
81
|
+
dataContractId: new pshenmic_dpp_1.IdentifierWASM(contractInfo.contractId),
|
|
82
82
|
tokenContractPosition: contractInfo.tokenContractPosition
|
|
83
83
|
}];
|
|
84
84
|
}
|
|
@@ -67,7 +67,7 @@ function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
|
67
67
|
throw new Error('Metadata not found');
|
|
68
68
|
}
|
|
69
69
|
_b = (0, wasm_drive_verify_1.verifyTokenTotalSupplyAndAggregatedIdentityBalance)(proof.grovedbProof, tokenId.bytes(), true, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.root_hash, totalSupplyAndBalance = _b.total_supply_and_balance;
|
|
70
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
70
|
+
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
71
71
|
case 2:
|
|
72
72
|
quorumPublicKey = _c.sent();
|
|
73
73
|
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
2
|
+
import { IdentifierLike, TokenTransitionParams, TokenTransitionType } from '../types';
|
|
3
3
|
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances';
|
|
4
4
|
import { IdentityTokenBalances } from './getIdentityTokensBalances';
|
|
5
5
|
import { TokenContractInfo } from './getTokenContractInfo';
|
|
6
6
|
import { TokenTotalSupply } from './getTokenTotalSupply';
|
|
7
|
+
import { StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
7
8
|
/**
|
|
8
9
|
* Tokens controller for requesting information about tokens and tokens holders
|
|
9
10
|
*
|
|
@@ -47,4 +48,27 @@ export default class TokensController {
|
|
|
47
48
|
* @return {Promise<TokenTotalSupply>}
|
|
48
49
|
*/
|
|
49
50
|
getTokenTotalSupply(tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a Token Base Transition that contains base information about token transition
|
|
53
|
+
*
|
|
54
|
+
* @param tokenId {IdentifierLike} - token identifier
|
|
55
|
+
* @param ownerId {IdentifierLike} - identity identifier of sender of the transaction
|
|
56
|
+
*
|
|
57
|
+
* @return {TokenBaseTransitionWASM}
|
|
58
|
+
*/
|
|
59
|
+
createBaseTransition(tokenId: IdentifierLike, ownerId: IdentifierLike): Promise<TokenBaseTransitionWASM>;
|
|
60
|
+
/**
|
|
61
|
+
* Helper function for creation of a token state transition to be broadcasted in the network
|
|
62
|
+
*
|
|
63
|
+
* You have to pass token base transition acquired from .createBaseTransition() method
|
|
64
|
+
* together with token transition type and its params
|
|
65
|
+
*
|
|
66
|
+
* @param base {TokenBaseTransitionWASM} - token Base transition
|
|
67
|
+
* @param ownerId {IdentifierLike} - `identity identifier of the owner of the transaction`
|
|
68
|
+
* @param type {TokenTransitionType} - token transition type as string (f.e. 'transfer')
|
|
69
|
+
* @param params {TokenTransitionParams} - params required for a token transition
|
|
70
|
+
*
|
|
71
|
+
* @return {StateTransitionWASM}
|
|
72
|
+
*/
|
|
73
|
+
createStateTransition(base: TokenBaseTransitionWASM, ownerId: IdentifierLike, type: TokenTransitionType, params: TokenTransitionParams): StateTransitionWASM;
|
|
50
74
|
}
|
package/src/tokens/index.js
CHANGED
|
@@ -40,6 +40,9 @@ var getIdentitiesTokenBalances_1 = require("./getIdentitiesTokenBalances");
|
|
|
40
40
|
var getIdentityTokensBalances_1 = require("./getIdentityTokensBalances");
|
|
41
41
|
var getTokenContractInfo_1 = require("./getTokenContractInfo");
|
|
42
42
|
var getTokenTotalSupply_1 = require("./getTokenTotalSupply");
|
|
43
|
+
var createStateTransition_1 = require("./createStateTransition");
|
|
44
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
45
|
+
var getIdentityContractNonce_1 = require("../identities/getIdentityContractNonce");
|
|
43
46
|
/**
|
|
44
47
|
* Tokens controller for requesting information about tokens and tokens holders
|
|
45
48
|
*
|
|
@@ -119,6 +122,53 @@ var TokensController = /** @class */ (function () {
|
|
|
119
122
|
});
|
|
120
123
|
});
|
|
121
124
|
};
|
|
125
|
+
/**
|
|
126
|
+
* Creates a Token Base Transition that contains base information about token transition
|
|
127
|
+
*
|
|
128
|
+
* @param tokenId {IdentifierLike} - token identifier
|
|
129
|
+
* @param ownerId {IdentifierLike} - identity identifier of sender of the transaction
|
|
130
|
+
*
|
|
131
|
+
* @return {TokenBaseTransitionWASM}
|
|
132
|
+
*/
|
|
133
|
+
TokensController.prototype.createBaseTransition = function (tokenId, ownerId) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var _a, dataContractId, tokenContractPosition, identityContractNonce;
|
|
136
|
+
return __generator(this, function (_b) {
|
|
137
|
+
switch (_b.label) {
|
|
138
|
+
case 0: return [4 /*yield*/, (0, getTokenContractInfo_1.default)(this.grpcPool, tokenId)];
|
|
139
|
+
case 1:
|
|
140
|
+
_a = _b.sent(), dataContractId = _a.dataContractId, tokenContractPosition = _a.tokenContractPosition;
|
|
141
|
+
return [4 /*yield*/, (0, getIdentityContractNonce_1.default)(this.grpcPool, ownerId, dataContractId)];
|
|
142
|
+
case 2:
|
|
143
|
+
identityContractNonce = _b.sent();
|
|
144
|
+
return [2 /*return*/, new pshenmic_dpp_1.TokenBaseTransitionWASM(identityContractNonce + BigInt(1), tokenContractPosition, dataContractId, tokenId, undefined)];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Helper function for creation of a token state transition to be broadcasted in the network
|
|
151
|
+
*
|
|
152
|
+
* You have to pass token base transition acquired from .createBaseTransition() method
|
|
153
|
+
* together with token transition type and its params
|
|
154
|
+
*
|
|
155
|
+
* @param base {TokenBaseTransitionWASM} - token Base transition
|
|
156
|
+
* @param ownerId {IdentifierLike} - `identity identifier of the owner of the transaction`
|
|
157
|
+
* @param type {TokenTransitionType} - token transition type as string (f.e. 'transfer')
|
|
158
|
+
* @param params {TokenTransitionParams} - params required for a token transition
|
|
159
|
+
*
|
|
160
|
+
* @return {StateTransitionWASM}
|
|
161
|
+
*/
|
|
162
|
+
TokensController.prototype.createStateTransition = function (base, ownerId, type, params) {
|
|
163
|
+
var owner = new pshenmic_dpp_1.IdentifierWASM(ownerId);
|
|
164
|
+
if (params.identityId != null) {
|
|
165
|
+
params.identityId = new pshenmic_dpp_1.IdentifierWASM(params.identityId);
|
|
166
|
+
}
|
|
167
|
+
if (params.price != null && typeof params.price === 'bigint') {
|
|
168
|
+
params.price = pshenmic_dpp_1.TokenPricingScheduleWASM.SinglePrice(params.price);
|
|
169
|
+
}
|
|
170
|
+
return (0, createStateTransition_1.default)(base, owner, type, params);
|
|
171
|
+
};
|
|
122
172
|
return TokensController;
|
|
123
173
|
}());
|
|
124
174
|
exports.default = TokensController;
|
package/src/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
1
|
+
import { IdentifierWASM, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
2
2
|
import { Versions } from 'dashhd';
|
|
3
3
|
export { IdentifierWASM, IdentityWASM, DocumentWASM, DataContractWASM, StateTransitionWASM, IdentityPublicKeyWASM } from 'pshenmic-dpp';
|
|
4
4
|
export type IdentifierLike = IdentifierWASM | string | Uint8Array;
|
|
@@ -135,3 +135,14 @@ export interface DataContractConfig {
|
|
|
135
135
|
requiresIdentityEncryptionBoundedKey?: number | null;
|
|
136
136
|
requiresIdentityDecryptionBoundedKey?: number | null;
|
|
137
137
|
}
|
|
138
|
+
export type TokenTransitionType = 'burn' | 'mint' | 'transfer' | 'freeze' | 'unfreeze' | 'destroyFrozenFunds' | 'emergencyAction' | 'directPurchase' | 'setPriceForDirectPurchase';
|
|
139
|
+
export interface TokenTransitionParams {
|
|
140
|
+
identityId?: IdentifierLike;
|
|
141
|
+
amount?: bigint;
|
|
142
|
+
price?: bigint | TokenPricingScheduleWASM;
|
|
143
|
+
totalAgreedPrice?: bigint;
|
|
144
|
+
publicNote?: string;
|
|
145
|
+
sharedEncryptedNote?: string;
|
|
146
|
+
privateEncryptedNote?: string;
|
|
147
|
+
emergencyAction?: TokenEmergencyActionWASM;
|
|
148
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { MasternodeList } from '../types';
|
|
2
|
-
export default function
|
|
2
|
+
export default function getDAPINodeList(network: 'testnet' | 'mainnet'): Promise<MasternodeList>;
|
|
@@ -36,42 +36,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.default =
|
|
40
|
-
function
|
|
39
|
+
exports.default = getDAPINodeList;
|
|
40
|
+
function getDAPINodeList(network) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
42
|
-
var
|
|
42
|
+
var url, resp, resultSet;
|
|
43
43
|
return __generator(this, function (_a) {
|
|
44
44
|
switch (_a.label) {
|
|
45
45
|
case 0:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
mainnet: 'https://rpc.digitalcash.dev'
|
|
49
|
-
}[network];
|
|
50
|
-
payload = JSON.stringify({
|
|
51
|
-
method: 'masternodelist',
|
|
52
|
-
params: [
|
|
53
|
-
'evo'
|
|
54
|
-
]
|
|
55
|
-
});
|
|
56
|
-
return [4 /*yield*/, fetch(baseUrl, {
|
|
57
|
-
method: 'POST',
|
|
58
|
-
headers: {
|
|
59
|
-
// "Authorization": `Basic ${basicAuth}`,
|
|
60
|
-
'Content-Type': 'application/json'
|
|
61
|
-
},
|
|
62
|
-
body: payload
|
|
63
|
-
})];
|
|
46
|
+
url = "https://".concat(network === 'mainnet' ? '' : 'testnet.', "platform-explorer.pshenmic.dev/validators?isActive=true");
|
|
47
|
+
return [4 /*yield*/, fetch(url)];
|
|
64
48
|
case 1:
|
|
65
49
|
resp = _a.sent();
|
|
50
|
+
if (resp.status !== 200) {
|
|
51
|
+
throw new Error('Failed to query Platform Explorer for active validators');
|
|
52
|
+
}
|
|
66
53
|
return [4 /*yield*/, resp.json()];
|
|
67
54
|
case 2:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
return [2 /*return*/, data.result];
|
|
55
|
+
resultSet = (_a.sent()).resultSet;
|
|
56
|
+
return [2 /*return*/, resultSet
|
|
57
|
+
// eslint-disable-next-line
|
|
58
|
+
.map(function (validator) { var _a, _b; return ((_b = (_a = validator === null || validator === void 0 ? void 0 : validator.proTxInfo) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.service) ? "https://".concat(validator.proTxInfo.state.service.split(':')[0]).concat(network === 'mainnet' ? '' : ':1443') : undefined; })
|
|
59
|
+
.filter(function (e) { return e != null; })];
|
|
75
60
|
}
|
|
76
61
|
});
|
|
77
62
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getQuorumPublicKey(quorumType: number, quorumHash: string): Promise<string>;
|
|
1
|
+
export declare function getQuorumPublicKey(network: string, quorumType: number, quorumHash: string): Promise<string>;
|
|
@@ -38,9 +38,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getQuorumPublicKey = getQuorumPublicKey;
|
|
40
40
|
var cache = {};
|
|
41
|
-
function getQuorumPublicKey(quorumType, quorumHash) {
|
|
41
|
+
function getQuorumPublicKey(network, quorumType, quorumHash) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var cached,
|
|
43
|
+
var cached, url, resp, data, quorumPublicKey;
|
|
44
44
|
return __generator(this, function (_a) {
|
|
45
45
|
switch (_a.label) {
|
|
46
46
|
case 0:
|
|
@@ -48,32 +48,19 @@ function getQuorumPublicKey(quorumType, quorumHash) {
|
|
|
48
48
|
if (cached != null) {
|
|
49
49
|
return [2 /*return*/, cached];
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
method: 'quorum', params: ['info', quorumType, quorumHash]
|
|
55
|
-
});
|
|
56
|
-
return [4 /*yield*/, fetch(baseUrl, {
|
|
57
|
-
method: 'POST',
|
|
58
|
-
headers: {
|
|
59
|
-
Authorization: "Basic ".concat(basicAuth), 'Content-Type': 'application/json'
|
|
60
|
-
},
|
|
61
|
-
body: payload
|
|
51
|
+
url = "https://".concat(network === 'mainnet' ? '' : 'testnet.', "platform-explorer.pshenmic.dev/quorum/info?quorumType=").concat(quorumType, "&quorumHash=").concat(quorumHash);
|
|
52
|
+
return [4 /*yield*/, fetch(url, {
|
|
53
|
+
method: 'GET'
|
|
62
54
|
})];
|
|
63
55
|
case 1:
|
|
64
56
|
resp = _a.sent();
|
|
65
|
-
if (resp.status
|
|
66
|
-
throw new Error('
|
|
57
|
+
if (resp.status !== 200) {
|
|
58
|
+
throw new Error('Failed to query Platform Explorer for quorum public keys');
|
|
67
59
|
}
|
|
68
60
|
return [4 /*yield*/, resp.json()];
|
|
69
61
|
case 2:
|
|
70
62
|
data = _a.sent();
|
|
71
|
-
|
|
72
|
-
err = new Error(data.error.message);
|
|
73
|
-
Object.assign(err, data.error);
|
|
74
|
-
throw err;
|
|
75
|
-
}
|
|
76
|
-
quorumPublicKey = data.result.quorumPublicKey;
|
|
63
|
+
quorumPublicKey = data.quorumPublicKey;
|
|
77
64
|
cache["".concat(quorumType, "_").concat(quorumHash)] = quorumPublicKey;
|
|
78
65
|
return [2 /*return*/, quorumPublicKey];
|
|
79
66
|
}
|