Skip to content

Commit c8c908d

Browse files
committed
carrot+fcmp: unbreak wallet2::create_transactions_*()
Partially reverts 9338706. Resolves monero-project#70 by reverting methods to previous API. Keeps the functional behavior of monero-project#61.
1 parent 354062d commit c8c908d

File tree

11 files changed

+268
-346
lines changed

11 files changed

+268
-346
lines changed

src/simplewallet/simplewallet.cpp

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6484,7 +6484,8 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
64846484
return false;
64856485
}
64866486

6487-
// Fail on parsed long payment ID
6487+
std::vector<uint8_t> extra;
6488+
bool payment_id_seen = false;
64886489
if (!local_args.empty())
64896490
{
64906491
std::string payment_id_str = local_args.back();
@@ -6524,7 +6525,6 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65246525

65256526
vector<cryptonote::address_parse_info> dsts_info;
65266527
vector<cryptonote::tx_destination_entry> dsts;
6527-
std::pair<crypto::hash8, std::size_t> payment_id{crypto::null_hash8, 0};
65286528
for (size_t i = 0; i < local_args.size(); )
65296529
{
65306530
dsts_info.emplace_back();
@@ -6586,18 +6586,19 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65866586

65876587
if (info.has_payment_id || !payment_id_uri.empty())
65886588
{
6589-
if (payment_id.first != crypto::null_hash8) // other pid seen before
6589+
if (payment_id_seen)
65906590
{
65916591
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
65926592
return false;
65936593
}
65946594

6595-
crypto::hash ignored_long_pid;
6595+
crypto::hash payment_id;
6596+
std::string extra_nonce;
65966597
if (info.has_payment_id)
65976598
{
6598-
payment_id = {info.payment_id, dsts.size()};
6599+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
65996600
}
6600-
else if (tools::wallet2::parse_payment_id(payment_id_uri, ignored_long_pid))
6601+
else if (tools::wallet2::parse_payment_id(payment_id_uri, payment_id))
66016602
{
66026603
LONG_PAYMENT_ID_SUPPORT_CHECK();
66036604
}
@@ -6606,6 +6607,13 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
66066607
fail_msg_writer() << tr("failed to parse payment id, though it was detected");
66076608
return false;
66086609
}
6610+
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
6611+
if(!r)
6612+
{
6613+
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
6614+
return false;
6615+
}
6616+
payment_id_seen = true;
66096617
}
66106618

66116619
dsts.push_back(de);
@@ -6623,7 +6631,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
66236631
try
66246632
{
66256633
// figure out what tx will be necessary
6626-
auto ptx_vector = m_wallet->create_transactions_2(dsts, payment_id, fake_outs_count, priority, /*extra=*/{},
6634+
auto ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, priority, extra,
66276635
m_current_subaddress_account, subaddr_indices, subtract_fee_from_outputs);
66286636

66296637
if (ptx_vector.empty())
@@ -7059,13 +7067,14 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vect
70597067
}
70607068
}
70617069

7062-
// Fail on parsed long payment ID
7070+
std::vector<uint8_t> extra;
7071+
bool payment_id_seen = false;
70637072
if (local_args.size() >= 2)
70647073
{
70657074
std::string payment_id_str = local_args.back();
70667075

7067-
crypto::hash ignored_long_pid;
7068-
bool r = tools::wallet2::parse_long_payment_id(payment_id_str, ignored_long_pid);
7076+
crypto::hash payment_id;
7077+
bool r = tools::wallet2::parse_long_payment_id(payment_id_str, payment_id);
70697078
if(r)
70707079
{
70717080
LONG_PAYMENT_ID_SUPPORT_CHECK();
@@ -7077,6 +7086,8 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vect
70777086
print_usage();
70787087
return true;
70797088
}
7089+
if (payment_id_seen)
7090+
local_args.pop_back();
70807091
}
70817092

70827093
cryptonote::address_parse_info info;
@@ -7087,12 +7098,31 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vect
70877098
return true;
70887099
}
70897100

7101+
if (info.has_payment_id)
7102+
{
7103+
if (payment_id_seen)
7104+
{
7105+
fail_msg_writer() << tr("a single transaction cannot use more than one payment id: ") << local_args[0];
7106+
return true;
7107+
}
7108+
7109+
std::string extra_nonce;
7110+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
7111+
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
7112+
if(!r)
7113+
{
7114+
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
7115+
return true;
7116+
}
7117+
payment_id_seen = true;
7118+
}
7119+
70907120
SCOPED_WALLET_UNLOCK();
70917121

70927122
try
70937123
{
70947124
// figure out what tx will be necessary
7095-
auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, outputs, info.payment_id, fake_outs_count, priority, /*extra=*/{}, account, subaddr_indices);
7125+
auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, outputs, fake_outs_count, priority, extra, account, subaddr_indices);
70967126

70977127
if (ptx_vector.empty())
70987128
{
@@ -7287,11 +7317,13 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
72877317
}
72887318
}
72897319

