Skip to content

Commit

Permalink
Add derives for data model
Browse files Browse the repository at this point in the history
Signed-off-by: i1i1 <vanyarybin1@live.ru>
  • Loading branch information
i1i1 committed Aug 4, 2021
1 parent 5620ac7 commit addcb0d
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 37 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/iroha2-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,22 @@ jobs:
uses: codecov/codecov-action@v1
with:
file: lcov.info

publish-artifacts:
runs-on: [self-hosted, Linux] #ubuntu-latest
container: rust:1.52-buster
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ${{ env.CACHE_PATHS }}
key: ${{ hashFiles('Cargo.toml') }}
- name: Run schema generation
run: |
mkdir -p target/schema
cargo run -p iroha_schema_bin > target/schema/schema.json
- name: Upload schema
uses: actions/upload-artifact@v2
with:
name: schema
path: target/schema
38 changes: 24 additions & 14 deletions iroha_data_model/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use iroha_derive::FromVariant;
use iroha_schema::prelude::*;
use iroha_version::prelude::*;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};

declare_versioned_with_scale!(VersionedEventSocketMessage 1..2, Debug, Clone, FromVariant, IntoSchema);

Expand Down Expand Up @@ -41,9 +42,9 @@ impl VersionedEventSocketMessage {
#[version_with_scale(
n = 1,
versioned = "VersionedEventSocketMessage",
derive = "Debug, Clone, IntoSchema"
derive = "Debug, Clone, IntoSchema, Deserialize, Serialize"
)]
#[derive(Debug, Clone, IntoSchema, FromVariant, Encode, Decode)]
#[derive(Debug, Clone, IntoSchema, FromVariant, Decode, Encode, Deserialize, Serialize)]
pub enum EventSocketMessage {
/// Request sent by client to subscribe to events.
SubscriptionRequest(SubscriptionRequest),
Expand All @@ -59,11 +60,13 @@ pub enum EventSocketMessage {

//TODO: Sign request?
/// Subscription Request to listen to events
#[derive(Debug, Encode, Decode, Copy, Clone, IntoSchema)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, Copy, Clone, IntoSchema)]
pub struct SubscriptionRequest(pub EventFilter);

/// Event.
#[derive(Debug, Encode, Decode, Eq, PartialEq, Clone, FromVariant, IntoSchema)]
#[derive(
Debug, Decode, Encode, Deserialize, Serialize, Eq, PartialEq, Clone, FromVariant, IntoSchema,
)]
pub enum Event {
/// Pipeline event.
Pipeline(pipeline::Event),
Expand All @@ -72,7 +75,7 @@ pub enum Event {
}

/// Event filter.
#[derive(Debug, Encode, Decode, Clone, Copy, FromVariant, IntoSchema)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, Clone, Copy, FromVariant, IntoSchema)]
pub enum EventFilter {
/// Listen to pipeline events with filter.
Pipeline(pipeline::EventFilter),
Expand All @@ -96,11 +99,12 @@ pub mod data {
use iroha_derive::FromVariant;
use iroha_schema::prelude::*;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};

use crate::prelude::*;

/// Entity type to filter events.
#[derive(Debug, Encode, Decode, Eq, PartialEq, Copy, Clone)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, Eq, PartialEq, Copy, Clone)]
pub enum EntityType {
/// Account.
Account,
Expand All @@ -115,7 +119,7 @@ pub mod data {
}

/// Entity type to filter events.
#[derive(Debug, Encode, Decode, Eq, PartialEq, Copy, Clone)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, Eq, PartialEq, Copy, Clone)]
pub enum Status {
/// Entity was added, registered, minted or another action was made to make entity appear on
/// the blockchain for the first time.
Expand All @@ -128,7 +132,7 @@ pub mod data {
}

/// Enumeration of all possible Iroha data entities.
#[derive(Clone, Debug, Encode, Decode, FromVariant)]
#[derive(Clone, Debug, Decode, Encode, Deserialize, Serialize, FromVariant)]
pub enum Entity {
/// Account.
Account(Box<Account>),
Expand Down Expand Up @@ -156,7 +160,7 @@ pub mod data {

//TODO: implement filter for data entities
/// Event filter.
#[derive(Debug, Encode, Decode, Copy, Clone, IntoSchema)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, Copy, Clone, IntoSchema)]
pub struct EventFilter;

impl EventFilter {
Expand All @@ -168,7 +172,9 @@ pub mod data {

//TODO: implement event for data entities
/// Event.
#[derive(Debug, Encode, Decode, Copy, Clone, Eq, PartialEq, IntoSchema)]
#[derive(
Debug, Decode, Encode, Deserialize, Serialize, Copy, Clone, Eq, PartialEq, IntoSchema,
)]
pub struct Event;

/// Exports common structs and enums from this module.
Expand Down Expand Up @@ -197,7 +203,7 @@ pub mod pipeline {
use crate::isi::Instruction;

/// Event filter.
#[derive(Debug, Encode, Decode, Copy, Clone, IntoSchema)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, Copy, Clone, IntoSchema)]
pub struct EventFilter {
/// Filter by Entity if `Some`, if `None` all entities are accepted.
pub entity: Option<EntityType>,
Expand Down Expand Up @@ -249,7 +255,9 @@ pub mod pipeline {
}

/// Entity type to filter events.
#[derive(Debug, Encode, Decode, Eq, PartialEq, Copy, Clone, IntoSchema)]
#[derive(
Debug, Decode, Encode, Deserialize, Serialize, Eq, PartialEq, Copy, Clone, IntoSchema,
)]
pub enum EntityType {
/// Block.
Block,
Expand Down Expand Up @@ -425,7 +433,7 @@ pub mod pipeline {
}

/// Entity type to filter events.
#[derive(Debug, Encode, Decode, Eq, PartialEq, Clone, IntoSchema)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, Eq, PartialEq, Clone, IntoSchema)]
pub struct Event {
/// Type of entity that caused this event.
pub entity_type: EntityType,
Expand All @@ -447,7 +455,9 @@ pub mod pipeline {
}

/// Entity type to filter events.
#[derive(Debug, Encode, Decode, Eq, PartialEq, Clone, FromVariant, IntoSchema)]
#[derive(
Debug, Decode, Encode, Deserialize, Serialize, Eq, PartialEq, Clone, FromVariant, IntoSchema,
)]
pub enum Status {
/// Entity has been seen in blockchain, but has not passed validation.
Validating,
Expand Down
33 changes: 23 additions & 10 deletions iroha_data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ impl From<LengthLimits> for RangeInclusive<usize> {
pub mod world {
//! Structures, traits and impls related to `World`.
use iroha_schema::prelude::*;
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};

#[cfg(feature = "roles")]
use crate::role::RolesMap;
Expand Down Expand Up @@ -427,7 +429,20 @@ pub mod world {
}

/// The ID of the `World`. The `World` has only a single instance, therefore the ID has no fields.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, IntoSchema)]
#[derive(
Debug,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
Copy,
Serialize,
Deserialize,
Decode,
Encode,
IntoSchema,
)]
pub struct WorldId;

impl From<WorldId> for IdBox {
Expand Down Expand Up @@ -685,7 +700,7 @@ pub mod account {
pub const ACCOUNT_SIGNATORIES_VALUE: &str = "account_signatories";

/// Genesis account. Used to mainly be converted to ordinary `Account` struct.
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize, Decode, Encode, IntoSchema)]
pub struct GenesisAccount {
public_key: PublicKey,
}
Expand Down Expand Up @@ -1569,17 +1584,15 @@ pub mod domain {
pub type DomainsMap = DashMap<Name, Domain>;

/// Genesis domain. It will contain only one `genesis` account.
#[derive(Debug)]
#[derive(Debug, Decode, Encode, Deserialize, Serialize, IntoSchema)]
pub struct GenesisDomain {
genesis_account_public_key: PublicKey,
genesis_key: PublicKey,
}

impl GenesisDomain {
/// Returns `GenesisDomain`.
pub const fn new(genesis_account_public_key: PublicKey) -> Self {
GenesisDomain {
genesis_account_public_key,
}
pub const fn new(genesis_key: PublicKey) -> Self {
Self { genesis_key }
}
}

Expand All @@ -1589,7 +1602,7 @@ pub mod domain {
name: GENESIS_DOMAIN_NAME.to_owned(),
accounts: iter::once((
<Account as Identifiable>::Id::genesis_account(),
GenesisAccount::new(domain.genesis_account_public_key).into(),
GenesisAccount::new(domain.genesis_key).into(),
))
.collect(),
asset_definitions: BTreeMap::default(),
Expand Down Expand Up @@ -2057,7 +2070,7 @@ pub mod transaction {
versioned = "VersionedPendingTransactions",
derive = "Debug, Clone"
)]
#[derive(Debug, Clone, Encode, Decode, Io, IntoSchema)]
#[derive(Debug, Clone, Encode, Decode, Deserialize, Serialize, Io, IntoSchema)]
pub struct PendingTransactions(pub Vec<Transaction>);

impl FromIterator<Transaction> for PendingTransactions {
Expand Down
6 changes: 3 additions & 3 deletions iroha_data_model/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl QueryOutput for QueryBox {
}

/// Payload of a query.
#[derive(Debug, Io, Encode, Decode, Clone, IntoSchema)]
#[derive(Debug, Io, Decode, Encode, Deserialize, Serialize, Clone, IntoSchema)]
pub struct Payload {
/// Timestamp of the query creation.
#[codec(compact)]
Expand All @@ -116,7 +116,7 @@ impl Payload {
}

/// I/O ready structure to send queries.
#[derive(Debug, Io, Encode, Decode, Clone)]
#[derive(Debug, Io, Decode, Encode, Deserialize, Serialize, Clone)]
pub struct QueryRequest {
/// Payload
pub payload: Payload,
Expand All @@ -130,7 +130,7 @@ declare_versioned_with_scale!(VersionedSignedQueryRequest 1..2, Debug, Clone, ir
versioned = "VersionedSignedQueryRequest",
derive = "Debug, Clone, IntoSchema"
)]
#[derive(Debug, Clone, Io, Encode, Decode, IntoSchema)]
#[derive(Debug, Clone, Io, Decode, Encode, Deserialize, Serialize, IntoSchema)]
pub struct SignedQueryRequest {
/// Payload
pub payload: Payload,
Expand Down
72 changes: 62 additions & 10 deletions iroha_schema/iroha_schema_bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use std::collections::BTreeMap;

use iroha_data_model::prelude::*;
use iroha_schema::prelude::*;

macro_rules! to_json {
Expand All @@ -16,13 +15,66 @@ macro_rules! to_json {
}

fn main() {
println!(
"{}",
to_json!(
VersionedTransaction,
VersionedSignedQueryRequest,
VersionedQueryResult,
VersionedEventSocketMessage,
)
)
use iroha_data_model::{
expression::*,
isi::{If, *},
prelude::*,
};

let json = to_json! {
// $ rg '^pub (struct|enum)' | rg -v '(<|Builder|LengthLimits|QueryRequest)' | cut -d' ' -f3 | sed -e 's/[(].*//' -e 's/$/,/' | sort
Add,
And,
BurnBox,
Contains,
ContainsAll,
ContainsAny,
ContextValue,
Divide,
Equal,
Event,
EventFilter,
EventSocketMessage,
Expression,
FailBox,
GrantBox,
Greater,
IdBox,
IdentifiableBox,
If,
If,
Instruction,
Less,
MintBox,
Mod,
Multiply,
Not,
Or,
Pair,
Parameter,
Payload,
QueryBox,
QueryResult,
RaiseTo,
RegisterBox,
RemoveKeyValueBox,
SequenceBox,
SetBox,
SetKeyValueBox,
SignedQueryRequest,
SubscriptionRequest,
Subtract,
TransferBox,
UnregisterBox,
Value,
Where,

// All versioned
VersionedTransaction,
VersionedSignedQueryRequest,
VersionedQueryResult,
VersionedEventSocketMessage,
};

println!("{}", json)
}

0 comments on commit addcb0d

Please sign in to comment.