more stuff

This commit is contained in:
Sean Darcy 2022-03-08 08:52:47 +11:00 committed by Thomas Winget
parent d1b7d7bb0b
commit 54910dae5c
5 changed files with 42 additions and 10 deletions

View File

@ -269,10 +269,16 @@ namespace wallet
index.push_back(src_entr.global_index);
input_to_key.key_offsets = cryptonote::absolute_output_offsets_to_relative(input_to_key.key_offsets);
ptx.tx.vin.push_back(input_to_key);
i++;
}
// TODO sean the inputs should be sorted by key_image
// Sort the inputs by their key image
std::sort(ptx.tx.vin.begin(), ptx.tx.vin.end(), [&](const auto& a, const auto& b) {
const cryptonote::txin_to_key &tk0 = var::get<cryptonote::txin_to_key>(a);
const cryptonote::txin_to_key &tk1 = var::get<cryptonote::txin_to_key>(b);
return memcmp(&tk0.k_image, &tk1.k_image, sizeof(tk0.k_image)) > 0;
});
std::vector<rct::key> amount_keys;
amount_keys.clear();
@ -291,7 +297,6 @@ namespace wallet
outamounts.push_back(recipient.amount);
amount_out += recipient.amount;
// TODO sean the output should be shuffled
// also a change address needs to be in here
i++;
}
@ -299,6 +304,10 @@ namespace wallet
crypto::public_key change_out_eph_public_key = generate_change_address_ephemeral_keys(tx_key, ptx.change, i, amount_keys);
cryptonote::tx_out change_out{};
change_out.amount = ptx.change.amount;
std::cout << __FILE__ << ":" << __LINE__ << " (" << __func__ << ") TODO sean remove this - sum inputs: " << ptx.sum_inputs() << " - debug\n";
std::cout << __FILE__ << ":" << __LINE__ << " (" << __func__ << ") TODO sean remove this - sum outputs: " << ptx.sum_outputs() << " - debug\n";
std::cout << __FILE__ << ":" << __LINE__ << " (" << __func__ << ") TODO sean remove this - fee: " << ptx.get_fee() << " - debug\n";
std::cout << __FILE__ << ":" << __LINE__ << " (" << __func__ << ") TODO sean remove this - change amount: " << ptx.change.amount << " - debug\n";
cryptonote::txout_to_key change_tk{};
change_tk.key = change_out_eph_public_key;
change_out.target = change_tk;

View File

@ -30,7 +30,7 @@ namespace wallet
return std::accumulate(
chosen_outputs.begin(),
chosen_outputs.end(),
0,
int64_t{0},
[](int64_t accumulator, const Output& output) { return accumulator + output.amount; });
}
@ -40,7 +40,7 @@ namespace wallet
return std::accumulate(
recipients.begin(),
recipients.end(),
0,
int64_t{0},
[](int64_t accumulator, const cryptonote::tx_destination_entry& recipient) {
return accumulator + recipient.amount;
});
@ -60,7 +60,7 @@ namespace wallet
int64_t burn_pct = 0;
int64_t fee_percent = BLINK_BURN_TX_FEE_PERCENT_V18; // 100%
if (blink)
fee_percent = BLINK_MINER_TX_FEE_PERCENT + burn_pct; // Blink ends up being 300%
fee_percent = BLINK_MINER_TX_FEE_PERCENT + BLINK_BURN_TX_FEE_PERCENT_V18 + burn_pct; // Blink ends up being 300%
int64_t fee = (get_tx_weight(n_inputs) * fee_per_byte + (recipients.size() + 1) * fee_per_output) * fee_percent / 100;
// Add fixed amount to the fee for items such as burning. This is defined in the pending transactions
@ -79,6 +79,7 @@ namespace wallet
size_t n_outputs = recipients.size() + 1; // Recipients plus change
if (n_outputs == 0)
throw std::runtime_error{"Get Transaction Weight called on a transaction with no recipients"};
std::cout << __FILE__ << ":" << __LINE__ << " (" << __func__ << ") TODO sean remove this - n_outputs " << n_outputs << " - debug\n";
size += 1 + 6; // tx prefix, first few bytes
size += n_inputs * (1+6+(mixin_count+1)*2+32); // vin

View File

@ -17,11 +17,6 @@ class MockDaemonComms: public DefaultDaemonComms
return std::make_shared<oxenmq::OxenMQ>();
}
std::pair<int64_t, int64_t>
get_fee_parameters() override {
return std::make_pair(0,0);
}
std::future<std::vector<Decoy>>
fetch_decoys(const std::vector<int64_t>& indexes) override {
auto p = std::promise<std::vector<Decoy>>();

View File

@ -12,6 +12,9 @@ class MockKeyring : public Keyring
MockKeyring() : Keyring({},{},{},{}) {}
std::vector<std::tuple<crypto::public_key, uint64_t, uint64_t, cryptonote::subaddress_index> > ours;
std::vector<crypto::public_key> predetermined_output_ephemeral_keys{};
int64_t last_output_ephemeral_key = 0;
void
add_key_index_pair_as_ours(
@ -87,6 +90,29 @@ class MockKeyring : public Keyring
return 0;
}
void
add_tx_key(const std::string_view& key)
{
predetermined_output_ephemeral_keys.push_back(crypto::public_key{});
crypto::public_key& ephemeral_key = predetermined_output_ephemeral_keys.back();
tools::hex_to_type(key, ephemeral_key);
}
crypto::public_key
generate_output_ephemeral_keys(const crypto::secret_key& tx_key, const cryptonote::tx_destination_entry& dst_entr, const size_t output_index, std::vector<rct::key>& amount_keys)
{
if (predetermined_output_ephemeral_keys.size() > 0)
{
auto& return_key = predetermined_output_ephemeral_keys[last_output_ephemeral_key];
if (last_output_ephemeral_key + 1 == static_cast<int64_t>(predetermined_output_ephemeral_keys.size()))
last_output_ephemeral_key = 0;
else
last_output_ephemeral_key++;
return return_key;
}
return Keyring::generate_output_ephemeral_keys(tx_key, dst_entr, output_index, amount_keys);
}
};

View File

@ -147,6 +147,7 @@ TEST_CASE("Transaction Signing", "[wallet,tx]")
auto decoy_selector = std::make_unique<wallet::MockDecoySelector>();
decoy_selector->add_index({894631, 1038224, 1049882, 1093414, 1093914, 1094315, 1094323, 1094368, 1094881, 1094887});
ctor_for_signing.decoy_selector = std::move(decoy_selector);
MDEBUG(__FILE__ << ":" << __LINE__ << " (" << __func__ << ") TODO sean remove this - ctor fee_per_byte " << ctor_for_signing.fee_per_byte << " - debug");
wallet::Output o{};
o.amount = 1000000000000;