-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi send #1445
base: master
Are you sure you want to change the base?
Multi send #1445
Conversation
WalkthroughThe changes primarily focus on enhancing the functionality and validation of Spark transactions, including minting, sending, and spending Spark tokens. The updates introduce new parameters, improve transaction handling, and refine the logic for validating and processing transactions. Additionally, modifications in the UI components reflect these backend changes, ensuring seamless integration and user experience. Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 9
Outside diff range and nitpick comments (1)
src/qt/walletmodel.cpp (1)
Line range hint
1358-1412
: RefactorprepareMintSparkTransaction
to improve readability and maintainability.The
prepareMintSparkTransaction
method has multiple responsibilities, including validation, transaction creation, and error handling. Consider breaking this method into smaller, more focused methods. For example, separate the validation logic into a methodvalidateRecipients
, and the transaction creation logic intocreateMintSparkTransaction
. This will make the code easier to maintain and test.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (16)
- qa/rpc-tests/llmq-is-spark.py (1 hunks)
- qa/rpc-tests/spark_mint.py (1 hunks)
- qa/rpc-tests/spark_setmintstatus_validation.py (2 hunks)
- qa/rpc-tests/spark_spend_gettransaction.py (1 hunks)
- src/qt/sendcoinsdialog.cpp (4 hunks)
- src/qt/sparkmodel.cpp (2 hunks)
- src/qt/walletmodel.cpp (3 hunks)
- src/qt/walletmodeltransaction.cpp (2 hunks)
- src/spark/sparkwallet.cpp (9 hunks)
- src/spark/sparkwallet.h (1 hunks)
- src/test/evospork_tests.cpp (1 hunks)
- src/test/fixtures.cpp (2 hunks)
- src/wallet/rpcwallet.cpp (3 hunks)
- src/wallet/test/spark_tests.cpp (9 hunks)
- src/wallet/wallet.cpp (7 hunks)
- src/wallet/wallet.h (2 hunks)
Files not reviewed due to errors (6)
- qa/rpc-tests/spark_setmintstatus_validation.py (no review received)
- src/qt/walletmodeltransaction.cpp (no review received)
- qa/rpc-tests/spark_spend_gettransaction.py (no review received)
- qa/rpc-tests/llmq-is-spark.py (no review received)
- src/qt/sparkmodel.cpp (no review received)
- qa/rpc-tests/spark_mint.py (no review received)
Additional context used
Ruff
qa/rpc-tests/spark_setmintstatus_validation.py
3-3:
from test_framework.util import *
used; unable to detect undefined names
13-13:
enable_mocktime
may be undefined, or defined from star imports
14-14:
start_nodes
may be undefined, or defined from star imports
65-65:
assert_raises
may be undefined, or defined from star imports
65-65:
JSONRPCException
may be undefined, or defined from star imports
66-66:
assert_raises
may be undefined, or defined from star imports
66-66:
JSONRPCException
may be undefined, or defined from star imports
67-67:
assert_raises
may be undefined, or defined from star imports
67-67:
JSONRPCException
may be undefined, or defined from star imports
68-68:
assert_raises
may be undefined, or defined from star imports
68-68:
JSONRPCException
may be undefined, or defined from star imports
69-69:
assert_raises
may be undefined, or defined from star imports
69-69:
JSONRPCException
may be undefined, or defined from star importsqa/rpc-tests/spark_spend_gettransaction.py
2-2:
from decimal import *
used; unable to detect undefined names
5-5:
from test_framework.util import *
used; unable to detect undefined names
15-15:
enable_mocktime
may be undefined, or defined from star imports
16-16:
start_nodes
may be undefined, or defined from star imports
29-29: Local variable
valid_address
is assigned to but never used
55-55:
Decimal
may be undefined, or defined from star imports
65-65:
Decimal
may be undefined, or defined from star imports
77-77:
assert_raises
may be undefined, or defined from star imports
77-77:
JSONRPCException
may be undefined, or defined from star importsqa/rpc-tests/llmq-is-spark.py
6-6:
from test_framework.mininode import *
used; unable to detect undefined names
8-8:
test_framework.util.sync_blocks
imported but unused
8-8:
test_framework.util.set_node_times
imported but unused
9-9:
test_framework.util.isolate_node
imported but unused
9-9:
test_framework.util.reconnect_isolated_node
imported but unused
9-9:
test_framework.util.set_mocktime
imported but unused
9-9:
test_framework.util.get_mocktime
imported but unused
10-10:
test_framework.util.assert_equal
imported but unused
11-11:
test_framework.util.bitcoind_processes
imported but unused
11-11:
test_framework.util.start_nodes
imported but unused
11-11:
test_framework.util.start_node
imported but unused
11-11:
test_framework.util.connect_nodes_bi
imported but unused
43-43: Statement ends with an unnecessary semicolon
56-56: Statement ends with an unnecessary semicolon
Additional comments not posted (19)
src/spark/sparkwallet.h (1)
117-117
: The addition ofvecSend
parameter inCreateSparkMintTransactions
method aligns with the PR's multi-send feature.src/test/fixtures.cpp (1)
Line range hint
362-373
: The initialization ofvecSend
and its use inMintAndStoreSpark
correctly reflects the changes made inCSparkWallet
. This ensures that the test setup aligns with the new functionality.src/wallet/test/spark_tests.cpp (1)
79-80
: The introduction ofvecSend
in various test cases correctly reflects the updated method signature inMintAndStoreSpark
. The tests are well-structured to check the new functionality.Also applies to: 185-186, 335-336, 426-427, 477-477
src/qt/sendcoinsdialog.cpp (4)
533-533
: Confirm the handling of Spark transactions in non-anonymous mode.Verification successful
Let's proceed by examining the implementation of the
mintSparkCoins
method inwalletmodel.cpp
to ensure it handles Spark transactions correctly.
Let's try a different approach to locate and review the implementation of the
mintSparkCoins
method inwalletmodel.cpp
.
The implementation of the
mintSparkCoins
method inwalletmodel.cpp
has been successfully retrieved. The method appears to handle Spark transactions by committing transactions and processing recipients' messages.
- The method locks the wallet and main chain.
- It iterates over the transactions and commits each one.
- It handles messages from recipients and serializes the transaction.
This confirms that the
mintSparkCoins
method is designed to handle Spark transactions properly whenfAnonymousMode
is false,sparkAddressCount
is greater than 0, andspark::IsSparkAllowed()
returns true.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that Spark transactions are handled correctly when `fAnonymousMode` is false and `sparkAddressCount` is greater than 0. # Test: Search for the method usage. Expect: Proper transaction handling. rg --type cpp $'mintSparkCoins'Length of output: 421
Script:
#!/bin/bash # Description: Retrieve the implementation of the mintSparkCoins method in walletmodel.cpp to verify proper handling of Spark transactions. # Extract the implementation of mintSparkCoins from walletmodel.cpp ast-grep --lang cpp --pattern $'WalletModel::SendCoinsReturn WalletModel::mintSparkCoins($_, $_, $_) { $$$ }'Length of output: 112
Script:
#!/bin/bash # Description: Retrieve the implementation of the mintSparkCoins method in walletmodel.cpp to verify proper handling of Spark transactions. # Extract the implementation of mintSparkCoins from walletmodel.cpp using ripgrep to locate the function definition. rg --type cpp --context 20 'WalletModel::SendCoinsReturn WalletModel::mintSparkCoins'Length of output: 2834
491-491
: Check the total amount calculation logic for various transaction scenarios.Verification successful
The
getTotalTransactionAmount
method inwalletmodeltransaction.cpp
sums up the amounts from therecipients
list. This logic appears straightforward and correct for calculating the total transaction amount.The usage of this method in
sendcoinsdialog.cpp
andlelantusdialog.cpp
also seems consistent with its purpose.
sendcoinsdialog.cpp
:
mintSparkAmount += transaction.getTotalTransactionAmount();
totalAmount = currentTransaction.getTotalTransactionAmount() + txFee;
lelantusdialog.cpp
:
allAmount += wtx.getTotalTransactionAmount();
These usages indicate that the total transaction amount is being correctly calculated and used in different contexts.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the total amount is calculated correctly for different transaction scenarios, especially when `fAnonymousMode` is toggled. # Test: Search for the method usage. Expect: Correct total amount calculations. rg --type cpp $'getTotalTransactionAmount'Length of output: 492
Script:
#!/bin/bash # Retrieve the implementation of getTotalTransactionAmount in walletmodeltransaction.cpp ast-grep --lang cpp --pattern $'CAmount WalletModelTransaction::getTotalTransactionAmount() { $$$ }' --json # Retrieve the usage of getTotalTransactionAmount in sendcoinsdialog.cpp rg --type cpp 'getTotalTransactionAmount' src/qt/sendcoinsdialog.cpp # Retrieve the usage of getTotalTransactionAmount in lelantusdialog.cpp rg --type cpp 'getTotalTransactionAmount' src/qt/lelantusdialog.cppLength of output: 454
Script:
#!/bin/bash # Retrieve the implementation of getTotalTransactionAmount in walletmodeltransaction.cpp rg --type cpp 'CAmount WalletModelTransaction::getTotalTransactionAmount' src/qt/walletmodeltransaction.cppLength of output: 169
Script:
#!/bin/bash # Retrieve the full implementation of getTotalTransactionAmount in walletmodeltransaction.cpp rg --type cpp -A 10 -B 10 'CAmount WalletModelTransaction::getTotalTransactionAmount' src/qt/walletmodeltransaction.cppLength of output: 588
465-465
: Validate the calculation of transaction fees and sizes for Spark transactions.
335-335
: Ensure correct handling of Spark transactions whenfAnonymousMode
is false.Verification successful
Ensure correct handling of Spark transactions when
fAnonymousMode
is false.The
prepareMintSparkTransaction
method insrc/qt/walletmodel.cpp
correctly handles Spark transactions, including checks for valid addresses, amounts, and balance. The method prepares the transaction data and ensures that the transaction is created successfully, emitting error messages if any issues arise.
src/qt/walletmodel.cpp
: Implementation ofprepareMintSparkTransaction
method.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the `prepareMintSparkTransaction` method correctly handles transactions when `fAnonymousMode` is false and `sparkAddressCount` is greater than 0. # Test: Search for the method usage. Expect: Proper handling of transactions. rg --type cpp $'prepareMintSparkTransaction'Length of output: 571
Script:
#!/bin/bash # Extract the implementation of the `prepareMintSparkTransaction` method from `src/qt/walletmodel.cpp`. ast-grep --lang cpp --pattern $'SendCoinsReturn WalletModel::prepareMintSparkTransaction($_, $_, $_, $_, $_) { $$$ }' src/qt/walletmodel.cppLength of output: 143
Script:
#!/bin/bash # Extract the implementation of the `prepareMintSparkTransaction` method from `src/qt/walletmodel.cpp` with a more flexible pattern. ast-grep --lang cpp --pattern $'SendCoinsReturn WalletModel::prepareMintSparkTransaction($_, $_, $_, $_, $_) { $$$ }' src/qt/walletmodel.cppLength of output: 143
Script:
#!/bin/bash # Search for the definition of `prepareMintSparkTransaction` in `src/qt/walletmodel.cpp` and extract the surrounding lines to get the full implementation. rg --context 20 'SendCoinsReturn WalletModel::prepareMintSparkTransaction' src/qt/walletmodel.cppLength of output: 1482
Script:
#!/bin/bash # Search for the definition of `prepareMintSparkTransaction` in `src/qt/walletmodel.cpp` and extract more surrounding lines to get the full implementation. rg --context 50 'SendCoinsReturn WalletModel::prepareMintSparkTransaction' src/qt/walletmodel.cppLength of output: 3279
Script:
#!/bin/bash # Search for the definition of `prepareMintSparkTransaction` in `src/qt/walletmodel.cpp` and extract even more surrounding lines to get the full implementation. rg --context 100 'SendCoinsReturn WalletModel::prepareMintSparkTransaction' src/qt/walletmodel.cppLength of output: 7304
src/wallet/wallet.h (2)
1041-1041
: Ensure the new method signature is consistent with its implementation and usage across the project.Verification successful
The method signature for
CreateSparkMintTransactions
is consistent across the project. The header file, source file implementations, and usages all align with the new signature.
- Header File:
src/wallet/wallet.h
- Source File Implementations:
src/wallet/wallet.cpp
,src/spark/sparkwallet.cpp
- Usages:
src/wallet/wallet.cpp
,src/qt/walletmodel.cpp
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the new method signature for `CreateSparkMintTransactions` is used consistently across the project. # Test: Search for the method usage. Expect: Only occurrences of the new signature. ast-grep --lang cpp --pattern $'class CWallet { $$$ CreateSparkMintTransactions($_, $_, $_, $_, $_, $_, $_, $_, $_, $_) { $$$ } $$$ }'Length of output: 494
Script:
#!/bin/bash # Description: Verify the method signature for `CreateSparkMintTransactions` in the header file and its implementation and usage across the project. # Step 1: Search for the method signature in the header file. echo "Searching for method signature in header files..." ast-grep --lang cpp --pattern 'CreateSparkMintTransactions(const std::vector<CRecipient>&, $_, $_, $_, $_, $_, $_, $_, $_)' > header_signature.txt # Step 2: Search for the method implementation in the source files. echo "Searching for method implementation in source files..." ast-grep --lang cpp --pattern 'CreateSparkMintTransactions(const std::vector<CRecipient>&, $_, $_, $_, $_, $_, $_, $_, $_) {' > source_implementation.txt # Step 3: Search for the method usage across the project. echo "Searching for method usage across the project..." rg 'CreateSparkMintTransactions\(' > method_usage.txt # Combine results for review. echo "Combining results..." cat header_signature.txt source_implementation.txt method_usage.txtLength of output: 1634
1092-1092
: Ensure the new method signature is consistent with its implementation and usage across the project.src/spark/sparkwallet.cpp (2)
753-753
: Ensure proper error handling forCreateSparkMintTransactions
.
1267-1270
: Verify logic for handling remaining transaction value.src/wallet/rpcwallet.cpp (2)
3642-3658
: Ensure the help text and examples are clear and accurate.Verification successful
The help text and examples for the
mintspark
command insrc/wallet/rpcwallet.cpp
appear to be accurate and consistent with the function's implementation. The function definition and the help text both describe the command's usage, parameters, and expected results clearly.
- The help text specifies the format for the
mintspark
command, including the address, amount, memo, and subtractfee parameters.- The examples provided in the help text demonstrate typical use cases for the
mintspark
command, including sending amounts to transparent and private addresses.Based on the extracted implementation and the provided help text, no discrepancies were found.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the accuracy of the help text and examples for the `mintspark` command. # Test: Search for the `mintspark` command usage in the documentation and compare with the help text. rg --type markdown $'mintspark'Length of output: 30
Script:
#!/bin/bash # Description: Locate the implementation of the `mintspark` command in the codebase and review its parameters and usage. # Search for the `mintspark` command implementation in the codebase. ast-grep --lang cpp --pattern $'void mintspark($_) { $$$ }'Length of output: 62
Script:
#!/bin/bash # Description: Search for the `mintspark` keyword in the codebase to locate its definition and usage. # Search for the `mintspark` keyword in the codebase. rg 'mintspark'Length of output: 4136
Script:
#!/bin/bash # Description: Extract the implementation of the `mintspark` function from `src/wallet/rpcwallet.cpp`. # Extract the implementation of the `mintspark` function. ast-grep --lang cpp --pattern $'UniValue mintspark(const JSONRPCRequest& request) { $$$ }' src/wallet/rpcwallet.cppLength of output: 118
Script:
#!/bin/bash # Description: Search for the `mintspark` function definition in `src/wallet/rpcwallet.cpp`. # Search for the `mintspark` function definition. rg 'UniValue mintspark' src/wallet/rpcwallet.cppLength of output: 100
Script:
#!/bin/bash # Description: Extract the full implementation of the `mintspark` function from `src/wallet/rpcwallet.cpp`. # Extract the full implementation of the `mintspark` function. rg -A 50 'UniValue mintspark' src/wallet/rpcwallet.cppLength of output: 4071
3675-3755
: Review the logic for handling Spark and Bitcoin addresses, validating parameters, and preparing data for transaction creation.Verification successful
The verification process has confirmed the presence and implementation of the functions and classes involved in the logic for handling Spark and Bitcoin addresses, validating parameters, and preparing data for transaction creation. The following points summarize the findings:
- The
decode
method for Spark addresses is implemented insrc/libspark/keys.cpp
.- The
CBitcoinAddress
class and itsIsValid
method are implemented insrc/base58.cpp
.- The
AmountFromValue
function is implemented insrc/rpc/server.cpp
.- The
MintAndStoreSpark
method is implemented insrc/wallet/wallet.cpp
.These implementations confirm that the logic in the provided code snippet is supported by the necessary functions and classes.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the logic for handling Spark and Bitcoin addresses, validating parameters, and preparing data for transaction creation. # Test: Search for similar logic in other parts of the codebase and compare for consistency. rg --type cpp $'address handling'Length of output: 34
Script:
#!/bin/bash # Description: Gather information about the implementation of sAddress.decode, CBitcoinAddress, AmountFromValue, and MintAndStoreSpark. # Find the implementation of sAddress.decode ast-grep --lang cpp --pattern $'class Address { $$$ decode($_) { $$$ } $$$ }' # Find the implementation of CBitcoinAddress ast-grep --lang cpp --pattern $'class CBitcoinAddress { $$$ IsValid() { $$$ } $$$ }' # Find the implementation of AmountFromValue ast-grep --lang cpp --pattern $'AmountFromValue($_) { $$$ }' # Find the implementation of MintAndStoreSpark ast-grep --lang cpp --pattern $'class CWallet { $$$ MintAndStoreSpark($_, $_, $_, $_) { $$$ } $$$ }'Length of output: 1401
Script:
#!/bin/bash # Description: Gather information about the implementation of sAddress.decode, CBitcoinAddress, AmountFromValue, and MintAndStoreSpark with refined patterns. # Find the implementation of sAddress.decode ast-grep --lang cpp --pattern $'class $_ { $$$ unsigned char decode($_) { $$$ } $$$ }' # Find the implementation of CBitcoinAddress ast-grep --lang cpp --pattern $'class CBitcoinAddress { $$$ bool IsValid() const { $$$ } $$$ }' # Find the implementation of AmountFromValue ast-grep --lang cpp --pattern $'CAmount AmountFromValue(const UniValue& value) { $$$ }' # Find the implementation of MintAndStoreSpark ast-grep --lang cpp --pattern $'class CWallet { $$$ std::string MintAndStoreSpark(const std::vector<CRecipient>& recipients, const std::vector<spark::MintedCoinData>& outputs, std::vector<std::pair<CWalletTx, CAmount>>& wtxAndFee, bool subtractFeeFromAmount) { $$$ } $$$ }'Length of output: 1621
Script:
#!/bin/bash # Description: Gather information about the implementation of sAddress.decode, CBitcoinAddress, AmountFromValue, and MintAndStoreSpark using rg. # Search for the implementation of sAddress.decode rg 'decode' --type cpp # Search for the implementation of CBitcoinAddress rg 'CBitcoinAddress' --type cpp # Search for the implementation of AmountFromValue rg 'AmountFromValue' --type cpp # Search for the implementation of MintAndStoreSpark rg 'MintAndStoreSpark' --type cppLength of output: 62035
src/wallet/wallet.cpp (6)
Line range hint
1-1
: LGTM! Simple and straightforward addition operation.
5612-5612
: LGTM! Updated function signature aligns with the PR's objectives.
5646-5646
: LGTM! Proper use of the updatedCreateSparkMintTransactions
function.
8176-8176
: LGTM! Consistent update to function signature.
8187-8187
: LGTM! Correct usage of the updatedCreateSparkMintTransactions
.
5927-5927
: Verify the intention behind using empty vectors inMintAndStoreSpark
.Verification successful
Verify the context and intention behind using empty vectors in
MintAndStoreSpark
by examining the function definition and relevant test cases.
Correct the regex pattern in the
rg
command and re-run theast-grep
command to gather the necessary information.
The use of empty vectors
{}
inMintAndStoreSpark
is intentional and validated through test cases. The tests check for expected outcomes, indicating that this usage is correct and purposeful.
- [src/wallet/test/spark_tests.cpp]
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for other occurrences of MintAndStoreSpark to ensure consistency. # Test: Search for other uses of MintAndStoreSpark. Expect: Consistent usage or clear documentation when empty vectors are passed. rg --type cpp $'MintAndStoreSpark'Length of output: 2187
Script:
#!/bin/bash # Description: Retrieve the definition of MintAndStoreSpark and relevant test cases to understand the usage of empty vectors. # Retrieve the function definition from wallet.cpp ast-grep --lang cpp --pattern $'std::string CWallet::MintAndStoreSpark($_, $_, $_, $_, $_, $_, $_) { $$$ }' src/wallet/wallet.cpp # Retrieve the relevant test cases from spark_tests.cpp rg --type cpp --context 10 $'MintAndStoreSpark({}, {}, wtxAndFee, false, true)' src/wallet/test/spark_tests.cppLength of output: 388
Script:
#!/bin/bash # Description: Retrieve the definition of MintAndStoreSpark and relevant test cases to understand the usage of empty vectors. # Retrieve the function definition from wallet.cpp ast-grep --lang cpp --pattern $'std::string CWallet::MintAndStoreSpark($_, $_, $_, $_, $_, $_, $_) { $$$ }' src/wallet/wallet.cpp # Retrieve the relevant test cases from spark_tests.cpp with corrected regex pattern rg --type cpp --context 10 'MintAndStoreSpark\(\{\}, \{\}, wtxAndFee, false, true\)' src/wallet/test/spark_tests.cppLength of output: 1581
std::vector<CRecipient> vecSend; | ||
std::vector<spark::MintedCoinData> mints{{address, 50*COIN, ""}}; | ||
std::string error = pwalletMain->MintAndStoreSpark(mints, wtxAndFee, false); | ||
std::string error = pwalletMain->MintAndStoreSpark(vecSend, mints, wtxAndFee, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling for MintAndStoreSpark
.
The function MintAndStoreSpark
is called without handling potential errors. It's good practice to handle or assert expected outcomes to ensure robustness, especially in test environments. Consider adding error handling or assertions to check the return value.
CAmount nValue = 0; | ||
for (const auto& recipient : vecSend) | ||
{ | ||
if (nValue < 0 || recipient.nAmount < 0) | ||
{ | ||
strFailReason = _("Transaction amounts must not be negative"); | ||
return false; | ||
} | ||
nValue += recipient.nAmount; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for negative transaction amounts.
The check for negative transaction amounts is crucial to prevent erroneous or malicious inputs. Ensure that this validation is robust and consider adding more detailed error messages or handling specific edge cases.
@@ -774,11 +784,14 @@ | |||
assert(txNew.nLockTime <= (unsigned int) chainActive.Height()); | |||
assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | |||
std::vector<spark::MintedCoinData> outputs_ = outputs; | |||
std::vector<CRecipient> sendOutputs = vecSend; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor to improve clarity and maintainability.
Consider renaming valueToSendInTx
to valueToProcessInTx
to better reflect its usage in the context of both sending and processing transactions.
Also applies to: 825-825
sendValue = valueToSendInTx; | ||
if (subtractFeeFromAmount) | ||
nValueToSelect = mintedValue; | ||
nValueToSelect = sendValue; | ||
else | ||
nValueToSelect = mintedValue + nFeeRet; | ||
nValueToSelect = sendValue + nFeeRet; | ||
|
||
// if no enough coins in this group then subtract fee from mint | ||
if (nValueToSelect > itr->first && !subtractFeeFromAmount) { | ||
nValueToSelect = mintedValue; | ||
mintedValue -= nFeeRet; | ||
nValueToSelect = sendValue; | ||
sendValue -= nFeeRet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize fee calculation logic.
The fee calculation logic is repeated multiple times. Consider extracting this into a separate method to reduce redundancy and improve code maintainability.
} | ||
|
||
if (!MoneyRange(mintedValue) || mintedValue == 0) { | ||
if (!MoneyRange(sendValue) || sendValue == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential division by zero in fee distribution.
There is a potential risk of division by zero when calculating singleFee
. Ensure that totalOutputs
is never zero before performing the division.
size_t totalOutputs = singleTxOutputs.size() + singleTxSendOutputs.size(); | ||
CAmount singleFee = nFeeRet / totalOutputs; | ||
CAmount remainder = nFeeRet % totalOutputs; | ||
|
||
for (size_t i = 0; i < singleTxOutputs.size(); ++i) { | ||
if (singleTxOutputs[i].v <= singleFee) { | ||
remainder += singleTxOutputs[i].v - singleFee; | ||
singleTxOutputs.erase(singleTxOutputs.begin() + i); | ||
reminder += singleTxOutputs[i].v - singleFee; | ||
--i; | ||
} else { | ||
singleTxOutputs[i].v -= singleFee; | ||
if (remainder > 0 && singleTxOutputs[i].v > remainder) { | ||
singleTxOutputs[i].v -= remainder; | ||
remainder = 0; | ||
} | ||
} | ||
singleTxOutputs[i].v -= singleFee; | ||
if (reminder > 0 && singleTxOutputs[i].v > nFeeRet % singleTxOutputs.size()) {// first receiver pays the remainder not divisible by output count | ||
singleTxOutputs[i].v -= reminder; | ||
reminder = 0; | ||
} | ||
|
||
for (size_t i = 0; i < singleTxSendOutputs.size(); ++i) { | ||
if (singleTxSendOutputs[i].nAmount <= singleFee) { | ||
remainder += singleTxSendOutputs[i].nAmount - singleFee; | ||
singleTxSendOutputs.erase(singleTxSendOutputs.begin() + i); | ||
--i; | ||
} else { | ||
singleTxSendOutputs[i].nAmount -= singleFee; | ||
if (remainder > 0 && singleTxSendOutputs[i].nAmount > remainder) { | ||
singleTxSendOutputs[i].nAmount -= remainder; | ||
remainder = 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refine fee subtraction logic for clarity.
The logic for subtracting fees from transaction outputs is complex and could be simplified. Consider breaking down the operations into smaller, more manageable functions or adding more comments to clarify the steps involved.
This update enhances multi-sending capabilities. Previously, sending from a transparent address was limited to either another transparent address or a private address. Now, you can send Firo from a transparent address to a private and transparent address. Transaction fees will be evenly distributed across all transactions. When the fee is intended to be deducted from the sent amount, it will be deducted from the total transaction, not from any specific transaction. Sending Firo has now become more versatile and functional.