@dashevo/dapi-grpc 0.24.0-dev.1 → 0.24.0-dev.10
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/core_protoc.js +1 -7
- 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 +1 -7
- 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/platform_pbjs.js +348 -20
- package/clients/platform/v0/nodejs/platform_protoc.js +109 -23
- 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 +109 -23
- 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 +3 -3
- package/protos/platform/v0/platform.proto +6 -1
- package/scripts/build.sh +11 -10
- package/clients/core/v0/web/core_grpc_web_pb.js +0 -495
- package/clients/platform/v0/web/platform_grpc_web_pb.js +0 -505
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
|
};
|
|
@@ -13,13 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
var jspb = require('google-protobuf');
|
|
15
15
|
var goog = jspb;
|
|
16
|
-
var global = (
|
|
17
|
-
if (this) { return this; }
|
|
18
|
-
if (typeof window !== 'undefined') { return window; }
|
|
19
|
-
if (typeof global !== 'undefined') { return global; }
|
|
20
|
-
if (typeof self !== 'undefined') { return self; }
|
|
21
|
-
return Function('return this')();
|
|
22
|
-
}.call(null));
|
|
16
|
+
var global = Function('return this')();
|
|
23
17
|
|
|
24
18
|
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, global);
|
|
25
19
|
goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, global);
|
|
@@ -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;
|