Skip to content

Commit

Permalink
* Introduce RPC and new protocol crate
Browse files Browse the repository at this point in the history
* Fork ledger traits

* Subxt based client - connectivity
* Development runtime - working, global logger use needs to consider rust::tracing
* Signature and address types, substrate crypto used directly for account signatures
* Seed mechanism changed in ChronicleSigning to allow us to supply a specific seed
* Remove transaction costs and balance checks
  • Loading branch information
ryan-s-roberts committed Jan 2, 2024
1 parent f0c4df1 commit 5649c2b
Show file tree
Hide file tree
Showing 91 changed files with 9,495 additions and 5,494 deletions.
5,376 changes: 3,031 additions & 2,345 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 16 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ members = [
"crates/chronicle-domain",
"crates/chronicle-domain-lint",
"crates/chronicle-domain-test",
"crates/chronicle-protocol",
"crates/chronicle-synth",
"crates/chronicle-signing",
"crates/chronicle-telemetry",
"crates/gq-subscribe",
"crates/id-provider",
"crates/opa-tp",
"crates/opa-tp-protocol",
"crates/opactl",
"crates/sawtooth-tp",
"crates/pallet-chronicle",
"crates/pallet-opa",
"node/runtime-chronicle",
"node/node-chronicle",
"crates/embedded-substrate",
"crates/runtime-api-chronicle",
"crates/protocol-substrate-chronicle",
"crates/protocol-substrate-opa",
]

