Skip to content

Commit aa24ad3

Browse files
committed
carrot+fcmp: send to integrated address [WIP]
1 parent 643e48a commit aa24ad3

File tree

13 files changed

+376
-334
lines changed

13 files changed

+376
-334
lines changed

src/carrot_impl/tx_proposal_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void make_carrot_transaction_proposal_v1_transfer(
258258
// shadow subtractable_selfsend_payment_proposals and adjust for default case (no subtractable provided)
259259
const auto &subtractable_selfsend_payment_proposals_ref = subtractable_selfsend_payment_proposals;
260260
std::set<std::size_t> subtractable_selfsend_payment_proposals = subtractable_selfsend_payment_proposals_ref;
261-
if (subtractable_selfsend_payment_proposals.empty())
261+
if (subtractable_normal_payment_proposals.empty() && subtractable_selfsend_payment_proposals.empty())
262262
subtractable_selfsend_payment_proposals.insert(selfsend_payment_proposals.size() - 1);
263263

264264
const bool has_subbable_normal = !subtractable_normal_payment_proposals.empty();

src/simplewallet/simplewallet.cpp

Lines changed: 21 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6492,8 +6492,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
64926492
return false;
64936493
}
64946494

6495-
std::vector<uint8_t> extra;
6496-
bool payment_id_seen = false;
6495+
// Fail on parsed long payment ID
64976496
if (!local_args.empty())
64986497
{
64996498
std::string payment_id_str = local_args.back();
@@ -6533,6 +6532,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65336532

65346533
vector<cryptonote::address_parse_info> dsts_info;
65356534
vector<cryptonote::tx_destination_entry> dsts;
6535+
std::pair<crypto::hash8, std::size_t> payment_id{crypto::null_hash8, 0};
65366536
for (size_t i = 0; i < local_args.size(); )
65376537
{
65386538
dsts_info.emplace_back();
@@ -6594,19 +6594,18 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
65946594

65956595
if (info.has_payment_id || !payment_id_uri.empty())
65966596
{
6597-
if (payment_id_seen)
6597+
if (payment_id.first != crypto::null_hash8) // other pid seen before
65986598
{
65996599
fail_msg_writer() << tr("a single transaction cannot use more than one payment id");
66006600
return false;
66016601
}
66026602

6603-
crypto::hash payment_id;
6604-
std::string extra_nonce;
6603+
crypto::hash ignored_long_pid;
66056604
if (info.has_payment_id)
66066605
{
6607-
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
6606+
payment_id = {info.payment_id, dsts.size()};
66086607
}
6609-
else if (tools::wallet2::parse_payment_id(payment_id_uri, payment_id))
6608+
else if (tools::wallet2::parse_payment_id(payment_id_uri, ignored_long_pid))
66106609
{
66116610
LONG_PAYMENT_ID_SUPPORT_CHECK();
66126611
}
@@ -6615,13 +6614,6 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
66156614
fail_msg_writer() << tr("failed to parse payment id, though it was detected");
66166615
return false;
66176616
}
6618-
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
6619-
if(!r)
6620-
{
6621-
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
6622-
return false;
6623-
}
6624-
payment_id_seen = true;
66256617
}
66266618

66276619
dsts.push_back(de);
@@ -6639,7 +6631,7 @@ bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool ca
66396631
try
66406632
{
66416633
// figure out what tx will be necessary
6642-
auto ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, priority, extra,
6634+
auto ptx_vector = m_wallet->create_transactions_2(dsts, payment_id, fake_outs_count, priority, /*extra=*/{},
66436635
m_current_subaddress_account, subaddr_indices, subtract_fee_from_outputs);
66446636

66456637
if (ptx_vector.empty())
@@ -7075,14 +7067,13 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vect
70757067
}
70767068
}
70777069

7078-
std::vector<uint8_t> extra;
7079-
bool payment_id_seen = false;
7070+
// Fail on parsed long payment ID
70807071
if (local_args.size() >= 2)
70817072
{
70827073
std::string payment_id_str = local_args.back();
70837074

7084-
crypto::hash payment_id;
7085-
bool r = tools::wallet2::parse_long_payment_id(payment_id_str, payment_id);
7075+
crypto::hash ignored_long_pid;
7076+
bool r = tools::wallet2::parse_long_payment_id(payment_id_str, ignored_long_pid);
70867077
if(r)
70877078
{
70887079
LONG_PAYMENT_ID_SUPPORT_CHECK();
@@ -7094,8 +7085,6 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vect
70947085
print_usage();
70957086
return true;
70967087
}
7097-
if (payment_id_seen)
7098-
local_args.pop_back();
70997088
}
71007089

71017090
cryptonote::address_parse_info info;
@@ -7106,31 +7095,12 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vect
71067095
return true;
71077096
}
71087097

7109-
if (info.has_payment_id)
7110-
{
7111-
if (payment_id_seen)
7112-
{
7113-
fail_msg_writer() << tr("a single transaction cannot use more than one payment id: ") << local_args[0];
7114-
return true;
7115-
}
7116-
7117-
std::string extra_nonce;
7118-
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
7119-
bool r = add_extra_nonce_to_tx_extra(extra, extra_nonce);
7120-
if(!r)
7121-
{
7122-
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
7123-
return true;
7124-
}
7125-
payment_id_seen = true;
7126-
}
7127-
71287098
SCOPED_WALLET_UNLOCK();
71297099

71307100
try
71317101
{
71327102
// figure out what tx will be necessary
7133-
auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, outputs, fake_outs_count, priority, extra, account, subaddr_indices);
7103+
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);
71347104

