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

Refactoring #56

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
members = ["testing-utils/test-moat-cli", "moat-cli/moat-cli-common", "moat-cli/moat-cli-user", "moat-cli/moat-cli-lp", "moat-cli/moat-cli-sp", "testing-utils/test-moat-request", "moat-core", "wallet-accessor", "integration-tests", "macros/code-hasher", "moat-example"]
members = ["moat-cli/moat-cli-common", "moat-cli/moat-cli-user", "moat-cli/moat-cli-lp", "moat-cli/moat-cli-sp", "moat-core", "integration-tests", "macros/code-hasher", "moat-example"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ The moat-cli utility can be used from the POV of any of the parties involved in
Users can request licenses and use them. To run the user CLI, simply run:

```sh
cargo r --release --bin moat-cli-user -- --wallet-path ~/.dusk/rusk-wallet --wallet-pass <PASSWORD>
cargo r --release --bin moat-cli-user -- --wallet-pass <PASSWORD>
```

### License Provider

LPs can scan the Blockchain for requests and issue licenses if the requests are valid. To run the LP CLI, simply run:

```sh
cargo r --release --bin moat-cli-lp -- --wallet-path ~/.dusk/rusk-wallet --wallet-pass <PASSWORD>
cargo r --release --bin moat-cli-lp -- --wallet-pass <PASSWORD>
```

### Service Provider

SPs can get requests from users to grant their services, and accept or deny them by checking if the session cookies provided by the users are valid. To run the SP CLI, simply run:

```sh
cargo r --release --bin moat-cli-sp -- --wallet-path ~/.dusk/rusk-wallet --wallet-pass <PASSWORD>
cargo r --release --bin moat-cli-sp -- --wallet-pass <PASSWORD>
```
3 changes: 1 addition & 2 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
moat-core={ path = "../moat-core" }
moat={ path = "../moat-core" }

[dev-dependencies]
dusk-wallet = "0.20.1-rc.0"
Expand All @@ -15,7 +15,6 @@ poseidon-merkle = { version = "0.3", features = ["rkyv-impl"] }
dusk-pki = { version = "0.13", default-features = false, features = ["rkyv-impl"] }
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }
dusk-bls12_381 = "0.12"
wallet-accessor = { path = "../wallet-accessor" }
rkyv = { version = "=0.7.39" }
tokio = { version = "1.15", features = ["rt-multi-thread", "time", "fs", "macros"] }
tokio-tungstenite = { version = "0.19", default-features = false, features = ["connect"] }
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/blockchain/get_crs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::RuskHttpClient;
use moat_core::{CrsGetter, Error};
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::{CrsGetter, Error};
use toml_base_config::BaseConfig;
use tracing::trace;
use wallet_accessor::BlockchainAccessConfig;

