|
9 | 9 | #include "util.h" // for LogPrintf
|
10 | 10 |
|
11 | 11 | #include <boost/date_time/posix_time/posix_time.hpp>
|
| 12 | +#include <limits> |
| 13 | +#include <map> |
12 | 14 |
|
13 | 15 | // Default BDAP Monthly Fees
|
14 |
| -std::map<int32_t, CAmount> mapDefaultMonthlyFees = { |
15 |
| - {BDAP_MONTHY_USER_FEE, 50 * BDAP_CREDIT}, |
16 |
| - {BDAP_MONTHY_GROUP_FEE, 200 * BDAP_CREDIT}, |
17 |
| - {BDAP_MONTHY_CERTIFICATE_FEE, 100 * BDAP_CREDIT}, |
18 |
| - {BDAP_MONTHY_SIDECHAIN_FEE, 1000 * BDAP_CREDIT}, |
| 16 | +std::map<int32_t, CFeeItem> mapDefaultMonthlyFees = { |
| 17 | + {BDAP_MONTHY_USER_FEE, CFeeItem(BDAP_MONTHY_USER_FEE, 50 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 18 | + {BDAP_MONTHY_GROUP_FEE, CFeeItem(BDAP_MONTHY_GROUP_FEE, 200 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 19 | + {BDAP_MONTHY_CERTIFICATE_FEE, CFeeItem(BDAP_MONTHY_CERTIFICATE_FEE, 100 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 20 | + {BDAP_MONTHY_SIDECHAIN_FEE, CFeeItem(BDAP_MONTHY_SIDECHAIN_FEE, 1000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
19 | 21 | };
|
20 | 22 |
|
21 | 23 | // Default BDAP One Time Fees
|
22 |
| -std::map<int32_t, CAmount> mapOneTimeFees = { |
23 |
| - {BDAP_ONE_TIME_REQUEST_LINK_FEE, 99 * BDAP_CREDIT}, |
24 |
| - {BDAP_ONE_TIME_ACCEPT_LINK_FEE, 99 * BDAP_CREDIT}, |
25 |
| - {BDAP_ONE_TIME_AUDIT_RECORD_FEE, 99 * BDAP_CREDIT}, |
| 24 | +std::multimap<int32_t, CFeeItem> mapOneTimeFees = { |
| 25 | + {BDAP_ONE_TIME_REQUEST_LINK_FEE, CFeeItem(BDAP_ONE_TIME_REQUEST_LINK_FEE, 99 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 26 | + {BDAP_ONE_TIME_ACCEPT_LINK_FEE, CFeeItem(BDAP_ONE_TIME_ACCEPT_LINK_FEE, 99 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 27 | + {BDAP_ONE_TIME_AUDIT_RECORD_FEE, CFeeItem(BDAP_ONE_TIME_AUDIT_RECORD_FEE, 99 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
26 | 28 | };
|
27 | 29 |
|
28 | 30 | // Default BDAP Non-Refundable Security Deposit Fees
|
29 |
| -std::map<int32_t, CAmount> mapNoRefundDeposits = { |
30 |
| - {BDAP_NON_REFUNDABLE_USER_DEPOSIT, 1000 * BDAP_CREDIT}, |
31 |
| - {BDAP_NON_REFUNDABLE_GROUP_DEPOSIT, 10000 * BDAP_CREDIT}, |
32 |
| - {BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT, 5000 * BDAP_CREDIT}, |
33 |
| - {BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT, 25000 * BDAP_CREDIT}, |
| 31 | +std::map<int32_t, CFeeItem> mapNoRefundDeposits = { |
| 32 | + {BDAP_NON_REFUNDABLE_USER_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_USER_DEPOSIT, 1000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 33 | + {BDAP_NON_REFUNDABLE_GROUP_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_GROUP_DEPOSIT, 10000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 34 | + {BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT, 5000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
| 35 | + {BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT, CFeeItem(BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT, 25000 * BDAP_CREDIT, 0, std::numeric_limits<unsigned int>::max())}, |
34 | 36 | };
|
35 | 37 |
|
36 | 38 | bool GetBDAPFees(const opcodetype& opCodeAction, const opcodetype& opCodeObject, const BDAP::ObjectType objType, const uint16_t nMonths, CAmount& monthlyFee, CAmount& oneTimeFee, CAmount& depositFee)
|
37 | 39 | {
|
38 | 40 | std::string strObjectType = BDAP::GetObjectTypeString((unsigned int)objType);
|
39 | 41 | LogPrint("bdap", "%s -- strObjectType = %s, OpAction %d, OpObject %d\n", __func__, strObjectType, opCodeAction, opCodeObject);
|
40 | 42 | if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_USER) {
|
41 |
| - // new BDAP user account |
| 43 | + // Fees for a new BDAP user account |
42 | 44 | oneTimeFee = 0;
|
43 |
| - monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_USER_FEE] * nMonths; |
44 |
| - depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_USER_DEPOSIT]; |
| 45 | + CFeeItem feeMonthly; |
| 46 | + std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_USER_FEE); |
| 47 | + if (iMonthly != mapDefaultMonthlyFees.end()) { |
| 48 | + feeMonthly = iMonthly->second; |
| 49 | + monthlyFee = (nMonths * feeMonthly.Fee); |
| 50 | + } |
| 51 | + CFeeItem feeDeposit; |
| 52 | + std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_USER_DEPOSIT); |
| 53 | + if (iDeposit != mapNoRefundDeposits.end()) { |
| 54 | + feeDeposit = iDeposit->second; |
| 55 | + depositFee = feeDeposit.Fee; |
| 56 | + } |
45 | 57 |
|
46 | 58 | } else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_GROUP) {
|
47 |
| - // new BDAP group account |
| 59 | + // Fees for a new BDAP group account |
48 | 60 | oneTimeFee = 0;
|
49 |
| - monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_GROUP_FEE] * nMonths; |
50 |
| - depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_GROUP_DEPOSIT]; |
| 61 | + CFeeItem feeMonthly; |
| 62 | + std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_GROUP_FEE); |
| 63 | + if (iMonthly != mapDefaultMonthlyFees.end()) { |
| 64 | + feeMonthly = iMonthly->second; |
| 65 | + monthlyFee = (nMonths * feeMonthly.Fee); |
| 66 | + } |
| 67 | + CFeeItem feeDeposit; |
| 68 | + std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_GROUP_DEPOSIT); |
| 69 | + if (iDeposit != mapNoRefundDeposits.end()) { |
| 70 | + feeDeposit = iDeposit->second; |
| 71 | + depositFee = feeDeposit.Fee; |
| 72 | + } |
51 | 73 |
|
52 | 74 | } else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_CERTIFICATE && objType == BDAP::ObjectType::BDAP_CERTIFICATE) {
|
53 |
| - // new BDAP certificate |
| 75 | + // Fees for a new BDAP certificate |
54 | 76 | oneTimeFee = 0;
|
55 |
| - monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_CERTIFICATE_FEE] * nMonths; |
56 |
| - depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT]; |
| 77 | + CFeeItem feeMonthly; |
| 78 | + std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_CERTIFICATE_FEE); |
| 79 | + if (iMonthly != mapDefaultMonthlyFees.end()) { |
| 80 | + feeMonthly = iMonthly->second; |
| 81 | + monthlyFee = (nMonths * feeMonthly.Fee); |
| 82 | + } |
| 83 | + CFeeItem feeDeposit; |
| 84 | + std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_CERTIFICATE_DEPOSIT); |
| 85 | + if (iDeposit != mapNoRefundDeposits.end()) { |
| 86 | + feeDeposit = iDeposit->second; |
| 87 | + depositFee = feeDeposit.Fee; |
| 88 | + } |
57 | 89 |
|
58 | 90 | } else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_SIDECHAIN && objType == BDAP::ObjectType::BDAP_SIDECHAIN) {
|
59 |
| - // new BDAP sidechain entry |
| 91 | + // Fees for a new BDAP sidechain entry |
60 | 92 | oneTimeFee = 0;
|
61 |
| - monthlyFee = mapDefaultMonthlyFees[BDAP_MONTHY_SIDECHAIN_FEE] * nMonths; |
62 |
| - depositFee = mapNoRefundDeposits[BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT]; |
| 93 | + CFeeItem feeMonthly; |
| 94 | + std::multimap<int32_t, CFeeItem>::iterator iMonthly = mapDefaultMonthlyFees.find(BDAP_MONTHY_SIDECHAIN_FEE); |
| 95 | + if (iMonthly != mapDefaultMonthlyFees.end()) { |
| 96 | + feeMonthly = iMonthly->second; |
| 97 | + monthlyFee = (nMonths * feeMonthly.Fee); |
| 98 | + } |
| 99 | + CFeeItem feeDeposit; |
| 100 | + std::multimap<int32_t, CFeeItem>::iterator iDeposit = mapNoRefundDeposits.find(BDAP_NON_REFUNDABLE_SIDECHAIN_DEPOSIT); |
| 101 | + if (iDeposit != mapNoRefundDeposits.end()) { |
| 102 | + feeDeposit = iDeposit->second; |
| 103 | + depositFee = feeDeposit.Fee; |
| 104 | + } |
63 | 105 |
|
64 | 106 | } else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_LINK_REQUEST && objType == BDAP::ObjectType::BDAP_LINK_REQUEST) {
|
65 |
| - // new BDAP link request |
66 |
| - oneTimeFee = mapOneTimeFees[BDAP_ONE_TIME_REQUEST_LINK_FEE]; |
| 107 | + // Fees for a new BDAP link request |
| 108 | + CFeeItem feeOneTime; |
| 109 | + std::multimap<int32_t, CFeeItem>::iterator iOneTime = mapOneTimeFees.find(BDAP_ONE_TIME_REQUEST_LINK_FEE); |
| 110 | + if (iOneTime != mapOneTimeFees.end()) { |
| 111 | + feeOneTime = iOneTime->second; |
| 112 | + oneTimeFee = feeOneTime.Fee; |
| 113 | + } |
67 | 114 | monthlyFee = 0;
|
68 | 115 | depositFee = BDAP_CREDIT;
|
69 | 116 |
|
70 | 117 | } else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_LINK_ACCEPT && objType == BDAP::ObjectType::BDAP_LINK_ACCEPT) {
|
71 |
| - // new BDAP link accept |
72 |
| - oneTimeFee = mapOneTimeFees[BDAP_ONE_TIME_ACCEPT_LINK_FEE]; |
| 118 | + // Fees for a new BDAP link accept |
| 119 | + CFeeItem feeOneTime; |
| 120 | + std::multimap<int32_t, CFeeItem>::iterator iOneTime = mapOneTimeFees.find(BDAP_ONE_TIME_ACCEPT_LINK_FEE); |
| 121 | + if (iOneTime != mapOneTimeFees.end()) { |
| 122 | + feeOneTime = iOneTime->second; |
| 123 | + oneTimeFee = feeOneTime.Fee; |
| 124 | + } |
73 | 125 | monthlyFee = 0;
|
74 | 126 | depositFee = BDAP_CREDIT;
|
75 | 127 |
|
76 | 128 | } else if (opCodeAction == OP_BDAP_NEW && opCodeObject == OP_BDAP_AUDIT && objType == BDAP::ObjectType::BDAP_AUDIT) {
|
77 |
| - // new BDAP audit record |
78 |
| - oneTimeFee = mapOneTimeFees[BDAP_ONE_TIME_AUDIT_RECORD_FEE]; |
| 129 | + // Fees for a new BDAP audit record |
| 130 | + CFeeItem feeOneTime; |
| 131 | + std::multimap<int32_t, CFeeItem>::iterator iOneTime = mapOneTimeFees.find(BDAP_ONE_TIME_AUDIT_RECORD_FEE); |
| 132 | + if (iOneTime != mapOneTimeFees.end()) { |
| 133 | + feeOneTime = iOneTime->second; |
| 134 | + oneTimeFee = feeOneTime.Fee; |
| 135 | + } |
79 | 136 | monthlyFee = 0;
|
80 | 137 | depositFee = BDAP_CREDIT;
|
81 | 138 |
|
82 | 139 | } else if (opCodeAction == OP_BDAP_MODIFY && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_USER) {
|
83 |
| - // update BDAP user account entry |
| 140 | + // Fees for an update BDAP user account entry |
84 | 141 | oneTimeFee = 0;
|
85 | 142 | monthlyFee = 0;
|
86 | 143 | depositFee = BDAP_CREDIT;
|
87 | 144 |
|
88 | 145 | } else if (opCodeAction == OP_BDAP_MODIFY && opCodeObject == OP_BDAP_ACCOUNT_ENTRY && objType == BDAP::ObjectType::BDAP_GROUP) {
|
89 |
| - // update BDAP group account entry |
| 146 | + // Fees for an update BDAP group account entry |
90 | 147 | oneTimeFee = 0;
|
91 | 148 | monthlyFee = 0;
|
92 | 149 | depositFee = BDAP_CREDIT;
|
93 |
| - } else if (objType == BDAP::ObjectType::BDAP_DEFAULT_TYPE) { |
94 |
| - // ********** TODO (BDAP): Remove this |
95 |
| - oneTimeFee = 0; |
| 150 | + } else { |
| 151 | + oneTimeFee = BDAP_CREDIT; |
96 | 152 | monthlyFee = 0;
|
97 | 153 | depositFee = BDAP_CREDIT;
|
98 |
| - } |
99 |
| - else { |
100 | 154 | LogPrintf("%s -- BDAP operation code pair (%d and %d) for %s not found or unsupported.\n", __func__, opCodeAction, opCodeObject, strObjectType);
|
101 |
| - return false; |
102 | 155 | }
|
103 | 156 |
|
104 | 157 | return true;
|
|
0 commit comments