diff --git a/html/js/cn_util.js b/html/js/cn_util.js index 466ec18..7bea2bd 100644 --- a/html/js/cn_util.js +++ b/html/js/cn_util.js @@ -1754,7 +1754,9 @@ var cnUtil = (function(initConfig) { } var found_money = JSBigInt.ZERO; var sources = []; - console.log('Selected transfers: ', outputs); + + //console.log('Selected transfers: ', outputs); + for (i = 0; i < outputs.length; ++i) { found_money = found_money.add(outputs[i].amount); if (found_money.compare(UINT64_MAX) !== -1) { @@ -1780,6 +1782,9 @@ var cnUtil = (function(initConfig) { var oe = {}; oe.index = out.global_index.toString(); oe.key = out.public_key; + + console.log('outputs[',i,']: ', outputs[i]); + if (rct){ if (out.rct){ oe.commit = out.rct.slice(0,64); //add commitment from rct mix outs diff --git a/html/js/crc32.js b/html/js/crc32.js index c4beef4..090dc5d 100755 --- a/html/js/crc32.js +++ b/html/js/crc32.js @@ -62,4 +62,4 @@ var crc32 = (function () { }; return crc32; -})(); \ No newline at end of file +})(); diff --git a/src/CurrentBlockchainStatus.cpp b/src/CurrentBlockchainStatus.cpp index 443aa4b..67598e2 100644 --- a/src/CurrentBlockchainStatus.cpp +++ b/src/CurrentBlockchainStatus.cpp @@ -176,8 +176,47 @@ CurrentBlockchainStatus::tx_exist(const string& tx_hash_str) throw runtime_error("(hex_to_pod(tx_hash_str, tx_hash) failed!"); } +bool +CurrentBlockchainStatus::get_tx_with_output( + uint64_t output_idx, uint64_t amount, + transaction& tx, uint64_t& output_idx_in_tx) +{ + + tx_out_index tx_out_idx; + + try + { + // get pair pair where first is tx hash + // and second is local index of the output i in that tx + tx_out_idx = core_storage->get_db() + .get_output_tx_and_index(amount, output_idx); + } + catch (const OUTPUT_DNE &e) + { + + string out_msg = fmt::format( + "Output with amount {:d} and index {:d} does not exist!", + amount, output_idx + ); - bool + cerr << out_msg << endl; + + return false; + } + + output_idx_in_tx = tx_out_idx.second; + + if (!mcore.get_tx(tx_out_idx.first, tx)) + { + cerr << "Cant get tx: " << tx_out_idx.first << endl; + + return false; + } + + return true; +} + +bool CurrentBlockchainStatus::get_output_keys(const uint64_t& amount, const vector& absolute_offsets, vector& outputs) diff --git a/src/CurrentBlockchainStatus.h b/src/CurrentBlockchainStatus.h index 8336b48..d3666bb 100644 --- a/src/CurrentBlockchainStatus.h +++ b/src/CurrentBlockchainStatus.h @@ -103,6 +103,10 @@ struct CurrentBlockchainStatus static bool tx_exist(const string& tx_hash_str); + static bool + get_tx_with_output(uint64_t output_idx, uint64_t amount, + transaction& tx, uint64_t& output_idx_in_tx); + static bool get_output_keys(const uint64_t& amount, const vector& absolute_offsets, diff --git a/src/YourMoneroRequests.cpp b/src/YourMoneroRequests.cpp index 798aa48..c7079e4 100644 --- a/src/YourMoneroRequests.cpp +++ b/src/YourMoneroRequests.cpp @@ -462,18 +462,57 @@ YourMoneroRequests::get_random_outs(const shared_ptr< Session > session, const B for (const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry& out: outs.outs) { - uint64_t global_amount_index = out.global_amount_index; - j_outputs.push_back(json { + transaction random_output_tx; + uint64_t output_idx_in_tx; + + if (!CurrentBlockchainStatus::get_tx_with_output( + global_amount_index, outs.amount, + random_output_tx, output_idx_in_tx)) + { + cerr << "cant get random output transaction" << endl; + break; + } + + //cout << pod_to_hex(out.out_key) << endl; + //cout << pod_to_hex(get_transaction_hash(random_output_tx)) << endl; + //cout << output_idx_in_tx << endl; + + // placeholder variable for ringct outputs info + // that we need to save in database + string rtc_outpk; + string rtc_mask("0", 64); + string rtc_amount("0", 64); + + json out_details { {"global_index", out.global_amount_index}, {"public_key" , pod_to_hex(out.out_key)} - }); - } + }; + + + if (random_output_tx.version > 1 && !is_coinbase(random_output_tx)) + { + rtc_outpk = pod_to_hex(random_output_tx.rct_signatures.outPk[output_idx_in_tx].mask); + rtc_mask = pod_to_hex(random_output_tx.rct_signatures.ecdhInfo[output_idx_in_tx].mask); + rtc_amount = pod_to_hex(random_output_tx.rct_signatures.ecdhInfo[output_idx_in_tx].amount); + } + else + { + rtc_outpk = pod_to_hex(rct::pk2rct(out.out_key)); + } + + out_details["rct"]= rtc_outpk + rtc_mask + rtc_amount; + + j_outputs.push_back(out_details); + + } // for (const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::out_entry& out: outs.outs) j_amount_outs.push_back(j_outs); - } - } + + } // for (const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount& outs: found_outputs) + + } // if (CurrentBlockchainStatus::get_random_outputs(amounts, count, found_outputs)) string response_body = j_response.dump();