dash-platform-sdk 1.0.0

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.
@@ -0,0 +1,33 @@
1
+ import { GetDocumentsRequest } from '../../proto/generated/platform.js'
2
+ import { base58 } from '@scure/base'
3
+ import cbor from 'cbor'
4
+
5
+ export default async function getDocuments(dataContractId, documentType, where, orderBy, limit = 100, startAt, startAfter, prove = false) {
6
+ const getDocumentsRequest = new GetDocumentsRequest.fromPartial({
7
+ v0: {
8
+ dataContractId: base58.decode(dataContractId),
9
+ documentType,
10
+ where: where ? cbor.encode(where) : undefined,
11
+ orderBy: orderBy ? cbor.encode(orderBy): undefined,
12
+ limit,
13
+ startAt : startAt ? startAt : undefined,
14
+ startAfter : startAfter ? startAfter : undefined,
15
+ prove
16
+ }
17
+ })
18
+
19
+ const { v0 } = await this.client.getDocuments(getDocumentsRequest)
20
+
21
+ return v0.documents.documents
22
+ }
23
+
24
+ //*
25
+ //
26
+ // message GetDocumentsRequestV0 {
27
+ // // Specifies the starting point for the document retrieval
28
+ // oneof start {
29
+ // bytes start_after = 6; // Start retrieval after this document
30
+ // bytes start_at = 7; // Start retrieval at this document
31
+ // }
32
+ // bool prove = 8; // Flag to request a proof as the response
33
+ // }*/
@@ -0,0 +1,19 @@
1
+ import { GetStatusRequest } from '../../proto/generated/platform.js'
2
+
3
+ export default async function getStatus() {
4
+ const getStatusRequest = new GetStatusRequest.fromPartial({v0: {}});
5
+
6
+ const response = await this.client.getStatus(getStatusRequest)
7
+
8
+ const {v0} = response
9
+
10
+ // map buffers to hex string
11
+ v0.node.id = v0.node.id.reduce((code, acc) => acc + code.toString(16), "")
12
+ v0.node.proTxHash = v0.node.proTxHash.reduce((code, acc) => acc + code.toString(16), "")
13
+ v0.chain.latestBlockHash = v0.chain.latestBlockHash.reduce((code, acc) => acc + code.toString(16), "")
14
+ v0.chain.latestAppHash = v0.chain.latestAppHash.reduce((code, acc) => acc + code.toString(16), "")
15
+ v0.chain.earliestAppHash = v0.chain.earliestAppHash.reduce((code, acc) => acc + code.toString(16), "")
16
+ v0.chain.earliestBlockHash = v0.chain.earliestBlockHash.reduce((code, acc) => acc + code.toString(16), "")
17
+
18
+ return v0
19
+ }
@@ -0,0 +1,64 @@
1
+ import DashPlatformSDK from '../../index'
2
+
3
+ let sdk
4
+
5
+ describe('DashPlatformSDK', () => {
6
+ beforeAll(() => {
7
+ sdk = new DashPlatformSDK()
8
+ })
9
+
10
+ test('should be constructable throw `new`', () => {
11
+ expect(sdk).toEqual(expect.any(DashPlatformSDK))
12
+ })
13
+
14
+ test('should be able to call getStatus', async () => {
15
+ const status = await sdk.utils.getStatus()
16
+
17
+ expect(status.version.software.dapi).toEqual(expect.any(String))
18
+ expect(status.version.software.drive).toEqual(expect.any(String))
19
+
20
+ expect(status.version.software.tenderdash).toEqual(expect.any(String))
21
+ expect(status.version.protocol.tenderdash.p2p).toEqual(expect.any(Number))
22
+ expect(status.version.protocol.tenderdash.block).toEqual(expect.any(Number))
23
+
24
+ expect(status.version.protocol.drive.latest).toEqual(expect.any(Number))
25
+ expect(status.version.protocol.drive.current).toEqual(expect.any(Number))
26
+
27
+ expect(status.node.id).toEqual(expect.any(String))
28
+ expect(status.node.proTxHash).toEqual(expect.any(String))
29
+
30
+ expect(status.chain.catchingUp).toEqual(expect.any(Boolean))
31
+ expect(status.chain.latestBlockHash).toEqual(expect.any(String))
32
+ expect(status.chain.latestAppHash).toEqual(expect.any(String))
33
+ expect(status.chain.latestBlockHeight).toEqual(expect.any(String))
34
+ expect(status.chain.earliestBlockHash).toEqual(expect.any(String))
35
+ expect(status.chain.earliestAppHash).toEqual(expect.any(String))
36
+ expect(status.chain.earliestBlockHeight).toEqual(expect.any(String))
37
+ expect(status.chain.maxPeerBlockHeight).toEqual(expect.any(String))
38
+ expect(status.chain.coreChainLockedHeight).toEqual(expect.any(Number))
39
+
40
+ expect(status.network.chainId).toEqual(expect.any(String))
41
+ expect(status.network.peersCount).toEqual(expect.any(Number))
42
+ expect(status.network.listening).toEqual(expect.any(Boolean))
43
+
44
+ expect(status.stateSync.totalSyncedTime).toEqual(expect.any(String))
45
+ expect(status.stateSync.remainingTime).toEqual(expect.any(String))
46
+ expect(status.stateSync.totalSnapshots).toEqual(expect.any(Number))
47
+ expect(status.stateSync.chunkProcessAvgTime).toEqual(expect.any(String))
48
+ expect(status.stateSync.snapshotHeight).toEqual(expect.any(String))
49
+ expect(status.stateSync.snapshotChunksCount).toEqual(expect.any(String))
50
+ expect(status.stateSync.backfilledBlocks).toEqual(expect.any(String))
51
+ expect(status.stateSync.backfillBlocksTotal).toEqual(expect.any(String))
52
+
53
+ expect(status.time.local).toEqual(expect.any(String))
54
+ expect(status.time.block).toEqual(expect.any(String))
55
+ expect(status.time.genesis).toEqual(expect.any(String))
56
+ expect(status.time.epoch).toEqual(expect.any(Number))
57
+ })
58
+
59
+ test('should be able to call getDocuments()', async () => {
60
+ const documents = await sdk.documents.get('GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec', 'domain')
61
+
62
+ expect(documents.length).toEqual(100)
63
+ })
64
+ })
@@ -0,0 +1,18 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ mode: 'production',
5
+ entry: './index.js',
6
+ resolve: {
7
+ fallback: {
8
+ "stream": require.resolve("stream-browserify"),
9
+ "buffer": require.resolve("buffer/")
10
+ },
11
+ },
12
+ output: {
13
+ globalObject: 'this',
14
+ path: path.resolve(__dirname, 'dist'),
15
+ libraryTarget: 'umd'
16
+ },
17
+ };
18
+