[workspace.dependencies]
Expand All @@ -29,16 +29,12 @@ anyhow = "1.0.6"
assert_fs = "1.0"
async-graphql = "5.0.9"
async-graphql-poem = "5.0.9"
async-stl-client = { git = "https://github.com/btpworks/async-stl-sdk" }
async-stream = "0.3.3"
async-trait = "0.1.61"
backoff = { version = "0.4.0", features = ["futures", "tokio"] }
base64 = "0.21"
bytes = "1.3.0"
cached = "0.42"
frame-support = "24.0.0"
frame-system = "24.0.0"
frame-benchmarking = "24.0.0"
cfg-if = "1.0.0"
chronicle-signing = { path = "crates/chronicle-signing" }
chrono = "0.4.26"
Expand All @@ -53,14 +49,13 @@ criterion = { version = "0.5.1", features = ["async_futures", "async_tokio"] }
crossbeam = "0.8.1"
custom_error = "1.9.2"
derivative = "2.2.0"
diesel = { version = "2.0.0-rc.0", features = [
"postgres",
"uuid",
"chrono",
"r2d2",
] }
diesel_migrations = { version = "2.0.0-rc.0", features = ["postgres"] }
diesel = { version = "2.1", features = ["postgres", "uuid", "chrono", "r2d2"] }
diesel-async = { version = "0.4" }
diesel_migrations = { version = "2.1", features = ["postgres"] }
dotenvy = "0.15"
frame-benchmarking = "24.0.0"
frame-support = "24.0.0"
frame-system = "24.0.0"
futures = "0.3.21"
genco = "0.16.1"
glob = "0.3.0"
Expand All @@ -80,18 +75,22 @@ k256 = { version = "0.11.3", features = [
"ecdsa",
"pkcs8",
"sha256",
"keccak256",
"std",
"pem",
"serde",
] }
lazy_static = "1.4.0"
locspan = "0.7"
lru = "0.11"
macro-attr-2018 = "3.0.0"
maplit = "1.0.2"
metrics = "0.21.0"
metrics-exporter-prometheus = "0.12.1"
mime = "0.3"
mobc = "0.8"
mockito = "1.1"
newtype-derive-2018 = "0.2.1"
oauth2 = "4.4"
opa = { git = "https://github.com/tamasfe/opa-rs", rev = "3cf7fea" }
openssl = { version = "0.10" }
Expand Down Expand Up @@ -127,18 +126,16 @@ rust-embed = { version = "6.6.0", features = [
"debug-embed",
"include-exclude",
] }
sawtooth-sdk = { git = "https://github.com/hyperledger/sawtooth-sdk-rust", rev = "5a300de" }
secret-vault = { version = "1.8", features = [] }
secret-vault-value = "0.3"
serde = "1.0.152"
serde_derive = "1.0.152"
serde_json = "1.0.93"
serde_yaml = "0.9.14"
shellexpand = "3.0.0"
macro-attr-2018 = "3.0.0"
newtype-derive-2018 = "0.2.1"
temp-dir = "0.1.11"
tempfile = "3.4.0"
testcontainers = "0.14"
thiserror = "1.0"
tmq = "0.3"
tokio = { version = "1.27", features = [
Expand Down Expand Up @@ -166,4 +163,3 @@ uuid = "1.2.2"
valico = "3.6.0"
vaultrs = "*"
zmq = { version = "0.9", features = ["vendored"] }
testcontainers = "0.14"
24 changes: 14 additions & 10 deletions crates/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.7.5"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true }
async-graphql = { workspace = true, features = [
"opentelemetry",
"chrono",
Expand All @@ -14,20 +15,24 @@ async-graphql = { workspace = true, features = [
"uuid",
] }
async-graphql-poem = { workspace = true }
async-stl-client = { workspace = true }
async-stream = { workspace = true }
async-trait = { workspace = true }
base64 = { workspace = true }
cached = { workspace = true }
cfg-if = { workspace = true }
chronicle-protocol = { path = "../chronicle-protocol" }
chronicle-signing = { workspace = true }
chronicle-telemetry = { path = "../chronicle-telemetry" }
chrono = { workspace = true }
common = { path = "../common" }
common = { path = "../common", features = [
"json-ld",
"diesel-bindings",
"graphql-bindings",
"std",
] }
custom_error = { workspace = true }
derivative = { workspace = true }
diesel = { workspace = true }
diesel-async = { workspace = true }
diesel_migrations = { workspace = true }
futures = { workspace = true }
glob = { workspace = true }
Expand All @@ -45,12 +50,13 @@ poem = { workspace = true }
portpicker = { workspace = true }
prost = { workspace = true }
protobuf = { workspace = true }
protocol-substrate-chronicle = { path = "../protocol-substrate-chronicle" }
protocol-substrate-opa = { path = "../protocol-substrate-opa" }
r2d2 = { workspace = true }
rand = { workspace = true }
rand_core = { workspace = true }
reqwest = { workspace = true }
sawtooth-sdk = { workspace = true }
sawtooth_tp = { path = "../sawtooth-tp" }
rust-embed = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
Expand All @@ -64,11 +70,9 @@ user-error = { workspace = true }
uuid = { workspace = true }

[dev-dependencies]
assert_fs = { workspace = true }
chronicle-protocol = { path = "../chronicle-protocol" }
insta = { workspace = true, features = ["json", "yaml"] }
opa-tp-protocol = { path = "../opa-tp-protocol" }
tempfile = { workspace = true }
assert_fs = { workspace = true }
insta = { workspace = true, features = ["json", "yaml"] }
tempfile = { workspace = true }

[build-dependencies]

Expand Down
33 changes: 13 additions & 20 deletions crates/api/src/chronicle_graphql/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::opa::{ExecutorContext, OpaExecutorError};
use async_graphql::{
extensions::OpenTelemetry,
http::{playground_source, GraphQLPlaygroundConfig, ALL_WEBSOCKET_PROTOCOLS},
Expand All @@ -12,9 +13,8 @@ use chrono::NaiveDateTime;
use common::{
identity::{AuthId, IdentityError, JwtClaims, OpaData, SignedIdentity},
ledger::{SubmissionError, SubmissionStage},
opa::{ExecutorContext, OpaExecutorError},
prov::{
to_json_ld::ToJson, ChronicleIri, ChronicleTransactionId, ExternalId, ExternalIdPart,
json_ld::ToJson, ChronicleIri, ChronicleTransactionId, ExternalId, ExternalIdPart,
ProvModel,
},
};
Expand Down Expand Up @@ -292,10 +292,7 @@ impl From<SignedIdentity> for CommitIdentity {
CommitIdentity {
identity: identity.identity,
signature: identity.signature.map(|x| hex::encode(&*x)).unwrap_or_default(),
verifying_key: identity
.verifying_key
.map(|x| hex::encode(x.to_bytes()))
.unwrap_or_default(),
verifying_key: identity.verifying_key.map(|x| hex::encode(x)).unwrap_or_default(),
}
}
}
Expand Down Expand Up @@ -810,8 +807,8 @@ impl IriEndpoint {
.body("failed to compact JSON response"))
},
},
Err(StoreError::Db(diesel::result::Error::NotFound))
| Err(StoreError::RecordNotFound) => {
Err(StoreError::Db(diesel::result::Error::NotFound)) |
Err(StoreError::RecordNotFound) => {
tracing::debug!("not found: {prov_type} {} in {ns}", id.external_id_part());
Ok(poem::Response::builder()
.status(StatusCode::NOT_FOUND)
Expand Down Expand Up @@ -875,9 +872,8 @@ impl IriEndpoint {

match ChronicleIri::from_str(&ns_iri.iri) {
Ok(iri) => Ok(Ok((ns_iri.ns.into(), iri))),
Err(error) => {
Ok(Err(Response::builder().status(StatusCode::NOT_FOUND).body(error.to_string())))
},
Err(error) =>
Ok(Err(Response::builder().status(StatusCode::NOT_FOUND).body(error.to_string()))),
}
}

Expand All @@ -888,24 +884,21 @@ impl IriEndpoint {
claims: Option<&JwtClaims>,
) -> poem::Result<poem::Response> {
match self.parse_ns_iri_from_uri_path(req).await? {
Ok((ns, ChronicleIri::Activity(id))) => {
Ok((ns, ChronicleIri::Activity(id))) =>
self.response_for_query(claims, "activity", &id, &ns, |mut conn, id, ns| {
self.store.prov_model_for_activity_id(&mut conn, id, ns)
})
.await
},
Ok((ns, ChronicleIri::Agent(id))) => {
.await,
Ok((ns, ChronicleIri::Agent(id))) =>
self.response_for_query(claims, "agent", &id, &ns, |mut conn, id, ns| {
self.store.prov_model_for_agent_id(&mut conn, id, ns)
})
.await
},
Ok((ns, ChronicleIri::Entity(id))) => {
.await,
Ok((ns, ChronicleIri::Entity(id))) =>
self.response_for_query(claims, "entity", &id, &ns, |mut conn, id, ns| {
self.store.prov_model_for_entity_id(&mut conn, id, ns)
})
.await
},
.await,
Ok(_) => Ok(poem::Response::builder()
.status(StatusCode::NOT_FOUND)
.body("may query only: activity, agent, entity")),
Expand Down
3 changes: 1 addition & 2 deletions crates/api/src/chronicle_graphql/mutation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Primitive mutation operations that are not in terms of particular domain types

use crate::commands::{ActivityCommand, AgentCommand, ApiCommand, ApiResponse, EntityCommand};
use async_graphql::Context;
use chrono::{DateTime, Utc};
use common::{
attributes::Attributes,
commands::{ActivityCommand, AgentCommand, ApiCommand, ApiResponse, EntityCommand},
identity::AuthId,
prov::{operations::DerivationType, ActivityId, AgentId, EntityId, Role},
};
Expand Down
14 changes: 3 additions & 11 deletions crates/api/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::pin::Pin;
use std::{path::PathBuf, sync::Arc};
#[cfg(feature = "std")]
use std::{path::PathBuf, sync::Arc};

Expand All @@ -7,7 +8,7 @@ use futures::AsyncRead;

use serde::{Deserialize, Serialize};

use crate::{
use common::{
attributes::Attributes,
prov::{
operations::{ChronicleOperation, DerivationType},
Expand All @@ -16,13 +17,6 @@ use crate::{
},
};

#[cfg(not(feature = "std"))]
use parity_scale_codec::{
alloc::boxed::Box, alloc::string::String, alloc::sync::Arc, alloc::vec::Vec,
};
#[cfg(not(feature = "std"))]
use scale_info::prelude::*;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum NamespaceCommand {
Create { external_id: ExternalId },
Expand All @@ -47,7 +41,6 @@ pub enum AgentCommand {
role: Option<Role>,
},
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ActivityCommand {
Create {
Expand Down Expand Up @@ -156,8 +149,7 @@ impl ActivityCommand {
#[derive(Clone)]
pub enum PathOrFile {
Path(PathBuf),
File(Arc<Pin<Box<dyn AsyncRead + Sync + Send>>>), /* Non serialisable variant, used in
* process */
File(Arc<Pin<Box<dyn AsyncRead + Sync + Send>>>),
}

impl core::fmt::Debug for PathOrFile {
Expand Down
Loading

0 comments on commit 5649c2b

Please sign in to comment.