@dashevo/dapi-grpc 2.0.0-dev.1 → 2.0.0-rc.2
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/Cargo.toml +18 -9
- package/build.rs +41 -4
- package/clients/drive/v0/nodejs/DrivePromiseClient.js +111 -0
- package/clients/drive/v0/nodejs/drive_pbjs.js +74060 -0
- package/clients/drive/v0/nodejs/drive_protoc.js +420 -0
- package/clients/drive/v0/web/drive_pb.d.ts +56 -0
- package/clients/drive/v0/web/drive_pb.js +420 -0
- package/clients/drive/v0/web/drive_pb_service.d.ts +63 -0
- package/clients/drive/v0/web/drive_pb_service.js +61 -0
- package/clients/platform/v0/nodejs/PlatformPromiseClient.js +0 -39
- package/clients/platform/v0/nodejs/platform_pbjs.js +12498 -10042
- package/clients/platform/v0/nodejs/platform_protoc.js +17686 -15269
- package/clients/platform/v0/web/platform_pb.d.ts +755 -433
- package/clients/platform/v0/web/platform_pb.js +17686 -15269
- package/clients/platform/v0/web/platform_pb_service.d.ts +57 -19
- package/clients/platform/v0/web/platform_pb_service.js +101 -21
- package/lib/getDriveDefinition.js +18 -0
- package/node.js +19 -0
- package/package.json +2 -2
- package/protos/drive/v0/drive.proto +18 -0
- package/protos/platform/v0/platform.proto +558 -501
- package/scripts/build.sh +55 -0
- package/scripts/patch-protobuf-js.sh +3 -2
- package/src/lib.rs +23 -0
package/Cargo.toml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "dapi-grpc"
|
|
3
3
|
description = "GRPC client for Dash Platform"
|
|
4
|
-
version = "2.0.0-
|
|
4
|
+
version = "2.0.0-rc.2"
|
|
5
5
|
authors = [
|
|
6
6
|
"Samuel Westrich <sam@dash.org>",
|
|
7
7
|
"Igor Markin <igor.markin@dash.org>",
|
|
@@ -15,6 +15,8 @@ license = "MIT"
|
|
|
15
15
|
|
|
16
16
|
[features]
|
|
17
17
|
default = ["core", "platform", "client"]
|
|
18
|
+
# Internal Drive endpoints. Used by DAPI
|
|
19
|
+
drive = ["platform"]
|
|
18
20
|
core = []
|
|
19
21
|
platform = []
|
|
20
22
|
# Re-export Dash Platform protobuf types as `dapi_grpc::platform::proto`
|
|
@@ -25,21 +27,28 @@ tenderdash-proto = []
|
|
|
25
27
|
client = ["platform"]
|
|
26
28
|
|
|
27
29
|
# Build tonic server code. Includes all client features and adds server-specific dependencies.
|
|
28
|
-
server = [
|
|
30
|
+
server = [
|
|
31
|
+
"platform",
|
|
32
|
+
"tenderdash-proto/server",
|
|
33
|
+
"client",
|
|
34
|
+
"drive",
|
|
35
|
+
"tonic/router",
|
|
36
|
+
]
|
|
29
37
|
|
|
30
38
|
serde = ["dep:serde", "dep:serde_bytes", "tenderdash-proto/serde"]
|
|
31
39
|
mocks = ["serde", "dep:serde_json"]
|
|
32
40
|
|
|
33
41
|
[dependencies]
|
|
34
|
-
tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "1.
|
|
42
|
+
tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "1.4.0", tag = "v1.4.0", default-features = false }
|
|
35
43
|
|
|
36
44
|
prost = { version = "0.13" }
|
|
37
45
|
futures-core = "0.3.30"
|
|
38
|
-
tonic = { version = "0.
|
|
46
|
+
tonic = { version = "0.13.0", features = [
|
|
39
47
|
"codegen",
|
|
40
48
|
"prost",
|
|
49
|
+
"tls-ring",
|
|
41
50
|
], default-features = false }
|
|
42
|
-
serde = { version = "1.0.
|
|
51
|
+
serde = { version = "1.0.219", optional = true, features = ["derive"] }
|
|
43
52
|
serde_bytes = { version = "0.11.12", optional = true }
|
|
44
53
|
serde_json = { version = "1.0", optional = true }
|
|
45
54
|
dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
|
|
@@ -49,18 +58,18 @@ platform-version = { path = "../rs-platform-version" }
|
|
|
49
58
|
getrandom = { version = "0.2", features = ["js"] }
|
|
50
59
|
|
|
51
60
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
52
|
-
tonic = { version = "0.
|
|
61
|
+
tonic = { version = "0.13.0", features = [
|
|
53
62
|
"codegen",
|
|
54
63
|
"prost",
|
|
55
64
|
"channel",
|
|
56
65
|
"transport",
|
|
57
|
-
"tls",
|
|
58
|
-
"tls-roots",
|
|
66
|
+
"tls-native-roots",
|
|
59
67
|
"tls-webpki-roots",
|
|
68
|
+
"tls-ring",
|
|
60
69
|
], default-features = false }
|
|
61
70
|
|
|
62
71
|
[build-dependencies]
|
|
63
|
-
tonic-build = { version = "0.
|
|
72
|
+
tonic-build = { version = "0.13.0" }
|
|
64
73
|
|
|
65
74
|
[lib]
|
|
66
75
|
|
package/build.rs
CHANGED
|
@@ -47,6 +47,16 @@ fn generate_code(typ: ImplType) {
|
|
|
47
47
|
.generate()
|
|
48
48
|
.expect("generate platform proto");
|
|
49
49
|
|
|
50
|
+
let drive = MappingConfig::new(
|
|
51
|
+
PathBuf::from("protos/drive/v0/drive.proto"),
|
|
52
|
+
PathBuf::from("src/drive"),
|
|
53
|
+
&typ,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
configure_drive(drive)
|
|
57
|
+
.generate()
|
|
58
|
+
.expect("generate platform proto");
|
|
59
|
+
|
|
50
60
|
println!("cargo:rerun-if-changed=./protos");
|
|
51
61
|
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SERDE");
|
|
52
62
|
println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH");
|
|
@@ -63,7 +73,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
|
63
73
|
// Derive features for versioned messages
|
|
64
74
|
//
|
|
65
75
|
// "GetConsensusParamsRequest" is excluded as this message does not support proofs
|
|
66
|
-
const VERSIONED_REQUESTS: [&str;
|
|
76
|
+
const VERSIONED_REQUESTS: [&str; 42] = [
|
|
67
77
|
"GetDataContractHistoryRequest",
|
|
68
78
|
"GetDataContractRequest",
|
|
69
79
|
"GetDataContractsRequest",
|
|
@@ -75,10 +85,10 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
|
75
85
|
"GetIdentityContractNonceRequest",
|
|
76
86
|
"GetIdentityBalanceAndRevisionRequest",
|
|
77
87
|
"GetIdentityBalanceRequest",
|
|
88
|
+
"GetIdentityByNonUniquePublicKeyHashRequest",
|
|
78
89
|
"GetIdentityByPublicKeyHashRequest",
|
|
79
90
|
"GetIdentityKeysRequest",
|
|
80
91
|
"GetIdentityRequest",
|
|
81
|
-
"GetProofsRequest",
|
|
82
92
|
"WaitForStateTransitionResultRequest",
|
|
83
93
|
"GetProtocolVersionUpgradeStateRequest",
|
|
84
94
|
"GetProtocolVersionUpgradeVoteStatusRequest",
|
|
@@ -96,8 +106,10 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
|
96
106
|
"GetStatusRequest",
|
|
97
107
|
"GetIdentityTokenBalancesRequest",
|
|
98
108
|
"GetIdentitiesTokenBalancesRequest",
|
|
109
|
+
"GetTokenPerpetualDistributionLastClaimRequest",
|
|
99
110
|
"GetIdentityTokenInfosRequest",
|
|
100
111
|
"GetIdentitiesTokenInfosRequest",
|
|
112
|
+
"GetTokenDirectPurchasePricesRequest",
|
|
101
113
|
"GetTokenStatusesRequest",
|
|
102
114
|
"GetTokenTotalSupplyRequest",
|
|
103
115
|
"GetGroupInfoRequest",
|
|
@@ -110,8 +122,11 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
|
110
122
|
// - "GetConsensusParamsResponse"
|
|
111
123
|
// - "GetStatusResponse"
|
|
112
124
|
//
|
|
125
|
+
// The following responses are excluded as they need custom proof handling:
|
|
126
|
+
// - "GetIdentityByNonUniquePublicKeyHashResponse"
|
|
127
|
+
//
|
|
113
128
|
// "GetEvonodesProposedEpochBlocksResponse" is used for 2 Requests
|
|
114
|
-
const VERSIONED_RESPONSES: [&str;
|
|
129
|
+
const VERSIONED_RESPONSES: [&str; 40] = [
|
|
115
130
|
"GetDataContractHistoryResponse",
|
|
116
131
|
"GetDataContractResponse",
|
|
117
132
|
"GetDataContractsResponse",
|
|
@@ -126,7 +141,6 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
|
126
141
|
"GetIdentityByPublicKeyHashResponse",
|
|
127
142
|
"GetIdentityKeysResponse",
|
|
128
143
|
"GetIdentityResponse",
|
|
129
|
-
"GetProofsResponse",
|
|
130
144
|
"WaitForStateTransitionResultResponse",
|
|
131
145
|
"GetEpochsInfoResponse",
|
|
132
146
|
"GetProtocolVersionUpgradeStateResponse",
|
|
@@ -143,8 +157,10 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
|
143
157
|
"GetEvonodesProposedEpochBlocksResponse",
|
|
144
158
|
"GetIdentityTokenBalancesResponse",
|
|
145
159
|
"GetIdentitiesTokenBalancesResponse",
|
|
160
|
+
"GetTokenPerpetualDistributionLastClaimResponse",
|
|
146
161
|
"GetIdentityTokenInfosResponse",
|
|
147
162
|
"GetIdentitiesTokenInfosResponse",
|
|
163
|
+
"GetTokenDirectPurchasePricesResponse",
|
|
148
164
|
"GetTokenStatusesResponse",
|
|
149
165
|
"GetTokenTotalSupplyResponse",
|
|
150
166
|
"GetGroupInfoResponse",
|
|
@@ -210,6 +226,19 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
|
210
226
|
platform
|
|
211
227
|
}
|
|
212
228
|
|
|
229
|
+
fn configure_drive(drive: MappingConfig) -> MappingConfig {
|
|
230
|
+
drive
|
|
231
|
+
.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#)
|
|
232
|
+
.type_attribute(
|
|
233
|
+
".",
|
|
234
|
+
r#"#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]"#,
|
|
235
|
+
)
|
|
236
|
+
.type_attribute(
|
|
237
|
+
".",
|
|
238
|
+
r#"#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]"#,
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
213
242
|
/// Check for duplicate messages in the list.
|
|
214
243
|
fn check_unique(messages: &[&'static str]) -> Result<(), String> {
|
|
215
244
|
let mut hashset: HashSet<&'static str> = HashSet::new();
|
|
@@ -322,6 +351,14 @@ impl MappingConfig {
|
|
|
322
351
|
self
|
|
323
352
|
}
|
|
324
353
|
|
|
354
|
+
#[allow(unused)]
|
|
355
|
+
fn includes(mut self, includes: &[PathBuf]) -> Self {
|
|
356
|
+
for include in includes {
|
|
357
|
+
self.proto_includes.push(abs_path(include));
|
|
358
|
+
}
|
|
359
|
+
self
|
|
360
|
+
}
|
|
361
|
+
|
|
325
362
|
#[allow(unused)]
|
|
326
363
|
fn field_attribute(mut self, path: &str, attribute: &str) -> Self {
|
|
327
364
|
self.builder = self.builder.field_attribute(path, attribute);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const grpc = require('@grpc/grpc-js');
|
|
2
|
+
const { promisify } = require('util');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
convertObjectToMetadata,
|
|
6
|
+
utils: {
|
|
7
|
+
isObject,
|
|
8
|
+
},
|
|
9
|
+
client: {
|
|
10
|
+
interceptors: {
|
|
11
|
+
jsonToProtobufInterceptorFactory,
|
|
12
|
+
},
|
|
13
|
+
converters: {
|
|
14
|
+
jsonToProtobufFactory,
|
|
15
|
+
protobufToJsonFactory,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
} = require('@dashevo/grpc-common');
|
|
19
|
+
|
|
20
|
+
const { URL } = require('url');
|
|
21
|
+
const {
|
|
22
|
+
org: {
|
|
23
|
+
dash: {
|
|
24
|
+
platform: {
|
|
25
|
+
drive: {
|
|
26
|
+
v0: {
|
|
27
|
+
GetProofsRequest: PBJSGetProofsRequest,
|
|
28
|
+
GetProofsResponse: PBJSGetProofsResponse,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
} = require('./drive_pbjs');
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
GetProofsResponse: ProtocGetProofsResponse,
|
|
38
|
+
} = require('./drive_protoc');
|
|
39
|
+
|
|
40
|
+
const getDriveDefinition = require('../../../../lib/getDriveDefinition');
|
|
41
|
+
|
|
42
|
+
const DriveNodeJSClient = getDriveDefinition(0);
|
|
43
|
+
|
|
44
|
+
class DrivePromiseClient {
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} hostname
|
|
47
|
+
* @param {?Object} credentials
|
|
48
|
+
* @param {?Object} options
|
|
49
|
+
*/
|
|
50
|
+
constructor(hostname, credentials, options = {}) {
|
|
51
|
+
if (credentials !== undefined) {
|
|
52
|
+
throw new Error('"credentials" option is not supported yet');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const url = new URL(hostname);
|
|
56
|
+
const { protocol, host: strippedHostname } = url;
|
|
57
|
+
|
|
58
|
+
// See this issue https://github.com/nodejs/node/issues/3176
|
|
59
|
+
// eslint-disable-next-line no-param-reassign
|
|
60
|
+
credentials = protocol.replace(':', '') === 'https' ? grpc.credentials.createSsl() : grpc.credentials.createInsecure();
|
|
61
|
+
|
|
62
|
+
this.client = new DriveNodeJSClient(strippedHostname, credentials, options);
|
|
63
|
+
|
|
64
|
+
this.client.getProofs = promisify(
|
|
65
|
+
this.client.getProofs.bind(this.client),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
this.protocolVersion = undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param {!GetProofsRequest} request
|
|
74
|
+
* @param {?Object<string, string>} metadata
|
|
75
|
+
* @param {CallOptions} [options={}]
|
|
76
|
+
* @returns {Promise<!GetProofsResponse>}
|
|
77
|
+
*/
|
|
78
|
+
getProofs(request, metadata = {}, options = {}) {
|
|
79
|
+
if (!isObject(metadata)) {
|
|
80
|
+
throw new Error('metadata must be an object');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return this.client.getProofs(
|
|
84
|
+
request,
|
|
85
|
+
convertObjectToMetadata(metadata),
|
|
86
|
+
{
|
|
87
|
+
interceptors: [
|
|
88
|
+
jsonToProtobufInterceptorFactory(
|
|
89
|
+
jsonToProtobufFactory(
|
|
90
|
+
ProtocGetProofsResponse,
|
|
91
|
+
PBJSGetProofsResponse,
|
|
92
|
+
),
|
|
93
|
+
protobufToJsonFactory(
|
|
94
|
+
PBJSGetProofsRequest,
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
],
|
|
98
|
+
...options,
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {string} protocolVersion
|
|
105
|
+
*/
|
|
106
|
+
setProtocolVersion(protocolVersion) {
|
|
107
|
+
this.protocolVersion = protocolVersion;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = DrivePromiseClient;
|