From 39df8497e33ede0d69e0338c315c6ce36f248c8f Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Fri, 5 May 2017 07:32:02 +0800 Subject: [PATCH] mixins public keys added to api/transactions --- README.md | 29 ++++++++++++++++++++++++----- src/page.h | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cc2936c..67467d5 100644 --- a/README.md +++ b/README.md @@ -226,19 +226,33 @@ The explorer has JSON api. For the API, it uses conventions defined by [JSend](h curl -w "\n" -X GET "http://139.162.32.245:8081/api/transaction/6093260dbe79fd6277694d14789dc8718f1bd54457df8bab338c2efa3bb0f03d" ``` +Partial results shown: + ```json { "data": { "block_height": 1268252, - "coinbase": 0, + "coinbase": false, "confirmations": 1, - "fee": 12517785574, + "current_height": 1268253, + "extra": "01be23e277aed6b5f41f66b05244bf994c13108347366ec678ae16657f0fc3a22b", "inputs": [ { "amount": 0, - "key_image": "67838fd0ffd79f13e735830d3ec60412aed59e53e1f997feb6f73d088b949611" + "key_image": "67838fd0ffd79f13e735830d3ec60412aed59e53e1f997feb6f73d088b949611", + "mixins": [ + { + "block_no": 1238623, + "public_key": "0a5b853c55303c10e1326acfb085b9e246e088b1ccac7e37f7a810d46a28a914" + }, + { + "block_no": 1246942, + "public_key": "527cf86f5abbfb006c970f7c6eb40493786d4751306f8985c6a43f98a88c0dff" + } + ] } ], + "mixin": 9, "outputs": [ { "amount": 0, @@ -249,12 +263,17 @@ curl -w "\n" -X GET "http://139.162.32.245:8081/api/transaction/6093260dbe79fd6 "public_key": "e25f00fceb77af841d780b68647618812695b4ca6ebe338faba6e077f758ac30" } ], + "payment_id": "", + "payment_id8": "", "rct_type": 1, - "size": 13323000000000000, "timestamp": 1489753456, "timestamp_utc": "2017-03-17 12:24:16", + "tx_fee": 12517785574, "tx_hash": "6093260dbe79fd6277694d14789dc8718f1bd54457df8bab338c2efa3bb0f03d", - "version": 2 + "tx_size": 13323, + "tx_version": 2, + "xmr_inputs": 0, + "xmr_outputs": 0 }, "status": "success" } diff --git a/src/page.h b/src/page.h index 491b2c0..0682394 100644 --- a/src/page.h +++ b/src/page.h @@ -3962,12 +3962,45 @@ namespace xmreg json inputs; - for (const auto& input: txd.input_key_imgs) + for (const txin_to_key &in_key: txd.input_key_imgs) { + + // get absolute offsets of mixins + std::vector absolute_offsets + = cryptonote::relative_output_offsets_to_absolute( + in_key.key_offsets); + + // get public keys of outputs used in the mixins that match to the offests + std::vector outputs; + + try + { + core_storage->get_db().get_output_key(in_key.amount, + absolute_offsets, + outputs); + } + catch (const OUTPUT_DNE &e) + { + j_response["status"] = "error"; + j_response["message"] = "Failed to retrive outputs (mixins) used in key images"; + return j_response; + } + inputs.push_back(json { - {"key_image" , pod_to_hex(input.k_image)}, - {"amount" , input.amount} + {"key_image" , pod_to_hex(in_key.k_image)}, + {"amount" , in_key.amount}, + {"mixins" , json {}} }); + + json& mixins = inputs.back()["mixins"]; + + for (const output_data_t& output_data: outputs) + { + mixins.push_back(json { + {"public_key" , pod_to_hex(output_data.pubkey)}, + {"block_no" , output_data.height}, + }); + } } if (found_in_mempool == false)