full import wallet uses integrated addresses now

pull/30/head
moneroexamples 7 years ago
parent 77077d6896
commit 879854cddf

@ -44,7 +44,7 @@ thinwalletCtrls.controller("ImportWalletCtrl", function($scope, $location, $http
address: AccountService.getAddress(),
view_key: AccountService.getViewKey()
}).success(function(data) {
$scope.command = 'transfer ' + data.payment_address + ' ' + cnUtil.formatMoney(data.import_fee) + ' ' + data.payment_id;
$scope.command = 'transfer ' + data.payment_address + ' ' + cnUtil.formatMoney(data.import_fee);
$scope.payment_id = data.payment_id;
$scope.payment_address = data.payment_address;
$scope.import_fee = new JSBigInt(data.import_fee);

@ -19,16 +19,20 @@
It should not take more than few minutes before your transfer is detected in the mempool.
</div>
</div>
<!--
<label class="field-label review" for="Mnemonic-2">Payment command</label>
<div class="review-text address">{{command}} </div>
</div>
<label class="field-label review" for="Mnemonic-2">Payment address</label>
-->
<label class="field-label review" for="Mnemonic-2">
Transfer {{import_fee | money:false:true}} into the following integrated address
</label>
<div class="move-text-div">
<div class="review-text address">{{payment_address}}</div>
<div class="review-text address" style="font-size: 10px">{{payment_address}}</div>
</div>
<label class="field-label review" for="Mnemonic-2">Payment ID (make sure to use this)</label>
<label class="field-label review" for="Mnemonic-2">Payment ID (for your reference, as it is embedded into the integrated address)</label>
<div class="move-text-div">
<div class="review-text">{{payment_id}}</div>
</div>

@ -113,16 +113,16 @@ xmreg::CurrentBlockchainStatus::import_fee
if (testnet)
{
xmreg::CurrentBlockchainStatus::import_payment_address
xmreg::CurrentBlockchainStatus::import_payment_address_str
= config_json["wallet_import"]["testnet"]["address"];
xmreg::CurrentBlockchainStatus::import_payment_viewkey
xmreg::CurrentBlockchainStatus::import_payment_viewkey_str
= config_json["wallet_import"]["testnet"]["viewkey"];
}
else
{
xmreg::CurrentBlockchainStatus::import_payment_address
xmreg::CurrentBlockchainStatus::import_payment_address_str
= config_json["wallet_import"]["mainnet"]["address"];
xmreg::CurrentBlockchainStatus::import_payment_viewkey
xmreg::CurrentBlockchainStatus::import_payment_viewkey_str
= config_json["wallet_import"]["mainnet"]["viewkey"];
}

@ -32,11 +32,11 @@ uint64_t CurrentBlockchainStatus::refresh_block_status_every_seco
uint64_t CurrentBlockchainStatus::max_number_of_blocks_to_import{8000};
uint64_t CurrentBlockchainStatus::search_thread_life_in_seconds {600}; // 10 minutes
vector<pair<uint64_t, transaction>> CurrentBlockchainStatus::mempool_txs;
string CurrentBlockchainStatus::import_payment_address;
string CurrentBlockchainStatus::import_payment_viewkey;
string CurrentBlockchainStatus::import_payment_address_str;
string CurrentBlockchainStatus::import_payment_viewkey_str;
uint64_t CurrentBlockchainStatus::import_fee {10000000000}; // 0.01 xmr
account_public_address CurrentBlockchainStatus::address;
secret_key CurrentBlockchainStatus::viewkey;
account_public_address CurrentBlockchainStatus::import_payment_address;
secret_key CurrentBlockchainStatus::import_payment_viewkey;
map<string, unique_ptr<TxSearch>> CurrentBlockchainStatus::searching_threads;
cryptonote::Blockchain* CurrentBlockchainStatus::core_storage;
unique_ptr<xmreg::MicroCore> CurrentBlockchainStatus::mcore;
@ -48,25 +48,25 @@ CurrentBlockchainStatus::start_monitor_blockchain_thread()
TxSearch::set_search_thread_life(search_thread_life_in_seconds);
if (!import_payment_address.empty() && !import_payment_viewkey.empty())
if (!import_payment_address_str.empty() && !import_payment_viewkey_str.empty())
{
if (!xmreg::parse_str_address(
import_payment_address_str,
import_payment_address,
address,
testnet))
{
cerr << "Cant parse address_str: "
<< import_payment_address
<< import_payment_address_str
<< endl;
return;
}
if (!xmreg::parse_str_secret_key(
import_payment_viewkey,
viewkey))
import_payment_viewkey_str,
import_payment_viewkey))
{
cerr << "Cant parse the viewkey_str: "
<< import_payment_viewkey
<< import_payment_viewkey_str
<< endl;
return;
}
@ -323,6 +323,27 @@ CurrentBlockchainStatus::get_output_keys(const uint64_t& amount,
return true;
}
string
CurrentBlockchainStatus::get_account_integrated_address_as_str(
crypto::hash8 const& payment_id8)
{
return cryptonote::get_account_integrated_address_as_str(testnet,
import_payment_address, payment_id8);
}
string
CurrentBlockchainStatus::get_account_integrated_address_as_str(
string const& payment_id8_str)
{
crypto::hash8 payment_id8;
if (!hex_to_pod(payment_id8_str, payment_id8))
return string {};
return get_account_integrated_address_as_str(payment_id8);
}
bool
CurrentBlockchainStatus::get_amount_specific_indices(const crypto::hash& tx_hash,
vector<uint64_t>& out_indices)
@ -543,37 +564,79 @@ CurrentBlockchainStatus::search_if_payment_made(
string tx_payment_id_str = get_payment_id_as_string(tx);
if (payment_id_str != tx_payment_id_str)
// we are interested only in txs with encrypted payments id8
// they have length of 16 characters.
if (tx_payment_id_str.length() != 16)
{
// check tx having specific payment id only
continue;
}
public_key tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(tx);
// we have some tx with encrypted payment_id8
// need to decode it using tx public key, and our
// private view key, before we can comapre it is
// what we are after.
// <public_key , amount , out idx>
vector<tuple<txout_to_key, uint64_t, uint64_t>> outputs;
crypto::hash8 encrypted_payment_id8;
outputs = get_ouputs_tuple(tx);
if (!hex_to_pod(tx_payment_id_str, encrypted_payment_id8))
{
cerr << "failed parsing hex to pod for encrypted_payment_id8" << '\n';
}
// decrypt the encrypted_payment_id8
public_key tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(tx);
// for each output, in a tx, check if it belongs
// to the given account of specific address and viewkey
// public transaction key is combined with our viewkey
// to create, so called, derived key.
key_derivation derivation;
if (!generate_key_derivation(tx_pub_key, viewkey, derivation))
if (!generate_key_derivation(tx_pub_key, import_payment_viewkey, derivation))
{
cerr << "Cant get derived key for: " << "\n"
<< "pub_tx_key: " << tx_pub_key << " and "
<< "prv_view_key" << viewkey << endl;
<< "prv_view_key" << import_payment_viewkey << endl;
return false;
}
string tx_hash_str = pod_to_hex(get_transaction_hash(tx));
// decrypt encrypted payment id, as used in integreated addresses
crypto::hash8 decrypted_payment_id8 = encrypted_payment_id8;
if (decrypted_payment_id8 != null_hash8)
{
if (!decrypt_payment_id(decrypted_payment_id8, tx_pub_key, import_payment_viewkey))
{
cerr << "Cant decrypt decrypted_payment_id8: "
<< pod_to_hex(decrypted_payment_id8) << "\n";
}
}
string decrypted_tx_payment_id_str = pod_to_hex(decrypted_payment_id8);
// check if decrypted payment id matches what we have stored
// in mysql.
if (payment_id_str != decrypted_tx_payment_id_str)
{
// check tx having specific payment id only
continue;
}
// if everything ok with payment id, we proceed with
// checking if the amount transfered is correct.
// for each output, in a tx, check if it belongs
// to the given account of specific address and viewkey
// <public_key , amount , out idx>
vector<tuple<txout_to_key, uint64_t, uint64_t>> outputs;
outputs = get_ouputs_tuple(tx);
string tx_hash_str = pod_to_hex(get_transaction_hash(tx));
uint64_t total_received {0};
@ -591,7 +654,7 @@ CurrentBlockchainStatus::search_if_payment_made(
derive_public_key(derivation,
output_idx_in_tx,
address.m_spend_public_key,
import_payment_address.m_spend_public_key,
generated_tx_pubkey);
// check if generated public key matches the current output's key
@ -612,7 +675,7 @@ CurrentBlockchainStatus::search_if_payment_made(
r = decode_ringct(tx.rct_signatures,
tx_pub_key,
viewkey,
import_payment_viewkey,
output_idx_in_tx,
tx.rct_signatures.ecdhInfo[output_idx_in_tx].mask,
rct_amount);

@ -53,14 +53,14 @@ struct CurrentBlockchainStatus
static uint64_t search_thread_life_in_seconds;
static string import_payment_address;
static string import_payment_viewkey;
static string import_payment_address_str;
static string import_payment_viewkey_str;
static uint64_t import_fee;
static uint64_t spendable_age;
static uint64_t spendable_age_coinbase;
static account_public_address address;
static secret_key viewkey;
static account_public_address import_payment_address;
static secret_key import_payment_viewkey;
// vector of mempool transactions that all threads
// can refer to
@ -123,6 +123,12 @@ struct CurrentBlockchainStatus
const vector<uint64_t>& absolute_offsets,
vector<cryptonote::output_data_t>& outputs);
static string
get_account_integrated_address_as_str(crypto::hash8 const& payment_id8);
static string
get_account_integrated_address_as_str(string const& payment_id8_str);
static bool
get_output(const uint64_t amount,
const uint64_t global_output_index,

@ -740,11 +740,14 @@ YourMoneroRequests::import_wallet_request(const shared_ptr< Session > session, c
bool request_fulfilled = bool {xmr_payment.request_fulfilled};
string integrated_address =
CurrentBlockchainStatus::get_account_integrated_address_as_str(xmr_payment.payment_id);
j_response["payment_id"] = xmr_payment.payment_id;
j_response["import_fee"] = xmr_payment.import_fee;
j_response["new_request"] = false;
j_response["request_fulfilled"] = request_fulfilled;
j_response["payment_address"] = xmr_payment.payment_address;
j_response["payment_address"] = integrated_address;
j_response["status"] = "Payment not yet received";
string tx_hash_with_payment;
@ -815,12 +818,17 @@ YourMoneroRequests::import_wallet_request(const shared_ptr< Session > session, c
uint64_t payment_table_id {0};
crypto::hash8 random_payment_id8 = crypto::rand<crypto::hash8>();
string integrated_address =
CurrentBlockchainStatus::get_account_integrated_address_as_str(random_payment_id8);
xmr_payment.address = xmr_address;
xmr_payment.payment_id = pod_to_hex(generated_payment_id());
xmr_payment.payment_id = pod_to_hex(random_payment_id8);
xmr_payment.import_fee = CurrentBlockchainStatus::import_fee; // xmr
xmr_payment.request_fulfilled = false;
xmr_payment.tx_hash = ""; // no tx_hash yet with the payment
xmr_payment.payment_address = CurrentBlockchainStatus::import_payment_address;
xmr_payment.payment_address = integrated_address;
if ((payment_table_id = xmr_accounts->insert_payment(xmr_payment)) != 0)

Loading…
Cancel
Save