diff --git a/integration-tests/tests/int_test_user.rs b/integration-tests/tests/int_test_user.rs index 294642b..015ebe9 100644 --- a/integration-tests/tests/int_test_user.rs +++ b/integration-tests/tests/int_test_user.rs @@ -31,7 +31,7 @@ use moat_core::Error::InvalidQueryResponse; use moat_core::{ BcInquirer, CitadelInquirer, Error, JsonLoader, LicenseCircuit, LicenseSessionId, PayloadSender, RequestCreator, RequestJson, StreamAux, - TxAwaiter, ARITY, DEPTH, + TxAwaiter, ARITY, DEPTH, LICENSE_CONTRACT_ID, USE_LICENSE_METHOD_NAME, }; use poseidon_merkle::Opening; use rand::rngs::StdRng; @@ -146,13 +146,15 @@ async fn prove_and_send_use_license( public_inputs, }; - let tx_id = PayloadSender::send_use_license( + let tx_id = PayloadSender::send_to_contract_method( use_license_arg, &blockchain_config, &wallet_path, &PwdHash(PWD_HASH.to_string()), GAS_LIMIT, GAS_PRICE, + LICENSE_CONTRACT_ID, + USE_LICENSE_METHOD_NAME, ) .await?; TxAwaiter::wait_for(&client, tx_id).await?; @@ -332,6 +334,7 @@ async fn user_round_trip() -> Result<(), Error> { hex::encode(session.public_inputs[0].to_bytes()) ); - // if we try to call use_license again, it will be rejected + // if we try to call use_license with the same license again, it will be + // rejected Ok(()) } diff --git a/integration-tests/tests/send_request.rs b/integration-tests/tests/send_request.rs index 6c5e280..a708a40 100644 --- a/integration-tests/tests/send_request.rs +++ b/integration-tests/tests/send_request.rs @@ -8,7 +8,7 @@ use dusk_jubjub::BlsScalar; use dusk_wallet::{RuskHttpClient, WalletPath}; use moat_core::{ Error, PayloadRetriever, PayloadSender, RequestCreator, RequestJson, - MAX_REQUEST_SIZE, + LICENSE_CONTRACT_ID, MAX_REQUEST_SIZE, NOOP_METHOD_NAME, }; use moat_core::{JsonLoader, TxAwaiter}; use rand::rngs::StdRng; @@ -59,13 +59,15 @@ async fn send_request() -> Result<(), Error> { PathBuf::from(WALLET_PATH).as_path().join("wallet.dat"), ); - let tx_id = PayloadSender::send_noop( + let tx_id = PayloadSender::send_to_contract_method( (request, 0u64, BlsScalar::one()), &config, &wallet_path, &PwdHash(PWD_HASH.to_string()), GAS_LIMIT, GAS_PRICE, + LICENSE_CONTRACT_ID, + NOOP_METHOD_NAME, ) .await?; let client = RuskHttpClient::new(config.rusk_address); diff --git a/integration-tests/tests/stake_add_owner.rs b/integration-tests/tests/stake_add_owner.rs index 7f78397..bf68ec7 100644 --- a/integration-tests/tests/stake_add_owner.rs +++ b/integration-tests/tests/stake_add_owner.rs @@ -5,10 +5,8 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat_core::{ - Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter, - ADD_OWNER_METHOD_NAME, STAKE_CONTRACT_ID, -}; +use moat_core::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter}; +use phoenix_core::transaction::ModuleId; use std::path::PathBuf; use toml_base_config::BaseConfig; use wallet_accessor::BlockchainAccessConfig; @@ -20,6 +18,13 @@ const PWD_HASH: &str = const GAS_LIMIT: u64 = 5_000_000_000; const GAS_PRICE: u64 = 1; +pub const STAKE_CONTRACT_ID: ModuleId = { + let mut bytes = [0u8; 32]; + bytes[0] = 0x02; + bytes +}; +pub const ADD_OWNER_METHOD_NAME: &str = "add_owner"; + #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "int_tests"), ignore)] async fn stake_add_owner() -> Result<(), Error> { diff --git a/license-provider/src/license_issuer.rs b/license-provider/src/license_issuer.rs index 64c82c7..fa07cb2 100644 --- a/license-provider/src/license_issuer.rs +++ b/license-provider/src/license_issuer.rs @@ -8,7 +8,10 @@ use dusk_jubjub::{BlsScalar, JubJubAffine, JubJubScalar}; use dusk_pki::SecretSpendKey; use dusk_poseidon::sponge; use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat_core::{Error, PayloadSender, TxAwaiter, MAX_LICENSE_SIZE}; +use moat_core::{ + Error, PayloadSender, TxAwaiter, ISSUE_LICENSE_METHOD_NAME, + LICENSE_CONTRACT_ID, MAX_LICENSE_SIZE, +}; use rand::{CryptoRng, RngCore}; use tracing::trace; use wallet_accessor::{BlockchainAccessConfig, Password}; @@ -59,13 +62,15 @@ impl LicenseIssuer { "sending issue license with license blob size={}", tuple.0.len() ); - let tx_id = PayloadSender::send_issue_license( + let tx_id = PayloadSender::send_to_contract_method( tuple, &self.config, &self.wallet_path, &self.password, self.gas_limit, self.gas_price, + LICENSE_CONTRACT_ID, + ISSUE_LICENSE_METHOD_NAME, ) .await?; let client = RuskHttpClient::new(self.config.rusk_address.clone()); diff --git a/license-provider/src/reference_lp.rs b/license-provider/src/reference_lp.rs index e31cb6a..3aff0c7 100644 --- a/license-provider/src/reference_lp.rs +++ b/license-provider/src/reference_lp.rs @@ -71,7 +71,7 @@ impl ReferenceLP { RequestScanner::scan_block_range(height, height_end, cfg) .await?; total += requests.len(); - let owned_requests = self.filter_owned_requests(&requests)?; + let owned_requests = self.retain_owned_requests(requests); total_owned += owned_requests.len(); for owned_request in owned_requests { self.insert_request(owned_request); @@ -95,7 +95,7 @@ impl ReferenceLP { let mut total_owned = 0usize; let requests = RequestScanner::scan_last_blocks(n, cfg).await?; total += requests.len(); - let owned_requests = self.filter_owned_requests(&requests)?; + let owned_requests = self.retain_owned_requests(requests); total_owned += owned_requests.len(); for owned_request in owned_requests { self.insert_request(owned_request); @@ -103,20 +103,14 @@ impl ReferenceLP { Ok((total, total_owned)) } - /// Given a collection of requests, returns a new collection - /// containing only requests relevant to `this` license provider - pub fn filter_owned_requests( + /// Given a collection of requests, retain only those requests + /// in the collection which are owned by 'this' license provider + pub fn retain_owned_requests( &self, - requests: &[Request], - ) -> Result, Error> { - let mut relevant_requests: Vec = Vec::new(); - for request in requests.iter() { - if self.is_owned_request(request) { - let r = Request { ..*request }; - relevant_requests.push(r); - } - } - Ok(relevant_requests) + mut requests: Vec, + ) -> Vec { + requests.retain(|request| self.is_owned_request(request)); + requests } fn is_owned_request(&self, request: &Request) -> bool { diff --git a/license-provider/tests/test_lp.rs b/license-provider/tests/test_lp.rs index 7e893e3..b09d006 100644 --- a/license-provider/tests/test_lp.rs +++ b/license-provider/tests/test_lp.rs @@ -20,11 +20,10 @@ fn lp_filter_requests() -> Result<(), Error> { .expect("transactions file should load correctly"); let requests = RequestScanner::scan_transactions(txs); - - let relevant_requests = reference_lp.filter_owned_requests(&requests)?; - assert_eq!(requests.len(), 9); - assert_eq!(relevant_requests.len(), 2); + + let owned_requests = reference_lp.retain_owned_requests(requests); + assert_eq!(owned_requests.len(), 2); Ok(()) } diff --git a/moat-cli/src/main.rs b/moat-cli/src/main.rs index 7b6e510..cddc91a 100644 --- a/moat-cli/src/main.rs +++ b/moat-cli/src/main.rs @@ -60,7 +60,10 @@ use crate::args::Args; use clap::Parser; use dusk_wallet::WalletPath; -use moat_core::{JsonLoader, PayloadSender, RequestCreator, RequestJson}; +use moat_core::{ + JsonLoader, PayloadSender, RequestCreator, RequestJson, + LICENSE_CONTRACT_ID, NOOP_METHOD_NAME, +}; use rand::rngs::StdRng; use rand::SeedableRng; use std::error::Error; @@ -104,13 +107,15 @@ async fn main() -> Result<(), Box> { PwdHash(pwd_hash) }; - PayloadSender::send_noop( + PayloadSender::send_to_contract_method( request, &blockchain_access_config, &wallet_path, &psw, gas_limit, gas_price, + LICENSE_CONTRACT_ID, + NOOP_METHOD_NAME, ) .await?; diff --git a/moat-core/src/types.rs b/moat-core/src/bc_types.rs similarity index 63% rename from moat-core/src/types.rs rename to moat-core/src/bc_types.rs index 25d7cdb..30d3457 100644 --- a/moat-core/src/types.rs +++ b/moat-core/src/bc_types.rs @@ -5,50 +5,9 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::JsonLoader; -use phoenix_core::transaction::ModuleId; - -pub const STAKE_CONTRACT_ID: ModuleId = { - let mut bytes = [0u8; 32]; - bytes[0] = 0x02; - bytes -}; -pub const LICENSE_CONTRACT_ID: ModuleId = { - let mut bytes = [0u8; 32]; - bytes[0] = 0x03; - bytes -}; - -// license contract method names -pub const NOOP_METHOD_NAME: &str = "noop"; -pub const ISSUE_LICENSE_METHOD_NAME: &str = "issue_license"; -pub const USE_LICENSE_METHOD_NAME: &str = "use_license"; -pub const GET_LICENSES_METHOD_NAME: &str = "get_licenses"; -pub const GET_MERKLE_OPENING_METHOD_NAME: &str = "get_merkle_opening"; -pub const GET_SESSION_METHOD_NAME: &str = "get_session"; -pub const GET_INFO_METHOD_NAME: &str = "get_info"; - -// stake contract method names -pub const ADD_OWNER_METHOD_NAME: &str = "add_owner"; - pub const MAX_CALL_SIZE: usize = 65536; -pub const MAX_REQUEST_SIZE: usize = 8192; -pub const MAX_LICENSE_SIZE: usize = 16384; pub const MAX_RESPONSE_SIZE: usize = 65536; -#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] -pub struct RequestJson { - pub user_ssk: String, - pub provider_psk: String, -} - -impl JsonLoader for RequestJson {} - -#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] -pub struct ContractInfo { - pub method: String, - pub contract: String, -} - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] pub struct Tx { pub id: String, @@ -75,12 +34,6 @@ pub struct CallInfoJson { pub data: String, } -#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] -pub struct TxJson { - pub anchor: String, - pub call: CallInfoJson, -} - #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] pub struct Header { pub height: u64, diff --git a/moat-core/src/blockchain_requests/payload_extractor.rs b/moat-core/src/blockchain_requests/payload_extractor.rs index bf499ab..47fda2f 100644 --- a/moat-core/src/blockchain_requests/payload_extractor.rs +++ b/moat-core/src/blockchain_requests/payload_extractor.rs @@ -6,8 +6,8 @@ use rkyv::{check_archived_root, Archive, Deserialize, Infallible}; +use crate::bc_types::Tx; use crate::error::Error; -use crate::types::Tx; use crate::Error::PayloadNotPresent; use bytecheck::CheckBytes; use rkyv::validation::validators::DefaultValidator; diff --git a/moat-core/src/blockchain_requests/payload_sender.rs b/moat-core/src/blockchain_requests/payload_sender.rs index 487a99c..6d92b9d 100644 --- a/moat-core/src/blockchain_requests/payload_sender.rs +++ b/moat-core/src/blockchain_requests/payload_sender.rs @@ -5,10 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::error::Error; -use crate::{ - ISSUE_LICENSE_METHOD_NAME, LICENSE_CONTRACT_ID, MAX_CALL_SIZE, - NOOP_METHOD_NAME, USE_LICENSE_METHOD_NAME, -}; +use crate::MAX_CALL_SIZE; use dusk_jubjub::BlsScalar; use dusk_wallet::WalletPath; use phoenix_core::transaction::ModuleId; @@ -18,81 +15,6 @@ use wallet_accessor::{BlockchainAccessConfig, Password, WalletAccessor}; pub struct PayloadSender; impl PayloadSender { - /// Sends a given payload to the noop method - pub async fn send_noop

( - payload: P, - cfg: &BlockchainAccessConfig, - wallet_path: &WalletPath, - password: &Password, - gas_limit: u64, - gas_price: u64, - ) -> Result - where - P: rkyv::Serialize>, - { - Self::send_to_contract_method( - payload, - cfg, - wallet_path, - password, - gas_limit, - gas_price, - LICENSE_CONTRACT_ID, - NOOP_METHOD_NAME, - ) - .await - } - - /// Sends a given payload to the issue license method - pub async fn send_issue_license

( - payload: P, - cfg: &BlockchainAccessConfig, - wallet_path: &WalletPath, - password: &Password, - gas_limit: u64, - gas_price: u64, - ) -> Result - where - P: rkyv::Serialize>, - { - Self::send_to_contract_method( - payload, - cfg, - wallet_path, - password, - gas_limit, - gas_price, - LICENSE_CONTRACT_ID, - ISSUE_LICENSE_METHOD_NAME, - ) - .await - } - - /// Sends a given payload to the use license method - pub async fn send_use_license

( - payload: P, - cfg: &BlockchainAccessConfig, - wallet_path: &WalletPath, - password: &Password, - gas_limit: u64, - gas_price: u64, - ) -> Result - where - P: rkyv::Serialize>, - { - Self::send_to_contract_method( - payload, - cfg, - wallet_path, - password, - gas_limit, - gas_price, - LICENSE_CONTRACT_ID, - USE_LICENSE_METHOD_NAME, - ) - .await - } - /// Sends payload to a given method #[allow(clippy::too_many_arguments)] pub async fn send_to_contract_method( @@ -113,7 +35,6 @@ impl PayloadSender { WalletAccessor::new(wallet_path.clone(), password.clone()); let tx_id = wallet_accessor .send( - // (payload, 1u64, BlsScalar::one()), payload, contract_id, method.as_ref().to_string(), diff --git a/moat-core/src/blockchain_requests/request_scanner.rs b/moat-core/src/blockchain_requests/request_scanner.rs index a0eb8b1..441cf77 100644 --- a/moat-core/src/blockchain_requests/request_scanner.rs +++ b/moat-core/src/blockchain_requests/request_scanner.rs @@ -45,7 +45,6 @@ impl RequestScanner { height_end: u64, cfg: &BlockchainAccessConfig, ) -> Result<(Vec, u64), Error> { - // let client = Client::new(cfg.graphql_address.clone()); let client = RuskHttpClient::new(cfg.rusk_address.clone()); let (txs, top) = TxRetriever::txs_from_block_range(&client, height_beg, height_end) diff --git a/moat-core/src/contract_queries/citadel_inquirer.rs b/moat-core/src/citadel_queries/citadel_inquirer.rs similarity index 93% rename from moat-core/src/contract_queries/citadel_inquirer.rs rename to moat-core/src/citadel_queries/citadel_inquirer.rs index c6ed158..7175a7c 100644 --- a/moat-core/src/contract_queries/citadel_inquirer.rs +++ b/moat-core/src/citadel_queries/citadel_inquirer.rs @@ -4,8 +4,8 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::contract_queries::block::Block; use crate::error::Error; +use crate::BlockInPlace; use crate::{ ContractInquirer, LicenseSession, LicenseSessionId, ARITY, DEPTH, GET_INFO_METHOD_NAME, GET_LICENSES_METHOD_NAME, @@ -21,11 +21,11 @@ use zk_citadel::license::License; pub struct CitadelInquirer {} impl CitadelInquirer { - // vector overhead needed as get_licenses returns licenses + // vector overhead length is needed as get_licenses returns licenses // serialized as vector of bytes - const VEC_OVERHEAD: usize = 8; + const VEC_OVERHEAD_LEN: usize = 8; pub const GET_LICENSES_ITEM_LEN: usize = - std::mem::size_of::<(u64, License)>() + Self::VEC_OVERHEAD; + std::mem::size_of::<(u64, License)>() + Self::VEC_OVERHEAD_LEN; pub async fn get_licenses( client: &RuskHttpClient, diff --git a/moat-core/src/contract_queries/citadel_inquirer_ws.rs b/moat-core/src/citadel_queries/citadel_inquirer_ws.rs similarity index 100% rename from moat-core/src/contract_queries/citadel_inquirer_ws.rs rename to moat-core/src/citadel_queries/citadel_inquirer_ws.rs diff --git a/moat-core/src/contract_queries/citadel_types.rs b/moat-core/src/citadel_queries/citadel_types.rs similarity index 100% rename from moat-core/src/contract_queries/citadel_types.rs rename to moat-core/src/citadel_queries/citadel_types.rs diff --git a/moat-core/src/citadel_queries/mod.rs b/moat-core/src/citadel_queries/mod.rs new file mode 100644 index 0000000..7c5791d --- /dev/null +++ b/moat-core/src/citadel_queries/mod.rs @@ -0,0 +1,13 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +// Copyright (c) DUSK NETWORK. All rights reserved. + +mod citadel_inquirer; +mod citadel_inquirer_ws; +mod citadel_types; + +pub use citadel_inquirer::CitadelInquirer; +pub use citadel_inquirer_ws::CitadelInquirerWs; +pub use citadel_types::{LicenseSession, LicenseSessionId}; diff --git a/moat-core/src/citadel_types.rs b/moat-core/src/citadel_types.rs new file mode 100644 index 0000000..5e5fa20 --- /dev/null +++ b/moat-core/src/citadel_types.rs @@ -0,0 +1,34 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +// +// Copyright (c) DUSK NETWORK. All rights reserved. + +use crate::JsonLoader; +use phoenix_core::transaction::ModuleId; + +pub const LICENSE_CONTRACT_ID: ModuleId = { + let mut bytes = [0u8; 32]; + bytes[0] = 0x03; + bytes +}; + +pub const MAX_REQUEST_SIZE: usize = 8192; +pub const MAX_LICENSE_SIZE: usize = 16384; + +// license contract method names +pub const NOOP_METHOD_NAME: &str = "noop"; +pub const ISSUE_LICENSE_METHOD_NAME: &str = "issue_license"; +pub const USE_LICENSE_METHOD_NAME: &str = "use_license"; +pub const GET_LICENSES_METHOD_NAME: &str = "get_licenses"; +pub const GET_MERKLE_OPENING_METHOD_NAME: &str = "get_merkle_opening"; +pub const GET_SESSION_METHOD_NAME: &str = "get_session"; +pub const GET_INFO_METHOD_NAME: &str = "get_info"; + +#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] +pub struct RequestJson { + pub user_ssk: String, + pub provider_psk: String, +} + +impl JsonLoader for RequestJson {} diff --git a/moat-core/src/contract_queries/block.rs b/moat-core/src/contract_queries/block.rs index 6423018..2e09b57 100644 --- a/moat-core/src/contract_queries/block.rs +++ b/moat-core/src/contract_queries/block.rs @@ -7,7 +7,7 @@ use tokio::runtime::Handle; use tokio::task::block_in_place; -pub(crate) trait Block { +pub trait BlockInPlace { fn wait(self) -> ::Output where Self: Sized, @@ -17,4 +17,4 @@ pub(crate) trait Block { } } -impl Block for F where F: futures::Future {} +impl BlockInPlace for F where F: futures::Future {} diff --git a/moat-core/src/contract_queries/contract_inquirer.rs b/moat-core/src/contract_queries/contract_inquirer.rs index 8aa2ef8..4763cca 100644 --- a/moat-core/src/contract_queries/contract_inquirer.rs +++ b/moat-core/src/contract_queries/contract_inquirer.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::contract_queries::block::Block; +use crate::contract_queries::block::BlockInPlace; use crate::error::Error; use crate::Error::InvalidQueryResponse; use crate::MAX_CALL_SIZE; diff --git a/moat-core/src/contract_queries/mod.rs b/moat-core/src/contract_queries/mod.rs index 33835ee..469a635 100644 --- a/moat-core/src/contract_queries/mod.rs +++ b/moat-core/src/contract_queries/mod.rs @@ -4,18 +4,13 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -mod block; -mod citadel_inquirer; -mod citadel_inquirer_ws; -mod citadel_types; +pub(crate) mod block; mod contract_inquirer; mod contract_inquirer_ws; mod stream_aux; mod ws_types; -pub use citadel_inquirer::CitadelInquirer; -pub use citadel_inquirer_ws::CitadelInquirerWs; -pub use citadel_types::{LicenseSession, LicenseSessionId}; +pub use block::*; pub use contract_inquirer::ContractInquirer; pub use contract_inquirer_ws::ContractInquirerWs; pub use stream_aux::StreamAux; diff --git a/moat-core/src/contract_queries/stream_aux.rs b/moat-core/src/contract_queries/stream_aux.rs index 1babd74..cf606ad 100644 --- a/moat-core/src/contract_queries/stream_aux.rs +++ b/moat-core/src/contract_queries/stream_aux.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::contract_queries::block::Block; +use crate::contract_queries::block::BlockInPlace; use crate::Error; use bytecheck::CheckBytes; use bytes::Bytes; @@ -33,14 +33,13 @@ impl StreamAux { let mut buffer = vec![]; while let Some(http_chunk) = stream.next().wait() { buffer.extend_from_slice( - &http_chunk.map_err(|_| { - Error::StreamItem(Box::from("chunking error")) - })?, + &http_chunk + .map_err(|_| Error::Stream(Box::from("chunking error")))?, ); let mut chunk = buffer.chunks_exact(L); for bytes in chunk.by_ref() { let item: R = rkyv::from_bytes(bytes).map_err(|_| { - Error::StreamItem(Box::from("deserialization error")) + Error::Stream(Box::from("deserialization error")) })?; if filter(&item)? { return Ok(item); @@ -48,7 +47,7 @@ impl StreamAux { } buffer = chunk.remainder().to_vec(); } - Err(Error::StreamItem(Box::from("item not found"))) + Err(Error::Stream(Box::from("item not found"))) } /// Collects all items and returns them in a vector, @@ -67,14 +66,13 @@ impl StreamAux { let mut buffer = vec![]; while let Some(http_chunk) = stream.next().wait() { buffer.extend_from_slice( - &http_chunk.map_err(|_| { - Error::StreamItem(Box::from("chunking error")) - })?, + &http_chunk + .map_err(|_| Error::Stream(Box::from("chunking error")))?, ); let mut chunk = buffer.chunks_exact(L); for bytes in chunk.by_ref() { let item: R = rkyv::from_bytes(bytes).map_err(|_| { - Error::StreamItem(Box::from("deserialization error")) + Error::Stream(Box::from("deserialization error")) })?; vec.push(item); } diff --git a/moat-core/src/error.rs b/moat-core/src/error.rs index 0f2cff5..2c03921 100644 --- a/moat-core/src/error.rs +++ b/moat-core/src/error.rs @@ -12,73 +12,73 @@ pub enum Error { #[error("Payload not present or incorrect: {0:?}")] PayloadNotPresent(Box), #[error(transparent)] - JsonParsingError(Arc), + JsonParsing(Arc), #[error(transparent)] - FileError(Arc), + IO(Arc), #[error(transparent)] - DuskWalletError(Arc), + DuskWallet(Arc), #[error("A serialization error occurred: {0:?}")] - BytesError(Arc), + Bytes(Arc), #[error("A serialization error occurred.")] Rkyv, #[error(transparent)] - HexError(Arc), + Hex(Arc), #[error("A GraphQL error occurred: {0:?}")] - GQLError(Box), + GQL(Box), #[error("TransactionNotFound")] TransactionNotFound, #[error("A base64 decode error occurred: {0:?}")] - Base64DecodeError(Arc), + Base64Decode(Arc), #[error(transparent)] - WebSocketError(Arc), + WebSocket(Arc), #[error("WebSocketStreamClosed")] WebSocketStreamClosed, #[error("Invalid query response: {0:?}")] InvalidQueryResponse(Box), #[error("Transaction error: {0:?}")] - TransactionError(Box), + Transaction(Box), #[error("Stream item not present or stream error: {0:?}")] - StreamItem(Box), + Stream(Box), } impl From for Error { fn from(e: serde_json::Error) -> Self { - Error::JsonParsingError(Arc::from(e)) + Error::JsonParsing(Arc::from(e)) } } impl From for Error { fn from(e: std::io::Error) -> Self { - Error::FileError(Arc::from(e)) + Error::IO(Arc::from(e)) } } impl From for Error { fn from(e: dusk_wallet::Error) -> Self { - Error::DuskWalletError(Arc::from(e)) + Error::DuskWallet(Arc::from(e)) } } impl From for Error { fn from(e: dusk_bytes::Error) -> Self { - Error::BytesError(Arc::from(e)) + Error::Bytes(Arc::from(e)) } } impl From for Error { fn from(e: hex::FromHexError) -> Self { - Error::HexError(Arc::from(e)) + Error::Hex(Arc::from(e)) } } impl From for Error { fn from(e: base64::DecodeError) -> Self { - Error::Base64DecodeError(Arc::from(e)) + Error::Base64Decode(Arc::from(e)) } } impl From for Error { fn from(e: tokio_tungstenite::tungstenite::Error) -> Self { - Error::WebSocketError(Arc::from(e)) + Error::WebSocket(Arc::from(e)) } } diff --git a/moat-core/src/lib.rs b/moat-core/src/lib.rs index 69a8712..ce2c189 100644 --- a/moat-core/src/lib.rs +++ b/moat-core/src/lib.rs @@ -11,24 +11,29 @@ //! Integration test for the library are provided in the `integration-test` //! subproject. +mod bc_types; mod blockchain_requests; mod circuit; +mod citadel_queries; +mod citadel_types; mod contract_queries; mod error; mod json_loader; mod tx_retrievals; -mod types; +pub use bc_types::*; pub use blockchain_requests::{ PayloadExtractor, PayloadRetriever, PayloadSender, RequestCreator, RequestScanner, }; pub use circuit::*; +pub use citadel_queries::{ + CitadelInquirer, CitadelInquirerWs, LicenseSession, LicenseSessionId, +}; +pub use citadel_types::*; pub use contract_queries::{ - CitadelInquirer, CitadelInquirerWs, ContractInquirer, ContractInquirerWs, - LicenseSession, LicenseSessionId, StreamAux, + block::*, ContractInquirer, ContractInquirerWs, StreamAux, }; pub use error::Error; pub use json_loader::JsonLoader; pub use tx_retrievals::{BcInquirer, TxAwaiter, TxRetriever}; -pub use types::*; diff --git a/moat-core/src/tx_retrievals/bc_inquirer.rs b/moat-core/src/tx_retrievals/bc_inquirer.rs index fc136fb..b5d205d 100644 --- a/moat-core/src/tx_retrievals/bc_inquirer.rs +++ b/moat-core/src/tx_retrievals/bc_inquirer.rs @@ -4,8 +4,8 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use crate::bc_types::*; use crate::error::Error; -use crate::types::*; use dusk_wallet::{RuskHttpClient, RuskRequest}; pub struct BcInquirer; diff --git a/moat-core/src/tx_retrievals/tx_awaiter.rs b/moat-core/src/tx_retrievals/tx_awaiter.rs index b8f74e5..8998077 100644 --- a/moat-core/src/tx_retrievals/tx_awaiter.rs +++ b/moat-core/src/tx_retrievals/tx_awaiter.rs @@ -4,9 +4,9 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::types::{SpentTx2, SpentTxResponse2, TxStatus}; +use crate::bc_types::{SpentTx2, SpentTxResponse2, TxStatus}; use crate::Error; -use crate::Error::TransactionError; +use crate::Error::Transaction; use dusk_bls12_381::BlsScalar; use dusk_wallet::{RuskHttpClient, RuskRequest}; use std::time::Duration; @@ -74,7 +74,7 @@ impl TxAwaiter { match status { TxStatus::Ok => break, TxStatus::Error(err) => { - return Err(TransactionError(Box::from(err)))? + return Err(Transaction(Box::from(err)))? } TxStatus::NotFound => { trace!("Awaiting ({}) for {}", i, tx_id.as_ref()); @@ -84,7 +84,7 @@ impl TxAwaiter { } } if i > TIMEOUT_SECS { - Err(TransactionError(Box::from("Confirmation timed out"))) + Err(Transaction(Box::from("Confirmation timed out"))) } else { Ok(()) } diff --git a/moat-core/src/tx_retrievals/tx_retriever.rs b/moat-core/src/tx_retrievals/tx_retriever.rs index 570ea49..1afa3a7 100644 --- a/moat-core/src/tx_retrievals/tx_retriever.rs +++ b/moat-core/src/tx_retrievals/tx_retriever.rs @@ -4,8 +4,8 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. +use crate::bc_types::*; use crate::error::Error; -use crate::types::*; use crate::Error::TransactionNotFound; use crate::{BcInquirer, QueryResult}; use dusk_wallet::RuskHttpClient;