Skip to content

Commit 2a6ff8d

Browse files
author
Vyacheslav
authored
Merge pull request hyperledger-indy#659 from SergeyPalamarchuk/get_validator_info
Get validator info
2 parents 173dc78 + 7e86939 commit 2a6ff8d

File tree

26 files changed

+539
-19
lines changed

26 files changed

+539
-19
lines changed

ci/indy-pool.dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ RUN pip3 install -U \
1919
setuptools
2020

2121
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 68DB5E88
22-
ARG indy_stream=rc
22+
ARG indy_stream=master
2323
RUN echo "deb https://repo.sovrin.org/deb xenial $indy_stream" >> /etc/apt/sources.list
2424

2525
RUN useradd -ms /bin/bash -u $uid indy
2626

27-
ARG indy_plenum_ver=1.2.38
28-
ARG indy_anoncreds_ver=1.0.11
29-
ARG indy_node_ver=1.3.56
30-
ARG python3_indy_crypto_ver=0.2.0
31-
ARG indy_crypto_ver=0.1.6
27+
ARG indy_plenum_ver=1.2.369
28+
ARG indy_anoncreds_ver=1.0.32
29+
ARG indy_node_ver=1.3.425
30+
ARG python3_indy_crypto_ver=0.4.1
31+
ARG indy_crypto_ver=0.4.0
3232

3333
RUN apt-get update -y && apt-get install -y \
3434
indy-plenum=${indy_plenum_ver} \

cli/src/commands/ledger.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,47 @@ pub mod schema_command {
326326
}
327327
}
328328

