@dashevo/dapi-grpc 1.0.0-dev.1 → 1.0.0-dev.11
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 +30 -16
- package/build.rs +49 -23
- package/clients/core/v0/rust/core_example.rs +1 -1
- package/clients/platform/v0/nodejs/PlatformPromiseClient.js +153 -0
- package/clients/platform/v0/nodejs/platform_pbjs.js +3022 -1060
- package/clients/platform/v0/nodejs/platform_protoc.js +2620 -729
- package/clients/platform/v0/rust/platform_example.rs +1 -1
- package/clients/platform/v0/web/PlatformPromiseClient.js +42 -0
- package/clients/platform/v0/web/platform_pb.d.ts +257 -0
- package/clients/platform/v0/web/platform_pb.js +2620 -729
- package/clients/platform/v0/web/platform_pb_service.d.ts +38 -0
- package/clients/platform/v0/web/platform_pb_service.js +80 -0
- package/package.json +2 -2
- package/protos/platform/v0/platform.proto +84 -0
- package/src/core/proto/org.dash.platform.dapi.v0.rs +577 -0
- package/src/lib.rs +7 -0
- package/src/mock.rs +68 -0
- package/src/platform/proto/org.dash.platform.dapi.v0.rs +1727 -0
- package/test/unit/clients/platform/v0/nodejs/PlatformPromiseClient.spec.js +33 -0
package/Cargo.toml
CHANGED
|
@@ -1,36 +1,50 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "dapi-grpc"
|
|
3
3
|
description = "GRPC client for Dash Platform"
|
|
4
|
-
version = "1.0.0-dev.
|
|
4
|
+
version = "1.0.0-dev.11"
|
|
5
5
|
authors = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
"Samuel Westrich <sam@dash.org>",
|
|
7
|
+
"Igor Markin <igor.markin@dash.org>",
|
|
8
|
+
"Łukasz Klimek <lukasz.klimek@dash.org>",
|
|
9
|
+
"Anton Suprunchuk <anton.suprunchuk@dash.org>",
|
|
10
|
+
"Ivan Shumkov <shumkov@dash.org>",
|
|
11
11
|
]
|
|
12
12
|
edition = "2021"
|
|
13
|
-
rust-version = "1.
|
|
13
|
+
rust-version = "1.76"
|
|
14
14
|
license = "MIT"
|
|
15
15
|
|
|
16
16
|
[features]
|
|
17
|
-
|
|
17
|
+
# Enable all features by default, otherwise different crates
|
|
18
|
+
# triggier bulding proto with different feature set that overwrites
|
|
19
|
+
# previous results and causes build errors
|
|
20
|
+
default = ["core", "platform", "client", "serde", "server"]
|
|
18
21
|
core = []
|
|
19
22
|
platform = []
|
|
20
23
|
# Re-export Dash Platform protobuf types as `dapi_grpc::platform::proto`
|
|
24
|
+
# Note: client needs tls and tls-roots to connect to testnet which uses TLS.
|
|
21
25
|
tenderdash-proto = []
|
|
22
|
-
client = [
|
|
26
|
+
client = [
|
|
27
|
+
"tonic/channel",
|
|
28
|
+
"tonic/transport",
|
|
29
|
+
"tonic/tls",
|
|
30
|
+
"tonic/tls-roots",
|
|
31
|
+
"platform",
|
|
32
|
+
]
|
|
33
|
+
server = ["tonic/channel", "tonic/transport", "platform"]
|
|
23
34
|
serde = ["dep:serde", "dep:serde_bytes"]
|
|
35
|
+
mocks = ["dep:serde_json"]
|
|
24
36
|
|
|
25
37
|
[dependencies]
|
|
26
|
-
prost = { version = "0.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
prost = { version = "0.12.3" }
|
|
39
|
+
futures-core = "0.3.30"
|
|
40
|
+
tonic = { version = "0.11", features = [
|
|
41
|
+
"codegen",
|
|
42
|
+
"prost",
|
|
30
43
|
], default-features = false }
|
|
31
|
-
serde = { version = "1.0.
|
|
44
|
+
serde = { version = "1.0.197", optional = true, features = ["derive"] }
|
|
32
45
|
serde_bytes = { version = "0.11.12", optional = true }
|
|
33
|
-
|
|
46
|
+
serde_json = { version = "1.0", optional = true }
|
|
47
|
+
tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "0.14.0-dev.12", default-features = false }
|
|
34
48
|
dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
|
|
35
49
|
platform-version = { path = "../rs-platform-version" }
|
|
36
50
|
|
|
@@ -49,4 +63,4 @@ name = "platform_example"
|
|
|
49
63
|
path = "clients/platform/v0/rust/platform_example.rs"
|
|
50
64
|
|
|
51
65
|
[package.metadata.cargo-machete]
|
|
52
|
-
ignored = ["platform-version", "serde_bytes"]
|
|
66
|
+
ignored = ["platform-version", "serde_bytes", "futures-core"]
|
package/build.rs
CHANGED
|
@@ -6,7 +6,23 @@ use std::{
|
|
|
6
6
|
use tonic_build::Builder;
|
|
7
7
|
|
|
8
8
|
fn main() {
|
|
9
|
-
|
|
9
|
+
let core = MappingConfig::new(
|
|
10
|
+
PathBuf::from("protos/core/v0/core.proto"),
|
|
11
|
+
PathBuf::from("src/core/proto"),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
configure_core(core)
|
|
15
|
+
.generate()
|
|
16
|
+
.expect("generate core proto");
|
|
17
|
+
|
|
18
|
+
let platform = MappingConfig::new(
|
|
19
|
+
PathBuf::from("protos/platform/v0/platform.proto"),
|
|
20
|
+
PathBuf::from("src/platform/proto"),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
configure_platform(platform)
|
|
24
|
+
.generate()
|
|
25
|
+
.expect("generate platform proto");
|
|
10
26
|
|
|
11
27
|
println!("cargo:rerun-if-changed=./protos");
|
|
12
28
|
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SERDE");
|
|
@@ -18,29 +34,20 @@ struct MappingConfig {
|
|
|
18
34
|
builder: Builder,
|
|
19
35
|
proto_includes: Vec<PathBuf>,
|
|
20
36
|
}
|
|
21
|
-
/// Generate Rust definitions from Protobuf definitions
|
|
22
|
-
pub fn generate() -> Result<(), std::io::Error> {
|
|
23
|
-
let core = MappingConfig::new(
|
|
24
|
-
PathBuf::from("protos/core/v0/core.proto"),
|
|
25
|
-
PathBuf::from("src/core/proto"),
|
|
26
|
-
);
|
|
27
|
-
core.generate().unwrap();
|
|
28
|
-
|
|
29
|
-
let mut platform = MappingConfig::new(
|
|
30
|
-
PathBuf::from("protos/platform/v0/platform.proto"),
|
|
31
|
-
PathBuf::from("src/platform/proto"),
|
|
32
|
-
);
|
|
33
37
|
|
|
38
|
+
fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
|
|
34
39
|
// Derive features for versioned messages
|
|
35
40
|
//
|
|
36
41
|
// "GetConsensusParamsRequest" is excluded as this message does not support proofs
|
|
37
|
-
const VERSIONED_REQUESTS: [&str;
|
|
42
|
+
const VERSIONED_REQUESTS: [&str; 18] = [
|
|
38
43
|
"GetDataContractHistoryRequest",
|
|
39
44
|
"GetDataContractRequest",
|
|
40
45
|
"GetDataContractsRequest",
|
|
41
46
|
"GetDocumentsRequest",
|
|
42
47
|
"GetIdentitiesByPublicKeyHashesRequest",
|
|
43
48
|
"GetIdentitiesRequest",
|
|
49
|
+
"GetIdentityNonceRequest",
|
|
50
|
+
"GetIdentityContractNonceRequest",
|
|
44
51
|
"GetIdentityBalanceAndRevisionRequest",
|
|
45
52
|
"GetIdentityBalanceRequest",
|
|
46
53
|
"GetIdentityByPublicKeyHashRequest",
|
|
@@ -50,10 +57,11 @@ pub fn generate() -> Result<(), std::io::Error> {
|
|
|
50
57
|
"WaitForStateTransitionResultRequest",
|
|
51
58
|
"GetProtocolVersionUpgradeStateRequest",
|
|
52
59
|
"GetProtocolVersionUpgradeVoteStatusRequest",
|
|
60
|
+
"GetPathElementsRequest",
|
|
53
61
|
];
|
|
54
62
|
|
|
55
63
|
// "GetConsensusParamsResponse" is excluded as this message does not support proofs
|
|
56
|
-
const VERSIONED_RESPONSES: [&str;
|
|
64
|
+
const VERSIONED_RESPONSES: [&str; 19] = [
|
|
57
65
|
"GetDataContractHistoryResponse",
|
|
58
66
|
"GetDataContractResponse",
|
|
59
67
|
"GetDataContractsResponse",
|
|
@@ -62,6 +70,8 @@ pub fn generate() -> Result<(), std::io::Error> {
|
|
|
62
70
|
"GetIdentitiesResponse",
|
|
63
71
|
"GetIdentityBalanceAndRevisionResponse",
|
|
64
72
|
"GetIdentityBalanceResponse",
|
|
73
|
+
"GetIdentityNonceResponse",
|
|
74
|
+
"GetIdentityContractNonceResponse",
|
|
65
75
|
"GetIdentityByPublicKeyHashResponse",
|
|
66
76
|
"GetIdentityKeysResponse",
|
|
67
77
|
"GetIdentityResponse",
|
|
@@ -70,6 +80,7 @@ pub fn generate() -> Result<(), std::io::Error> {
|
|
|
70
80
|
"GetEpochsInfoResponse",
|
|
71
81
|
"GetProtocolVersionUpgradeStateResponse",
|
|
72
82
|
"GetProtocolVersionUpgradeVoteStatusResponse",
|
|
83
|
+
"GetPathElementsResponse",
|
|
73
84
|
];
|
|
74
85
|
|
|
75
86
|
// Derive VersionedGrpcMessage on requests
|
|
@@ -92,6 +103,9 @@ pub fn generate() -> Result<(), std::io::Error> {
|
|
|
92
103
|
.message_attribute(msg, r#"#[grpc_versions(0)]"#);
|
|
93
104
|
}
|
|
94
105
|
|
|
106
|
+
// All messages can be mocked.
|
|
107
|
+
platform = platform.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
|
|
108
|
+
|
|
95
109
|
#[cfg(feature = "serde")]
|
|
96
110
|
let platform = platform
|
|
97
111
|
.type_attribute(
|
|
@@ -132,9 +146,21 @@ pub fn generate() -> Result<(), std::io::Error> {
|
|
|
132
146
|
.field_attribute("Proof.signature", r#"#[serde(with = "serde_bytes")]"#)
|
|
133
147
|
.field_attribute("Proof.block_id_hash", r#"#[serde(with = "serde_bytes")]"#);
|
|
134
148
|
|
|
135
|
-
platform
|
|
149
|
+
platform
|
|
150
|
+
}
|
|
136
151
|
|
|
137
|
-
|
|
152
|
+
fn configure_core(mut core: MappingConfig) -> MappingConfig {
|
|
153
|
+
// All messages can be mocked.
|
|
154
|
+
core = core.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
|
|
155
|
+
|
|
156
|
+
// Serde support
|
|
157
|
+
#[cfg(feature = "serde")]
|
|
158
|
+
let core = core.type_attribute(
|
|
159
|
+
".",
|
|
160
|
+
r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
core
|
|
138
164
|
}
|
|
139
165
|
|
|
140
166
|
impl MappingConfig {
|
|
@@ -142,16 +168,16 @@ impl MappingConfig {
|
|
|
142
168
|
let protobuf_file = abs_path(&protobuf_file);
|
|
143
169
|
let out_dir = abs_path(&out_dir);
|
|
144
170
|
|
|
171
|
+
let build_server = cfg!(feature = "server");
|
|
172
|
+
let build_client = cfg!(feature = "client");
|
|
173
|
+
|
|
145
174
|
let builder = tonic_build::configure()
|
|
146
|
-
.build_server(
|
|
175
|
+
.build_server(build_server)
|
|
176
|
+
.build_client(build_client)
|
|
177
|
+
.build_transport(build_server || build_client)
|
|
147
178
|
.out_dir(out_dir.clone())
|
|
148
179
|
.protoc_arg("--experimental_allow_proto3_optional");
|
|
149
180
|
|
|
150
|
-
#[cfg(feature = "client")]
|
|
151
|
-
let builder = builder.build_client(true).build_transport(true);
|
|
152
|
-
#[cfg(not(feature = "client"))]
|
|
153
|
-
let builder = builder.build_client(false).build_transport(false);
|
|
154
|
-
|
|
155
181
|
Self {
|
|
156
182
|
protobuf_file,
|
|
157
183
|
out_dir,
|
|
@@ -48,6 +48,14 @@ const {
|
|
|
48
48
|
PBJSGetProtocolVersionUpgradeVoteStatusResponse,
|
|
49
49
|
GetProtocolVersionUpgradeStateRequest: PBJSGetProtocolVersionUpgradeStateRequest,
|
|
50
50
|
GetProtocolVersionUpgradeStateResponse: PBJSGetProtocolVersionUpgradeStateResponse,
|
|
51
|
+
GetProofsRequest: PBJSGetProofsRequest,
|
|
52
|
+
GetProofsResponse: PBJSGetProofsResponse,
|
|
53
|
+
GetIdentityContractNonceRequest: PBJSGetIdentityContractNonceRequest,
|
|
54
|
+
GetIdentityContractNonceResponse: PBJSGetIdentityContractNonceResponse,
|
|
55
|
+
GetIdentityNonceRequest: PBJSGetIdentityNonceRequest,
|
|
56
|
+
GetIdentityNonceResponse: PBJSGetIdentityNonceResponse,
|
|
57
|
+
GetIdentityKeysRequest: PBJSGetIdentityKeysRequest,
|
|
58
|
+
GetIdentityKeysResponse: PBJSGetIdentityKeysResponse,
|
|
51
59
|
},
|
|
52
60
|
},
|
|
53
61
|
},
|
|
@@ -67,6 +75,10 @@ const {
|
|
|
67
75
|
GetEpochsInfoResponse: ProtocGetEpochsInfoResponse,
|
|
68
76
|
GetProtocolVersionUpgradeVoteStatusResponse: ProtocGetProtocolVersionUpgradeVoteStatusResponse,
|
|
69
77
|
GetProtocolVersionUpgradeStateResponse: ProtocGetProtocolVersionUpgradeStateResponse,
|
|
78
|
+
GetProofsResponse: ProtocGetProofsResponse,
|
|
79
|
+
GetIdentityContractNonceResponse: ProtocGetIdentityContractNonceResponse,
|
|
80
|
+
GetIdentityNonceResponse: ProtocGetIdentityNonceResponse,
|
|
81
|
+
GetIdentityKeysResponse: ProtocGetIdentityKeysResponse,
|
|
70
82
|
} = require('./platform_protoc');
|
|
71
83
|
|
|
72
84
|
const getPlatformDefinition = require('../../../../lib/getPlatformDefinition');
|
|
@@ -137,6 +149,22 @@ class PlatformPromiseClient {
|
|
|
137
149
|
this.client.getProtocolVersionUpgradeState.bind(this.client),
|
|
138
150
|
);
|
|
139
151
|
|
|
152
|
+
this.client.getProofs = promisify(
|
|
153
|
+
this.client.getProofs.bind(this.client),
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
this.client.getIdentityContractNonce = promisify(
|
|
157
|
+
this.client.getIdentityContractNonce.bind(this.client),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
this.client.getIdentityNonce = promisify(
|
|
161
|
+
this.client.getIdentityNonce.bind(this.client),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
this.client.getIdentityKeys = promisify(
|
|
165
|
+
this.client.getIdentityKeys.bind(this.client),
|
|
166
|
+
);
|
|
167
|
+
|
|
140
168
|
this.protocolVersion = undefined;
|
|
141
169
|
}
|
|
142
170
|
|
|
@@ -496,6 +524,131 @@ class PlatformPromiseClient {
|
|
|
496
524
|
);
|
|
497
525
|
}
|
|
498
526
|
|
|
527
|
+
/**
|
|
528
|
+
*
|
|
529
|
+
* @param {!GetProofsRequest} request
|
|
530
|
+
* @param {?Object<string, string>} metadata
|
|
531
|
+
* @param {CallOptions} [options={}]
|
|
532
|
+
* @returns {Promise<!GetProofsResponse>}
|
|
533
|
+
*/
|
|
534
|
+
getProofs(request, metadata = {}, options = {}) {
|
|
535
|
+
if (!isObject(metadata)) {
|
|
536
|
+
throw new Error('metadata must be an object');
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
return this.client.getProofs(
|
|
540
|
+
request,
|
|
541
|
+
convertObjectToMetadata(metadata),
|
|
542
|
+
{
|
|
543
|
+
interceptors: [
|
|
544
|
+
jsonToProtobufInterceptorFactory(
|
|
545
|
+
jsonToProtobufFactory(
|
|
546
|
+
ProtocGetProofsResponse,
|
|
547
|
+
PBJSGetProofsResponse,
|
|
548
|
+
),
|
|
549
|
+
protobufToJsonFactory(
|
|
550
|
+
PBJSGetProofsRequest,
|
|
551
|
+
),
|
|
552
|
+
),
|
|
553
|
+
],
|
|
554
|
+
...options,
|
|
555
|
+
},
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* @param {!PBJSGetIdentityContractNonceRequest} getIdentityContractNonceRequest
|
|
561
|
+
* @param {?Object<string, string>} metadata
|
|
562
|
+
* @param {CallOptions} [options={}]
|
|
563
|
+
* @return {Promise<!GetIdentityContractNonceResponse>}
|
|
564
|
+
*/
|
|
565
|
+
getIdentityContractNonce(
|
|
566
|
+
getIdentityContractNonceRequest,
|
|
567
|
+
metadata = {},
|
|
568
|
+
options = {},
|
|
569
|
+
) {
|
|
570
|
+
if (!isObject(metadata)) {
|
|
571
|
+
throw new Error('metadata must be an object');
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return this.client.getIdentityContractNonce(
|
|
575
|
+
getIdentityContractNonceRequest,
|
|
576
|
+
convertObjectToMetadata(metadata),
|
|
577
|
+
{
|
|
578
|
+
interceptors: [
|
|
579
|
+
jsonToProtobufInterceptorFactory(
|
|
580
|
+
jsonToProtobufFactory(
|
|
581
|
+
ProtocGetIdentityContractNonceResponse,
|
|
582
|
+
PBJSGetIdentityContractNonceResponse,
|
|
583
|
+
),
|
|
584
|
+
protobufToJsonFactory(
|
|
585
|
+
PBJSGetIdentityContractNonceRequest,
|
|
586
|
+
),
|
|
587
|
+
),
|
|
588
|
+
],
|
|
589
|
+
...options,
|
|
590
|
+
},
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
getIdentityNonce(
|
|
595
|
+
getIdentityNonceRequest,
|
|
596
|
+
metadata = {},
|
|
597
|
+
options = {},
|
|
598
|
+
) {
|
|
599
|
+
if (!isObject(metadata)) {
|
|
600
|
+
throw new Error('metadata must be an object');
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return this.client.getIdentityNonce(
|
|
604
|
+
getIdentityNonceRequest,
|
|
605
|
+
convertObjectToMetadata(metadata),
|
|
606
|
+
{
|
|
607
|
+
interceptors: [
|
|
608
|
+
jsonToProtobufInterceptorFactory(
|
|
609
|
+
jsonToProtobufFactory(
|
|
610
|
+
ProtocGetIdentityNonceResponse,
|
|
611
|
+
PBJSGetIdentityNonceResponse,
|
|
612
|
+
),
|
|
613
|
+
protobufToJsonFactory(
|
|
614
|
+
PBJSGetIdentityNonceRequest,
|
|
615
|
+
),
|
|
616
|
+
),
|
|
617
|
+
],
|
|
618
|
+
...options,
|
|
619
|
+
},
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
getIdentityKeys(
|
|
624
|
+
getIdentityKeysRequest,
|
|
625
|
+
metadata = {},
|
|
626
|
+
options = {},
|
|
627
|
+
) {
|
|
628
|
+
if (!isObject(metadata)) {
|
|
629
|
+
throw new Error('metadata must be an object');
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
return this.client.getIdentityKeys(
|
|
633
|
+
getIdentityKeysRequest,
|
|
634
|
+
convertObjectToMetadata(metadata),
|
|
635
|
+
{
|
|
636
|
+
interceptors: [
|
|
637
|
+
jsonToProtobufInterceptorFactory(
|
|
638
|
+
jsonToProtobufFactory(
|
|
639
|
+
ProtocGetIdentityKeysResponse,
|
|
640
|
+
PBJSGetIdentityKeysResponse,
|
|
641
|
+
),
|
|
642
|
+
protobufToJsonFactory(
|
|
643
|
+
PBJSGetIdentityKeysRequest,
|
|
644
|
+
),
|
|
645
|
+
),
|
|
646
|
+
],
|
|
647
|
+
...options,
|
|
648
|
+
},
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
|
|
499
652
|
/**
|
|
500
653
|
* @param {string} protocolVersion
|
|
501
654
|
*/
|