@dashevo/dapi-grpc 0.24.0-dev.5 → 0.24.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.
- package/README.md +3 -3
- package/browser.js +13 -5
- package/clients/core/v0/nodejs/CorePromiseClient.js +2 -1
- package/clients/core/v0/nodejs/core_protoc.js +33 -33
- package/clients/core/v0/web/CorePromiseClient.js +159 -0
- package/clients/core/v0/web/core_pb.d.ts +783 -0
- package/clients/core/v0/web/core_pb.js +33 -33
- package/clients/core/v0/web/core_pb_service.d.ts +161 -0
- package/clients/core/v0/web/core_pb_service.js +317 -0
- package/clients/platform/v0/nodejs/PlatformPromiseClient.js +2 -1
- package/clients/platform/v0/nodejs/platform_pbjs.js +348 -20
- package/clients/platform/v0/nodejs/platform_protoc.js +131 -39
- package/clients/platform/v0/web/PlatformPromiseClient.js +130 -0
- package/clients/platform/v0/web/platform_pb.d.ts +608 -0
- package/clients/platform/v0/web/platform_pb.js +131 -39
- package/clients/platform/v0/web/platform_pb_service.d.ts +177 -0
- package/clients/platform/v0/web/platform_pb_service.js +301 -0
- package/lib/utils/parseMetadata.js +27 -0
- package/node.js +4 -0
- package/package.json +4 -4
- package/protos/platform/v0/platform.proto +6 -1
- package/scripts/build.sh +3 -3
- package/scripts/patch-protobuf-js.sh +30 -0
- package/clients/core/v0/web/core_grpc_web_pb.js +0 -499
- package/clients/platform/v0/web/platform_grpc_web_pb.js +0 -509
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# DAPI GRPC
|
|
2
2
|
|
|
3
|
-
[](https://github.com/dashpay/platform/actions/workflows/release.yml)
|
|
4
4
|
[](https://npmjs.org/package/@dashevo/dapi-grpc)
|
|
5
|
-
[](https://github.com/dashpay/platform/releases/latest)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
8
|
Decentralized API GRPC definition files and generated clients
|
|
@@ -135,7 +135,7 @@ Available methods :
|
|
|
135
135
|
|
|
136
136
|
## Contributing
|
|
137
137
|
|
|
138
|
-
Feel free to dive in! [Open an issue](https://github.com/
|
|
138
|
+
Feel free to dive in! [Open an issue](https://github.com/dashpay/platform/issues/new/choose) or submit PRs.
|
|
139
139
|
|
|
140
140
|
## License
|
|
141
141
|
|
package/browser.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { grpc: { Metadata } } = require('@improbable-eng/grpc-web');
|
|
2
|
+
const CorePromiseClient = require('./clients/core/v0/web/CorePromiseClient');
|
|
3
|
+
const PlatformPromiseClient = require('./clients/platform/v0/web/PlatformPromiseClient');
|
|
4
|
+
|
|
5
|
+
const coreMessages = require('./clients/core/v0/web/core_pb');
|
|
6
|
+
const platformMessages = require('./clients/platform/v0/web/platform_pb');
|
|
7
|
+
const parseMetadata = require('./lib/utils/parseMetadata');
|
|
3
8
|
|
|
4
9
|
module.exports = {
|
|
5
10
|
v0: {
|
|
6
|
-
|
|
7
|
-
...
|
|
8
|
-
|
|
11
|
+
...coreMessages,
|
|
12
|
+
...platformMessages,
|
|
13
|
+
CorePromiseClient,
|
|
14
|
+
PlatformPromiseClient,
|
|
9
15
|
},
|
|
16
|
+
parseMetadata,
|
|
17
|
+
Metadata,
|
|
10
18
|
};
|
|
@@ -73,8 +73,9 @@ class CorePromiseClient {
|
|
|
73
73
|
const url = new URL(hostname);
|
|
74
74
|
const { protocol, host: strippedHostname } = url;
|
|
75
75
|
|
|
76
|
+
// See this issue https://github.com/nodejs/node/issues/3176
|
|
76
77
|
// eslint-disable-next-line no-param-reassign
|
|
77
|
-
credentials = protocol === 'https' ? grpc.credentials.createSsl() : grpc.credentials.createInsecure();
|
|
78
|
+
credentials = protocol.replace(':', '') === 'https' ? grpc.credentials.createSsl() : grpc.credentials.createInsecure();
|
|
78
79
|
|
|
79
80
|
this.client = new CoreNodeJSClient(strippedHostname, credentials, options);
|
|
80
81
|
|
|
@@ -13,39 +13,39 @@
|
|
|
13
13
|
|
|
14
14
|
var jspb = require('google-protobuf');
|
|
15
15
|
var goog = jspb;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null,
|
|
19
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null,
|
|
20
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null,
|
|
21
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null,
|
|
22
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null,
|
|
23
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null,
|
|
24
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null,
|
|
25
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null,
|
|
26
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null,
|
|
27
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null,
|
|
28
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null,
|
|
29
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null,
|
|
30
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null,
|
|
31
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null,
|
|
32
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null,
|
|
33
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Chain', null,
|
|
34
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode', null,
|
|
35
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode.Status', null,
|
|
36
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Network', null,
|
|
37
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.NetworkFee', null,
|
|
38
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Status', null,
|
|
39
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Time', null,
|
|
40
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Version', null,
|
|
41
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null,
|
|
42
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null,
|
|
43
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null,
|
|
44
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null,
|
|
45
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null,
|
|
46
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null,
|
|
47
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null,
|
|
48
|
-
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null,
|
|
16
|
+
const proto = {};
|
|
17
|
+
|
|
18
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, { proto });
|
|
19
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, { proto });
|
|
20
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, { proto });
|
|
21
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, { proto });
|
|
22
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, { proto });
|
|
23
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, { proto });
|
|
24
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, { proto });
|
|
25
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, { proto });
|
|
26
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, { proto });
|
|
27
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, { proto });
|
|
28
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, { proto });
|
|
29
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, { proto });
|
|
30
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, { proto });
|
|
31
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, { proto });
|
|
32
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, { proto });
|
|
33
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Chain', null, { proto });
|
|
34
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode', null, { proto });
|
|
35
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode.Status', null, { proto });
|
|
36
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Network', null, { proto });
|
|
37
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.NetworkFee', null, { proto });
|
|
38
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Status', null, { proto });
|
|
39
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Time', null, { proto });
|
|
40
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Version', null, { proto });
|
|
41
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, { proto });
|
|
42
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, { proto });
|
|
43
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, { proto });
|
|
44
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, { proto });
|
|
45
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, { proto });
|
|
46
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, { proto });
|
|
47
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, { proto });
|
|
48
|
+
goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, { proto });
|
|
49
49
|
/**
|
|
50
50
|
* Generated by JsPbCodeGenerator.
|
|
51
51
|
* @param {Array=} opt_data Optional initial data array, typically from a
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const { promisify } = require('util');
|
|
2
|
+
const GrpcError = require('@dashevo/grpc-common/lib/server/error/GrpcError');
|
|
3
|
+
|
|
4
|
+
const { CoreClient } = require('./core_pb_service');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Function rewires @imporbable-eng/grpc-web stream
|
|
8
|
+
* to comply with the EventEmitter interface
|
|
9
|
+
* @param stream
|
|
10
|
+
* @return {!grpc.web.ClientReadableStream}
|
|
11
|
+
*/
|
|
12
|
+
const rewireStream = (stream) => {
|
|
13
|
+
const defaultOnFunction = stream.on.bind(stream);
|
|
14
|
+
|
|
15
|
+
// Rewire default on function to comply with EventEmitter interface
|
|
16
|
+
stream.on = ((type, handler) => {
|
|
17
|
+
if (type === 'error') { // Handle `error` event using `end` event
|
|
18
|
+
return stream.on('end', (payload) => {
|
|
19
|
+
if (payload) {
|
|
20
|
+
const { code, details, metadata } = payload;
|
|
21
|
+
if (code !== 0) {
|
|
22
|
+
const error = new GrpcError(code, details);
|
|
23
|
+
// It is important to assign metadata to the error object
|
|
24
|
+
// instead of passing it as GrpcError constructor argument
|
|
25
|
+
// Otherwise it will be converted to grpc-js metadata
|
|
26
|
+
// Which is not compatible with web
|
|
27
|
+
error.metadata = metadata;
|
|
28
|
+
handler(error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
// `data` event could be processed normally
|
|
34
|
+
return defaultOnFunction(type, handler);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Assign an empty function to `once` method
|
|
39
|
+
// because @imporbable-eng/grpc-web doesn't expose it and
|
|
40
|
+
// stream cancellation detaches all handlers internally
|
|
41
|
+
stream.removeListener = () => {}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
class CorePromiseClient {
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} hostname
|
|
47
|
+
* @param {?Object} credentials
|
|
48
|
+
* @param {?Object} options
|
|
49
|
+
*/
|
|
50
|
+
constructor(hostname, credentials , options = {}) {
|
|
51
|
+
this.client = new CoreClient(hostname, options)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {!GetStatusRequest} getStatusRequest
|
|
56
|
+
* @param {?Object<string, string>} metadata
|
|
57
|
+
* @return {Promise<!GetStatusResponse>}
|
|
58
|
+
*/
|
|
59
|
+
getStatus(getStatusRequest, metadata = {}) {
|
|
60
|
+
return promisify(
|
|
61
|
+
this.client.getStatus.bind(this.client),
|
|
62
|
+
)(
|
|
63
|
+
getStatusRequest,
|
|
64
|
+
metadata,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {!GetBlockRequest} getBlockRequest
|
|
70
|
+
* @param {?Object<string, string>} metadata
|
|
71
|
+
* @return {Promise<!GetBlockResponse>}
|
|
72
|
+
*/
|
|
73
|
+
getBlock(getBlockRequest, metadata = {}) {
|
|
74
|
+
return promisify(
|
|
75
|
+
this.client.getBlock.bind(this.client),
|
|
76
|
+
)(
|
|
77
|
+
getBlockRequest,
|
|
78
|
+
metadata,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {!BroadcastTransactionRequest} broadcastTransactionRequest
|
|
84
|
+
* @param {?Object<string, string>} metadata
|
|
85
|
+
* @return {Promise<!BroadcastTransactionResponse>}
|
|
86
|
+
*/
|
|
87
|
+
broadcastTransaction(broadcastTransactionRequest, metadata = {}) {
|
|
88
|
+
return promisify(
|
|
89
|
+
this.client.broadcastTransaction.bind(this.client),
|
|
90
|
+
)(
|
|
91
|
+
broadcastTransactionRequest,
|
|
92
|
+
metadata,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {!GetTransactionRequest} getTransactionRequest
|
|
98
|
+
* @param {?Object<string, string>} metadata
|
|
99
|
+
* @return {Promise<!GetTransactionResponse>}
|
|
100
|
+
*/
|
|
101
|
+
getTransaction(getTransactionRequest, metadata = {}) {
|
|
102
|
+
return promisify(
|
|
103
|
+
this.client.getTransaction.bind(this.client),
|
|
104
|
+
)(
|
|
105
|
+
getTransactionRequest,
|
|
106
|
+
metadata,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {!GetEstimatedTransactionFeeRequest} getEstimatedTransactionFeeRequest
|
|
112
|
+
* @param {?Object<string, string>} metadata
|
|
113
|
+
* @returns {Promise<!GetEstimatedTransactionFeeResponse>}
|
|
114
|
+
*/
|
|
115
|
+
getEstimatedTransactionFee(getEstimatedTransactionFeeRequest, metadata = {}) {
|
|
116
|
+
return promisify(
|
|
117
|
+
this.client.getEstimatedTransactionFee.bind(this.client),
|
|
118
|
+
)(
|
|
119
|
+
getEstimatedTransactionFeeRequest,
|
|
120
|
+
metadata,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {!BlockHeadersWithChainLocksRequest} blockHeadersWithChainLocksRequest
|
|
126
|
+
* @param {?Object<string, string>} metadata
|
|
127
|
+
* @return {!grpc.web.ClientReadableStream<!BlockHeadersWithChainLocksResponse>|undefined}
|
|
128
|
+
*/
|
|
129
|
+
subscribeToBlockHeadersWithChainLocks(
|
|
130
|
+
blockHeadersWithChainLocksRequest,
|
|
131
|
+
metadata = {},
|
|
132
|
+
) {
|
|
133
|
+
const stream = this.client.subscribeToBlockHeadersWithChainLocks(
|
|
134
|
+
blockHeadersWithChainLocksRequest,
|
|
135
|
+
metadata,
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
rewireStream(stream);
|
|
139
|
+
|
|
140
|
+
return stream;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @param {TransactionsWithProofsRequest} transactionsWithProofsRequest The request proto
|
|
145
|
+
* @param {?Object<string, string>} metadata User defined call metadata
|
|
146
|
+
* @return {!grpc.web.ClientReadableStream<!TransactionsWithProofsResponse>|undefined}
|
|
147
|
+
*/
|
|
148
|
+
subscribeToTransactionsWithProofs(transactionsWithProofsRequest, metadata = {}) {
|
|
149
|
+
const stream = this.client.subscribeToTransactionsWithProofs(
|
|
150
|
+
transactionsWithProofsRequest,
|
|
151
|
+
metadata
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
rewireStream(stream);
|
|
155
|
+
return stream;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
module.exports = CorePromiseClient;
|