329+
pub mod get_validator_info_command {
330+
use super::*;
331+
332+
command!(CommandMetadata::build("get-validator-info", "Get validator info from all nodes.")
333+
.add_example(r#"ledger get-validator-info"#)
334+
.finalize()
335+
);
336+
337+
fn execute(ctx: &CommandContext, params: &CommandParams) -> Result<(), ()> {
338+
trace!("execute >> ctx {:?} params {:?}", ctx, params);
339+
340+
let submitter_did = ensure_active_did(&ctx)?;
341+
let pool_handle = ensure_connected_pool_handle(&ctx)?;
342+
let wallet_handle = ensure_opened_wallet_handle(&ctx)?;
343+
344+
let response = Ledger::build_get_validator_info_request(&submitter_did)
345+
.and_then(|request| Ledger::sign_and_submit_request(pool_handle, wallet_handle, &submitter_did, &request))
346+
.map_err(|err| handle_transaction_error(err, None, None, None))?;
347+
348+
let responses = match serde_json::from_str::<HashMap<String, String>>(&response) {
349+
Ok(responses) => responses,
350+
Err(err) => {
351+
let response = serde_json::from_str::<Response<serde_json::Value>>(&response)
352+
.map_err(|err| println_err!("Invalid data has been received: {:?}", err))?;
353+
return handle_transaction_response(response).map(|result| println_succ!("{}", result));
354+
}
355+
};
356+
357+
for (node, response) in responses {
358+
let response = serde_json::from_str::<Response<serde_json::Value>>(&response)
359+
.map_err(|err| println_err!("Invalid data has been received: {:?}", err))?;
360+
println_succ!("Get validator info response for node {}:", node);
361+
let _res = handle_transaction_response(response).map(|result| println!("{}", result));
362+
}
363+
let res = Ok(());
364+
365+
trace!("execute << {:?}", res);
366+
res
367+
}
368+
}
369+
329370
pub mod get_schema_command {
330371
use super::*;
331372

@@ -1950,6 +1991,30 @@ pub mod tests {
19501991
}
19511992
}
19521993

1994+
mod get_validator_info {
1995+
use super::*;
1996+
1997+
#[test]
1998+
pub fn get_validator_info_works() {
1999+
TestUtils::cleanup_storage();
2000+
let ctx = CommandContext::new();
2001+
2002+
create_and_open_wallet(&ctx);
2003+
create_and_connect_pool(&ctx);
2004+
2005+
new_did(&ctx, SEED_TRUSTEE);
2006+
use_did(&ctx, DID_TRUSTEE);
2007+
{
2008+
let cmd = get_validator_info_command::new();
2009+
let mut params = CommandParams::new();
2010+
cmd.execute(&ctx, &params).unwrap();
2011+
}
2012+
close_and_delete_wallet(&ctx);
2013+
disconnect_and_delete_pool(&ctx);
2014+
TestUtils::cleanup_storage();
2015+
}
2016+
}
2017+
19532018
mod get_schema {
19542019
use super::*;
19552020

cli/src/libindy/ledger.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ impl Ledger {
191191
super::results::result_to_string(err, receiver)
192192
}
193193

194+
pub fn build_get_validator_info_request(submitter_did: &str) -> Result<String, ErrorCode> {
195+
let (receiver, command_handle, cb) = super::callbacks::_closure_to_cb_ec_string();
196+
197+
let submitter_did = CString::new(submitter_did).unwrap();
198+
199+
let err = unsafe {
200+
indy_build_get_validator_info_request(command_handle,
201+
submitter_did.as_ptr(),
202+
cb)
203+
};
204+
205+
super::results::result_to_string(err, receiver)
206+
}
207+
194208
pub fn build_get_cred_def_request(submitter_did: &str, id: &str) -> Result<String, ErrorCode> {
195209
let (receiver, command_handle, cb) = super::callbacks::_closure_to_cb_ec_string();
196210

@@ -360,6 +374,11 @@ extern {
360374
id: *const c_char,
361375
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode, request_json: *const c_char)>) -> ErrorCode;
362376

377+
#[no_mangle]
378+
fn indy_build_get_validator_info_request(command_handle: i32,
379+
submitter_did: *const c_char,
380+
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode, request_json: *const c_char)>) -> ErrorCode;
381+
363382
#[no_mangle]
364383
fn indy_build_cred_def_request(command_handle: i32,
365384
submitter_did: *const c_char,

cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ fn build_executor() -> CommandExecutor {
9595
.add_command(ledger::get_attrib_command::new())
9696
.add_command(ledger::schema_command::new())
9797
.add_command(ledger::get_schema_command::new())
98+
.add_command(ledger::get_validator_info_command::new())
9899
.add_command(ledger::cred_def_command::new())
99100
.add_command(ledger::get_cred_def_command::new())
100101
.add_command(ledger::node_command::new())

libindy/include/indy_ledger.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,27 @@ extern "C" {
476476
const char* request_json)
477477
);
478478

479+
/// Builds a GET_VALIDATOR_INFO request.
480+
///
481+
/// #Params
482+
/// command_handle: command handle to map callback to caller context.
483+
/// submitter_did: Id of Identity stored in secured Wallet.
484+
/// cb: Callback that takes command result as parameter.
485+
///
486+
/// #Returns
487+
/// Request result as json.
488+
///
489+
/// #Errors
490+
/// Common*
491+
492+
extern indy_error_t indy_build_get_validator_info_request(indy_handle_t command_handle,
493+
const char * submitter_did,
494+
void (*cb)(indy_handle_t xcommand_handle,
495+
indy_error_t err,
496+
const char* request_json)
497+
);
498+
499+
479500
/// Builds a GET_TXN request. Request to get any transaction by its seq_no.
480501
///
481502
/// #Params

libindy/src/api/ledger.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,39 @@ pub extern fn indy_build_node_request(command_handle: i32,
889889
res
890890
}
891891

892+
/// Builds a GET_VALIDATOR_INFO request.
893+
///
894+
/// #Params
895+
/// command_handle: command handle to map callback to caller context.
896+
/// submitter_did: Id of Identity stored in secured Wallet.
897+
/// cb: Callback that takes command result as parameter.
898+
///
899+
/// #Returns
900+
/// Request result as json.
901+
///
902+
/// #Errors
903+
/// Common*
904+
#[no_mangle]
905+
pub extern fn indy_build_get_validator_info_request(command_handle: i32,
906+
submitter_did: *const c_char,
907+
cb: Option<extern fn(xcommand_handle: i32, err: ErrorCode,
908+
request_json: *const c_char)>) -> ErrorCode {
909+
check_useful_c_str!(submitter_did, ErrorCode::CommonInvalidParam2);
910+
check_useful_c_callback!(cb, ErrorCode::CommonInvalidParam4);
911+
912+
let result = CommandExecutor::instance()
913+
.send(Command::Ledger(LedgerCommand::BuildGetValidatorInfoRequest(
914+
submitter_did,
915+
Box::new(move |result| {
916+
let (err, request_json) = result_to_err_code_1!(result, String::new());
917+
let request_json = CStringUtils::string_to_cstring(request_json);
918+
cb(command_handle, err, request_json.as_ptr())
919+
})
920+
)));
921+
922+
result_to_err_code!(result)
923+
}
924+
892925
/// Builds a GET_TXN request. Request to get any transaction by its seq_no.
893926
///
894927
/// #Params

libindy/src/commands/ledger.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ pub enum LedgerCommand {
108108
String, // target_did
109109
String, // data
110110
Box<Fn(Result<String, IndyError>) + Send>),
111+
BuildGetValidatorInfoRequest(
112+
String, // submitter did
113+
Box<Fn(Result<String, IndyError>) + Send>),
111114
BuildGetTxnRequest(
112115
String, // submitter did
113116
i32, // data
@@ -274,6 +277,10 @@ impl LedgerCommandExecutor {
274277
info!(target: "ledger_command_executor", "BuildNodeRequest command received");
275278
cb(self.build_node_request(&submitter_did, &target_did, &data));
276279
}
280+
LedgerCommand::BuildGetValidatorInfoRequest(submitter_did, cb) => {
281+
info!(target: "ledger_command_executor", "BuildGetValidatorInfoRequest command received");
282+
cb(self.build_get_validator_info_request(&submitter_did));
283+
}
277284
LedgerCommand::BuildGetTxnRequest(submitter_did, data, cb) => {
278285
info!(target: "ledger_command_executor", "BuildGetTxnRequest command received");
279286
cb(self.build_get_txn_request(&submitter_did, data));
@@ -640,6 +647,19 @@ impl LedgerCommandExecutor {
640647
Ok(res)
641648
}
642649

650+
fn build_get_validator_info_request(&self,
651+
submitter_did: &str) -> Result<String, IndyError> {
652+
info!("build_get_validator_info_request >>> submitter_did: {:?}", submitter_did);
653+
654+
self.crypto_service.validate_did(submitter_did)?;
655+
656+
let res = self.ledger_service.build_get_validator_info_request(submitter_did)?;
657+
658+
info!("build_get_validator_info_request <<< res: {:?}", res);
659+
660+
Ok(res)
661+
}
662+
643663
fn build_get_txn_request(&self,
644664
submitter_did: &str,
645665
data: i32) -> Result<String, IndyError> {

libindy/src/services/ledger/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub const SCHEMA: &'static str = "101";
55
pub const CRED_DEF: &'static str = "102";
66
pub const GET_ATTR: &'static str = "104";
77
pub const GET_NYM: &'static str = "105";
8+
pub const GET_VALIDATOR_INFO: &'static str = "119";
89
pub const GET_TXN: &'static str = "3";
910
pub const GET_SCHEMA: &'static str = "107";
1011
pub const GET_CRED_DEF: &'static str = "108";

libindy/src/services/ledger/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ impl LedgerService {
239239
Ok(request)
240240
}
241241

242+
pub fn build_get_validator_info_request(&self, identifier: &str) -> Result<String, CommonError> {
243+
let operation = GetValidatorInfoOperation::new();
244+
LedgerService::build_request(identifier, operation, "GET_VALIDATOR_INFO")
245+
.map_err(|err| CommonError::InvalidState(format!("Invalid get validator info request json: {:?}", err)))
246+
}
247+
242248
pub fn build_get_txn_request(&self, identifier: &str, data: i32) -> Result<String, CommonError> {
243249
info!("build_get_txn_request >>> identifier: {:?}, data {:?}", identifier, data);
244250

libindy/src/services/ledger/types.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,22 @@ impl GetDdoOperation {
303303

304304
impl JsonEncodable for GetDdoOperation {}
305305

306+
#[derive(Serialize, PartialEq, Debug)]
307+
pub struct GetValidatorInfoOperation {
308+
#[serde(rename = "type")]
309+
pub _type: String,
310+
}
311+
312+
impl GetValidatorInfoOperation {
313+
pub fn new() -> GetValidatorInfoOperation {
314+
GetValidatorInfoOperation {
315+
_type: GET_VALIDATOR_INFO.to_string(),
316+
}
317+
}
318+
}
319+
320+
impl JsonEncodable for GetValidatorInfoOperation {}
321+
306322
#[derive(Serialize, PartialEq, Debug)]
307323
pub struct GetTxnOperation {
308324
#[serde(rename = "type")]

0 commit comments

Comments
 (0)