71357105
if (ptx_vector.empty())
71367106
{
@@ -7325,13 +7295,11 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
73257295
}
73267296
}
73277297

7328-
std::vector<uint8_t> extra;
7329-
bool payment_id_seen = false;
7298+
// Fail on parsed long payment ID
73307299
if (local_args.size() == 3)
73317300
{
7332-
crypto::hash payment_id;
7333-
std::string extra_nonce;
7334-
if (tools::wallet2::parse_long_payment_id(local_args.back(), payment_id))
7301+
crypto::hash ignored_long_pid;
7302+
if (tools::wallet2::parse_long_payment_id(local_args.back(), ignored_long_pid))
73357303
{
73367304
LONG_PAYMENT_ID_SUPPORT_CHECK();
73377305
}
@@ -7340,15 +7308,6 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
73407308
fail_msg_writer() << tr("failed to parse Payment ID");
73417309
return true;
73427310
}
7343-
7344-
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
7345-
{
7346-
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
7347-
return true;
7348-
}
7349-
7350-
local_args.pop_back();
7351-
payment_id_seen = true;
73527311
}
73537312

73547313
if (local_args.size() != 2)
@@ -7371,30 +7330,12 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
73717330
return true;
73727331
}
73737332

7374-
if (info.has_payment_id)
7375-
{
7376-
if (payment_id_seen)
7377-
{
7378-
fail_msg_writer() << tr("a single transaction cannot use more than one payment id: ") << local_args[0];
7379-
return true;
7380-
}
7381-
7382-
std::string extra_nonce;
7383-
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
7384-
if (!add_extra_nonce_to_tx_extra(extra, extra_nonce))
7385-
{
7386-
fail_msg_writer() << tr("failed to set up payment id, though it was decoded correctly");
7387-
return true;
7388-
}
7389-
payment_id_seen = true;
7390-
}
7391-
73927333
SCOPED_WALLET_UNLOCK();
73937334

73947335
try
73957336
{
73967337
// figure out what tx will be necessary
7397-
auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, outputs, fake_outs_count, priority, extra);
7338+
auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, outputs, info.payment_id, fake_outs_count, priority, /*extra=*/{});
73987339

73997340
if (ptx_vector.empty())
74007341
{
@@ -7561,14 +7502,18 @@ bool simple_wallet::donate(const std::vector<std::string> &args_)
75617502
std::string amount_str;
75627503
std::string payment_id_str;
75637504
// get payment id and pop
7564-
crypto::hash payment_id;
7565-
crypto::hash8 payment_id8;
7505+
crypto::hash payment_id = crypto::null_hash;
7506+
crypto::hash8 payment_id8 = crypto::null_hash8;
75667507
if (tools::wallet2::parse_long_payment_id (local_args.back(), payment_id ) ||
75677508
tools::wallet2::parse_short_payment_id(local_args.back(), payment_id8))
75687509
{
75697510
payment_id_str = local_args.back();
75707511
local_args.pop_back();
75717512
}
7513+
if (payment_id != crypto::null_hash)
7514+
{
7515+
LONG_PAYMENT_ID_SUPPORT_CHECK();
7516+
}
75727517
// get amount and pop
75737518
uint64_t amount;
75747519
bool ok = cryptonote::parse_amount(amount, local_args.back());

src/wallet/api/wallet.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,6 @@ 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;
16361634
vector<cryptonote::tx_destination_entry> dsts;
16371635
if (!amount && dst_addr.size() > 1) {
16381636
setStatusError(tr("Sending all requires one destination address"));
@@ -1643,15 +1641,11 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
16431641
break;
16441642
}
16451643
if (!payment_id.empty()) {
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-
}
1644+
setStatusError(tr("Long payment IDs are obsolete and no longer supported"));
1645+
break;
16531646
}
16541647
bool error = false;
1648+
std::pair<crypto::hash8, std::size_t> payment_id{crypto::null_hash8, 0};
16551649
for (size_t i = 0; i < dst_addr.size() && !error; i++) {
16561650
if(!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), dst_addr[i])) {
16571651
// TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982
@@ -1660,12 +1654,12 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
16601654
break;
16611655
}
16621656
if (info.has_payment_id) {
1663-
if (!extra_nonce.empty()) {
1657+
if (payment_id.first != crypto::null_hash8) {
16641658
setStatusError(tr("a single transaction cannot use more than one payment id"));
16651659
error = true;
16661660
break;
16671661
}
1668-
set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, info.payment_id);
1662+
payment_id = {info.payment_id, dsts.size()};
16691663
}
16701664

16711665
if (amount) {
@@ -1686,22 +1680,21 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
16861680
if (error) {
16871681
break;
16881682
}
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-
}
16931683
try {
16941684
size_t fake_outs_count = mixin_count > 0 ? mixin_count : m_wallet->default_mixin();
16951685
fake_outs_count = m_wallet->adjust_mixin(mixin_count);
16961686

16971687
if (amount) {
1698-
transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count,
1688+
transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, payment_id, fake_outs_count,
16991689
adjusted_priority,
1700-
extra, subaddr_account, subaddr_indices);
1690+
/*extra=*/{},
1691+
subaddr_account, subaddr_indices);
17011692
} else {
1702-
transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1, fake_outs_count,
1693+
transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1,
1694+
payment_id.first, fake_outs_count,
17031695
adjusted_priority,
1704-
extra, subaddr_account, subaddr_indices);
1696+
/*extra=*/{}, subaddr_account,
1697+
subaddr_indices);
17051698
}
17061699
pendingTxPostProcess(transaction);
17071700

0 commit comments

Comments
 (0)