dash-platform-sdk 1.3.0-dev.5 → 1.3.0-dev.7
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 +17 -17
- package/index.d.ts +1 -1
- package/index.js +2 -0
- package/package.json +7 -5
- package/proto/generated/google/protobuf/wrappers.js +615 -0
- package/proto/generated/platform.client.d.ts +46 -46
- package/proto/generated/platform.client.js +175 -0
- package/proto/generated/platform.d.ts +1 -1
- package/proto/generated/platform.js +8277 -0
- package/src/DashPlatformSDK.d.ts +14 -14
- package/src/DashPlatformSDK.js +101 -0
- package/src/constants.js +10 -0
- package/src/contestedResources/createStateTransition.js +6 -0
- package/src/contestedResources/getContestedResourceVoteState.d.ts +3 -3
- package/src/contestedResources/getContestedResourceVoteState.js +72 -0
- package/src/contestedResources/index.d.ts +3 -3
- package/src/contestedResources/index.js +30 -0
- package/src/dataContracts/create.d.ts +1 -1
- package/src/dataContracts/create.js +11 -0
- package/src/dataContracts/createStateTransition.js +19 -0
- package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -2
- package/src/dataContracts/getDataContractByIdentifier.js +44 -0
- package/src/dataContracts/index.d.ts +2 -2
- package/src/dataContracts/index.js +57 -0
- package/src/documents/create.d.ts +1 -1
- package/src/documents/create.js +4 -0
- package/src/documents/createStateTransition.d.ts +1 -1
- package/src/documents/createStateTransition.js +52 -0
- package/src/documents/index.d.ts +2 -2
- package/src/documents/index.js +83 -0
- package/src/documents/query.d.ts +2 -2
- package/src/documents/query.js +62 -0
- package/src/grpcConnectionPool.d.ts +2 -2
- package/src/grpcConnectionPool.js +79 -0
- package/src/identities/createStateTransition.d.ts +1 -1
- package/src/identities/createStateTransition.js +34 -0
- package/src/identities/getIdentityBalance.d.ts +2 -2
- package/src/identities/getIdentityBalance.js +40 -0
- package/src/identities/getIdentityByIdentifier.d.ts +2 -2
- package/src/identities/getIdentityByIdentifier.js +40 -0
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +44 -0
- package/src/identities/getIdentityByPublicKeyHash.d.ts +1 -1
- package/src/identities/getIdentityByPublicKeyHash.js +40 -0
- package/src/identities/getIdentityContractNonce.d.ts +2 -2
- package/src/identities/getIdentityContractNonce.js +43 -0
- package/src/identities/getIdentityNonce.d.ts +2 -2
- package/src/identities/getIdentityNonce.js +41 -0
- package/src/identities/getIdentityPublicKeys.d.ts +2 -2
- package/src/identities/getIdentityPublicKeys.js +47 -0
- package/src/identities/index.d.ts +2 -2
- package/src/identities/index.js +141 -0
- package/src/keyPair/deriveChild.js +3 -0
- package/src/keyPair/derivePath.js +3 -0
- package/src/keyPair/index.d.ts +1 -1
- package/src/keyPair/index.js +89 -0
- package/src/keyPair/mnemonicToSeed.js +4 -0
- package/src/names/index.d.ts +2 -2
- package/src/names/index.js +102 -0
- package/src/names/registerName.d.ts +1 -1
- package/src/names/registerName.js +64 -0
- package/src/names/searchByIdentity.d.ts +1 -1
- package/src/names/searchByIdentity.js +5 -0
- package/src/names/searchByName.d.ts +1 -1
- package/src/names/searchByName.js +16 -0
- package/src/names/testNameContested.js +3 -0
- package/src/names/validateName.js +11 -0
- package/src/node/epochs.d.ts +1 -1
- package/src/node/epochs.js +46 -0
- package/src/node/index.d.ts +3 -3
- package/src/node/index.js +43 -0
- package/src/node/status.d.ts +2 -2
- package/src/node/status.js +41 -0
- package/src/node/totalCredits.d.ts +2 -2
- package/src/node/totalCredits.js +35 -0
- package/src/signer/AbstractSigner.js +1 -0
- package/src/signer/PrivateKeySigner.d.ts +1 -0
- package/src/signer/PrivateKeySigner.js +65 -0
- package/src/signer/setSigner.d.ts +1 -1
- package/src/signer/setSigner.js +5 -0
- package/src/stateTransitions/broadcast.d.ts +1 -1
- package/src/stateTransitions/broadcast.js +10 -0
- package/src/stateTransitions/index.d.ts +1 -1
- package/src/stateTransitions/index.js +34 -0
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +1 -1
- package/src/stateTransitions/waitForStateTransitionResult.js +8 -0
- package/src/tokens/createStateTransition.d.ts +1 -1
- package/src/tokens/createStateTransition.js +67 -0
- package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -2
- package/src/tokens/getIdentitiesTokenBalances.js +43 -0
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -2
- package/src/tokens/getIdentityTokensBalances.js +43 -0
- package/src/tokens/getTokenContractInfo.d.ts +2 -2
- package/src/tokens/getTokenContractInfo.js +43 -0
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -2
- package/src/tokens/getTokenDirectPurchasePrices.js +40 -0
- package/src/tokens/getTokenTotalSupply.d.ts +2 -2
- package/src/tokens/getTokenTotalSupply.js +41 -0
- package/src/tokens/index.d.ts +5 -5
- package/src/tokens/index.js +108 -0
- package/src/types.d.ts +2 -2
- package/src/types.js +15 -0
- package/src/utils/base58ToBytes.js +4 -0
- package/src/utils/bytesToHex.js +3 -0
- package/src/utils/bytesToTypedArray.js +3 -0
- package/src/utils/calculateMsgHash.js +31 -0
- package/src/utils/calculateSignHash.d.ts +1 -1
- package/src/utils/calculateSignHash.js +8 -0
- package/src/utils/calculateStateIdHash.d.ts +1 -1
- package/src/utils/calculateStateIdHash.js +10 -0
- package/src/utils/convertToHomographSafeChars.js +11 -0
- package/src/utils/createVoterIdentityId.js +13 -0
- package/src/utils/getEvonodeList.d.ts +1 -1
- package/src/utils/getEvonodeList.js +12 -0
- package/src/utils/getQuorumPublicKey.js +18 -0
- package/src/utils/getRandomArrayItem.js +3 -0
- package/src/utils/getRandomBytes.js +4 -0
- package/src/utils/hexToBytes.js +3 -0
- package/src/utils/index.js +61 -0
- package/src/utils/indexBytesToString.js +4 -0
- package/src/utils/sha256.js +15 -0
- package/src/utils/signHash.js +22 -0
- package/src/utils/signRequestId.js +19 -0
- package/src/utils/sleep.js +3 -0
- package/src/utils/stringToIndexValueBytes.js +10 -0
- package/src/utils/verifyTenderdashProof.d.ts +1 -1
- package/src/utils/verifyTenderdashProof.js +26 -0
- package/src/voting/createStateTransition.js +6 -0
- package/src/voting/createVote.js +5 -0
- package/src/voting/index.d.ts +1 -1
- package/src/voting/index.js +55 -0
- package/test/unit/ContestedResources.spec.js +258 -0
- package/test/unit/DataContract.spec.js +75 -0
- package/test/unit/Document.spec.js +109 -0
- package/test/unit/Identity.spec.js +232 -0
- package/test/unit/KeyPair.spec.js +34 -0
- package/test/unit/Names.spec.js +33 -0
- package/test/unit/Node.spec.js +58 -0
- package/test/unit/SDK.spec.js +10 -0
- package/test/unit/Tokens.spec.js +121 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GetTotalCreditsInPlatformRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { HALVING_INTERVAL, MAINNET_ACTIVATION_HEIGHT, TESTNET_ACTIVATION_HEIGHT } from '../constants.js';
|
|
3
|
+
import { PlatformVersionWASM, verifyTotalCreditsProof } from 'pshenmic-dpp';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
+
export default async function totalCredits(grpcPool, network) {
|
|
8
|
+
const getTotalCreditsInPlatformRequest = GetTotalCreditsInPlatformRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: { prove: true }
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const { response } = await grpcPool.getClient().getTotalCreditsInPlatform(getTotalCreditsInPlatformRequest);
|
|
15
|
+
const { version } = response;
|
|
16
|
+
if (version.oneofKind !== 'v0') {
|
|
17
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
18
|
+
}
|
|
19
|
+
const { v0 } = version;
|
|
20
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
21
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
22
|
+
}
|
|
23
|
+
const { result: { proof }, metadata } = v0;
|
|
24
|
+
if (metadata == null) {
|
|
25
|
+
throw new Error('Metadata not found');
|
|
26
|
+
}
|
|
27
|
+
const activationHeight = network === 'testnet' ? TESTNET_ACTIVATION_HEIGHT : MAINNET_ACTIVATION_HEIGHT;
|
|
28
|
+
const { rootHash, totalCredits } = verifyTotalCreditsProof(proof.grovedbProof, HALVING_INTERVAL, activationHeight, Number(metadata.height), PlatformVersionWASM.PLATFORM_V9);
|
|
29
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
30
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
31
|
+
if (!verify) {
|
|
32
|
+
throw new Error('Failed to verify query');
|
|
33
|
+
}
|
|
34
|
+
return totalCredits;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
// import { IdentityWASM, NetworkWASM, PrivateKeyWASM, StateTransitionWASM } from 'pshenmic-dpp'
|
|
3
|
+
// import { base64 } from '@scure/base'
|
|
4
|
+
// import { IdentitiesController } from '../identities'
|
|
5
|
+
// import {AbstractSigner} from "./AbstractSigner";
|
|
6
|
+
//
|
|
7
|
+
// export class PrivateKeySigner implements AbstractSigner {
|
|
8
|
+
// privateKey: PrivateKeyWASM
|
|
9
|
+
// identity: IdentityWASM
|
|
10
|
+
// identities: IdentitiesController
|
|
11
|
+
//
|
|
12
|
+
// constructor (identitiesController: IdentitiesController, privateKey: string | PrivateKeyWASM, network?: NetworkWASM | string) {
|
|
13
|
+
// this.identities = identitiesController
|
|
14
|
+
//
|
|
15
|
+
// if (typeof privateKey === 'string') {
|
|
16
|
+
// let privateKeyWASM
|
|
17
|
+
//
|
|
18
|
+
// try {
|
|
19
|
+
// privateKeyWASM = PrivateKeyWASM.fromWIF(privateKey)
|
|
20
|
+
// } catch (e) {
|
|
21
|
+
// }
|
|
22
|
+
//
|
|
23
|
+
// if (privateKey.length === 64 && !network) {
|
|
24
|
+
// throw new Error('Network must be specified if hex or base64 private key being used')
|
|
25
|
+
// }
|
|
26
|
+
//
|
|
27
|
+
// try {
|
|
28
|
+
// privateKeyWASM = PrivateKeyWASM.fromHex(privateKey, network)
|
|
29
|
+
// } catch (e) {
|
|
30
|
+
// }
|
|
31
|
+
//
|
|
32
|
+
// try {
|
|
33
|
+
// privateKeyWASM = PrivateKeyWASM.fromBytes(base64.decode(privateKey), network)
|
|
34
|
+
// } catch (e) {
|
|
35
|
+
// }
|
|
36
|
+
//
|
|
37
|
+
// if (privateKeyWASM == null) {
|
|
38
|
+
// throw new Error('Could not decode private key')
|
|
39
|
+
// }
|
|
40
|
+
// } else if (privateKey?.__type === 'PrivateKeyWASM') {
|
|
41
|
+
// this.privateKey = privateKey
|
|
42
|
+
// } else {
|
|
43
|
+
// throw new Error('Unrecognized private key type')
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
//
|
|
47
|
+
// async connect (): Promise<void> {
|
|
48
|
+
// this.identity = await this.identities.getIdentityByPublicKeyHash(this.privateKey.getPublicKeyHash())
|
|
49
|
+
// }
|
|
50
|
+
//
|
|
51
|
+
// getCurrentIdentity (): IdentityWASM {
|
|
52
|
+
// return this.identity
|
|
53
|
+
// }
|
|
54
|
+
//
|
|
55
|
+
// signStateTransition (stateTransition: StateTransitionWASM): void {
|
|
56
|
+
// const [identityPublicKey] = this.identity.getPublicKeys()
|
|
57
|
+
// .filter(identityPublicKey => identityPublicKey.getPublicKeyHash() === this.privateKey.getPublicKeyHash())
|
|
58
|
+
//
|
|
59
|
+
// if (identityPublicKey == null) {
|
|
60
|
+
// throw new Error('Could not find an identity public key of identity matching this private key')
|
|
61
|
+
// }
|
|
62
|
+
//
|
|
63
|
+
// stateTransition.sign(this.privateKey, identityPublicKey)
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AbstractSigner } from './AbstractSigner';
|
|
1
|
+
import { AbstractSigner } from './AbstractSigner.js';
|
|
2
2
|
export default function setSigner(signer: AbstractSigner): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
export default function broadcast(grpcPool: GRPCConnectionPool, stateTransition: StateTransitionWASM): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BroadcastStateTransitionRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
export default async function broadcast(grpcPool, stateTransition) {
|
|
3
|
+
if (stateTransition.signature.length === 0) {
|
|
4
|
+
throw new Error('State Transition is not signed');
|
|
5
|
+
}
|
|
6
|
+
const broadcastStateTransitionRequest = BroadcastStateTransitionRequest.create({
|
|
7
|
+
stateTransition: stateTransition.bytes()
|
|
8
|
+
});
|
|
9
|
+
await grpcPool.getClient().broadcastStateTransition(broadcastStateTransitionRequest);
|
|
10
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
/**
|
|
4
4
|
* Collection of methods to perform state transitions (transactions) such like broadcast, wait for state transition result
|
|
5
5
|
*
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import waitForStateTransitionResult from './waitForStateTransitionResult.js';
|
|
2
|
+
import broadcast from './broadcast.js';
|
|
3
|
+
/**
|
|
4
|
+
* Collection of methods to perform state transitions (transactions) such like broadcast, wait for state transition result
|
|
5
|
+
*
|
|
6
|
+
* @hideconstructor
|
|
7
|
+
*/
|
|
8
|
+
export class StateTransitionsController {
|
|
9
|
+
/** @ignore **/
|
|
10
|
+
grpcPool;
|
|
11
|
+
constructor(grpcPool) {
|
|
12
|
+
this.grpcPool = grpcPool;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Broadcasts a state transition to a network
|
|
16
|
+
*
|
|
17
|
+
* @param stateTransition {StateTransitionWASM}
|
|
18
|
+
*
|
|
19
|
+
* @return {Promise<void>}
|
|
20
|
+
*/
|
|
21
|
+
async broadcast(stateTransition) {
|
|
22
|
+
return await broadcast(this.grpcPool, stateTransition);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Waits for a given state transition to finalize in the network (usually 1-3 sec)
|
|
26
|
+
*
|
|
27
|
+
* @param stateTransition {StateTransitionWASM}
|
|
28
|
+
*
|
|
29
|
+
* @return {Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
async waitForStateTransitionResult(stateTransition) {
|
|
32
|
+
return await waitForStateTransitionResult(this.grpcPool, stateTransition);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
export default function waitForStateTransitionResult(grpcPool: GRPCConnectionPool, stateTransition: StateTransitionWASM): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default async function waitForStateTransitionResult(grpcPool, stateTransition) {
|
|
2
|
+
const url = `https://${grpcPool.network === 'mainnet' ? '' : 'testnet.'}platform-explorer.pshenmic.dev/waitForStateTransitionResult/${stateTransition.hash(false)}`;
|
|
3
|
+
const resp = await fetch(url);
|
|
4
|
+
if (resp.status !== 200) {
|
|
5
|
+
console.log(await resp.json());
|
|
6
|
+
throw new Error('Internal server error while waiting for state transition result');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IdentifierWASM, StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { TokenTransitionParams, TokenTransitionType } from '../types';
|
|
2
|
+
import { TokenTransitionParams, TokenTransitionType } from '../types.js';
|
|
3
3
|
export default function createStateTransition(base: TokenBaseTransitionWASM, ownerId: IdentifierWASM, type: TokenTransitionType, params: TokenTransitionParams): StateTransitionWASM;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { BatchedTransitionWASM, BatchTransitionWASM, TokenBurnTransitionWASM, TokenDestroyFrozenFundsTransitionWASM, TokenDirectPurchaseTransitionWASM, TokenEmergencyActionTransitionWASM, TokenFreezeTransitionWASM, TokenMintTransitionWASM, TokenSetPriceForDirectPurchaseTransitionWASM, TokenTransferTransitionWASM, TokenTransitionWASM, TokenUnFreezeTransitionWASM } from 'pshenmic-dpp';
|
|
2
|
+
const tokenTransitionsMap = {
|
|
3
|
+
burn: {
|
|
4
|
+
class: TokenBurnTransitionWASM,
|
|
5
|
+
arguments: ['amount', 'publicNote'],
|
|
6
|
+
optionalArguments: ['publicNote']
|
|
7
|
+
},
|
|
8
|
+
mint: {
|
|
9
|
+
class: TokenMintTransitionWASM,
|
|
10
|
+
arguments: ['identityId', 'amount', 'publicNote'],
|
|
11
|
+
optionalArguments: ['publicNote']
|
|
12
|
+
},
|
|
13
|
+
transfer: {
|
|
14
|
+
class: TokenTransferTransitionWASM,
|
|
15
|
+
arguments: ['identityId', 'amount', 'publicNote', 'sharedEncryptedNote', 'privateEncryptedNote'],
|
|
16
|
+
optionalArguments: ['publicNote', 'sharedEncryptedNote', 'privateEncryptedNote']
|
|
17
|
+
},
|
|
18
|
+
freeze: {
|
|
19
|
+
class: TokenFreezeTransitionWASM,
|
|
20
|
+
arguments: ['identityId', 'publicNote'],
|
|
21
|
+
optionalArguments: ['publicNote']
|
|
22
|
+
},
|
|
23
|
+
unfreeze: {
|
|
24
|
+
class: TokenUnFreezeTransitionWASM,
|
|
25
|
+
arguments: ['identityId', 'publicNote'],
|
|
26
|
+
optionalArguments: ['publicNote']
|
|
27
|
+
},
|
|
28
|
+
destroyFrozenFunds: {
|
|
29
|
+
class: TokenDestroyFrozenFundsTransitionWASM,
|
|
30
|
+
arguments: ['identityId', 'publicNote'],
|
|
31
|
+
optionalArguments: ['publicNote']
|
|
32
|
+
},
|
|
33
|
+
emergencyAction: {
|
|
34
|
+
class: TokenEmergencyActionTransitionWASM,
|
|
35
|
+
arguments: ['emergencyAction', 'publicNote'],
|
|
36
|
+
optionalArguments: ['publicNote']
|
|
37
|
+
},
|
|
38
|
+
directPurchase: {
|
|
39
|
+
class: TokenDirectPurchaseTransitionWASM,
|
|
40
|
+
arguments: ['amount', 'totalAgreedPrice'],
|
|
41
|
+
optionalArguments: []
|
|
42
|
+
},
|
|
43
|
+
setPriceForDirectPurchase: {
|
|
44
|
+
class: TokenSetPriceForDirectPurchaseTransitionWASM,
|
|
45
|
+
arguments: ['price', 'publicNote'],
|
|
46
|
+
optionalArguments: ['publicNote']
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export default function createStateTransition(base, ownerId, type, params) {
|
|
50
|
+
const { class: TransitionClass, arguments: classArguments, optionalArguments } = tokenTransitionsMap[type];
|
|
51
|
+
if (TransitionClass == null) {
|
|
52
|
+
throw new Error(`Unimplemented transition type: ${type}`);
|
|
53
|
+
}
|
|
54
|
+
// check if all required params for token transition exists
|
|
55
|
+
const [missingArgument] = classArguments
|
|
56
|
+
.filter((classArgument) => params[classArgument] == null &&
|
|
57
|
+
!optionalArguments.includes(classArgument));
|
|
58
|
+
if (missingArgument != null) {
|
|
59
|
+
throw new Error(`Token transition param "${missingArgument}" is missing`);
|
|
60
|
+
}
|
|
61
|
+
const transitionParams = classArguments.map((classArgument) => params[classArgument]);
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
const tokenTransition = new TransitionClass(base, ...transitionParams);
|
|
64
|
+
const tokenTransitionWASM = new TokenTransitionWASM(tokenTransition);
|
|
65
|
+
const batchedTransition = new BatchedTransitionWASM(tokenTransitionWASM);
|
|
66
|
+
return BatchTransitionWASM.fromV1BatchedTransitions([batchedTransition], ownerId, 1).toStateTransition();
|
|
67
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike } from '../types.js';
|
|
3
3
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
4
4
|
export interface IdentitiesTokenBalances {
|
|
5
5
|
identityId: IdentifierWASM;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GetIdentitiesTokenBalancesRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenBalancesForIdentitiesProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getIdentitiesTokenBalances(grpcPool, identifiers, tokenIdentifier) {
|
|
7
|
+
const ids = identifiers.map(identifier => new IdentifierWASM(identifier));
|
|
8
|
+
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
9
|
+
const getIdentitiesTokenBalancesRequest = GetIdentitiesTokenBalancesRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
tokenId: tokenId.bytes(),
|
|
14
|
+
identityIds: ids.map(id => id.bytes()),
|
|
15
|
+
prove: true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const { response } = await grpcPool.getClient().getIdentitiesTokenBalances(getIdentitiesTokenBalancesRequest);
|
|
20
|
+
const { version } = response;
|
|
21
|
+
if (version.oneofKind !== 'v0') {
|
|
22
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
23
|
+
}
|
|
24
|
+
const { v0 } = version;
|
|
25
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
26
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
27
|
+
}
|
|
28
|
+
const { result: { proof }, metadata } = v0;
|
|
29
|
+
if (metadata == null) {
|
|
30
|
+
throw new Error('Metadata not found');
|
|
31
|
+
}
|
|
32
|
+
const { rootHash, balances } = verifyTokenBalancesForIdentitiesProof(proof.grovedbProof, tokenId, true, ids, PlatformVersionWASM.PLATFORM_V9);
|
|
33
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
34
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
35
|
+
if (!verify) {
|
|
36
|
+
throw new Error('Failed to verify query');
|
|
37
|
+
}
|
|
38
|
+
return balances
|
|
39
|
+
.map((identityTokenBalance) => ({
|
|
40
|
+
identityId: new IdentifierWASM(identityTokenBalance.identityId),
|
|
41
|
+
balance: identityTokenBalance.balance
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike } from '../types.js';
|
|
3
3
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
4
4
|
export interface IdentityTokenBalances {
|
|
5
5
|
tokenId: IdentifierWASM;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokensBalancesForIdentityProof } from 'pshenmic-dpp';
|
|
2
|
+
import { GetIdentityTokenBalancesRequest } from '../../proto/generated/platform.js';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getIdentityTokensBalances(grpcPool, identifier, tokenIdentifiers) {
|
|
7
|
+
const id = new IdentifierWASM(identifier);
|
|
8
|
+
const tokenIds = tokenIdentifiers.map(tokenIdentifier => new IdentifierWASM(tokenIdentifier));
|
|
9
|
+
const getIdentityTokenBalancesRequest = GetIdentityTokenBalancesRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
tokenIds: tokenIds.map((identifier) => identifier.bytes()),
|
|
14
|
+
identityId: id.bytes(),
|
|
15
|
+
prove: true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const { response } = await grpcPool.getClient().getIdentityTokenBalances(getIdentityTokenBalancesRequest);
|
|
20
|
+
const { version } = response;
|
|
21
|
+
if (version.oneofKind !== 'v0') {
|
|
22
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
23
|
+
}
|
|
24
|
+
const { v0 } = version;
|
|
25
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
26
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
27
|
+
}
|
|
28
|
+
const { result: { proof }, metadata } = v0;
|
|
29
|
+
if (metadata == null) {
|
|
30
|
+
throw new Error('Metadata not found');
|
|
31
|
+
}
|
|
32
|
+
const { rootHash, balances } = verifyTokensBalancesForIdentityProof(proof.grovedbProof, tokenIds, id, true, PlatformVersionWASM.PLATFORM_V9);
|
|
33
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
34
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
35
|
+
if (!verify) {
|
|
36
|
+
throw new Error('Failed to verify query');
|
|
37
|
+
}
|
|
38
|
+
return balances
|
|
39
|
+
.map((tokenBalance) => ({
|
|
40
|
+
tokenId: new IdentifierWASM(tokenBalance.tokenId),
|
|
41
|
+
balance: tokenBalance.balance
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike } from '../types.js';
|
|
3
3
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
4
4
|
export interface TokenContractInfo {
|
|
5
5
|
dataContractId: IdentifierWASM;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { GetTokenContractInfoRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenContractInfoProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
7
|
+
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
8
|
+
const getTokenContractInfoRequest = GetTokenContractInfoRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
tokenId: (tokenId).bytes(),
|
|
13
|
+
prove: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getTokenContractInfo(getTokenContractInfoRequest);
|
|
18
|
+
const { version } = response;
|
|
19
|
+
if (version.oneofKind !== 'v0') {
|
|
20
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
21
|
+
}
|
|
22
|
+
const { v0 } = version;
|
|
23
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
24
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
25
|
+
}
|
|
26
|
+
const { result: { proof }, metadata } = v0;
|
|
27
|
+
if (metadata == null) {
|
|
28
|
+
throw new Error('Metadata not found');
|
|
29
|
+
}
|
|
30
|
+
const { rootHash, contractInfo } = verifyTokenContractInfoProof(proof.grovedbProof, tokenId, true, PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
if (contractInfo == null) {
|
|
32
|
+
throw new Error('ContractInfo not found');
|
|
33
|
+
}
|
|
34
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
35
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
36
|
+
if (!verify) {
|
|
37
|
+
throw new Error('Failed to verify query');
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
dataContractId: contractInfo.contractId,
|
|
41
|
+
tokenContractPosition: contractInfo.tokenContractPosition
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike, TokenDirectPurchasePrices } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike, TokenDirectPurchasePrices } from '../types.js';
|
|
3
3
|
export default function getTokenDirectPurchasePrices(grpcPool: GRPCConnectionPool, tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenDirectPurchasePrices } from 'pshenmic-dpp';
|
|
2
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
3
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import { GetTokenDirectPurchasePricesRequest } from '../../proto/generated/platform.js';
|
|
6
|
+
export default async function getTokenDirectPurchasePrices(grpcPool, tokenIdentifiers) {
|
|
7
|
+
const tokenIds = tokenIdentifiers.map(tokenId => new IdentifierWASM(tokenId).bytes());
|
|
8
|
+
const request = GetTokenDirectPurchasePricesRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
tokenIds,
|
|
13
|
+
prove: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getTokenDirectPurchasePrices(request);
|
|
18
|
+
const { version } = response;
|
|
19
|
+
if (version.oneofKind !== 'v0') {
|
|
20
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
21
|
+
}
|
|
22
|
+
const { v0 } = version;
|
|
23
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
24
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
25
|
+
}
|
|
26
|
+
const { result: { proof }, metadata } = v0;
|
|
27
|
+
if (metadata == null) {
|
|
28
|
+
throw new Error('Metadata not found');
|
|
29
|
+
}
|
|
30
|
+
const { rootHash, prices } = verifyTokenDirectPurchasePrices(proof.grovedbProof, tokenIds, true, PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
if (prices == null) {
|
|
32
|
+
throw new Error('Prices not found');
|
|
33
|
+
}
|
|
34
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
35
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
36
|
+
if (!verify) {
|
|
37
|
+
throw new Error('Failed to verify query');
|
|
38
|
+
}
|
|
39
|
+
return prices;
|
|
40
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike, TokenTotalSupply } from '../types';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike, TokenTotalSupply } from '../types.js';
|
|
3
3
|
export default function getTokenTotalSupply(grpcPool: GRPCConnectionPool, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { GetTokenTotalSupplyRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { IdentifierWASM, PlatformVersionWASM, verifyTokenTotalSupplyProof } from 'pshenmic-dpp';
|
|
3
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
4
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
6
|
+
export default async function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
7
|
+
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
8
|
+
const getTokenTotalSupplyRequest = GetTokenTotalSupplyRequest.create({
|
|
9
|
+
version: {
|
|
10
|
+
oneofKind: 'v0',
|
|
11
|
+
v0: {
|
|
12
|
+
tokenId: (tokenId).bytes(),
|
|
13
|
+
prove: true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const { response } = await grpcPool.getClient().getTokenTotalSupply(getTokenTotalSupplyRequest);
|
|
18
|
+
const { version } = response;
|
|
19
|
+
if (version.oneofKind !== 'v0') {
|
|
20
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
21
|
+
}
|
|
22
|
+
const { v0 } = version;
|
|
23
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
24
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
25
|
+
}
|
|
26
|
+
const { result: { proof }, metadata } = v0;
|
|
27
|
+
if (metadata == null) {
|
|
28
|
+
throw new Error('Metadata not found');
|
|
29
|
+
}
|
|
30
|
+
const { rootHash, totalBalance } = verifyTokenTotalSupplyProof(proof.grovedbProof, tokenId, true, PlatformVersionWASM.PLATFORM_V9);
|
|
31
|
+
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
32
|
+
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
33
|
+
if (!verify) {
|
|
34
|
+
throw new Error('Failed to verify query');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
tokenId,
|
|
38
|
+
totalSystemAmount: totalBalance.tokenSupply,
|
|
39
|
+
totalAggregatedAmountInUserAccounts: totalBalance.aggregatedTokenAccountBalances
|
|
40
|
+
};
|
|
41
|
+
}
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import GRPCConnectionPool from '../grpcConnectionPool';
|
|
2
|
-
import { IdentifierLike, TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../types';
|
|
3
|
-
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances';
|
|
4
|
-
import { IdentityTokenBalances } from './getIdentityTokensBalances';
|
|
5
|
-
import { TokenContractInfo } from './getTokenContractInfo';
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { IdentifierLike, TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../types.js';
|
|
3
|
+
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances.js';
|
|
4
|
+
import { IdentityTokenBalances } from './getIdentityTokensBalances.js';
|
|
5
|
+
import { TokenContractInfo } from './getTokenContractInfo.js';
|
|
6
6
|
import { StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
7
7
|
/**
|
|
8
8
|
* Tokens controller for requesting information about tokens and tokens holders
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import getIdentitiesTokenBalances from './getIdentitiesTokenBalances.js';
|
|
2
|
+
import getIdentityTokensBalances from './getIdentityTokensBalances.js';
|
|
3
|
+
import getTokenContractInfo from './getTokenContractInfo.js';
|
|
4
|
+
import getTokenTotalSupply from './getTokenTotalSupply.js';
|
|
5
|
+
import createStateTransition from './createStateTransition.js';
|
|
6
|
+
import { IdentifierWASM, TokenBaseTransitionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
7
|
+
import getIdentityContractNonce from '../identities/getIdentityContractNonce.js';
|
|
8
|
+
import getTokenDirectPurchasePrices from './getTokenDirectPurchasePrices.js';
|
|
9
|
+
/**
|
|
10
|
+
* Tokens controller for requesting information about tokens and tokens holders
|
|
11
|
+
*
|
|
12
|
+
* @hideconstructor
|
|
13
|
+
*/
|
|
14
|
+
export class TokensController {
|
|
15
|
+
/** @ignore **/
|
|
16
|
+
grpcPool;
|
|
17
|
+
constructor(grpcPool) {
|
|
18
|
+
this.grpcPool = grpcPool;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves a token balances for identities
|
|
22
|
+
*
|
|
23
|
+
* @param identifiers {IdentifierLike[]} - list of identifiers which balance we need to get
|
|
24
|
+
* @param tokenIdentifier {IdentifierLike} - token identifier
|
|
25
|
+
*
|
|
26
|
+
* @return {Promise<IdentitiesTokenBalances>}
|
|
27
|
+
*/
|
|
28
|
+
async getIdentitiesTokenBalances(identifiers, tokenIdentifier) {
|
|
29
|
+
return await getIdentitiesTokenBalances(this.grpcPool, identifiers, tokenIdentifier);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves a tokens balances for identity
|
|
33
|
+
*
|
|
34
|
+
* @param identifier {IdentifierLike} - identifier which balance we need to get
|
|
35
|
+
* @param tokenIdentifiers {IdentifierLike[]} - list of tokens ids which used in request
|
|
36
|
+
*
|
|
37
|
+
* @return {Promise<IdentityTokenBalances>}
|
|
38
|
+
*/
|
|
39
|
+
async getIdentityTokensBalances(identifier, tokenIdentifiers) {
|
|
40
|
+
return await getIdentityTokensBalances(this.grpcPool, identifier, tokenIdentifiers);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves a tokens contract info by id
|
|
44
|
+
*
|
|
45
|
+
* @param tokenIdentifier {IdentifierLike} - token id which contract info we need
|
|
46
|
+
*
|
|
47
|
+
* @return {Promise<TokenContractInfo>}
|
|
48
|
+
*/
|
|
49
|
+
async getTokenContractInfo(tokenIdentifier) {
|
|
50
|
+
return await getTokenContractInfo(this.grpcPool, tokenIdentifier);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves a token total supply
|
|
54
|
+
*
|
|
55
|
+
* @param tokenIdentifier {IdentifierLike} - token id which total supply we need
|
|
56
|
+
*
|
|
57
|
+
* @return {Promise<TokenTotalSupply>}
|
|
58
|
+
*/
|
|
59
|
+
async getTokenTotalSupply(tokenIdentifier) {
|
|
60
|
+
return await getTokenTotalSupply(this.grpcPool, tokenIdentifier);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves a tokens prices
|
|
64
|
+
*
|
|
65
|
+
* @param tokenIdentifiers {IdentifierLike[]} - token ids which price we need
|
|
66
|
+
*
|
|
67
|
+
* @return {Promise<TokenDirectPurchasePrices[]>}
|
|
68
|
+
*/
|
|
69
|
+
async getTokensDirectPurchasePrice(tokenIdentifiers) {
|
|
70
|
+
return await getTokenDirectPurchasePrices(this.grpcPool, tokenIdentifiers);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a Token Base Transition that contains base information about token transition
|
|
74
|
+
*
|
|
75
|
+
* @param tokenId {IdentifierLike} - token identifier
|
|
76
|
+
* @param ownerId {IdentifierLike} - identity identifier of sender of the transaction
|
|
77
|
+
*
|
|
78
|
+
* @return {TokenBaseTransitionWASM}
|
|
79
|
+
*/
|
|
80
|
+
async createBaseTransition(tokenId, ownerId) {
|
|
81
|
+
const { dataContractId, tokenContractPosition } = await getTokenContractInfo(this.grpcPool, tokenId);
|
|
82
|
+
const identityContractNonce = await getIdentityContractNonce(this.grpcPool, ownerId, dataContractId);
|
|
83
|
+
return new TokenBaseTransitionWASM(identityContractNonce + BigInt(1), tokenContractPosition, dataContractId, tokenId, undefined);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Helper function for creation of a token state transition to be broadcasted in the network
|
|
87
|
+
*
|
|
88
|
+
* You have to pass token base transition acquired from .createBaseTransition() method
|
|
89
|
+
* together with token transition type and its params
|
|
90
|
+
*
|
|
91
|
+
* @param base {TokenBaseTransitionWASM} - token Base transition
|
|
92
|
+
* @param ownerId {IdentifierLike} - `identity identifier of the owner of the transaction`
|
|
93
|
+
* @param type {TokenTransitionType} - token transition type as string (f.e. 'transfer')
|
|
94
|
+
* @param params {TokenTransitionParams} - params required for a token transition
|
|
95
|
+
*
|
|
96
|
+
* @return {StateTransitionWASM}
|
|
97
|
+
*/
|
|
98
|
+
createStateTransition(base, ownerId, type, params) {
|
|
99
|
+
const owner = new IdentifierWASM(ownerId);
|
|
100
|
+
if (params.identityId != null) {
|
|
101
|
+
params.identityId = new IdentifierWASM(params.identityId);
|
|
102
|
+
}
|
|
103
|
+
if (params.price != null && typeof params.price === 'bigint') {
|
|
104
|
+
params.price = TokenPricingScheduleWASM.SinglePrice(params.price);
|
|
105
|
+
}
|
|
106
|
+
return createStateTransition(base, owner, type, params);
|
|
107
|
+
}
|
|
108
|
+
}
|