Skip to content

Commit

Permalink
Add ttl to WalletGreen
Browse files Browse the repository at this point in the history
  • Loading branch information
AxVultis committed Apr 22, 2023
1 parent 8edffed commit a2f8ed3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/IWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ struct TransactionParameters
uint64_t unlockTimestamp = 0;
DonationSettings donation;
std::string changeDestination;
uint64_t ttl = 0;
};

struct WalletTransactionWithTransfers
Expand Down
2 changes: 1 addition & 1 deletion src/ConcealWallet/ConcealWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ bool conceal_wallet::transfer(const std::vector<std::string> &args) {
sendParams.destinations = cmd.dsts;
sendParams.messages = messages;
sendParams.extra = extraString;
sendParams.unlockTimestamp = ttl;
sendParams.ttl = ttl;
sendParams.changeDestination = m_wallet->getAddress(0);

crypto::SecretKey transactionSK;
Expand Down
21 changes: 17 additions & 4 deletions src/Wallet/WalletGreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,10 +1909,14 @@ namespace cn
uint64_t unlockTimestamp,
const DonationSettings &donation,
const cn::AccountPublicAddress &changeDestination,
uint64_t ttl,
PreparedTransaction &preparedTransaction,
crypto::SecretKey &transactionSK)
{

if (ttl != 0)
{
fee = 0;
}
preparedTransaction.destinations = convertOrdersToTransfers(orders);
preparedTransaction.neededMoney = countNeededMoney(preparedTransaction.destinations, fee);

Expand Down Expand Up @@ -1950,7 +1954,7 @@ namespace cn
decomposedOutputs.emplace_back(std::move(splittedChange));
}

preparedTransaction.transaction = makeTransaction(decomposedOutputs, keysInfo, messages, extra, unlockTimestamp, transactionSK);
preparedTransaction.transaction = makeTransaction(decomposedOutputs, keysInfo, messages, extra, unlockTimestamp, ttl, transactionSK);
}

void WalletGreen::validateTransactionParameters(const TransactionParameters &transactionParameters) const
Expand Down Expand Up @@ -1996,6 +2000,7 @@ namespace cn
transactionParameters.unlockTimestamp,
transactionParameters.donation,
changeDestination,
transactionParameters.ttl,
preparedTransaction,
transactionSK);

Expand Down Expand Up @@ -2591,7 +2596,7 @@ namespace cn
}

std::unique_ptr<cn::ITransaction> WalletGreen::makeTransaction(const std::vector<ReceiverAmounts> &decomposedOutputs,
std::vector<InputInfo> &keysInfo, const std::vector<WalletMessage> &messages, const std::string &extra, uint64_t unlockTimestamp, crypto::SecretKey &transactionSK)
std::vector<InputInfo> &keysInfo, const std::vector<WalletMessage> &messages, const std::string &extra, uint64_t unlockTimestamp, uint64_t ttl, crypto::SecretKey &transactionSK)
{

std::unique_ptr<ITransaction> tx = createTransaction();
Expand Down Expand Up @@ -2637,6 +2642,13 @@ namespace cn
}
}

if (ttl != 0)
{
BinaryArray ba;
cn::appendTTLToExtra(ba, ttl);
tx->appendExtra(ba);
}

for (const auto &amountToAddress : amountsToAddresses)
{
tx->addOutput(amountToAddress.second, *amountToAddress.first);
Expand Down Expand Up @@ -4063,7 +4075,7 @@ namespace cn

crypto::SecretKey txkey;
std::vector<WalletMessage> messages;
fusionTransaction = makeTransaction(std::vector<ReceiverAmounts>{decomposedOutputs}, keysInfo, messages, "", 0, txkey);
fusionTransaction = makeTransaction(std::vector<ReceiverAmounts>{decomposedOutputs}, keysInfo, messages, "", 0, 0, txkey);
transactionSize = getTransactionSize(*fusionTransaction);

++round;
Expand Down Expand Up @@ -4666,6 +4678,7 @@ namespace cn
sendingTransaction.unlockTimestamp,
sendingTransaction.donation,
changeDestination,
sendingTransaction.ttl,
preparedTransaction,
txSecretKey);

Expand Down
3 changes: 2 additions & 1 deletion src/Wallet/WalletGreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class WalletGreen : public IObservableImpl<IWalletObserver, IWallet>,
uint64_t unlockTimestamp,
const DonationSettings &donation,
const cn::AccountPublicAddress &changeDestinationAddress,
uint64_t ttl,
PreparedTransaction &preparedTransaction,
crypto::SecretKey &transactionSK);
void validateAddresses(const std::vector<std::string> &addresses) const;
Expand Down Expand Up @@ -302,7 +303,7 @@ class WalletGreen : public IObservableImpl<IWalletObserver, IWallet>,
ReceiverAmounts splitAmount(uint64_t amount, const AccountPublicAddress &destination, uint64_t dustThreshold) const;

std::unique_ptr<cn::ITransaction> makeTransaction(const std::vector<ReceiverAmounts> &decomposedOutputs,
std::vector<InputInfo> &keysInfo, const std::vector<WalletMessage> &messages, const std::string &extra, uint64_t unlockTimestamp, crypto::SecretKey &transactionSK);
std::vector<InputInfo> &keysInfo, const std::vector<WalletMessage> &messages, const std::string &extra, uint64_t unlockTimestamp, uint64_t ttl, crypto::SecretKey &transactionSK);

void sendTransaction(const cn::Transaction &cryptoNoteTransaction);
size_t validateSaveAndSendTransaction(const ITransactionReader &transaction, const std::vector<WalletTransfer> &destinations, bool isFusion, bool send);
Expand Down

0 comments on commit a2f8ed3

Please sign in to comment.