Skip to content

Commit

Permalink
Merge pull request #20 from zianksm/pre-release-v0.1.2
Browse files Browse the repository at this point in the history
Pre release v0.1.2
  • Loading branch information
zianksm authored Jun 20, 2023
2 parents 299cd8b + eb43760 commit 44795f7
Show file tree
Hide file tree
Showing 52 changed files with 1,847 additions and 1,312 deletions.
File renamed without changes.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"dhatu",
"mandala-node-runner",
]
27 changes: 23 additions & 4 deletions dhatu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
[package]
name = "dhatu"
version = "0.1.0"
version = "0.1.2"
edition = "2021"
license = "Apache-2.0"
description = "dhatu core libraries"
homepage = "https://github.com/zianksm/dhatu/tree/dev/dhatu#readme"
keywords = ["substrate", "dhatu", "dhatu-core", "mandala", "blockchain"]
exclude = ["src/registrar/signer/polkadot_metadata_small.scale"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# substrate stuff ( must be synchronized as these modules does not follow semver!)
sp-core = { version = "21.0.0", features = ["full_crypto"] }
sp-core = { version = "21.0.0", features = ["full_crypto", "std"] }
subxt = "0.29"
sp-keyring = "24.0.0"
schnorrkel = "0.9.1"

# async stuff
Expand All @@ -25,9 +29,24 @@ hex = "0.4.3"
parity-scale-codec = "3.5.0"
rand = "0.8.5"

# mock substrate account
sp-keyring = { version = "24.0.0", optional = true }

# custom erorr
thiserror = "1.0.40"

[dev-dependencies]
# testing
# mock traits and structs
mockall = "0.11.4"
# mock substrate account
sp-keyring = { version = "24.0.0" }
mockito = "1.0.2"

[features]
default = ["tokio", "serde"]
sp_keyring = []
unstable = ["default", "unstable_sp_core", "subxt", "sp-keyring"]
tokio = []
serde = []
unstable_sp_core = []
subxt = []
674 changes: 0 additions & 674 deletions dhatu/LICENSE

This file was deleted.

3 changes: 1 addition & 2 deletions dhatu/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# dhatu-identity-registrar
dhatu core libraries
# **Dhatu Core Libraries**
102 changes: 93 additions & 9 deletions dhatu/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,106 @@
use crate::{
registrar::key_manager::prelude::KeypairGenerationError,
tx::extrinsics::prelude::{reserve::FundsReserveError, CallbackExecutorError}, types::MandalaClientErorr,
};

/// the base error enum. this is the expected error type that will be returned.
#[derive(thiserror::Error, Debug)]
pub enum Error {
/// error when generating password for keypair phrase.
#[error("password generation error : {0}")]
PasswordGenError(String),
Password(#[from] PasswordGenerationError),

/// error when generating keypair.
#[error("keypair generation error : ")]
KeypairGenError(#[from] KeypairGenerationError),
Keypair(#[from] KeypairGenerationError),

/// error associated with the underlying blockchain rpc client.
#[error("mandala client error :")]
Client(#[from] MandalaClientErorr),

/// error associated with reserve funds transactions.
#[error("reserve error : ")]
ReserveError(#[from] FundsReserveError),
Reserve(#[from] FundsReserveError),

/// error when executing transaction http callback.
#[error("callback executor error : ")]
CallbackError(#[from] CallbackExecutorError)
Callback(#[from] CallbackExecutorError),

/// transaction related error.
#[error("error when submitting transaction : {0}")]
Transaction(#[from] subxt::Error),

/// error when encoding calldata to contract pallet payload.
#[error("error when converting to payload : {0}")]
Payload(#[from] ToPayloadError),

/// error when signing transaction.
#[error("error when signing transaction : {0}")]
Sign(#[from] TxBuilderError),
}

/// error related to keypair password generation.
#[derive(thiserror::Error, Debug)]
pub enum PasswordGenerationError {
#[error("invalid length. password length must be at least 32 characters long!")]
InvalidLength,
}

/// all error that can happen when generating and parsing keypair related stuff.
#[derive(thiserror::Error, Debug)]
pub enum KeypairGenerationError {
/// error parsing keypair.
#[error("{0}")]
PublicAddress(String),

/// error parsing mnemonic phrase.
#[error("fail to generate mnemonic phrase with {0}")]
MnemonicPhrase(String),

/// error parsing private key.
#[error("{0}")]
PrivateKey(#[from] sp_core::crypto::SecretStringError),

/// error recovering keypair.
#[error("{0}")]
Recover(String),
}

/// error that happens on the underlying blockchain rpc client.
#[derive(thiserror::Error, Debug)]
pub enum MandalaClientErorr {
/// error associating with the node connection
#[error("connection Error : {0}")]
Connection(#[from] subxt::Error),
}

/// reserve funds transaction error
#[derive(thiserror::Error, Debug)]
pub enum FundsReserveError {
/// rpc related error
#[error("{0}")]
RpcError(#[from] subxt::error::Error),

/// account does not exist, happens when trying
/// to transfer funds to an account that does not exist.
#[error("account does not exist!")]
NonExistentAccount,
}

/// errors related with executing transaction http callback.
#[derive(thiserror::Error, Debug)]
pub enum CallbackExecutorError {
/// failed to parse url.
#[error("{0}")]
InvalidUrl(String),
}

/// errors that can happen when encoding calldata to pallet contrats payload.
#[derive(thiserror::Error, Debug)]
pub enum ToPayloadError {
/// failed to parse account address.
#[error("{0}")]
AddressError(String),
}

/// errors that can happen when signing transaction.
#[derive(thiserror::Error, Debug)]
pub enum TxBuilderError {
#[error("{0}")]
SignErorr(#[from] subxt::Error),
}
6 changes: 6 additions & 0 deletions dhatu/src/ext/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[cfg(feature = "unstable_sp_core")]
pub use sp_core;
#[cfg(feature = "subxt")]
pub use subxt;
#[cfg(feature = "sp-keyring")]
pub use sp_keyring;
26 changes: 26 additions & 0 deletions dhatu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
//! dhatu core libraries. aims to abstract away the complexity of interacting to substrate blockchain.
//! for now, is meant to be used with mandala based blockchains. but in future, it will be extended to support other substrate based blockchains.
//! # Re-exports
//! ```
//! #[cfg(feature = "unstable_sp_core")]
//! pub use sp_core;
//! #[cfg(feature = "subxt")]
//! pub use subxt;
//! #[cfg(feature = "sp_keyring")]
//! pub use sp_keyring;
//! ```
//! due to the unstable nature of substrate modules, they are not re-exported by default.
//! if you want to interact with the some of the low level feature of dhatu and use the raw substrate primitive types,
//! we reccomend you to enable `unstable` feature flag to properly interact with the low level modules.
//!
//! see [ext] for more details.
/// error associated with dhatu
pub mod error;
/// re export external libraries that makes up dhatu.
pub mod ext;
/// crate private modules
pub(crate) mod private;
/// identity registrar, consist of types and modules regarding blockchain identity.
/// i.e keypair.
pub mod registrar;
/// transaction module, consist of extrinsics abstraction.
pub mod tx;
/// global crate level types, code inside this modules is meant to be used globally.
pub mod types;
Loading

0 comments on commit 44795f7

Please sign in to comment.