Skip to content

Commit 7bed154

Browse files
committed
Updated Libindy and Libnullpay
Signed-off-by: artem.ivanov <[email protected]>
1 parent d21b56c commit 7bed154

File tree

26 files changed

+727
-626
lines changed

26 files changed

+727
-626
lines changed

libindy/debian/changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ libindy (1.5.0) unstable; urgency=medium
2424
[the main payments operations](https://github.com/hyperledger/indy-sdk/tree/master/doc/design/007-cli-payments):
2525
* Creation of payment address
2626
* Listing of payment addresses
27-
* Getting list of UTXO for payment address
27+
* Getting list of sources for payment address
2828
* Sending payment transaction
2929
* Adding fees to transactions
3030
* Getting transactions fees amount

libindy/include/indy_payment.h

Lines changed: 138 additions & 85 deletions
Large diffs are not rendered by default.

libindy/src/api/payments.rs

Lines changed: 71 additions & 54 deletions
Large diffs are not rendered by default.

libindy/src/commands/payments.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ pub enum PaymentsCommand {
4848
ParseResponseWithFeesAck(
4949
i32, //handle
5050
Result<String, PaymentsError>),
51-
BuildGetUtxoRequest(
51+
BuildGetSourcesRequest(
5252
i32, //wallet_handle
5353
String, //submitter did
5454
String, //payment address
5555
Box<Fn(Result<(String, String), IndyError>) + Send>),
56-
BuildGetUtxoRequestAck(
56+
BuildGetSourcesRequestAck(
5757
i32, //handle
5858
Result<String, PaymentsError>),
59-
ParseGetUtxoResponse(
59+
ParseGetSourcesResponse(
6060
String, //type
6161
String, //response
6262
Box<Fn(Result<String, IndyError>) + Send>),
63-
ParseGetUtxoResponseAck(
63+
ParseGetSourcesResponseAck(
6464
i32, //cmd_handle
6565
Result<String, PaymentsError>),
6666
BuildPaymentReq(
@@ -164,21 +164,21 @@ impl PaymentsCommandExecutor {
164164
info!(target: "payments_command_executor", "ParseResponseWithFeesAck command received");
165165
self.parse_response_with_fees_ack(cmd_handle, result);
166166
}
167-
PaymentsCommand::BuildGetUtxoRequest(wallet_handle, submitter_did, payment_address, cb) => {
168-
info!(target: "payments_command_executor", "BuildGetUtxoRequest command received");
169-
self.build_get_utxo_request(wallet_handle, &submitter_did, &payment_address, cb);
167+
PaymentsCommand::BuildGetSourcesRequest(wallet_handle, submitter_did, payment_address, cb) => {
168+
info!(target: "payments_command_executor", "BuildGetSourcesRequest command received");
169+
self.build_get_sources_request(wallet_handle, &submitter_did, &payment_address, cb);
170170
}
171-
PaymentsCommand::BuildGetUtxoRequestAck(cmd_handle, result) => {
172-
info!(target: "payments_command_executor", "BuildGetUtxoRequestAck command received");
173-
self.build_get_utxo_request_ack(cmd_handle, result);
171+
PaymentsCommand::BuildGetSourcesRequestAck(cmd_handle, result) => {
172+
info!(target: "payments_command_executor", "BuildGetSourcesRequestAck command received");
173+
self.build_get_sources_request_ack(cmd_handle, result);
174174
}
175-
PaymentsCommand::ParseGetUtxoResponse(type_, response, cb) => {
176-
info!(target: "payments_command_executor", "ParseGetUtxoResponse command received");
177-
self.parse_get_utxo_response(&type_, &response, cb);
175+
PaymentsCommand::ParseGetSourcesResponse(type_, response, cb) => {
176+
info!(target: "payments_command_executor", "ParseGetSourcesResponse command received");
177+
self.parse_get_sources_response(&type_, &response, cb);
178178
}
179-
PaymentsCommand::ParseGetUtxoResponseAck(cmd_handle, result) => {
180-
info!(target: "payments_command_executor", "ParseGetUtxoResponseAck command received");
181-
self.parse_get_utxo_response_ack(cmd_handle, result);
179+
PaymentsCommand::ParseGetSourcesResponseAck(cmd_handle, result) => {
180+
info!(target: "payments_command_executor", "ParseGetSourcesResponseAck command received");
181+
self.parse_get_sources_response_ack(cmd_handle, result);
182182
}
183183
PaymentsCommand::BuildPaymentReq(wallet_handle, submitter_did, inputs, outputs, cb) => {
184184
info!(target: "payments_command_executor", "BuildPaymentReq command received");
@@ -351,8 +351,8 @@ impl PaymentsCommandExecutor {
351351
trace!("parse_response_with_fees_ack <<<");
352352
}
353353

354-
fn build_get_utxo_request(&self, wallet_handle: i32, submitter_did: &str, payment_address: &str, cb: Box<Fn(Result<(String, String), IndyError>) + Send>) {
355-
trace!("build_get_utxo_request >>> wallet_handle: {:?}, submitter_did: {:?}, payment_address: {:?}", wallet_handle, submitter_did, payment_address);
354+
fn build_get_sources_request(&self, wallet_handle: i32, submitter_did: &str, payment_address: &str, cb: Box<Fn(Result<(String, String), IndyError>) + Send>) {
355+
trace!("build_get_sources_request >>> wallet_handle: {:?}, submitter_did: {:?}, payment_address: {:?}", wallet_handle, submitter_did, payment_address);
356356
match self.crypto_service.validate_did(submitter_did).map_err(map_err_err!()) {
357357
Err(err) => return cb(Err(IndyError::from(err))),
358358
_ => ()
@@ -372,28 +372,28 @@ impl PaymentsCommandExecutor {
372372
let method_copy = method.to_string();
373373

374374
self._process_method(
375-
Box::new(move |get_utxo_txn_json| cb(get_utxo_txn_json.map(|s| (s, method.to_string())))),
376-
&|i| self.payments_service.build_get_utxo_request(i, &method_copy, wallet_handle, &submitter_did, payment_address)
375+
Box::new(move |get_sources_txn_json| cb(get_sources_txn_json.map(|s| (s, method.to_string())))),
376+
&|i| self.payments_service.build_get_sources_request(i, &method_copy, wallet_handle, &submitter_did, payment_address)
377377
);
378-
trace!("build_get_utxo_request <<<");
378+
trace!("build_get_sources_request <<<");
379379
}
380380

381-
fn build_get_utxo_request_ack(&self, cmd_handle: i32, result: Result<String, PaymentsError>) {
382-
trace!("build_get_utxo_request_ack >>> result: {:?}", result);
383-
self._common_ack_payments(cmd_handle, result, "BuildGetUtxoRequestAck");
384-
trace!("build_get_utxo_request_ack <<<");
381+
fn build_get_sources_request_ack(&self, cmd_handle: i32, result: Result<String, PaymentsError>) {
382+
trace!("build_get_sources_request_ack >>> result: {:?}", result);
383+
self._common_ack_payments(cmd_handle, result, "BuildGetSourcesRequestAck");
384+
trace!("build_get_sources_request_ack <<<");
385385
}
386386

387-
fn parse_get_utxo_response(&self, type_: &str, response: &str, cb: Box<Fn(Result<String, IndyError>) + Send>) {
388-
trace!("parse_get_utxo_response >>> response: {:?}", response);
389-
self._process_method(cb, &|i| self.payments_service.parse_get_utxo_response(i, type_, response));
390-
trace!("parse_get_utxo_response <<<");
387+
fn parse_get_sources_response(&self, type_: &str, response: &str, cb: Box<Fn(Result<String, IndyError>) + Send>) {
388+
trace!("parse_get_sources_response >>> response: {:?}", response);
389+
self._process_method(cb, &|i| self.payments_service.parse_get_sources_response(i, type_, response));
390+
trace!("parse_get_sources_response <<<");
391391
}
392392

393-
fn parse_get_utxo_response_ack(&self, cmd_handle: i32, result: Result<String, PaymentsError>) {
394-
trace!("parse_get_utxo_response_ack >>> result: {:?}", result);
395-
self._common_ack_payments(cmd_handle, result, "ParseGetUtxoResponseAck");
396-
trace!("parse_get_utxo_response_ack <<<");
393+
fn parse_get_sources_response_ack(&self, cmd_handle: i32, result: Result<String, PaymentsError>) {
394+
trace!("parse_get_sources_response_ack >>> result: {:?}", result);
395+
self._common_ack_payments(cmd_handle, result, "ParseGetSourcesResponseAck");
396+
trace!("parse_get_sources_response_ack <<<");
397397
}
398398

399399
fn build_payment_req(&self, wallet_handle: i32, submitter_did: &str, inputs: &str, outputs: &str, cb: Box<Fn(Result<(String, String), IndyError>) + Send>) {

libindy/src/services/payments.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub struct PaymentsMethod {
2020
create_address: CreatePaymentAddressCB,
2121
add_request_fees: AddRequestFeesCB,
2222
parse_response_with_fees: ParseResponseWithFeesCB,
23-
build_get_utxo_request: BuildGetUTXORequestCB,
24-
parse_get_utxo_response: ParseGetUTXOResponseCB,
23+
build_get_sources_request: BuildGetSourcesRequestCB,
24+
parse_get_sources_response: ParseGetSourcesResponseCB,
2525
build_payment_req: BuildPaymentReqCB,
2626
parse_payment_response: ParsePaymentResponseCB,
2727
build_mint_req: BuildMintReqCB,
@@ -36,8 +36,8 @@ impl PaymentsMethodCBs {
3636
pub fn new(create_address: CreatePaymentAddressCB,
3737
add_request_fees: AddRequestFeesCB,
3838
parse_response_with_fees: ParseResponseWithFeesCB,
39-
build_get_utxo_request: BuildGetUTXORequestCB,
40-
parse_get_utxo_response: ParseGetUTXOResponseCB,
39+
build_get_sources_request: BuildGetSourcesRequestCB,
40+
parse_get_sources_response: ParseGetSourcesResponseCB,
4141
build_payment_req: BuildPaymentReqCB,
4242
parse_payment_response: ParsePaymentResponseCB,
4343
build_mint_req: BuildMintReqCB,
@@ -48,8 +48,8 @@ impl PaymentsMethodCBs {
4848
create_address,
4949
add_request_fees,
5050
parse_response_with_fees,
51-
build_get_utxo_request,
52-
parse_get_utxo_response,
51+
build_get_sources_request,
52+
parse_get_sources_response,
5353
build_payment_req,
5454
parse_payment_response,
5555
build_mint_req,
@@ -126,35 +126,35 @@ impl PaymentsService {
126126
res
127127
}
128128

129-
pub fn build_get_utxo_request(&self, cmd_handle: i32, type_: &str, wallet_handle: i32, submitter_did: &str, address: &str) -> Result<(), PaymentsError> {
130-
trace!("build_get_utxo_request >>> type_: {:?}, wallet_handle: {:?}, submitter_did: {:?}, address: {:?}", type_, wallet_handle, submitter_did, address);
131-
let build_get_utxo_request: BuildGetUTXORequestCB = self.methods.borrow().get(type_)
132-
.ok_or(PaymentsError::UnknownType(format!("Unknown payment method {}", type_)))?.build_get_utxo_request;
129+
pub fn build_get_sources_request(&self, cmd_handle: i32, type_: &str, wallet_handle: i32, submitter_did: &str, address: &str) -> Result<(), PaymentsError> {
130+
trace!("build_get_sources_request >>> type_: {:?}, wallet_handle: {:?}, submitter_did: {:?}, address: {:?}", type_, wallet_handle, submitter_did, address);
131+
let build_get_sources_request: BuildGetSourcesRequestCB = self.methods.borrow().get(type_)
132+
.ok_or(PaymentsError::UnknownType(format!("Unknown payment method {}", type_)))?.build_get_sources_request;
133133

134134
let submitter_did = CString::new(submitter_did)?;
135135
let address = CString::new(address)?;
136136

137-
let err = build_get_utxo_request(cmd_handle, wallet_handle, submitter_did.as_ptr(), address.as_ptr(), cbs::build_get_utxo_request_cb(cmd_handle));
137+
let err = build_get_sources_request(cmd_handle, wallet_handle, submitter_did.as_ptr(), address.as_ptr(), cbs::build_get_sources_request_cb(cmd_handle));
138138

139139
let res = PaymentsService::consume_result(err);
140140

141-
trace!("build_get_utxo_request <<< result: {:?}", res);
141+
trace!("build_get_sources_request <<< result: {:?}", res);
142142

143143
res
144144
}
145145

146-
pub fn parse_get_utxo_response(&self, cmd_handle: i32, type_: &str, response: &str) -> Result<(), PaymentsError> {
147-
trace!("parse_get_utxo_response >>> type_: {:?}, response: {:?}", type_, response);
148-
let parse_get_utxo_response: ParseGetUTXOResponseCB = self.methods.borrow().get(type_)
149-
.ok_or(PaymentsError::UnknownType(format!("Unknown payment method {}", type_)))?.parse_get_utxo_response;
146+
pub fn parse_get_sources_response(&self, cmd_handle: i32, type_: &str, response: &str) -> Result<(), PaymentsError> {
147+
trace!("parse_get_sources_response >>> type_: {:?}, response: {:?}", type_, response);
148+
let parse_get_sources_response: ParseGetSourcesResponseCB = self.methods.borrow().get(type_)
149+
.ok_or(PaymentsError::UnknownType(format!("Unknown payment method {}", type_)))?.parse_get_sources_response;
150150

151151
let response = CString::new(response)?;
152152

153-
let err = parse_get_utxo_response(cmd_handle, response.as_ptr(), cbs::parse_get_utxo_response_cb(cmd_handle));
153+
let err = parse_get_sources_response(cmd_handle, response.as_ptr(), cbs::parse_get_sources_response_cb(cmd_handle));
154154

155155
let res = PaymentsService::consume_result(err);
156156

157-
trace!("parse_get_utxo_response <<< result: {:?}", res);
157+
trace!("parse_get_sources_response <<< result: {:?}", res);
158158

159159
res
160160
}
@@ -298,13 +298,13 @@ impl PaymentsService {
298298
return Err(PaymentsError::CommonError(CommonError::InvalidStructure("No outputs for transaction".to_string())));
299299
}
300300

301-
let payment_address_set: HashSet<String> = outputs.into_iter().map(|s| s.payment_address).collect();
302-
if payment_address_set.len() != outputs_len {
301+
let recipient_set: HashSet<String> = outputs.into_iter().map(|s| s.recipient).collect();
302+
if recipient_set.len() != outputs_len {
303303
error!("Several equal payment addresses");
304304
return Err(PaymentsError::CommonError(CommonError::InvalidStructure("Several equal payment addresses".to_string())));
305305
}
306306

307-
let payment_methods: Vec<Option<String>> = payment_address_set.into_iter().map(|s| self._parse_method_from_payment_address(s.as_str())).collect();
307+
let payment_methods: Vec<Option<String>> = recipient_set.into_iter().map(|s| self._parse_method_from_payment_address(s.as_str())).collect();
308308
if payment_methods.contains(&None) {
309309
error!("Some payment addresses are incorrectly formed");
310310
return Err(PaymentsError::CommonError(CommonError::InvalidStructure("Some payment addresses are incorrectly formed".to_string())));
@@ -354,8 +354,7 @@ impl PaymentsService {
354354

355355
#[derive(Debug, Serialize, Deserialize)]
356356
pub struct Output {
357-
#[serde(rename = "paymentAddress")]
358-
payment_address: String,
357+
pub recipient: String,
359358
amount: i32,
360359
extra: Option<String>
361360
}
@@ -405,16 +404,16 @@ mod cbs {
405404
send_ack(cmd_handle, Box::new(move |cmd_handle, result| PaymentsCommand::ParseResponseWithFeesAck(cmd_handle, result)))
406405
}
407406

408-
pub fn build_get_utxo_request_cb(cmd_handle: i32) -> Option<extern fn(command_handle: i32,
409-
err: ErrorCode,
410-
c_str: *const c_char) -> ErrorCode> {
411-
send_ack(cmd_handle, Box::new(move |cmd_handle, result| PaymentsCommand::BuildGetUtxoRequestAck(cmd_handle, result)))
407+
pub fn build_get_sources_request_cb(cmd_handle: i32) -> Option<extern fn(command_handle: i32,
408+
err: ErrorCode,
409+
c_str: *const c_char) -> ErrorCode> {
410+
send_ack(cmd_handle, Box::new(move |cmd_handle, result| PaymentsCommand::BuildGetSourcesRequestAck(cmd_handle, result)))
412411
}
413412

414-
pub fn parse_get_utxo_response_cb(cmd_handle: i32) -> Option<extern fn(command_handle: i32,
415-
err: ErrorCode,
416-
c_str: *const c_char) -> ErrorCode> {
417-
send_ack(cmd_handle, Box::new(move |cmd_handle, result| PaymentsCommand::ParseGetUtxoResponseAck(cmd_handle, result)))
413+
pub fn parse_get_sources_response_cb(cmd_handle: i32) -> Option<extern fn(command_handle: i32,
414+
err: ErrorCode,
415+
c_str: *const c_char) -> ErrorCode> {
416+
send_ack(cmd_handle, Box::new(move |cmd_handle, result| PaymentsCommand::ParseGetSourcesResponseAck(cmd_handle, result)))
418417
}
419418

420419
pub fn build_payment_req_cb(cmd_handle: i32) -> Option<extern fn(command_handle: i32,

0 commit comments

Comments
 (0)