Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rs-sdk: rust software development kit for Dash Platform #1208

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
28ba89c
feat!(drive): add block_id_hash to proof
lklimek Jun 27, 2023
d3ffb01
chore(dapi-grpc): format .proto code
lklimek Jun 27, 2023
008d551
feat(proto): include quorum_type in Proof and chain_id in ResponseMet…
lklimek Jun 27, 2023
7e1ffdd
feat: Drive Light Client with proof verification
lklimek Jun 28, 2023
bf20d9e
chore: update to tenderdash 0.13.0-dev.1
lklimek Jun 28, 2023
6db7fd5
chore: code cleanup and docs
lklimek Jun 28, 2023
70f11ec
fix(drive): invalid error message
lklimek Jun 29, 2023
2329759
test: tests working
lklimek Jun 29, 2023
7c2bdf6
test: uniffi proof test
lklimek Jun 29, 2023
8121b8c
chore: no documents and identities by pkh
jawid-h Jul 4, 2023
9dc981c
chore: identities by pk_hash
jawid-h Jul 5, 2023
df024b1
chore: get documents
jawid-h Jul 5, 2023
f064493
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Jul 17, 2023
85e3fb2
chore: fix platform.proto after merge
lklimek Jul 17, 2023
a42b5e9
feat(dapi-grpc): add serde support with serde feature
lklimek Jul 19, 2023
01b8265
test: drive-light-client test vectors support
lklimek Jul 19, 2023
009737f
fix: dapi bindings generation broken
lklimek Jul 19, 2023
76e18e2
test(light-client): test get identities by hashes not found
lklimek Jul 19, 2023
5075014
feat(dapi-grpc): enable serde feature by default
lklimek Jul 19, 2023
6ecedb7
test: move uniffi tests from src/ to tests/
lklimek Jul 21, 2023
df7f913
chore(dapi-grpc): simplify deserialization
lklimek Jul 21, 2023
9cb7a0f
feat: json encoding for bindings
lklimek Jul 21, 2023
fa4c475
chore: rebuild light client bindings
lklimek Jul 21, 2023
e4410b5
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Jul 21, 2023
734ee54
chore: cargo update
lklimek Jul 21, 2023
9d88a30
chore: fix deps after merge
lklimek Jul 21, 2023
24a6340
chore: move around bindings code
lklimek Jul 21, 2023
cdda96e
chore: typo
lklimek Jul 21, 2023
82ef535
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Jul 24, 2023
269145c
chore: add uniffi feature to disable uniffi code (remove in future)
lklimek Jul 24, 2023
6e5dff0
chore: core chain lock height needed to get pubkey
lklimek Jul 24, 2023
9b1a572
fix: uniffi feature not checking all places
lklimek Jul 24, 2023
aa57893
test: from_proof tests using macro
lklimek Jul 24, 2023
3039f7e
test: add missing from_proof tests
lklimek Jul 24, 2023
5c23ab5
test: update identities by hashes not found test vector
lklimek Jul 24, 2023
11d772d
test: identities not found
lklimek Jul 24, 2023
9af6cd2
chore: disable uniffi tests
lklimek Jul 25, 2023
fa6c60f
chore: remove uniffi-generated bindings
lklimek Jul 25, 2023
3c0eaf5
refactor: returns root-hash if an identity is not found (#1251)
shotonoff Jul 25, 2023
0ff69d2
chore: tests
lklimek Jul 25, 2023
8a46b45
feat: FromProof GetIdentityKeys
lklimek Jul 26, 2023
6a47d00
test: from_proof
lklimek Jul 27, 2023
e6b6585
fix: from_proof IdentityBalance
lklimek Jul 27, 2023
c41dd1b
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Jul 27, 2023
ea32d8e
refactor: rename rs-drive-light-client to rs-drive-proof-verifier
lklimek Jul 27, 2023
5c6d7a0
test: identity_ok
lklimek Jul 28, 2023
03319de
test: identity_keys_ok
lklimek Jul 28, 2023
072102d
test: proofs
lklimek Jul 28, 2023
fb59414
chore: improve todos in fromproof
lklimek Jul 28, 2023
ec4cdc0
feat(dapi): add missing gRPC endpoints (#1243)
jawid-h Aug 8, 2023
eadd882
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Aug 16, 2023
dd882f3
Merge remote-tracking branch 'origin/v0.25-dev-nightly' into rs-sdk-v…
lklimek Aug 22, 2023
76e8365
feat: verify contracts (#1325)
QuantumExplorer Aug 22, 2023
b09e352
Merge remote-tracking branch 'origin/feat/rs-drive-light-client' into…
lklimek Aug 23, 2023
4f7158c
chore: merge from_proof with versioning
lklimek Aug 23, 2023
10080e8
chore: merge versioning into rs-sdk feature branch (#1330)
lklimek Aug 23, 2023
3ebdd04
Merge remote-tracking branch 'origin/v0.25-dev-nightly' into feat/rs-…
lklimek Aug 25, 2023
f1271d5
Merge remote-tracking branch 'origin/v0.25-dev-nightly' into feat/rs-…
lklimek Aug 25, 2023
326a088
Merge remote-tracking branch 'origin/v0.25-dev-nightly' into feat/rs-…
lklimek Aug 25, 2023
16c0da9
Merge remote-tracking branch 'origin/v0.25-dev-nightly' into feat/rs-…
lklimek Aug 25, 2023
9f94174
Merge remote-tracking branch 'origin/v0.25-dev-nightly' into feat/rs-…
lklimek Aug 28, 2023
6653516
fix : a few fixes and new methods for verifying (#1326)
QuantumExplorer Aug 28, 2023
957e0a5
feat(dapi): rust client (#1238)
fominok Aug 29, 2023
1d72768
Merge remote-tracking branch 'origin/v0.25-dev-nightly' into feat/rs-…
lklimek Aug 29, 2023
89b887e
feat(drive): cbor serialization of DriveQuery (#1322)
lklimek Aug 31, 2023
1f55fd3
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Sep 1, 2023
b0b2cbf
chore: fix build issues after merge
lklimek Sep 1, 2023
4dd9a98
a few fixes
QuantumExplorer Sep 1, 2023
8d58ad9
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Sep 4, 2023
7b24349
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Sep 4, 2023
a0256e3
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Sep 5, 2023
1d8a16f
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Sep 28, 2023
039e3cf
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Sep 28, 2023
4aceca3
chore: fixes after merge
lklimek Sep 28, 2023
7f6927e
Merge remote-tracking branch 'origin/v0.25-dev' into feat/rs-drive-li…
lklimek Oct 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
348 changes: 344 additions & 4 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ members = [
"packages/feature-flags-contract",
"packages/dpns-contract",
"packages/data-contracts",
"packages/rs-drive-proof-verifier",
"packages/wasm-dpp",
"packages/rs-dapi-client",
"packages/rs-sdk",
]
8 changes: 6 additions & 2 deletions packages/dapi-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ tonic = { version = "0.9.2", features = [
"codegen",
"prost",
], default-features = false }

serde = { version = "1.0.171", optional = true, features = ["derive"] }
base64 = { version = "0.21.0", optional = true }
hex = { version = "0.4.3", optional = true }
tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci" }
[build-dependencies]
tonic-build = { version = "0.9.2" }

[features]
default = ["core", "platform", "client"]
default = ["core", "platform", "client", "serde"]
core = ["core_v0"]
platform = ["platform_v0"]
client = ["tonic/channel", "tonic/tls", "tonic/tls-roots", "platform"]
serde = ["dep:serde", "dep:base64", "dep:hex"]

core_v0 = []
platform_v0 = []
Expand Down
147 changes: 113 additions & 34 deletions packages/dapi-grpc/build.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,142 @@
use std::{
collections::HashMap,
fs::{create_dir_all, remove_dir_all},
path::PathBuf,
};

use tonic_build::Builder;

fn main() {
generate().expect("failed to compile protobuf definitions");

println!("cargo:rerun-if-changed=./protos");
println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SERDE");
}

struct MappingConfig {
protobuf_file: PathBuf,
out_dir: PathBuf,
builder: Builder,
proto_includes: Vec<PathBuf>,
}
/// Generate Rust definitions from Protobuf definitions
pub fn generate() -> Result<(), std::io::Error> {
// Mapping between protobuf files => output directory
let mut input = HashMap::<PathBuf, PathBuf>::new();
input.insert(
let core = MappingConfig::new(
PathBuf::from("protos/core/v0/core.proto"),
PathBuf::from("src/core/proto"),
);
input.insert(
core.generate().unwrap();

let platform = MappingConfig::new(
PathBuf::from("protos/platform/v0/platform.proto"),
PathBuf::from("src/platform/proto"),
);

let proto_includes = vec![abs_path(&PathBuf::from("protos"))];
#[cfg(feature = "serde")]
let platform = platform
.type_attribute(
".",
r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
)
.type_attribute(".", r#"#[serde(rename_all = "snake_case")]"#)
.field_attribute(
"id",
r#"#[serde(with = "crate::deserialization::base64string")]"#,
)
.field_attribute(
"identity_id",
r#"#[serde(with = "crate::deserialization::base64string")]"#,
)
.field_attribute(
"ids",
r#"#[serde(with = "crate::deserialization::vec_base64string")]"#,
)
.field_attribute(
"ResponseMetadata.height",
r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
)
.field_attribute(
"ResponseMetadata.time_ms",
r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
)
.field_attribute(
"start_at_ms",
r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
)
.field_attribute(
"public_key_hash",
r#"#[serde(with = "crate::deserialization::base64string")]"#,
)
.field_attribute(
"public_key_hashes",
r#"#[serde(with = "crate::deserialization::vec_base64string")]"#,
)
// Proof fields
.field_attribute(
"Proof.grovedb_proof",
r#"#[serde(with = "crate::deserialization::base64string")]"#,
)
.field_attribute(
"Proof.quorum_hash",
r#"#[serde(with = "crate::deserialization::base64string")]"#,
)
.field_attribute(
"Proof.signature",
r#"#[serde(with = "crate::deserialization::base64string")]"#,
)
.field_attribute(
"Proof.block_id_hash",
r#"#[serde(with = "crate::deserialization::base64string")]"#,
);

for (proto, dest) in input {
let proto = abs_path(&proto);
let dest = abs_path(&dest);
// Remove old compiled files; ignore errors
if dest.exists() {
remove_dir_all(&dest)?;
platform.generate().unwrap();

Ok(())
}

impl MappingConfig {
fn new(protobuf_file: PathBuf, out_dir: PathBuf) -> Self {
let protobuf_file = abs_path(&protobuf_file);
let out_dir = abs_path(&out_dir);

let builder = tonic_build::configure()
.build_server(false)
.out_dir(out_dir.clone())
.protoc_arg("--experimental_allow_proto3_optional");

#[cfg(feature = "client")]
let builder = builder.build_client(true).build_transport(true);
#[cfg(not(feature = "client"))]
let builder = pb.build_client(false).build_transport(false);

Self {
protobuf_file,
out_dir,
builder,
proto_includes: vec![abs_path(&PathBuf::from("protos"))],
}
create_dir_all(&dest)?;
}

generate1(&[proto], &proto_includes, &dest)?;
fn type_attribute(mut self, path: &str, attribute: &str) -> Self {
self.builder = self.builder.type_attribute(path, attribute);
self
}

Ok(())
}
fn field_attribute(mut self, path: &str, attribute: &str) -> Self {
self.builder = self.builder.field_attribute(path, attribute);
self
}

/// Run single generation process.
///
/// All paths must be absolute
fn generate1(
files: &[PathBuf],
proto_includes: &[PathBuf],
out_dir: &PathBuf,
) -> Result<(), std::io::Error> {
let pb = tonic_build::configure()
.build_server(false)
.out_dir(out_dir)
.protoc_arg("--experimental_allow_proto3_optional");
#[cfg(feature = "client")]
let pb = pb.build_client(true).build_transport(true);
#[cfg(not(feature = "client"))]
let pb = pb.build_client(false).build_transport(false);

pb.compile(files, proto_includes)
/// Run single generation process.
fn generate(self) -> Result<(), std::io::Error> {
// Remove old compiled files; ignore errors
if self.out_dir.exists() {
remove_dir_all(&self.out_dir)?;
}
create_dir_all(&self.out_dir)?;

self.builder
.compile(&[self.protobuf_file], &self.proto_includes)
}
}

fn abs_path(path: &PathBuf) -> PathBuf {
Expand Down
1 change: 1 addition & 0 deletions packages/dapi-grpc/protos/platform/v0/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ message GetProofsRequest {

message ContractRequest {
bytes contract_id = 1;
bool is_historical = 2;
}

repeated IdentityRequest identities = 1;
Expand Down
34 changes: 34 additions & 0 deletions packages/dapi-grpc/src/deserialization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pub use tenderdash_proto::serializers::bytes::{
base64string, hexstring, option_base64string, vec_base64string,
};

/// Serialize using [ToString] and deserialize using [FromStr] trait implementations.
pub mod from_to_string {
use std::{fmt::Display, str::FromStr};

use serde::{Deserialize, Serializer};

pub fn deserialize<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: serde::de::Deserializer<'de>,
T: FromStr,
T::Err: Display,
{
use serde::de::Error;

String::deserialize(deserializer).and_then(|string| {
string
.parse::<T>()
.map_err(|err| Error::custom(err.to_string()))
})
}

/// Serialize from T into string
pub fn serialize<S, T>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: ToString,
{
serializer.serialize_str(&value.to_string())
}
}
4 changes: 4 additions & 0 deletions packages/dapi-grpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ pub mod platform {
include!("platform/proto/org.dash.platform.dapi.v0.rs");
}
}

#[cfg(feature = "serde")]
// Serde deserialization logic
pub mod deserialization;
Loading