dash-platform-sdk 1.1.4 → 1.1.6
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 +1 -1
- package/src/node/status.js +11 -10
- package/src/tokens/createStateTransition.d.ts +3 -0
- package/src/tokens/createStateTransition.js +79 -0
- package/src/tokens/getTokenContractInfo.d.ts +1 -1
- package/src/tokens/getTokenContractInfo.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/test/unit/Tokens.spec.js +172 -1
package/package.json
CHANGED
package/src/node/status.js
CHANGED
|
@@ -38,17 +38,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.default = status;
|
|
40
40
|
var platform_1 = require("../../proto/generated/platform");
|
|
41
|
+
var bytesToHex_1 = require("../utils/bytesToHex");
|
|
41
42
|
function status(grpcPool) {
|
|
42
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
44
|
var getStatusRequest, response, v0;
|
|
44
|
-
var _a, _b, _c, _d, _e;
|
|
45
|
-
return __generator(this, function (
|
|
46
|
-
switch (
|
|
45
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
46
|
+
return __generator(this, function (_j) {
|
|
47
|
+
switch (_j.label) {
|
|
47
48
|
case 0:
|
|
48
49
|
getStatusRequest = platform_1.GetStatusRequest.fromPartial({ v0: {} });
|
|
49
50
|
return [4 /*yield*/, grpcPool.getClient().getStatus(getStatusRequest)];
|
|
50
51
|
case 1:
|
|
51
|
-
response =
|
|
52
|
+
response = _j.sent();
|
|
52
53
|
v0 = response.v0;
|
|
53
54
|
if (v0 == null) {
|
|
54
55
|
throw new Error('Unable to get node status');
|
|
@@ -56,8 +57,8 @@ function status(grpcPool) {
|
|
|
56
57
|
return [2 /*return*/, {
|
|
57
58
|
node: (v0.node != null)
|
|
58
59
|
? {
|
|
59
|
-
id: v0.node.id
|
|
60
|
-
proTxHash:
|
|
60
|
+
id: (0, bytesToHex_1.default)(v0.node.id),
|
|
61
|
+
proTxHash: v0.node.proTxHash != null ? (0, bytesToHex_1.default)(v0.node.proTxHash) : undefined
|
|
61
62
|
}
|
|
62
63
|
: undefined,
|
|
63
64
|
chain: (v0.chain != null)
|
|
@@ -67,10 +68,10 @@ function status(grpcPool) {
|
|
|
67
68
|
earliestBlockHeight: v0.chain.earliestBlockHeight,
|
|
68
69
|
maxPeerBlockHeight: v0.chain.maxPeerBlockHeight,
|
|
69
70
|
coreChainLockedHeight: v0.chain.coreChainLockedHeight,
|
|
70
|
-
latestBlockHash: (
|
|
71
|
-
latestAppHash: (_c = v0.chain) === null || _c === void 0 ? void 0 : _c.latestAppHash
|
|
72
|
-
earliestBlockHash: (
|
|
73
|
-
earliestAppHash: (
|
|
71
|
+
latestBlockHash: ((_a = v0.chain) === null || _a === void 0 ? void 0 : _a.latestBlockHash) != null ? (0, bytesToHex_1.default)((_b = v0.chain) === null || _b === void 0 ? void 0 : _b.latestBlockHash) : '',
|
|
72
|
+
latestAppHash: ((_c = v0.chain) === null || _c === void 0 ? void 0 : _c.latestAppHash) != null ? (0, bytesToHex_1.default)((_d = v0.chain) === null || _d === void 0 ? void 0 : _d.latestAppHash) : '',
|
|
73
|
+
earliestBlockHash: ((_e = v0.chain) === null || _e === void 0 ? void 0 : _e.earliestBlockHash) != null ? (0, bytesToHex_1.default)((_f = v0.chain) === null || _f === void 0 ? void 0 : _f.earliestBlockHash) : '',
|
|
74
|
+
earliestAppHash: ((_g = v0.chain) === null || _g === void 0 ? void 0 : _g.earliestAppHash) != null ? (0, bytesToHex_1.default)((_h = v0.chain) === null || _h === void 0 ? void 0 : _h.earliestAppHash) : ''
|
|
74
75
|
}
|
|
75
76
|
: undefined,
|
|
76
77
|
version: v0.version,
|
|
@@ -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
|
+
}
|
|
@@ -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>;
|
|
@@ -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
|
}
|
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
|
+
}
|
package/test/unit/Tokens.spec.js
CHANGED
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
var types_1 = require("../../src/types");
|
|
40
|
+
var pshenmic_dpp_1 = require("pshenmic-dpp");
|
|
40
41
|
var sdk;
|
|
41
42
|
describe('Tokens', function () {
|
|
42
43
|
beforeAll(function () {
|
|
@@ -63,7 +64,7 @@ describe('Tokens', function () {
|
|
|
63
64
|
case 0: return [4 /*yield*/, sdk.tokens.getTokenContractInfo('9YxdbQUjJmQsmVPen95HjAU3Esj7tVkWSY2EQWT84ZQP')];
|
|
64
65
|
case 1:
|
|
65
66
|
tokenContractInfo = _a.sent();
|
|
66
|
-
expect(tokenContractInfo.
|
|
67
|
+
expect(tokenContractInfo.dataContractId.base58()).toEqual('Y189uedQG3CJCuu83P3DqnG7ngQaRKz69x3gY8uDzQe');
|
|
67
68
|
expect(tokenContractInfo.tokenContractPosition).toEqual(0);
|
|
68
69
|
return [2 /*return*/];
|
|
69
70
|
}
|
|
@@ -97,4 +98,174 @@ describe('Tokens', function () {
|
|
|
97
98
|
}
|
|
98
99
|
});
|
|
99
100
|
}); });
|
|
101
|
+
test('should be able to create base token transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
102
|
+
var tokenBaseTransition;
|
|
103
|
+
return __generator(this, function (_a) {
|
|
104
|
+
switch (_a.label) {
|
|
105
|
+
case 0: return [4 /*yield*/, sdk.tokens.createBaseTransition('A36eJF2kyYXwxCtJGsgbR3CTAscUFaNxZN19UqUfM1kw', '34vkjdeUTP2z798SiXqoB6EAuobh51kXYURqVa9xkujf')];
|
|
106
|
+
case 1:
|
|
107
|
+
tokenBaseTransition = _a.sent();
|
|
108
|
+
expect(tokenBaseTransition).toBeInstanceOf(pshenmic_dpp_1.TokenBaseTransitionWASM);
|
|
109
|
+
return [2 /*return*/];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}); });
|
|
113
|
+
describe('create state transitions', function () {
|
|
114
|
+
test('should be able to create burn transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
115
|
+
var tokenId, owner, amount, tokenBaseTransition, stateTransition;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
120
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
121
|
+
amount = BigInt(10);
|
|
122
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
123
|
+
case 1:
|
|
124
|
+
tokenBaseTransition = _a.sent();
|
|
125
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'burn', { amount: amount });
|
|
126
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}); });
|
|
131
|
+
test('should be able to create mint transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
+
var tokenId, owner, recipientId, amount, tokenBaseTransition, stateTransition;
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
switch (_a.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
137
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
138
|
+
recipientId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
139
|
+
amount = BigInt(10);
|
|
140
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
141
|
+
case 1:
|
|
142
|
+
tokenBaseTransition = _a.sent();
|
|
143
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'mint', { identityId: recipientId, amount: amount });
|
|
144
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
145
|
+
return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}); });
|
|
149
|
+
test('should be able to create transfer transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
150
|
+
var tokenId, owner, recipient, amount, tokenBaseTransition, stateTransition;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
switch (_a.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
155
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
156
|
+
recipient = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
157
|
+
amount = BigInt(100);
|
|
158
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
159
|
+
case 1:
|
|
160
|
+
tokenBaseTransition = _a.sent();
|
|
161
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'transfer', { identityId: recipient, amount: amount });
|
|
162
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}); });
|
|
167
|
+
test('should be able to create freeze transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
168
|
+
var tokenId, owner, identityId, tokenBaseTransition, stateTransition;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
173
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
174
|
+
identityId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
175
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
176
|
+
case 1:
|
|
177
|
+
tokenBaseTransition = _a.sent();
|
|
178
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'freeze', { identityId: identityId });
|
|
179
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
180
|
+
return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}); });
|
|
184
|
+
test('should be able to create unfreeze transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
185
|
+
var tokenId, owner, identityId, tokenBaseTransition, stateTransition;
|
|
186
|
+
return __generator(this, function (_a) {
|
|
187
|
+
switch (_a.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
190
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
191
|
+
identityId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
192
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
193
|
+
case 1:
|
|
194
|
+
tokenBaseTransition = _a.sent();
|
|
195
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'unfreeze', { identityId: identityId });
|
|
196
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
197
|
+
return [2 /*return*/];
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}); });
|
|
201
|
+
test('should be able to create destroyFrozenFunds transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
202
|
+
var tokenId, owner, identityId, tokenBaseTransition, stateTransition;
|
|
203
|
+
return __generator(this, function (_a) {
|
|
204
|
+
switch (_a.label) {
|
|
205
|
+
case 0:
|
|
206
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
207
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
208
|
+
identityId = '8GopLQQCViyroS2gHktesGaCMe2tueXWeQ6Y9vpMFTEC';
|
|
209
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
210
|
+
case 1:
|
|
211
|
+
tokenBaseTransition = _a.sent();
|
|
212
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'destroyFrozenFunds', { identityId: identityId });
|
|
213
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
214
|
+
return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}); });
|
|
218
|
+
test('should be able to create emergency action transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
219
|
+
var tokenId, owner, emergencyAction, tokenBaseTransition, stateTransition;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
224
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
225
|
+
emergencyAction = pshenmic_dpp_1.TokenEmergencyActionWASM.Pause;
|
|
226
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
227
|
+
case 1:
|
|
228
|
+
tokenBaseTransition = _a.sent();
|
|
229
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'emergencyAction', { emergencyAction: emergencyAction });
|
|
230
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
231
|
+
return [2 /*return*/];
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}); });
|
|
235
|
+
test('should be able to create setPriceForDirectPurchase transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
236
|
+
var tokenId, owner, price, tokenBaseTransition, stateTransition;
|
|
237
|
+
return __generator(this, function (_a) {
|
|
238
|
+
switch (_a.label) {
|
|
239
|
+
case 0:
|
|
240
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
241
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
242
|
+
price = BigInt(10);
|
|
243
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
244
|
+
case 1:
|
|
245
|
+
tokenBaseTransition = _a.sent();
|
|
246
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'setPriceForDirectPurchase', { price: price });
|
|
247
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
248
|
+
return [2 /*return*/];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}); });
|
|
252
|
+
test('should be able to create directPurchase transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
253
|
+
var tokenId, owner, amount, totalAgreedPrice, tokenBaseTransition, stateTransition;
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
256
|
+
case 0:
|
|
257
|
+
tokenId = '6niNoQpsT9zyVDJtXcbpV3tR3qEGi6BC6xoDdJyx1u7C';
|
|
258
|
+
owner = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
|
|
259
|
+
amount = BigInt(10);
|
|
260
|
+
totalAgreedPrice = BigInt(100);
|
|
261
|
+
return [4 /*yield*/, sdk.tokens.createBaseTransition(tokenId, owner)];
|
|
262
|
+
case 1:
|
|
263
|
+
tokenBaseTransition = _a.sent();
|
|
264
|
+
stateTransition = sdk.tokens.createStateTransition(tokenBaseTransition, owner, 'directPurchase', { amount: amount, totalAgreedPrice: totalAgreedPrice });
|
|
265
|
+
expect(stateTransition).toBeInstanceOf(pshenmic_dpp_1.StateTransitionWASM);
|
|
266
|
+
return [2 /*return*/];
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}); });
|
|
270
|
+
});
|
|
100
271
|
});
|