diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp index 252911b..7b3e555 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -4907,9 +4907,17 @@ bool SelectCoins(int64 nTargetValue, set<CWalletTx*>& setCoinsRet) | |||
| 4907 | 4907 | ||
| 4908 | 4908 | ||
| 4909 | 4909 | ||
| 4910 | bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, int64& nFeeRequiredRet) | 4910 | // presultRet, when given, says WHY this returned false: the caller cannot work |
| 4911 | // it out afterwards. "Coin selection came up short" and "the wallet could not | ||
| 4912 | // build the transaction" are indistinguishable from the outside -- both are | ||
| 4913 | // just `false` -- and the difference decides whether a pool defers a payment | ||
| 4914 | // or counts it against the payment's retry budget. See WalletSendResult. | ||
| 4915 | bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, int64& nFeeRequiredRet, | ||
| 4916 | WalletSendResult* presultRet) | ||
| 4911 | { | 4917 | { |
| 4912 | nFeeRequiredRet = 0; | 4918 | nFeeRequiredRet = 0; |
| 4919 | if (presultRet) | ||
| 4920 | *presultRet = WALLET_SEND_FAILED; | ||
| 4913 | CRITICAL_BLOCK(cs_main) | 4921 | CRITICAL_BLOCK(cs_main) |
| 4914 | { | 4922 | { |
| 4915 | // txdb must be opened before the mapWallet lock | 4923 | // txdb must be opened before the mapWallet lock |
| @@ -4940,10 +4948,21 @@ bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, in | |||
| 4940 | // fixed this in 107d9e288. | 4948 | // fixed this in 107d9e288. |
| 4941 | int64 nTotalValue = nValue + nFee; | 4949 | int64 nTotalValue = nValue + nFee; |
| 4942 | 4950 | ||
| 4943 | // Choose coins to use | 4951 | // Choose coins to use. |
| 4952 | // | ||
| 4953 | // Failing here is a funding shortfall and nothing else: there | ||
| 4954 | // is not enough spendable coin for nValue plus the fee this | ||
| 4955 | // pass is working with. On the second and later passes that | ||
| 4956 | // fee is GetMinFee() of the transaction the first pass built, | ||
| 4957 | // so this is also how a wallet that can afford the amount but | ||
| 4958 | // not the 11 * CENT charged at 10,000 bytes reports itself. | ||
| 4944 | set<CWalletTx*> setCoins; | 4959 | set<CWalletTx*> setCoins; |
| 4945 | if (!SelectCoins(nTotalValue, setCoins)) | 4960 | if (!SelectCoins(nTotalValue, setCoins)) |
| 4961 | { | ||
| 4962 | if (presultRet) | ||
| 4963 | *presultRet = WALLET_SEND_INSUFFICIENT_FUNDS; | ||
| 4946 | return false; | 4964 | return false; |
| 4965 | } | ||
| 4947 | int64 nValueIn = 0; | 4966 | int64 nValueIn = 0; |
| 4948 | foreach(CWalletTx* pcoin, setCoins) | 4967 | foreach(CWalletTx* pcoin, setCoins) |
| 4949 | nValueIn += pcoin->GetCredit(); | 4968 | nValueIn += pcoin->GetCredit(); |
| @@ -5013,6 +5032,8 @@ bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, in | |||
| 5013 | } | 5032 | } |
| 5014 | } | 5033 | } |
| 5015 | } | 5034 | } |
| 5035 | if (presultRet) | ||
| 5036 | *presultRet = WALLET_SEND_OK; | ||
| 5016 | return true; | 5037 | return true; |
| 5017 | } | 5038 | } |
| 5018 | 5039 | ||
| @@ -5075,13 +5096,24 @@ bool CommitTransactionSpent(const CWalletTx& wtxNew) | |||
| 5075 | 5096 | ||
| 5076 | 5097 | ||
| 5077 | 5098 | ||
| 5078 | bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew) | 5099 | // outcomeRet reports what happened rather than only whether it worked. A |
| 5100 | // caller that has to decide what a failure MEANS -- the pool payout thread -- | ||
| 5101 | // cannot reconstruct it from a balance reading afterwards, because the fee | ||
| 5102 | // that was actually required depends on the size of a transaction that was | ||
| 5103 | // never built. See WalletSendResult. | ||
| 5104 | bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, | ||
| 5105 | SendMoneyOutcome& outcomeRet) | ||
| 5079 | { | 5106 | { |
| 5107 | outcomeRet.result = WALLET_SEND_FAILED; | ||
| 5108 | outcomeRet.nFeeRequired = 0; | ||
| 5080 | CRITICAL_BLOCK(cs_main) | 5109 | CRITICAL_BLOCK(cs_main) |
| 5081 | { | 5110 | { |
| 5082 | int64 nFeeRequired; | 5111 | int64 nFeeRequired; |
| 5083 | if (!CreateTransaction(scriptPubKey, nValue, wtxNew, nFeeRequired)) | 5112 | WalletSendResult createResult = WALLET_SEND_FAILED; |
| 5113 | if (!CreateTransaction(scriptPubKey, nValue, wtxNew, nFeeRequired, &createResult)) | ||
| 5084 | { | 5114 | { |
| 5115 | outcomeRet.result = createResult; | ||
| 5116 | outcomeRet.nFeeRequired = nFeeRequired; | ||
| 5085 | string strError; | 5117 | string strError; |
| 5086 | if (nValue + nFeeRequired > GetBalance()) | 5118 | if (nValue + nFeeRequired > GetBalance()) |
| 5087 | // Not an oversized transaction -- this branch is simply "the | 5119 | // Not an oversized transaction -- this branch is simply "the |
| @@ -5119,6 +5151,13 @@ bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew) | |||
| 5119 | } | 5151 | } |
| 5120 | wtxNew.RelayWalletTransaction(); | 5152 | wtxNew.RelayWalletTransaction(); |
| 5121 | } | 5153 | } |
| 5154 | outcomeRet.result = WALLET_SEND_OK; | ||
| 5122 | MainFrameRepaint(); | 5155 | MainFrameRepaint(); |
| 5123 | return true; | 5156 | return true; |
| 5124 | } | 5157 | } |
| 5158 | |||
| 5159 | bool SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew) | ||
| 5160 | { | ||
| 5161 | SendMoneyOutcome ignored; | ||
| 5162 | return SendMoney(scriptPubKey, nValue, wtxNew, ignored); | ||
| 5163 | } | ||