Skip to content

Commit

Permalink
Remove vcx_schema_prepare_for_endorser (#860)
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
  • Loading branch information
mirgee authored May 24, 2023
1 parent 2e8c737 commit d770c96
Show file tree
Hide file tree
Showing 17 changed files with 1,783 additions and 434 deletions.
8 changes: 1 addition & 7 deletions aries_vcx/src/global/author_agreement.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::errors::error::VcxResult;
use aries_vcx_core::global::author_agreement::{
get_txn_author_agreement, set_txn_author_agreement, TxnAuthorAgreementAcceptanceData,
};
use aries_vcx_core::global::author_agreement::{set_txn_author_agreement, TxnAuthorAgreementAcceptanceData};

pub fn proxy_set_txn_author_agreement(
text: Option<String>,
Expand All @@ -12,7 +10,3 @@ pub fn proxy_set_txn_author_agreement(
) -> VcxResult<()> {
set_txn_author_agreement(text, version, taa_digest, acc_mech_type, time_of_acceptance).map_err(|err| err.into())
}

pub fn proxy_get_txn_author_agreement() -> VcxResult<Option<TxnAuthorAgreementAcceptanceData>> {
get_txn_author_agreement().map_err(|err| err.into())
}
1,811 changes: 1,769 additions & 42 deletions aries_vcx/src/utils/constants.rs

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions aries_vcx/src/utils/mockdata/profile/mock_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_trait::async_trait;

use crate::utils::{
self,
constants::{rev_def_json, CRED_DEF_JSON, REV_REG_DELTA_JSON, REV_REG_ID, REV_REG_JSON, SCHEMA_JSON, SCHEMA_TXN},
constants::{rev_def_json, CRED_DEF_JSON, REV_REG_DELTA_JSON, REV_REG_ID, REV_REG_JSON, SCHEMA_JSON},
};

#[derive(Debug)]
Expand All @@ -15,10 +15,6 @@ pub(crate) struct MockLedger;
#[allow(unused)]
#[async_trait]
impl BaseLedger for MockLedger {
async fn sign_and_submit_request(&self, submitter_did: &str, request_json: &str) -> VcxCoreResult<String> {
Ok(r#"{"rc":"success"}"#.to_string())
}

async fn submit_request(&self, request_json: &str) -> VcxCoreResult<String> {
// not needed yet
Err(AriesVcxCoreError::from_msg(
Expand Down Expand Up @@ -95,10 +91,6 @@ impl BaseLedger for MockLedger {
Ok(r#"{"rc":"success"}"#.to_string())
}

async fn build_schema_request(&self, submitter_did: &str, schema_json: &str) -> VcxCoreResult<String> {
Ok(SCHEMA_TXN.to_string())
}

async fn publish_schema(
&self,
schema_json: &str,
Expand Down
29 changes: 0 additions & 29 deletions aries_vcx/tests/test_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,6 @@ mod integration_tests {
.await;
}

#[tokio::test]
#[ignore]
async fn test_endorse_transaction() {
SetupProfile::run(|setup| async move {
let ledger = Arc::clone(&setup.profile).inject_ledger();
let (author_did, _) = add_new_did(&setup.profile, &setup.institution_did, None).await.unwrap();
let (endorser_did, _) = add_new_did(&setup.profile, &setup.institution_did, Some("ENDORSER"))
.await
.unwrap();

let schema_request = ledger.build_schema_request(&author_did, SCHEMA_DATA).await.unwrap();
let schema_request = ledger
.set_endorser(&author_did, &schema_request, &endorser_did)
.await
.unwrap();
ledger
.endorse_transaction(&endorser_did, &schema_request)
.await
.unwrap();
let schema_data: SchemaData = serde_json::from_str(&SCHEMA_DATA).unwrap();
let schema_id = format!("{}:2:{}:1.0", author_did, schema_data.name);
thread::sleep(Duration::from_millis(50));
Schema::create_from_ledger_json(&setup.profile, "source_id", &schema_id)
.await
.unwrap();
})
.await;
}

#[tokio::test]
#[ignore]
async fn test_pool_add_get_service() {
Expand Down
6 changes: 0 additions & 6 deletions aries_vcx_core/src/ledger/base_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use crate::errors::error::VcxCoreResult;
/// Trait defining standard 'ledger' related functionality.
#[async_trait]
pub trait BaseLedger: std::fmt::Debug + Send + Sync {
// returns request result as JSON
async fn sign_and_submit_request(&self, submitter_did: &str, request_json: &str) -> VcxCoreResult<String>;

// returns request result as JSON
async fn submit_request(&self, request_json: &str) -> VcxCoreResult<String>;

Expand Down Expand Up @@ -104,9 +101,6 @@ pub trait BaseLedger: std::fmt::Debug + Send + Sync {
// returns request result as JSON
async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult<String>;

// returns request as JSON
async fn build_schema_request(&self, submitter_did: &str, schema_json: &str) -> VcxCoreResult<String>;

async fn publish_schema(
&self,
schema_json: &str,
Expand Down
14 changes: 0 additions & 14 deletions aries_vcx_core/src/ledger/indy_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ impl IndySdkLedger {

#[async_trait]
impl BaseLedger for IndySdkLedger {
async fn sign_and_submit_request(&self, submitter_did: &str, request_json: &str) -> VcxCoreResult<String> {
indy::ledger::transactions::libindy_sign_and_submit_request(
self.indy_wallet_handle,
self.indy_pool_handle,
submitter_did,
request_json,
)
.await
}

async fn submit_request(&self, request_json: &str) -> VcxCoreResult<String> {
indy::ledger::transactions::libindy_submit_request(self.indy_pool_handle, request_json).await
}
Expand Down Expand Up @@ -143,10 +133,6 @@ impl BaseLedger for IndySdkLedger {
.await
}

async fn build_schema_request(&self, submitter_did: &str, schema_json: &str) -> VcxCoreResult<String> {
indy::ledger::transactions::build_schema_request(submitter_did, schema_json).await
}

async fn publish_schema(
&self,
schema_json: &str,
Expand Down
12 changes: 0 additions & 12 deletions aries_vcx_core/src/ledger/indy_vdr_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ where
U: RequestSigner + Send + Sync,
V: ResponseCacher + Send + Sync,
{
async fn sign_and_submit_request(&self, submitter_did: &str, request_json: &str) -> VcxCoreResult<String> {
let request = PreparedRequest::from_request_json(request_json)?;

self._sign_and_submit_request(submitter_did, request).await
}

async fn submit_request(&self, request_json: &str) -> VcxCoreResult<String> {
let request = PreparedRequest::from_request_json(request_json)?;
self._submit_request(request).await
Expand Down Expand Up @@ -388,12 +382,6 @@ where
self._submit_request(request).await
}

async fn build_schema_request(&self, submitter_did: &str, schema_json: &str) -> VcxCoreResult<String> {
let request = self._build_schema_request(submitter_did, schema_json)?;
let request = _append_txn_author_agreement_to_request(request).await?;
Ok(request.req_json.to_string())
}

async fn publish_schema(
&self,
schema_json: &str,
Expand Down
3 changes: 1 addition & 2 deletions aries_vcx_core/src/ledger/response_cacher/in_memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod options;
pub use config::*;
pub use options::*;

use std::collections::HashMap;
use std::sync::Arc;
use std::time::Instant;

Expand Down Expand Up @@ -161,7 +160,7 @@ mod tests {

#[tokio::test]
async fn test_get_options_ttl_override_global_config_ttl() -> VcxCoreResult<()> {
let cacher = InMemoryResponseCacher::new(_cacher_config((Duration::from_millis(1))));
let cacher = InMemoryResponseCacher::new(_cacher_config(Duration::from_millis(1)));
let test_object = _test_object();

cacher.put("id1", test_object.clone()).await?;
Expand Down
4 changes: 2 additions & 2 deletions aries_vcx_core/src/ledger/response_cacher/noop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ impl NoopResponseCacher {
impl ResponseCacher for NoopResponseCacher {
type Options = ();

async fn put<S, T>(&self, id: S, obj: T) -> VcxCoreResult<()>
async fn put<S, T>(&self, _id: S, _obj: T) -> VcxCoreResult<()>
where
S: ToString + Send,
T: Serialize + for<'de> Deserialize<'de> + Send,
{
Ok(())
}

async fn get<S, T>(&self, id: S, opt: Option<Self::Options>) -> VcxCoreResult<Option<T>>
async fn get<S, T>(&self, _id: S, _opt: Option<Self::Options>) -> VcxCoreResult<Option<T>>
where
S: ToString + Send,
T: Serialize + for<'de> Deserialize<'de> + Send,
Expand Down
1 change: 0 additions & 1 deletion indy_ledger_response_parser/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use]
extern crate serde;

#[macro_use]
extern crate serde_json;

mod domain;
Expand Down
115 changes: 2 additions & 113 deletions libvcx/src/api_c/ledger/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,74 +84,6 @@ pub extern "C" fn vcx_schema_create(
SUCCESS_ERR_CODE
}

/// Create a new Schema object that will be published by Endorser later.
///
/// Note that Schema can't be used for credential issuing until it will be published on the ledger.
///
/// #Params
/// command_handle: command handle to map callback to user context.
///
/// source_id: Enterprise's personal identification for the user.
///
/// schema_name: Name of schema
///
/// version: version of schema
///
/// schema_data: list of attributes that will make up the schema (the number of attributes should be less or equal than 125)
///
/// endorser: DID of the Endorser that will submit the transaction.
///
/// # Example schema_data -> "["attr1", "attr2", "attr3"]"
///
/// cb: Callback that provides Schema handle and Schema transaction that should be passed to Endorser for publishing.
///
/// #Returns
/// Error code as a u32
#[no_mangle]
pub extern "C" fn vcx_schema_prepare_for_endorser(
command_handle: CommandHandle,
source_id: *const c_char,
schema_name: *const c_char,
version: *const c_char,
schema_data: *const c_char,
endorser: *const c_char,
cb: Option<
extern "C" fn(xcommand_handle: CommandHandle, err: u32, schema_handle: u32, schema_transaction: *const c_char),
>,
) -> u32 {
info!("vcx_schema_prepare_for_endorser >>>");

check_useful_c_callback!(cb, LibvcxErrorKind::InvalidOption);
check_useful_c_str!(schema_name, LibvcxErrorKind::InvalidOption);
check_useful_c_str!(version, LibvcxErrorKind::InvalidOption);
check_useful_c_str!(source_id, LibvcxErrorKind::InvalidOption);
check_useful_c_str!(schema_data, LibvcxErrorKind::InvalidOption);
check_useful_c_str!(endorser, LibvcxErrorKind::InvalidOption);

trace!(target: "vcx", "vcx_schema_prepare_for_endorser(command_handle: {}, source_id: {}, schema_name: {}, schema_data: {}, endorser: {})",
command_handle, source_id, schema_name, schema_data, endorser);

execute_async::<BoxFuture<'static, Result<(), ()>>>(Box::pin(async move {
match schema::prepare_schema_for_endorser(&source_id, schema_name, version, schema_data, endorser).await {
Ok((handle, transaction)) => {
trace!(target: "vcx", "vcx_schema_prepare_for_endorser(command_handle: {}, rc: {}, handle: {}, transaction: {}) source_id: {}",
command_handle, SUCCESS_ERR_CODE, handle, transaction, source_id);
let transaction = CStringUtils::string_to_cstring(transaction);
cb(command_handle, SUCCESS_ERR_CODE, handle, transaction.as_ptr());
}
Err(err) => {
set_current_error_vcx(&err);
error!("vcx_schema_prepare_for_endorser(command_handle: {}, rc: {}, handle: {}, transaction: {}) source_id: {}", command_handle, err, 0, "", source_id);
cb(command_handle, err.into(), 0, ptr::null_mut());
}
};

Ok(())
}));

SUCCESS_ERR_CODE
}

/// Takes the schema object and returns a json string of all its attributes
///
/// #Params
Expand Down Expand Up @@ -566,7 +498,6 @@ mod tests {
use aries_vcx::utils::devsetup::SetupMocks;
use libvcx_core::api_vcx::api_global::settings;
use libvcx_core::api_vcx::api_global::settings::get_config_value;
use libvcx_core::api_vcx::api_handle::schema::prepare_schema_for_endorser;
use libvcx_core::api_vcx::api_handle::schema::test_utils::prepare_schema_data;
use libvcx_core::errors;

Expand Down Expand Up @@ -680,55 +611,13 @@ mod tests {
assert_eq!(schema_as_json["data"].to_string(), data);
}

#[test]
#[cfg(feature = "general_test")]
fn test_vcx_prepare_schema_success() {
let _setup = SetupMocks::init();

let cb = return_types_u32::Return_U32_U32_STR::new().unwrap();
assert_eq!(
vcx_schema_prepare_for_endorser(
cb.command_handle,
CString::new("Test Source ID").unwrap().into_raw(),
CString::new("Test Schema").unwrap().into_raw(),
CString::new("0.0").unwrap().into_raw(),
CString::new("[\"attr\", \"att2\"]").unwrap().into_raw(),
CString::new("V4SGRU86Z58d6TV7PBUe6f").unwrap().into_raw(),
Some(cb.get_callback()),
),
SUCCESS_ERR_CODE
);
let (_handle, schema_transaction) = cb.receive(TimeoutUtils::some_short()).unwrap();
let schema_transaction = schema_transaction.unwrap();
let schema_transaction: serde_json::Value = serde_json::from_str(&schema_transaction).unwrap();
let expected_schema_transaction: serde_json::Value =
serde_json::from_str(utils::constants::REQUEST_WITH_ENDORSER).unwrap();
assert_eq!(expected_schema_transaction, schema_transaction);
}

#[tokio::test]
#[cfg(feature = "general_test")]
async fn test_vcx_schema_get_state() {
let _setup = SetupMocks::init();

let did = get_config_value(CONFIG_INSTITUTION_DID).unwrap();
let (handle, _) = prepare_schema_for_endorser(
"testid",
"name".to_string(),
"1.0".to_string(),
"[\"name\",\"gender\"]".to_string(),
"V4SGRU86Z58d6TV7PBUe6f".to_string(),
)
.await
.unwrap();
{
let cb = return_types_u32::Return_U32_U32::new().unwrap();
let _rc = vcx_schema_get_state(cb.command_handle, handle, Some(cb.get_callback()));
assert_eq!(
cb.receive(TimeoutUtils::some_medium()).unwrap(),
PublicEntityStateType::Built as u32
)
}
let (_, schema_name, schema_version, data) = prepare_schema_data();
let handle = vcx_schema_create_c_closure(&schema_name, &schema_version, &data).unwrap();
{
let cb = return_types_u32::Return_U32_U32::new().unwrap();
let _rc = vcx_schema_update_state(cb.command_handle, handle, Some(cb.get_callback()));
Expand Down
Loading

0 comments on commit d770c96

Please sign in to comment.