You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

walletmodeltransaction.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (c) 2011-2016 The Starwels developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "walletmodeltransaction.h"
  5. #include "policy/policy.h"
  6. #include "wallet/wallet.h"
  7. WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &_recipients) :
  8. recipients(_recipients),
  9. walletTransaction(0),
  10. keyChange(0),
  11. fee(0)
  12. {
  13. walletTransaction = new CWalletTx();
  14. }
  15. WalletModelTransaction::~WalletModelTransaction()
  16. {
  17. delete keyChange;
  18. delete walletTransaction;
  19. }
  20. QList<SendCoinsRecipient> WalletModelTransaction::getRecipients()
  21. {
  22. return recipients;
  23. }
  24. CWalletTx *WalletModelTransaction::getTransaction()
  25. {
  26. return walletTransaction;
  27. }
  28. unsigned int WalletModelTransaction::getTransactionSize()
  29. {
  30. return (!walletTransaction ? 0 : ::GetVirtualTransactionSize(*walletTransaction));
  31. }
  32. CAmount WalletModelTransaction::getTransactionFee()
  33. {
  34. return fee;
  35. }
  36. void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
  37. {
  38. fee = newFee;
  39. }
  40. void WalletModelTransaction::reassignAmounts(int nChangePosRet)
  41. {
  42. int i = 0;
  43. for (QList<SendCoinsRecipient>::iterator it = recipients.begin(); it != recipients.end(); ++it)
  44. {
  45. SendCoinsRecipient& rcp = (*it);
  46. if (rcp.paymentRequest.IsInitialized())
  47. {
  48. CAmount subtotal = 0;
  49. const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
  50. for (int j = 0; j < details.outputs_size(); j++)
  51. {
  52. const payments::Output& out = details.outputs(j);
  53. if (out.amount() <= 0) continue;
  54. if (i == nChangePosRet)
  55. i++;
  56. subtotal += walletTransaction->tx->vout[i].nValue;
  57. i++;
  58. }
  59. rcp.amount = subtotal;
  60. }
  61. else // normal recipient (no payment request)
  62. {
  63. if (i == nChangePosRet)
  64. i++;
  65. rcp.amount = walletTransaction->tx->vout[i].nValue;
  66. i++;
  67. }
  68. }
  69. }
  70. CAmount WalletModelTransaction::getTotalTransactionAmount()
  71. {
  72. CAmount totalTransactionAmount = 0;
  73. for (const SendCoinsRecipient &rcp : recipients)
  74. {
  75. totalTransactionAmount += rcp.amount;
  76. }
  77. return totalTransactionAmount;
  78. }
  79. void WalletModelTransaction::newPossibleKeyChange(CWallet *wallet)
  80. {
  81. keyChange = new CReserveKey(wallet);
  82. }
  83. CReserveKey *WalletModelTransaction::getPossibleKeyChange()
  84. {
  85. return keyChange;
  86. }