const MIN_CRS_SIZE: usize = 10 * 1024 * 1024;

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/blockchain/retrieve_txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::RuskHttpClient;
use moat_core::{Error, TxInquirer};
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::{Error, TxInquirer};
use toml_base_config::BaseConfig;
use tracing::trace;
use wallet_accessor::BlockchainAccessConfig;

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/blockchain/stake_add_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::{RuskHttpClient, WalletPath};
use moat_core::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter};
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::wallet_accessor::Password::PwdHash;
use moat::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter};
use phoenix_core::transaction::ModuleId;
use std::path::PathBuf;
use toml_base_config::BaseConfig;
use wallet_accessor::BlockchainAccessConfig;
use wallet_accessor::Password::PwdHash;

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
const PWD_HASH: &str =
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/citadel/int_test_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use moat_core::license_provider::ReferenceLP;
use moat_core::Error;
use moat::license_provider::ReferenceLP;
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::Error;
use toml_base_config::BaseConfig;
use wallet_accessor::BlockchainAccessConfig;

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "exp_tests"), ignore)]
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/tests/citadel/int_test_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ use dusk_bytes::DeserializableSlice;
use dusk_pki::SecretSpendKey;
use dusk_plonk::prelude::*;
use dusk_wallet::{RuskHttpClient, WalletPath};
use moat_core::license_provider::{LicenseIssuer, ReferenceLP};
use moat_core::{
use moat::license_provider::{LicenseIssuer, ReferenceLP};
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::wallet_accessor::Password::PwdHash;
use moat::{
BcInquirer, CitadelInquirer, CrsGetter, Error, JsonLoader, LicenseCircuit,
LicenseSessionId, LicenseUser, PayloadRetriever, RequestCreator,
RequestJson, RequestSender, TxAwaiter,
Expand All @@ -35,8 +37,6 @@ use rand::SeedableRng;
use std::path::PathBuf;
use toml_base_config::BaseConfig;
use tracing::{info, Level};
use wallet_accessor::BlockchainAccessConfig;
use wallet_accessor::Password::PwdHash;
use zk_citadel::license::Request;

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/tests/citadel/issue_license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

use dusk_jubjub::JubJubScalar;
use dusk_wallet::WalletPath;
use moat_core::license_provider::{LicenseIssuer, ReferenceLP};
use moat_core::{Error, JsonLoader, RequestCreator, RequestJson};
use moat::license_provider::{LicenseIssuer, ReferenceLP};
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::wallet_accessor::Password::PwdHash;
use moat::{Error, JsonLoader, RequestCreator, RequestJson};
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::path::PathBuf;
use toml_base_config::BaseConfig;
use wallet_accessor::BlockchainAccessConfig;
use wallet_accessor::Password::PwdHash;

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
const PWD_HASH: &str =
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/citadel/license_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use dusk_bls12_381::BlsScalar;
use dusk_wallet::RuskHttpClient;
use moat_core::{CitadelInquirer, Error, LicenseSessionId, StreamAux};
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::{CitadelInquirer, Error, LicenseSessionId, StreamAux};
use toml_base_config::BaseConfig;
use tracing::trace;
use wallet_accessor::BlockchainAccessConfig;

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/citadel/retrieve_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::RuskHttpClient;
use moat_core::{Error, PayloadRetriever, RequestScanner};
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::{Error, PayloadRetriever, RequestScanner};
use toml_base_config::BaseConfig;
use tracing::trace;
use wallet_accessor::BlockchainAccessConfig;
use zk_citadel::license::Request;

#[tokio::test(flavor = "multi_thread")]
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/citadel/send_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_wallet::{RuskHttpClient, WalletPath};
use moat_core::{
use moat::wallet_accessor::{BlockchainAccessConfig, Password::PwdHash};
use moat::{
Error, PayloadExtractor, PayloadRetriever, RequestCreator, RequestJson,
RequestSender, TxInquirer, MAX_REQUEST_SIZE,
};
use moat_core::{JsonLoader, TxAwaiter};
use moat::{JsonLoader, TxAwaiter};
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::path::PathBuf;
use std::time::Duration;
use tokio::time::sleep;
use toml_base_config::BaseConfig;
use tracing::Level;
use wallet_accessor::{BlockchainAccessConfig, Password::PwdHash};
use zk_citadel::license::Request;

const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet");
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/websocket/ws_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use moat_core::ContractInquirerWs;
use moat::ContractInquirerWs;

pub async fn send_request_to_ws_server(port: u32) {
let url = format!("127.0.0.1:{}", port);
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/websocket/ws_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::websocket::ws_license_contract_mock_multi_server;
use dusk_bls12_381::BlsScalar;
use moat_core::{CitadelInquirerWs, Error, LicenseSession, LicenseSessionId};
use moat::{CitadelInquirerWs, Error, LicenseSession, LicenseSessionId};

const TEST_DURATION_SECONDS: u64 = 4;
const PORT: u32 = 9126;
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/websocket/ws_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::websocket::ws_common::*;
use dusk_bls12_381::BlsScalar;
use futures_util::{SinkExt, StreamExt};
use moat_core::{Error, LicenseSession, MAX_RESPONSE_SIZE};
use moat::{Error, LicenseSession, MAX_RESPONSE_SIZE};
use tokio::net::{TcpListener, TcpStream};
use tokio_tungstenite::tungstenite::Message;
use tracing::trace;
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/websocket/ws_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::websocket::{
send_request_to_ws_server, ws_license_contract_mock_server,
};
use moat_core::Error;
use moat::Error;
use tracing::trace;

const TEST_DURATION_SECONDS: u64 = 4;
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
moat-core = { path = "../../moat-core" }
moat = { path = "../../moat-core" }
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }
dusk-wallet = "0.20.1-rc.0"
clap = { version = "4.0", features = ["derive", "env"] }
Expand Down
8 changes: 4 additions & 4 deletions moat-cli/moat-cli-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use thiserror::Error;
pub enum Error {
/// Moat core error
#[error(transparent)]
Moat(Arc<moat_core::Error>),
Moat(Arc<moat::Error>),
/// Interaction error
#[error(transparent)]
Interaction(Arc<requestty::ErrorKind>),
Expand All @@ -41,8 +41,8 @@ pub enum Error {
Wallet(Arc<dusk_wallet::Error>),
}

impl From<moat_core::Error> for Error {
fn from(e: moat_core::Error) -> Self {
impl From<moat::Error> for Error {
fn from(e: moat::Error) -> Self {
Error::Moat(Arc::from(e))
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ impl From<bs58::decode::Error> for Error {

impl From<dusk_plonk::error::Error> for Error {
fn from(e: dusk_plonk::error::Error) -> Self {
Error::Moat(Arc::from(moat_core::Error::Plonk(Arc::from(e))))
Error::Moat(Arc::from(moat::Error::Plonk(Arc::from(e))))
}
}

Expand Down
3 changes: 1 addition & 2 deletions moat-cli/moat-cli-lp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ edition = "2021"
[dependencies]
dusk-wallet = "0.20.1-rc.0"
dusk-jubjub = { version = "0.13", default-features = false }
wallet-accessor = { path = "../../wallet-accessor" }
moat-core = { path = "../../moat-core" }
moat = { path = "../../moat-core" }
moat-cli-common = { path = "../moat-cli-common" }
dusk-pki = "0.13"
zk-citadel = "0.6.0-rc.0"
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-lp/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use clap::Parser;
#[command(propagate_version = true)]
pub struct Args {
/// Wallet directory [default: `$HOME/.dusk/rusk-wallet`]
#[clap(short, long)]
#[clap(short, long, default_value = concat!(env!("HOME"), "/.dusk/rusk-wallet"))]
pub wallet_path: PathBuf,

/// Blockchain access config directory
Expand Down
6 changes: 3 additions & 3 deletions moat-cli/moat-cli-lp/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use crate::SeedableRng;
use dusk_jubjub::JubJubScalar;
use dusk_pki::SecretSpendKey;
use dusk_wallet::{RuskHttpClient, WalletPath};
use moat::license_provider::{LicenseIssuer, ReferenceLP};
use moat::wallet_accessor::{BlockchainAccessConfig, Password};
use moat::{BcInquirer, CitadelInquirer};
use moat_cli_common::Error;
use moat_core::license_provider::{LicenseIssuer, ReferenceLP};
use moat_core::{BcInquirer, CitadelInquirer};
use rand::rngs::StdRng;
use wallet_accessor::{BlockchainAccessConfig, Password};

/// Commands that can be run against the Moat
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-lp/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::prompt;
use crate::{Command, Menu};
use dusk_pki::SecretSpendKey;
use dusk_wallet::WalletPath;
use moat::wallet_accessor::{BlockchainAccessConfig, Password};
use moat_cli_common::Error;
use requestty::{ErrorKind, Question};
use wallet_accessor::{BlockchainAccessConfig, Password};

#[derive(PartialEq, Eq, Hash, Debug, Clone)]
enum OpSelection {
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-lp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ use clap::Parser;
use crate::config::LPCliConfig;
use crate::interactor::Interactor;
use dusk_wallet::{Wallet, WalletPath};
use moat::wallet_accessor::Password::{Pwd, PwdHash};
use moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor};
use moat_cli_common::Error;
use rand::SeedableRng;
use toml_base_config::BaseConfig;
use wallet_accessor::Password::{Pwd, PwdHash};
use wallet_accessor::{BlockchainAccessConfig, WalletAccessor};

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand Down
3 changes: 1 addition & 2 deletions moat-cli/moat-cli-sp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ edition = "2021"

[dependencies]
dusk-wallet = "0.20.1-rc.0"
wallet-accessor = { path = "../../wallet-accessor" }
moat-core = { path = "../../moat-core" }
moat = { path = "../../moat-core" }
moat-cli-common = { path = "../moat-cli-common" }
zk-citadel = "0.6.0-rc.0"
rkyv = { version = "=0.7.39" }
Expand Down
3 changes: 0 additions & 3 deletions moat-cli/moat-cli-sp/config.toml

This file was deleted.

2 changes: 1 addition & 1 deletion moat-cli/moat-cli-sp/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use clap::Parser;
#[command(propagate_version = true)]
pub struct Args {
/// Wallet directory [default: `$HOME/.dusk/rusk-wallet`]
#[clap(short, long)]
#[clap(short, long, default_value = concat!(env!("HOME"), "/.dusk/rusk-wallet"))]
pub wallet_path: PathBuf,

/// Blockchain access config directory
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-sp/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use dusk_bytes::DeserializableSlice;
use dusk_jubjub::JubJubAffine;
use dusk_pki::PublicSpendKey;
use dusk_wallet::RuskHttpClient;
use moat_core::{CitadelInquirer, LicenseSessionId};
use wallet_accessor::BlockchainAccessConfig;
use moat::wallet_accessor::BlockchainAccessConfig;
use moat::{CitadelInquirer, LicenseSessionId};
use zk_citadel::license::{Session, SessionCookie};

/// Commands that can be run against the Moat
Expand Down
2 changes: 1 addition & 1 deletion moat-cli/moat-cli-sp/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::prompt;
use crate::{Command, Menu};
use dusk_pki::PublicSpendKey;
use dusk_wallet::WalletPath;
use moat::wallet_accessor::{BlockchainAccessConfig, Password};
use moat_cli_common::Error;
use requestty::{ErrorKind, Question};
use wallet_accessor::{BlockchainAccessConfig, Password};

#[derive(PartialEq, Eq, Hash, Debug, Clone)]
enum OpSelection {
Expand Down
4 changes: 2 additions & 2 deletions moat-cli/moat-cli-sp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ use clap::Parser;
use crate::config::SPCliConfig;
use crate::interactor::Interactor;
use dusk_wallet::{Wallet, WalletPath};
use moat::wallet_accessor::Password::{Pwd, PwdHash};
use moat::wallet_accessor::{BlockchainAccessConfig, WalletAccessor};
use moat_cli_common::Error;
use toml_base_config::BaseConfig;
use wallet_accessor::Password::{Pwd, PwdHash};
use wallet_accessor::{BlockchainAccessConfig, WalletAccessor};

#[tokio::main]
async fn main() -> Result<(), Error> {
Expand Down
3 changes: 1 addition & 2 deletions moat-cli/moat-cli-user/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ edition = "2021"

[dependencies]
dusk-wallet = "0.20.1-rc.0"
wallet-accessor = { path = "../../wallet-accessor" }
moat-core = { path = "../../moat-core" }
moat = { path = "../../moat-core" }
moat-cli-common = { path = "../moat-cli-common" }
zk-citadel = "0.6.0-rc.0"
dusk-plonk = { version = "0.16", default-features = false, features = ["rkyv-impl", "alloc"] }
Expand Down
Loading