From 25e548af2e74bbff88cbc634de95d4bb17f11248 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Tue, 22 Nov 2016 10:43:08 +0800 Subject: [PATCH] fixed checking outputs with two public keys in tx extra --- src/page.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/page.h b/src/page.h index dff2d18..15d5c2d 100644 --- a/src/page.h +++ b/src/page.h @@ -228,6 +228,52 @@ namespace xmreg { return ss.str(); } + + + // based on + // crypto::public_key wallet2::get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td) const + public_key + get_tx_pub_key_from_received_outs(const transaction &tx) const + { + std::vector tx_extra_fields; + + if(!parse_tx_extra(tx.extra, tx_extra_fields)) + { + // Extra may only be partially parsed, it's OK if tx_extra_fields contains public key + } + + // Due to a previous bug, there might be more than one tx pubkey in extra, one being + // the result of a previously discarded signature. + // For speed, since scanning for outputs is a slow process, we check whether extra + // contains more than one pubkey. If not, the first one is returned. If yes, they're + // checked for whether they yield at least one output + tx_extra_pub_key pub_key_field; + + if (!find_tx_extra_field_by_type(tx_extra_fields, pub_key_field, 0)) + { + return null_pkey; + } + + public_key tx_pub_key = pub_key_field.pub_key; + + bool two_found = find_tx_extra_field_by_type(tx_extra_fields, pub_key_field, 1); + + if (!two_found) + { + // easy case, just one found + return tx_pub_key; + } + else + { + // just return second one if there are two. + // this does not require private view key, as + // its not needed for my use case. + return pub_key_field.pub_key; + } + + return null_pkey; + } + }; class page { @@ -3322,8 +3368,11 @@ namespace xmreg { // get tx hash txd.hash = get_transaction_hash(tx); - // get tx public key - txd.pk = get_tx_pub_key_from_extra(tx); + // get tx public key from extra + // this check if there are two public keys + // due to previous bug with sining txs: + // https://github.com/monero-project/monero/pull/1358/commits/7abfc5474c0f86e16c405f154570310468b635c2 + txd.pk = txd.get_tx_pub_key_from_received_outs(tx); // sum xmr in inputs and ouputs in the given tx txd.xmr_inputs = sum_money_in_inputs(tx);