Skip to content

Commit a6e7769

Browse files
authored
Merge pull request hyperledger-indy#901 from KitHat/master
New utxo-json format
2 parents 7ebb9ab + 183b9ae commit a6e7769

File tree

8 files changed

+49
-29
lines changed

8 files changed

+49
-29
lines changed

cli/src/commands/ledger.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ pub mod get_utxo_command {
872872
.map_err(|_| println_err!("Wrong data has been received"))?;
873873

874874
print_list_table(&utxo,
875-
&vec![("input", "Input"),
875+
&vec![("txo", "Txo"),
876+
("paymentAddress", "Payment Address"),
876877
("amount", "Amount"),
877878
("extra", "Extra")],
878879
"There are no utxo's");
@@ -922,7 +923,8 @@ pub mod payment_command {
922923
.map_err(|_| println_err!("Wrong data has been received"))?;
923924

924925
print_list_table(&utxo,
925-
&vec![("input", "Input"),
926+
&vec![("txo", "Txo"),
927+
("paymentAddress", "Payment Address"),
926928
("amount", "Amount"),
927929
("extra", "Extra")],
928930
"There are no utxo's");
@@ -1166,7 +1168,8 @@ fn print_response_utxo(utxo: Option<Vec<serde_json::Value>>) -> Result<(), ()> {
11661168
if !utxo.is_empty() {
11671169
println_succ!("Following Utxo has been received.");
11681170
print_list_table(&utxo,
1169-
&vec![("input", "Input"),
1171+
&vec![("txo", "Txo"),
1172+
("paymentAddress", "Payment Address"),
11701173
("amount", "Amount"),
11711174
("extra", "Extra")],
11721175
"");
@@ -3866,7 +3869,7 @@ pub mod tests {
38663869

38673870
let utxos = serde_json::from_str::<serde_json::Value>(&utxo_json).unwrap();
38683871
let utxo: &serde_json::Value = &utxos.as_array().unwrap()[0];
3869-
utxo["input"].as_str().unwrap().to_string()
3872+
utxo["txo"].as_str().unwrap().to_string()
38703873
}
38713874

38723875
#[cfg(feature = "nullpay_plugin")]

doc/design/004-payment-interface/README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ type AddRequestFeesCB = extern fn(command_handle: i32,
157157
/// #Returns
158158
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
159159
/// [{
160-
/// input: <str>, // UTXO input
160+
/// txo: <str>, // UTXO input
161+
/// paymentAddress: <str>, //payment address for this UTXO
161162
/// amount: <int>, // amount of tokens in this input
162163
/// extra: <str>, // optional data from payment transaction
163164
/// }]
@@ -193,7 +194,8 @@ type BuildGetUTXORequestCB = extern fn(command_handle: i32,
193194
/// #Returns
194195
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
195196
/// [{
196-
/// input: <str>, // UTXO input
197+
/// txo: <str>, // UTXO input
198+
/// paymentAddress: <str>, //payment address for this UTXO
197199
/// amount: <int>, // amount of tokens in this input
198200
/// extra: <str>, // optional data from payment transaction
199201
/// }]
@@ -245,7 +247,8 @@ type BuildPaymentReqCB = extern fn(command_handle: i32,
245247
/// #Returns
246248
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
247249
/// [{
248-
/// input: <str>, // UTXO input
250+
/// txo: <str>, // UTXO input
251+
/// paymentAddress: <str>, //payment address for this UTXO
249252
/// amount: <int>, // amount of tokens in this input
250253
/// extra: <str>, // optional data from payment transaction
251254
/// }]
@@ -442,7 +445,8 @@ pub extern fn indy_add_request_fees(command_handle: i32,
442445
/// #Returns
443446
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
444447
/// [{
445-
/// input: <str>, // UTXO input
448+
/// txo: <str>, // UTXO input
449+
/// paymentAddress: <str>, //payment address for this UTXO
446450
/// amount: <int>, // amount of tokens in this input
447451
/// extra: <str>, // optional data from payment transaction
448452
/// }]
@@ -482,7 +486,8 @@ pub extern fn indy_build_get_utxo_request(command_handle: i32,
482486
/// #Returns
483487
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
484488
/// [{
485-
/// input: <str>, // UTXO input
489+
/// txo: <str>, // UTXO input
490+
/// paymentAddress: <str>, //payment address for this UTXO
486491
/// amount: <int>, // amount of tokens in this input
487492
/// extra: <str>, // optional data from payment transaction
488493
/// }]
@@ -538,7 +543,8 @@ pub extern fn indy_build_payment_req(command_handle: i32,
538543
/// #Returns
539544
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
540545
/// [{
541-
/// input: <str>, // UTXO input
546+
/// txo: <str>, // UTXO input
547+
/// paymentAddress: <str>, //payment address for this UTXO
542548
/// amount: <int>, // amount of tokens in this input
543549
/// extra: <str>, // optional data from payment transaction
544550
/// }]

doc/design/007-cli-payments/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ indy> ledger get-utxo payment_address=<payment-address>
5050

5151
Returns:
5252

53-
* Table with columns: Input, Amount, Extra
53+
* Table with columns: Txo, Payment Address, Amount, Extra
5454

5555
### Send PAYMENT transaction
5656

libindy/src/api/payments.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ pub type AddRequestFeesCB = extern fn(command_handle: i32,
8181
/// #Returns
8282
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
8383
/// [{
84-
/// input: <str>, // UTXO input
84+
/// txo: <str>, // UTXO input
85+
/// paymentAddress: <str>, //payment address for this UTXO
8586
/// amount: <int>, // amount of tokens in this input
8687
/// extra: <str>, // optional data from payment transaction
8788
/// }]
@@ -117,7 +118,8 @@ pub type BuildGetUTXORequestCB = extern fn(command_handle: i32,
117118
/// #Returns
118119
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
119120
/// [{
120-
/// input: <str>, // UTXO input
121+
/// txo: <str>, // UTXO input
122+
/// paymentAddress: <str>, //payment address for this UTXO
121123
/// amount: <int>, // amount of tokens in this input
122124
/// extra: <str>, // optional data from payment transaction
123125
/// }]
@@ -169,7 +171,8 @@ pub type BuildPaymentReqCB = extern fn(command_handle: i32,
169171
/// #Returns
170172
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
171173
/// [{
172-
/// input: <str>, // UTXO input
174+
/// txo: <str>, // UTXO input
175+
/// paymentAddress: <str>, //payment address for this UTXO
173176
/// amount: <int>, // amount of tokens in this input
174177
/// extra: <str>, // optional data from payment transaction
175178
/// }]
@@ -544,7 +547,8 @@ pub extern fn indy_add_request_fees(command_handle: i32,
544547
/// #Returns
545548
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
546549
/// [{
547-
/// input: <str>, // UTXO input
550+
/// txo: <str>, // UTXO input
551+
/// paymentAddress: <str>, //payment address for this UTXO
548552
/// amount: <int>, // amount of tokens in this input
549553
/// extra: <str>, // optional data from payment transaction
550554
/// }]
@@ -645,7 +649,8 @@ pub extern fn indy_build_get_utxo_request(command_handle: i32,
645649
/// #Returns
646650
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
647651
/// [{
648-
/// input: <str>, // UTXO input
652+
/// txo: <str>, // UTXO input
653+
/// paymentAddress: <str>, //payment address for this UTXO
649654
/// amount: <int>, // amount of tokens in this input
650655
/// extra: <str>, // optional data from payment transaction
651656
/// }]
@@ -767,7 +772,8 @@ pub extern fn indy_build_payment_req(command_handle: i32,
767772
/// #Returns
768773
/// utxo_json - parsed (payment method and node version agnostic) utxo info as json:
769774
/// [{
770-
/// input: <str>, // UTXO input
775+
/// txo: <str>, // UTXO input
776+
/// paymentAddress: <str>, //payment address for this UTXO
771777
/// amount: <int>, // amount of tokens in this input
772778
/// extra: <str>, // optional data from payment transaction
773779
/// }]

libnullpay/src/services/payment_ledger.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub fn get_utxo_info(utxo: String) -> Option<UTXOInfo> {
3838
match get_txn(seq_no).map(|(_, outputs)| {
3939
outputs.into_iter().find(|out| out.payment_address == payment_address).map(|out| {
4040
UTXOInfo {
41-
input: utxo,
41+
txo: utxo,
42+
payment_address,
4243
amount: out.amount,
4344
extra: out.extra,
4445
}

libnullpay/src/utils/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ impl Clone for UTXOOutput {
1818

1919
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
2020
pub struct UTXOInfo {
21-
pub input: String,
21+
pub txo: String,
22+
#[serde(rename = "paymentAddress")]
23+
pub payment_address: String,
2224
pub amount: i32,
2325
pub extra: Option<String>
2426
}

libnullpay/tests/payments.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ mod high_cases {
202202

203203
//6. Create inputs and outputs
204204
let addr_1 = addresses.get(0).unwrap();
205-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
205+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
206206
let inputs = serde_json::to_string(&utxos_1).unwrap();
207207

208208
let outputs = vec![UTXOOutput {
@@ -260,7 +260,7 @@ mod high_cases {
260260
let utxos = payments_utils::get_utxos_with_balance(addresses.clone(), wallet_handle, pool_handle, SUBMITTER_DID);
261261

262262
let addr_1 = addresses.get(0).unwrap();
263-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
263+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
264264
let inputs = serde_json::to_string(&utxos_1).unwrap();
265265

266266
let outputs = vec![UTXOOutput {
@@ -315,7 +315,7 @@ mod high_cases {
315315

316316
//7. Create inputs and outputs
317317
let addr_1 = addresses_1.get(0).unwrap();
318-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
318+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
319319
let inputs = serde_json::to_string(&utxos_1).unwrap();
320320

321321
let outputs = vec![UTXOOutput {
@@ -357,7 +357,7 @@ mod high_cases {
357357

358358
//3. Prepare inputs and outputs for payment txn
359359
let addr_1 = addresses.get(0).unwrap();
360-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
360+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
361361
let inputs = serde_json::to_string(&utxos_1).unwrap();
362362

363363
let outputs = vec![UTXOOutput {
@@ -380,7 +380,7 @@ mod high_cases {
380380
let utxos: Vec<UTXOInfo> = serde_json::from_str(payment_resp_parsed.as_str()).unwrap();
381381
assert_eq!(utxos.len(), 2);
382382

383-
let utxos: HashMap<i32, String> = utxos.into_iter().map(|info| (info.amount, info.input)).collect();
383+
let utxos: HashMap<i32, String> = utxos.into_iter().map(|info| (info.amount, info.txo)).collect();
384384
let payment_utxo = utxos.get(&19).unwrap();
385385
let change_utxo = utxos.get(&1).unwrap();
386386

@@ -423,7 +423,7 @@ mod high_cases {
423423
let utxos = payments_utils::get_utxos_with_balance(addresses.clone(), wallet_handle, pool_handle, SUBMITTER_DID);
424424

425425
let addr_1 = addresses.get(0).unwrap();
426-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
426+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
427427
let inputs = serde_json::to_string(&utxos_1).unwrap();
428428

429429
let outputs = vec![UTXOOutput {
@@ -469,7 +469,7 @@ mod high_cases {
469469

470470
//3. Prepare inputs and outputs for payment txn
471471
let addr_1 = addresses.get(0).unwrap();
472-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
472+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
473473
let inputs = serde_json::to_string(&utxos_1).unwrap();
474474

475475
let outputs = vec![UTXOOutput {
@@ -563,7 +563,7 @@ mod medium_cases {
563563
let utxos = payments_utils::get_utxos_with_balance(addresses.clone(), wallet_handle, pool_handle, SUBMITTER_DID);
564564

565565
let addr_1 = addresses.get(0).unwrap();
566-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
566+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
567567
let inputs = serde_json::to_string(&utxos_1).unwrap();
568568

569569
let outputs = vec![UTXOOutput {
@@ -605,7 +605,7 @@ mod medium_cases {
605605
let utxos = payments_utils::get_utxos_with_balance(addresses.clone(), wallet_handle, pool_handle, SUBMITTER_DID);
606606

607607
let addr_1 = addresses.get(0).unwrap();
608-
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.input.clone()).collect();
608+
let utxos_1: Vec<String> = utxos.get(addr_1.as_str()).unwrap().into_iter().map(|info| info.txo.clone()).collect();
609609
let inputs = serde_json::to_string(&utxos_1).unwrap();
610610

611611
let outputs = vec![UTXOOutput {

libnullpay/tests/utils/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ impl Clone for UTXOOutput {
1818

1919
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq)]
2020
pub struct UTXOInfo {
21-
pub input: String,
21+
pub txo: String,
22+
#[serde(rename = "paymentAddress")]
23+
pub payment_address: String,
2224
pub amount: i32,
2325
pub extra: Option<String>
2426
}

0 commit comments

Comments
 (0)