7290-
// Fail on parsed long payment ID
7320+
std::vector<uint8_t> extra;
7321+
bool payment_id_seen = false;
72917322
if (local_args.size() == 3)
72927323
{
7293-
crypto::hash ignored_long_pid;
7294-
if (tools::wallet2::parse_long_payment_id(local_args.back(), ignored_long_pid))
7324+
crypto::hash payment_id;
7325+
std::string extra_nonce;
7326+
if (tools::wallet2::parse_long_payment_id(local_args.back(), payment_id))
72957327
{
72967328
LONG_PAYMENT_ID_SUPPORT_CHECK();
72977329
}
@@ -7300,6 +7332,15 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
73007332
fail_msg_writer() << tr("failed to parse Payment ID");
73017333
return true;
73027334
}
7335+
7336+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
7337+
{
7338+
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
7339+
return true;
7340+
}
7341+
7342+
local_args.pop_back();
7343+
payment_id_seen = true;
73037344
}
73047345

73057346
if (local_args.size() != 2)
@@ -7322,12 +7363,30 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
73227363
return true;
73237364
}
73247365

7366+
if (info.has_payment_id)
7367+
{
7368+
if (payment_id_seen)
7369+
{
7370+
fail_msg_writer() << tr("a single transaction cannot use more than one payment id: ") << local_args[0];
7371+
return true;
7372+
}
7373+
7374+
std::string extra_nonce;
7375+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
7376+
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
7377+
{
7378+
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
7379+
return true;
7380+
}
7381+
payment_id_seen = true;
7382+
}
7383+
73257384
SCOPED_WALLET_UNLOCK();
73267385

73277386
try
73287387
{
73297388
// figure out what tx will be necessary
7330-
auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, outputs, info.payment_id, fake_outs_count, priority, /*extra=*/{});
7389+
auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, outputs, fake_outs_count, priority, extra);
73317390

73327391
if (ptx_vector.empty())
73337392
{
@@ -7491,9 +7550,9 @@ bool simple_wallet::donate(const std::vector<std::string> &args_)
74917550
}
74927551
std::string amount_str;
74937552
std::string payment_id_str;
7494-
// get payment id and pop (long PIDs handled in `transfer()`)
7495-
crypto::hash payment_id = crypto::null_hash;
7496-
crypto::hash8 payment_id8 = crypto::null_hash8;
7553+
// get payment id and pop
7554+
crypto::hash payment_id;
7555+
crypto::hash8 payment_id8;
74977556
if (tools::wallet2::parse_long_payment_id (local_args.back(), payment_id ) ||
74987557
tools::wallet2::parse_short_payment_id(local_args.back(), payment_id8))
74997558
{

src/wallet/api/wallet.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,8 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
16311631
if (checkBackgroundSync("cannot create transactions"))
16321632
break;
16331633

1634+
std::vector<uint8_t> extra;
1635+
std::string extra_nonce;
16341636
vector<cryptonote::tx_destination_entry> dsts;
16351637
if (!amount && dst_addr.size() > 1) {
16361638
setStatusError(tr("Sending all requires one destination address"));
@@ -1641,11 +1643,15 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
16411643
break;
16421644
}
16431645
if (!payment_id.empty()) {
1644-
setStatusError(tr("Long payment IDs are obsolete and no longer supported"));
1645-
break;
1646+
crypto::hash payment_id_long;
1647+
if (tools::wallet2::parse_long_payment_id(payment_id, payment_id_long)) {
1648+
cryptonote::set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id_long);
1649+
} else {
1650+
setStatusError(tr("payment id has invalid format, expected 64 character hex string: ") + payment_id);
1651+
break;
1652+
}
16461653
}
16471654
bool error = false;
1648-
std::pair<crypto::hash8, std::size_t> payment_id{crypto::null_hash8, 0};
16491655
for (size_t i = 0; i < dst_addr.size() && !error; i++) {
16501656
if(!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), dst_addr[i])) {
16511657
// TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982
@@ -1654,12 +1660,12 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
16541660
break;
16551661
}
16561662
if (info.has_payment_id) {
1657-
if (payment_id.first != crypto::null_hash8) {
1663+
if (!extra_nonce.empty()) {
16581664
setStatusError(tr("a single transaction cannot use more than one payment id"));
16591665
error = true;
16601666
break;
16611667
}
1662-
payment_id = {info.payment_id, dsts.size()};
1668+
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
16631669
}
16641670

16651671
if (amount) {
@@ -1680,21 +1686,22 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
16801686
if (error) {
16811687
break;
16821688
}
1689+
if (!extra_nonce.empty() && !add_extra_nonce_to_tx_extra(extra, extra_nonce)) {
1690+
setStatusError(tr("failed to set up payment id, though it was decoded correctly"));
1691+
break;
1692+
}
16831693
try {
16841694
size_t fake_outs_count = mixin_count > 0 ? mixin_count : m_wallet->default_mixin();
16851695
fake_outs_count = m_wallet->adjust_mixin(mixin_count);
16861696

16871697
if (amount) {
1688-
transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, payment_id, fake_outs_count,
1698+
transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count,
16891699
adjusted_priority,
1690-
/*extra=*/{},
1691-
subaddr_account, subaddr_indices);
1700+
extra, subaddr_account, subaddr_indices);
16921701
} else {
1693-
transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1,
1694-
payment_id.first, fake_outs_count,
1702+
transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1, fake_outs_count,
16951703
adjusted_priority,
1696-
/*extra=*/{}, subaddr_account,
1697-
subaddr_indices);
1704+
extra, subaddr_account, subaddr_indices);
16981705
}
16991706
pendingTxPostProcess(transaction);
17001707

0 commit comments

Comments
 (0)