dash-platform-sdk 1.3.0-dev.4 → 1.3.0-dev.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 +21 -2
- package/package.json +29 -30
- package/proto/generated/google/protobuf/wrappers.d.ts +260 -29
- package/proto/generated/platform.client.d.ts +251 -0
- package/proto/generated/platform.d.ts +3682 -1939
- package/src/DashPlatformSDK.d.ts +5 -4
- package/src/contestedResources/createStateTransition.d.ts +1 -2
- package/src/grpcConnectionPool.d.ts +30 -8
- package/src/keyPair/deriveChild.d.ts +2 -2
- package/src/keyPair/derivePath.d.ts +2 -2
- package/src/keyPair/index.d.ts +39 -114
- package/src/keyPair/mnemonicToSeed.d.ts +1 -1
- package/src/names/searchByIdentity.d.ts +1 -1
- package/src/node/index.d.ts +3 -3
- package/src/node/totalCredits.d.ts +2 -1
- package/src/types.d.ts +6 -12
- package/src/utils/bytesToTypedArray.d.ts +1 -0
- package/src/utils/calculateMsgHash.d.ts +1 -1
- package/src/utils/calculateSignHash.d.ts +1 -1
- package/src/utils/calculateStateIdHash.d.ts +1 -1
- package/src/utils/createVoterIdentityId.d.ts +1 -1
- package/src/utils/getEvonodeList.d.ts +2 -2
- package/src/utils/sha256.d.ts +1 -1
- package/src/utils/signHash.d.ts +1 -1
- package/src/utils/signRequestId.d.ts +1 -1
- package/src/utils/verifyTenderdashProof.d.ts +1 -1
- package/src/voting/createStateTransition.d.ts +1 -2
- package/src/voting/index.d.ts +3 -4
- package/bundle.min.js.LICENSE.txt +0 -1
- package/index.js +0 -5
- package/proto/generated/google/protobuf/wrappers.js +0 -398
- package/proto/generated/platform.js +0 -18524
- package/src/DashPlatformSDK.js +0 -91
- package/src/constants.js +0 -13
- package/src/contestedResources/createStateTransition.js +0 -9
- package/src/contestedResources/getContestedResourceVoteState.js +0 -123
- package/src/contestedResources/index.js +0 -76
- package/src/dataContracts/create.js +0 -14
- package/src/dataContracts/createStateTransition.js +0 -23
- package/src/dataContracts/getDataContractByIdentifier.js +0 -87
- package/src/dataContracts/index.js +0 -103
- package/src/documents/create.js +0 -7
- package/src/documents/createStateTransition.js +0 -64
- package/src/documents/index.js +0 -130
- package/src/documents/query.js +0 -94
- package/src/grpcConnectionPool.js +0 -137
- package/src/identities/createStateTransition.js +0 -46
- package/src/identities/getIdentityBalance.js +0 -83
- package/src/identities/getIdentityByIdentifier.js +0 -83
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +0 -85
- package/src/identities/getIdentityByPublicKeyHash.js +0 -83
- package/src/identities/getIdentityContractNonce.js +0 -86
- package/src/identities/getIdentityNonce.js +0 -84
- package/src/identities/getIdentityPublicKeys.js +0 -85
- package/src/identities/index.js +0 -237
- package/src/keyPair/deriveChild.js +0 -50
- package/src/keyPair/derivePath.js +0 -50
- package/src/keyPair/index.js +0 -323
- package/src/keyPair/keyToPublicKey.d.ts +0 -2
- package/src/keyPair/keyToPublicKey.js +0 -47
- package/src/keyPair/keyToWalletId.d.ts +0 -2
- package/src/keyPair/keyToWalletId.js +0 -50
- package/src/keyPair/keyToXPrivateKey.d.ts +0 -3
- package/src/keyPair/keyToXPrivateKey.js +0 -50
- package/src/keyPair/keyToXPublicKey.d.ts +0 -3
- package/src/keyPair/keyToXPublicKey.js +0 -50
- package/src/keyPair/mnemonicToIdentityKey.d.ts +0 -3
- package/src/keyPair/mnemonicToIdentityKey.js +0 -57
- package/src/keyPair/mnemonicToSeed.js +0 -47
- package/src/keyPair/mnemonicToWallet.d.ts +0 -2
- package/src/keyPair/mnemonicToWallet.js +0 -55
- package/src/keyPair/privateKeyToWif.d.ts +0 -2
- package/src/keyPair/privateKeyToWif.js +0 -50
- package/src/keyPair/publicKeyToAddress.d.ts +0 -2
- package/src/keyPair/publicKeyToAddress.js +0 -50
- package/src/keyPair/seedToWallet.d.ts +0 -2
- package/src/keyPair/seedToWallet.js +0 -50
- package/src/keyPair/walletToIdentityKey.d.ts +0 -3
- package/src/keyPair/walletToIdentityKey.js +0 -56
- package/src/keyPair/xkeyToHDXKey.d.ts +0 -2
- package/src/keyPair/xkeyToHDXKey.js +0 -50
- package/src/names/index.js +0 -170
- package/src/names/registerName.js +0 -131
- package/src/names/searchByIdentity.js +0 -51
- package/src/names/searchByName.js +0 -64
- package/src/names/testNameContested.js +0 -6
- package/src/names/validateName.js +0 -14
- package/src/node/epochs.js +0 -88
- package/src/node/index.js +0 -102
- package/src/node/status.js +0 -85
- package/src/node/totalCredits.js +0 -76
- package/src/signer/AbstractSigner.js +0 -2
- package/src/signer/PrivateKeySigner.d.ts +0 -0
- package/src/signer/PrivateKeySigner.js +0 -64
- package/src/signer/setSigner.js +0 -8
- package/src/stateTransitions/broadcast.js +0 -60
- package/src/stateTransitions/index.js +0 -87
- package/src/stateTransitions/waitForStateTransitionResult.js +0 -60
- package/src/tokens/createStateTransition.js +0 -79
- package/src/tokens/getIdentitiesTokenBalances.js +0 -86
- package/src/tokens/getIdentityTokensBalances.js +0 -86
- package/src/tokens/getTokenContractInfo.js +0 -86
- package/src/tokens/getTokenDirectPurchasePrices.js +0 -83
- package/src/tokens/getTokenTotalSupply.js +0 -84
- package/src/tokens/index.js +0 -193
- package/src/types.js +0 -25
- package/src/utils/base58ToBytes.js +0 -7
- package/src/utils/bytesToHex.js +0 -6
- package/src/utils/calculateMsgHash.js +0 -34
- package/src/utils/calculateSignHash.js +0 -11
- package/src/utils/calculateStateIdHash.js +0 -12
- package/src/utils/convertToHomographSafeChars.js +0 -14
- package/src/utils/createVoterIdentityId.js +0 -12
- package/src/utils/getEvonodeList.js +0 -63
- package/src/utils/getQuorumPublicKey.js +0 -69
- package/src/utils/getRandomArrayItem.js +0 -6
- package/src/utils/getRandomBytes.js +0 -7
- package/src/utils/hexToBytes.js +0 -7
- package/src/utils/index.js +0 -68
- package/src/utils/indexBytesToString.js +0 -7
- package/src/utils/sha256.js +0 -13
- package/src/utils/signHash.js +0 -25
- package/src/utils/signRequestId.js +0 -22
- package/src/utils/sleep.js +0 -51
- package/src/utils/stringToIndexValueBytes.js +0 -13
- package/src/utils/verifyTenderdashProof.js +0 -30
- package/src/voting/createStateTransition.js +0 -9
- package/src/voting/createVote.js +0 -8
- package/src/voting/index.js +0 -62
- package/test/unit/ContestedResources.spec.js +0 -344
- package/test/unit/DataContract.spec.js +0 -142
- package/test/unit/Document.spec.js +0 -199
- package/test/unit/Identity.spec.js +0 -357
- package/test/unit/KeyPair.spec.js +0 -149
- package/test/unit/Names.spec.js +0 -96
- package/test/unit/Node.spec.js +0 -129
- package/test/unit/SDK.spec.js +0 -12
- package/test/unit/Tokens.spec.js +0 -288
package/src/DashPlatformSDK.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DashPlatformSDK = void 0;
|
|
4
|
-
var grpcConnectionPool_1 = require("./grpcConnectionPool");
|
|
5
|
-
var identities_1 = require("./identities");
|
|
6
|
-
var stateTransitions_1 = require("./stateTransitions");
|
|
7
|
-
var documents_1 = require("./documents");
|
|
8
|
-
var utils_1 = require("./utils");
|
|
9
|
-
var keyPair_1 = require("./keyPair");
|
|
10
|
-
var node_1 = require("./node");
|
|
11
|
-
var names_1 = require("./names");
|
|
12
|
-
var dataContracts_1 = require("./dataContracts");
|
|
13
|
-
var contestedResources_1 = require("./contestedResources");
|
|
14
|
-
var tokens_1 = require("./tokens");
|
|
15
|
-
var voting_1 = require("./voting");
|
|
16
|
-
/**
|
|
17
|
-
* Javascript SDK for that let you interact with a Dash Platform blockchain
|
|
18
|
-
*/
|
|
19
|
-
var DashPlatformSDK = /** @class */ (function () {
|
|
20
|
-
/**
|
|
21
|
-
* Constructs a new DashPlatformSDK instance, optionally pass options
|
|
22
|
-
* if you want to configure the SDK instance (network, dapiUrl, signer)
|
|
23
|
-
*
|
|
24
|
-
* @param options {SDKOptions=}
|
|
25
|
-
*/
|
|
26
|
-
function DashPlatformSDK(options) {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
if (options != null && (options.network == null || !['testnet', 'mainnet'].includes(options.network))) {
|
|
29
|
-
throw new Error('If options is passed, network must be set (either mainnet or testnet)');
|
|
30
|
-
}
|
|
31
|
-
this.network = (_a = options === null || options === void 0 ? void 0 : options.network) !== null && _a !== void 0 ? _a : 'testnet';
|
|
32
|
-
this.signer = options === null || options === void 0 ? void 0 : options.signer;
|
|
33
|
-
this.options = options;
|
|
34
|
-
this.utils = new utils_1.UtilsController();
|
|
35
|
-
// Compatibility
|
|
36
|
-
if ((options === null || options === void 0 ? void 0 : options.dapiUrl) != null && ((options === null || options === void 0 ? void 0 : options.grpc) == null)) {
|
|
37
|
-
// @ts-expect-error
|
|
38
|
-
this.options.grpc = { dapiUrl: options.dapiUrl };
|
|
39
|
-
}
|
|
40
|
-
this.grpcPool = new grpcConnectionPool_1.default(this.network, (_b = this.options) === null || _b === void 0 ? void 0 : _b.grpc);
|
|
41
|
-
this._initialize(this.grpcPool, this.network);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @private
|
|
45
|
-
*
|
|
46
|
-
* Internal function to initialize SDK GRPC connection pool. Is not meant to be used outside the SDK
|
|
47
|
-
*
|
|
48
|
-
* @param grpcPool
|
|
49
|
-
* @param network
|
|
50
|
-
*/
|
|
51
|
-
DashPlatformSDK.prototype._initialize = function (grpcPool, network) {
|
|
52
|
-
this.grpcPool = grpcPool;
|
|
53
|
-
this.stateTransitions = new stateTransitions_1.StateTransitionsController(grpcPool);
|
|
54
|
-
this.contestedResources = new contestedResources_1.ContestedResourcesController(grpcPool);
|
|
55
|
-
this.dataContracts = new dataContracts_1.DataContractsController(grpcPool);
|
|
56
|
-
this.identities = new identities_1.IdentitiesController(grpcPool);
|
|
57
|
-
this.documents = new documents_1.DocumentsController(grpcPool);
|
|
58
|
-
this.voting = new voting_1.VotingController();
|
|
59
|
-
this.node = new node_1.NodeController(grpcPool, network);
|
|
60
|
-
this.tokens = new tokens_1.TokensController(grpcPool);
|
|
61
|
-
this.names = new names_1.NamesController(grpcPool);
|
|
62
|
-
this.keyPair = new keyPair_1.KeyPairController();
|
|
63
|
-
};
|
|
64
|
-
DashPlatformSDK.prototype.setSigner = function (signer) {
|
|
65
|
-
this.signer = signer;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Get currently used network
|
|
69
|
-
*
|
|
70
|
-
* @return {string}
|
|
71
|
-
*/
|
|
72
|
-
DashPlatformSDK.prototype.getNetwork = function () {
|
|
73
|
-
return this.network;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Switches a network that SDK is currently connected to
|
|
77
|
-
*
|
|
78
|
-
* @param network {string}
|
|
79
|
-
*/
|
|
80
|
-
DashPlatformSDK.prototype.setNetwork = function (network) {
|
|
81
|
-
var _a;
|
|
82
|
-
if (network !== 'testnet' && network !== 'mainnet') {
|
|
83
|
-
throw new Error('Unknown network, should be mainnet or testnet');
|
|
84
|
-
}
|
|
85
|
-
this.network = network;
|
|
86
|
-
var grpcPool = new grpcConnectionPool_1.default(this.network, (_a = this.options) === null || _a === void 0 ? void 0 : _a.grpc);
|
|
87
|
-
this._initialize(grpcPool, this.network);
|
|
88
|
-
};
|
|
89
|
-
return DashPlatformSDK;
|
|
90
|
-
}());
|
|
91
|
-
exports.DashPlatformSDK = DashPlatformSDK;
|
package/src/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DPNS_DATA_CONTRACT_BYTES = exports.DPNS_DATA_CONTRACT_ID = exports.GRPC_DEFAULT_POOL_LIMIT = exports.MAINNET_ACTIVATION_HEIGHT = exports.TESTNET_ACTIVATION_HEIGHT = exports.HALVING_INTERVAL = exports.DAPI_DEFAULT_LIMIT = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Default amount of documents to retrieve from DAPI
|
|
6
|
-
*/
|
|
7
|
-
exports.DAPI_DEFAULT_LIMIT = 100;
|
|
8
|
-
exports.HALVING_INTERVAL = 210240;
|
|
9
|
-
exports.TESTNET_ACTIVATION_HEIGHT = 1066900;
|
|
10
|
-
exports.MAINNET_ACTIVATION_HEIGHT = 2128896;
|
|
11
|
-
exports.GRPC_DEFAULT_POOL_LIMIT = 5;
|
|
12
|
-
exports.DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
|
|
13
|
-
exports.DPNS_DATA_CONTRACT_BYTES = 'AeZoxlmvZq7h5ywYbd57W34KHXEqCcQNVyH2Ir9TxTFVAAAAAAABAQAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIGZG9tYWluFgsSEGRvY3VtZW50c011dGFibGUTABIMY2FuQmVEZWxldGVkEwESDHRyYW5zZmVyYWJsZQIBEgl0cmFkZU1vZGUCARIEdHlwZRIGb2JqZWN0EgdpbmRpY2VzFQIWBBIEbmFtZRIScGFyZW50TmFtZUFuZExhYmVsEgpwcm9wZXJ0aWVzFQIWARIabm9ybWFsaXplZFBhcmVudERvbWFpbk5hbWUSA2FzYxYBEg9ub3JtYWxpemVkTGFiZWwSA2FzYxIGdW5pcXVlEwESCWNvbnRlc3RlZBYDEgxmaWVsZE1hdGNoZXMVARYCEgVmaWVsZBIPbm9ybWFsaXplZExhYmVsEgxyZWdleFBhdHRlcm4SE15bYS16QS1aMDEtXXszLDE5fSQSCnJlc29sdXRpb24CABILZGVzY3JpcHRpb24SqklmIHRoZSBub3JtYWxpemVkIGxhYmVsIHBhcnQgb2YgdGhpcyBpbmRleCBpcyBsZXNzIHRoYW4gMjAgY2hhcmFjdGVycyAoYWxsIGFscGhhYmV0IGEteiwgQS1aLCAwLCAxLCBhbmQgLSkgdGhlbiBhIG1hc3Rlcm5vZGUgdm90ZSBjb250ZXN0IHRha2VzIHBsYWNlIHRvIGdpdmUgb3V0IHRoZSBuYW1lFgMSBG5hbWUSCmlkZW50aXR5SWQS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-1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = createStateTransition;
|
|
4
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
5
|
-
function createStateTransition(voteWASM, proTxHash, identityNonce) {
|
|
6
|
-
var voterIdentity = pshenmic_dpp_1.IdentifierWASM.fromHex(proTxHash);
|
|
7
|
-
var masternodeVoteTransition = new pshenmic_dpp_1.MasternodeVoteTransitionWASM(proTxHash, voterIdentity, voteWASM, identityNonce);
|
|
8
|
-
return masternodeVoteTransition.toStateTransition();
|
|
9
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.default = getContestedResourceVoteState;
|
|
51
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
52
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
53
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
54
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
55
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
56
|
-
function getContestedResourceVoteState(grpcPool, contract, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, count) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var getContestedResourceVoteStateRequest, v0, _a, proof, metadata, _b, rootHash, result, quorumPublicKey, verify, contenders, winner;
|
|
59
|
-
var _c, _d;
|
|
60
|
-
return __generator(this, function (_e) {
|
|
61
|
-
switch (_e.label) {
|
|
62
|
-
case 0:
|
|
63
|
-
if (startAtIdentifierInfo != null) {
|
|
64
|
-
startAtIdentifierInfo = {
|
|
65
|
-
startIdentifier: (new pshenmic_dpp_1.IdentifierWASM(startAtIdentifierInfo.startIdentifier)).bytes(),
|
|
66
|
-
startIdentifierIncluded: startAtIdentifierInfo.startIdentifierIncluded
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
getContestedResourceVoteStateRequest = platform_1.GetContestedResourceVoteStateRequest.fromPartial({
|
|
70
|
-
v0: {
|
|
71
|
-
contractId: contract.id.bytes(),
|
|
72
|
-
documentTypeName: documentTypeName,
|
|
73
|
-
indexName: indexName,
|
|
74
|
-
indexValues: indexValues,
|
|
75
|
-
resultType: resultType,
|
|
76
|
-
allowIncludeLockedAndAbstainingVoteTally: allowIncludeLockedAndAbstainingVoteTally,
|
|
77
|
-
startAtIdentifierInfo: startAtIdentifierInfo,
|
|
78
|
-
count: count,
|
|
79
|
-
prove: true
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return [4 /*yield*/, grpcPool.getClient().getContestedResourceVoteState(getContestedResourceVoteStateRequest)];
|
|
83
|
-
case 1:
|
|
84
|
-
v0 = (_e.sent()).v0;
|
|
85
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
86
|
-
if (proof == null) {
|
|
87
|
-
throw new Error('Proof not found');
|
|
88
|
-
}
|
|
89
|
-
if (metadata == null) {
|
|
90
|
-
throw new Error('Metadata not found');
|
|
91
|
-
}
|
|
92
|
-
_b = (0, pshenmic_dpp_1.verifyVotePollVoteStateProof)(proof.grovedbProof, contract, documentTypeName, indexName, indexValues, resultType, allowIncludeLockedAndAbstainingVoteTally, count, startAtIdentifierInfo, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, result = _b.result;
|
|
93
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
94
|
-
case 2:
|
|
95
|
-
quorumPublicKey = _e.sent();
|
|
96
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
97
|
-
if (!verify) {
|
|
98
|
-
throw new Error('Failed to verify query');
|
|
99
|
-
}
|
|
100
|
-
contenders = (result !== null && result !== void 0 ? result : { contenders: [] }).contenders;
|
|
101
|
-
winner = (result !== null && result !== void 0 ? result : { winner: undefined }).winner;
|
|
102
|
-
if (contenders.length === 0) {
|
|
103
|
-
throw new Error('Vote state not found');
|
|
104
|
-
}
|
|
105
|
-
return [2 /*return*/, {
|
|
106
|
-
contenders: contenders.map(function (contender) { return (__assign(__assign({}, contender), { identifier: contender.identityId, document: contender.serializedDocument != null ? pshenmic_dpp_1.DocumentWASM.fromBytes(contender.serializedDocument, contract, documentTypeName, pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9) : undefined })); }),
|
|
107
|
-
abstainVoteTally: (_c = result === null || result === void 0 ? void 0 : result.abstainingVoteTally) !== null && _c !== void 0 ? _c : 0,
|
|
108
|
-
lockVoteTally: (_d = result === null || result === void 0 ? void 0 : result.lockedVoteTally) !== null && _d !== void 0 ? _d : 0,
|
|
109
|
-
finishedVoteInfo: (winner != null)
|
|
110
|
-
? {
|
|
111
|
-
type: winner.type,
|
|
112
|
-
wonByIdentityId: winner.identityId != null ? new pshenmic_dpp_1.IdentifierWASM(winner.identityId) : undefined,
|
|
113
|
-
finishedAtBlockHeight: winner.blockInfo.height,
|
|
114
|
-
finishedAtCoreBlockHeight: winner.blockInfo.coreHeight,
|
|
115
|
-
finishedAtBlockTimeMs: winner.blockInfo.timeMs,
|
|
116
|
-
finishedAtEpoch: winner.blockInfo.epoch
|
|
117
|
-
}
|
|
118
|
-
: undefined
|
|
119
|
-
}];
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ContestedResourcesController = void 0;
|
|
40
|
-
var getContestedResourceVoteState_1 = require("./getContestedResourceVoteState");
|
|
41
|
-
/**
|
|
42
|
-
* Contested Resources controller for requesting information about contested resources
|
|
43
|
-
*
|
|
44
|
-
* @hideconstructor
|
|
45
|
-
*/
|
|
46
|
-
var ContestedResourcesController = /** @class */ (function () {
|
|
47
|
-
function ContestedResourcesController(grpcPool) {
|
|
48
|
-
this.grpcPool = grpcPool;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Retrieves an info about vote state for contested resource
|
|
52
|
-
*
|
|
53
|
-
* @param contract {DataContractWASM} - instance of contract with contested resource
|
|
54
|
-
* @param documentTypeName {string} - document type name of contested resource
|
|
55
|
-
* @param indexName {string} - index name of contested resource
|
|
56
|
-
* @param indexValuesBytes {Uint8Array[]} - Array of contested values in bytes
|
|
57
|
-
* @param resultType {ContestedResourceVoteState} - enum for result info
|
|
58
|
-
* @param allowIncludeLockedAndAbstainingVoteTally {boolean}
|
|
59
|
-
* @param startAtIdentifierInfo {StartAtIdentifierInfo=}
|
|
60
|
-
* @param count {number=}
|
|
61
|
-
*
|
|
62
|
-
* @return {Promise<ContestedResourceVoteState>}
|
|
63
|
-
*/
|
|
64
|
-
ContestedResourcesController.prototype.getContestedResourceVoteState = function (contract, documentTypeName, indexName, indexValuesBytes, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, count) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
return __generator(this, function (_a) {
|
|
67
|
-
switch (_a.label) {
|
|
68
|
-
case 0: return [4 /*yield*/, (0, getContestedResourceVoteState_1.default)(this.grpcPool, contract, documentTypeName, indexName, indexValuesBytes, resultType, allowIncludeLockedAndAbstainingVoteTally, startAtIdentifierInfo, count)];
|
|
69
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
return ContestedResourcesController;
|
|
75
|
-
}());
|
|
76
|
-
exports.ContestedResourcesController = ContestedResourcesController;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = createDataContract;
|
|
4
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
5
|
-
function createDataContract(ownerId, identityNonce, schema, tokenConfiguration, config, fullValidation, platformVersion) {
|
|
6
|
-
var id = new pshenmic_dpp_1.IdentifierWASM(ownerId);
|
|
7
|
-
var dataContract = new pshenmic_dpp_1.DataContractWASM(id, identityNonce, schema,
|
|
8
|
-
// we don't know what that param means yet
|
|
9
|
-
null, tokenConfiguration, fullValidation !== null && fullValidation !== void 0 ? fullValidation : true, platformVersion !== null && platformVersion !== void 0 ? platformVersion : pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9);
|
|
10
|
-
if (config != null) {
|
|
11
|
-
dataContract.setConfig(config, platformVersion);
|
|
12
|
-
}
|
|
13
|
-
return dataContract;
|
|
14
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataContractTransitionType = void 0;
|
|
4
|
-
exports.default = createStateTransition;
|
|
5
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
6
|
-
var DataContractTransitionType;
|
|
7
|
-
(function (DataContractTransitionType) {
|
|
8
|
-
DataContractTransitionType[DataContractTransitionType["Create"] = 0] = "Create";
|
|
9
|
-
DataContractTransitionType[DataContractTransitionType["Update"] = 1] = "Update";
|
|
10
|
-
})(DataContractTransitionType || (exports.DataContractTransitionType = DataContractTransitionType = {}));
|
|
11
|
-
var dataContractTransitionsMap = {
|
|
12
|
-
create: pshenmic_dpp_1.DataContractCreateTransitionWASM,
|
|
13
|
-
update: pshenmic_dpp_1.DataContractUpdateTransitionWASM
|
|
14
|
-
};
|
|
15
|
-
function createStateTransition(dataContract, type, identityNonce) {
|
|
16
|
-
var TransitionClass = dataContractTransitionsMap[type];
|
|
17
|
-
if (TransitionClass == null) {
|
|
18
|
-
throw new Error("Unknown DataContract transition type: ".concat(type, ". Should be 'create' or 'update'."));
|
|
19
|
-
}
|
|
20
|
-
// @ts-expect-error
|
|
21
|
-
var dataContractTransition = new TransitionClass(dataContract, identityNonce);
|
|
22
|
-
return dataContractTransition.toStateTransition();
|
|
23
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.default = getByIdentifier;
|
|
40
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
41
|
-
var platform_1 = require("../../proto/generated/platform");
|
|
42
|
-
var getQuorumPublicKey_1 = require("../utils/getQuorumPublicKey");
|
|
43
|
-
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
44
|
-
var verifyTenderdashProof_1 = require("../utils/verifyTenderdashProof");
|
|
45
|
-
var constants_1 = require("../constants");
|
|
46
|
-
function getByIdentifier(grpcPool, identifier) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var id, getDataContractRequest, v0, _a, proof, metadata, _b, rootHash, dataContract, quorumPublicKey, verify;
|
|
49
|
-
return __generator(this, function (_c) {
|
|
50
|
-
switch (_c.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
id = new pshenmic_dpp_1.IdentifierWASM(identifier);
|
|
53
|
-
if (id.base58() === constants_1.DPNS_DATA_CONTRACT_ID) {
|
|
54
|
-
return [2 /*return*/, pshenmic_dpp_1.DataContractWASM.fromBase64(constants_1.DPNS_DATA_CONTRACT_BYTES, true, 9)];
|
|
55
|
-
}
|
|
56
|
-
getDataContractRequest = platform_1.GetDataContractRequest.fromPartial({
|
|
57
|
-
v0: {
|
|
58
|
-
id: id.bytes(),
|
|
59
|
-
prove: true
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
return [4 /*yield*/, grpcPool.getClient().getDataContract(getDataContractRequest)];
|
|
63
|
-
case 1:
|
|
64
|
-
v0 = (_c.sent()).v0;
|
|
65
|
-
_a = v0, proof = _a.proof, metadata = _a.metadata;
|
|
66
|
-
if (proof == null) {
|
|
67
|
-
throw new Error('Proof not found');
|
|
68
|
-
}
|
|
69
|
-
if (metadata == null) {
|
|
70
|
-
throw new Error('Metadata not found');
|
|
71
|
-
}
|
|
72
|
-
_b = (0, pshenmic_dpp_1.verifyContractProof)(proof.grovedbProof, undefined, false, false, id.bytes(), pshenmic_dpp_1.PlatformVersionWASM.PLATFORM_V9), rootHash = _b.rootHash, dataContract = _b.dataContract;
|
|
73
|
-
if (dataContract == null) {
|
|
74
|
-
throw new Error("Data Contract with identifier ".concat(id.base58(), " not found"));
|
|
75
|
-
}
|
|
76
|
-
return [4 /*yield*/, (0, getQuorumPublicKey_1.getQuorumPublicKey)(grpcPool.network, proof.quorumType, (0, bytesToHex_1.default)(proof.quorumHash))];
|
|
77
|
-
case 2:
|
|
78
|
-
quorumPublicKey = _c.sent();
|
|
79
|
-
verify = (0, verifyTenderdashProof_1.default)(proof, metadata, rootHash, quorumPublicKey);
|
|
80
|
-
if (!verify) {
|
|
81
|
-
throw new Error('Failed to verify query');
|
|
82
|
-
}
|
|
83
|
-
return [2 /*return*/, dataContract];
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.DataContractsController = void 0;
|
|
40
|
-
var getDataContractByIdentifier_1 = require("./getDataContractByIdentifier");
|
|
41
|
-
var create_1 = require("./create");
|
|
42
|
-
var createStateTransition_1 = require("./createStateTransition");
|
|
43
|
-
/**
|
|
44
|
-
* Collection of methods necessary to work with Data Contracts in the network,
|
|
45
|
-
* such as data contract creation or retrieval
|
|
46
|
-
*
|
|
47
|
-
* @hideconstructor
|
|
48
|
-
*/
|
|
49
|
-
var DataContractsController = /** @class */ (function () {
|
|
50
|
-
function DataContractsController(grpcPool) {
|
|
51
|
-
this.grpcPool = grpcPool;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Creates an instance of {DataContractWASM} that can be used to
|
|
55
|
-
* register a data contract in the network.
|
|
56
|
-
*
|
|
57
|
-
* @param ownerId {IdentifierLike} Identifier of the Data Contract's owner
|
|
58
|
-
* @param identityNonce {bigint} Identity nonce
|
|
59
|
-
* @param schema {object} Data Contract schema in json
|
|
60
|
-
* @param tokenConfiguration {object=} Token configuration
|
|
61
|
-
* @param config {DataContractConfig=} Data Contract config
|
|
62
|
-
* @param fullValidation {true=} Full validation (omit it)
|
|
63
|
-
* @param platformVersion {PlatformVersionWASM=} version of the platform
|
|
64
|
-
*
|
|
65
|
-
* @return {DataContractWASM}
|
|
66
|
-
*/
|
|
67
|
-
DataContractsController.prototype.create = function (ownerId, identityNonce, schema, fullValidation, tokenConfiguration, config, platformVersion) {
|
|
68
|
-
return (0, create_1.default)(ownerId, identityNonce, schema, tokenConfiguration, config, fullValidation, platformVersion);
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Retrieves a Data Contract by an identifier from the network
|
|
72
|
-
*
|
|
73
|
-
* @param identifier {IdentifierLike} Identifier of the Data Contract
|
|
74
|
-
*
|
|
75
|
-
* @return {Promise<DataContractWASM>}
|
|
76
|
-
*/
|
|
77
|
-
DataContractsController.prototype.getDataContractByIdentifier = function (identifier) {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
-
return __generator(this, function (_a) {
|
|
80
|
-
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, (0, getDataContractByIdentifier_1.default)(this.grpcPool, identifier)];
|
|
82
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Helper function to create a state transition from a {DataContractWASM} instance
|
|
89
|
-
* Pass {DataContractTransitionType} in type param to specify which type of operation you want
|
|
90
|
-
* to make: create or update.
|
|
91
|
-
*
|
|
92
|
-
* @param dataContract {DataContractWASM} An instance of DataContractWASM to create or update
|
|
93
|
-
* @param type {string} type of identity state transition to do, must be 'create' or 'update'
|
|
94
|
-
* @param identityNonce {bigint} identity contract nonce
|
|
95
|
-
*
|
|
96
|
-
* @return {StateTransitionWASM}
|
|
97
|
-
*/
|
|
98
|
-
DataContractsController.prototype.createStateTransition = function (dataContract, type, identityNonce) {
|
|
99
|
-
return (0, createStateTransition_1.default)(dataContract, type, identityNonce);
|
|
100
|
-
};
|
|
101
|
-
return DataContractsController;
|
|
102
|
-
}());
|
|
103
|
-
exports.DataContractsController = DataContractsController;
|
package/src/documents/create.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = createDocument;
|
|
4
|
-
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
5
|
-
function createDocument(dataContractId, documentType, data, owner, revision, documentId) {
|
|
6
|
-
return new pshenmic_dpp_1.DocumentWASM(data, documentType, revision !== null && revision !== void 0 ? revision : BigInt(1), dataContractId, owner, documentId);
|
|
7
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
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 documentTransitionsMap = {
|
|
15
|
-
create: {
|
|
16
|
-
class: pshenmic_dpp_1.DocumentCreateTransitionWASM,
|
|
17
|
-
arguments: ['identityContractNonce'],
|
|
18
|
-
optionalArguments: ['prefundedVotingBalance', 'tokenPaymentInfo']
|
|
19
|
-
},
|
|
20
|
-
replace: {
|
|
21
|
-
class: pshenmic_dpp_1.DocumentReplaceTransitionWASM,
|
|
22
|
-
arguments: ['identityContractNonce'],
|
|
23
|
-
optionalArguments: ['tokenPaymentInfo']
|
|
24
|
-
},
|
|
25
|
-
delete: {
|
|
26
|
-
class: pshenmic_dpp_1.DocumentDeleteTransitionWASM,
|
|
27
|
-
arguments: ['identityContractNonce'],
|
|
28
|
-
optionalArguments: ['tokenPaymentInfo']
|
|
29
|
-
},
|
|
30
|
-
updatePrice: {
|
|
31
|
-
class: pshenmic_dpp_1.DocumentUpdatePriceTransitionWASM,
|
|
32
|
-
arguments: ['identityContractNonce', 'price'],
|
|
33
|
-
optionalArguments: ['tokenPaymentInfo']
|
|
34
|
-
},
|
|
35
|
-
transfer: {
|
|
36
|
-
class: pshenmic_dpp_1.DocumentTransferTransitionWASM,
|
|
37
|
-
arguments: ['identityContractNonce', 'recipientId'],
|
|
38
|
-
optionalArguments: ['tokenPaymentInfo']
|
|
39
|
-
},
|
|
40
|
-
purchase: {
|
|
41
|
-
class: pshenmic_dpp_1.DocumentPurchaseTransitionWASM,
|
|
42
|
-
arguments: ['identityContractNonce', 'amount'],
|
|
43
|
-
optionalArguments: ['tokenPaymentInfo']
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
function createStateTransition(document, type, params) {
|
|
47
|
-
var _a = documentTransitionsMap[type], TransitionClass = _a.class, classArguments = _a.arguments, optionalArguments = _a.optionalArguments;
|
|
48
|
-
if (TransitionClass == null) {
|
|
49
|
-
throw new Error("Unimplemented transition type: ".concat(type));
|
|
50
|
-
}
|
|
51
|
-
// check if all required params for document transition exists
|
|
52
|
-
var missingArgument = classArguments
|
|
53
|
-
.filter(function (classArgument) { return params[classArgument] == null &&
|
|
54
|
-
!(optionalArguments).includes(classArgument); })[0];
|
|
55
|
-
if (missingArgument != null) {
|
|
56
|
-
throw new Error("Document transition param \"".concat(missingArgument, "\" is missing"));
|
|
57
|
-
}
|
|
58
|
-
var transitionParams = classArguments.concat(optionalArguments).map(function (classArgument) { return params[classArgument]; });
|
|
59
|
-
// @ts-expect-error
|
|
60
|
-
var documentTransition = new (TransitionClass.bind.apply(TransitionClass, __spreadArray([void 0, document], transitionParams, false)))().toDocumentTransition();
|
|
61
|
-
var batchedTransition = new pshenmic_dpp_1.BatchedTransitionWASM(documentTransition);
|
|
62
|
-
var batch = pshenmic_dpp_1.BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition], document.ownerId, 1);
|
|
63
|
-
return batch.toStateTransition();
|
|
64
|
-
}
|