|
12 | 12 | #include "rpcserver.h"
|
13 | 13 | #include "policy/policy.h"
|
14 | 14 | #include "primitives/transaction.h"
|
| 15 | +#include "utilmoneystr.h" |
15 | 16 | #include "utilstrencodings.h"
|
16 | 17 | #include "dynode-sync.h"
|
17 | 18 | #include "spork.h"
|
@@ -126,8 +127,10 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
|
126 | 127 | // Get BDAP fees
|
127 | 128 | CAmount monthlyFee, oneTimeFee, depositFee;
|
128 | 129 | if (!GetBDAPFees(OP_BDAP_NEW, OP_BDAP_ACCOUNT_ENTRY, bdapType, nMonths, monthlyFee, oneTimeFee, depositFee))
|
129 |
| - throw JSONRPCError(RPC_BDAP_FEE_UNKNOWN, strprintf("Error calculating BDAP fees.")); |
130 |
| - LogPrintf("%s -- monthlyFee %d, oneTimeFee %d, depositFee %d\n", __func__, monthlyFee, oneTimeFee, depositFee); |
| 130 | + throw JSONRPCError(RPC_BDAP_FEE_UNKNOWN, strprintf("Error calculating BDAP user account fees.")); |
| 131 | + LogPrintf("%s -- monthlyFee %d, oneTimeFee %d, depositFee %d\n", __func__, |
| 132 | + FormatMoney(monthlyFee), FormatMoney(oneTimeFee), FormatMoney(depositFee)); |
| 133 | + |
131 | 134 | // Create BDAP operation script
|
132 | 135 | CScript scriptPubKey;
|
133 | 136 | std::vector<unsigned char> vchFullObjectPath = txDomainEntry.vchFullObjectPath();
|
@@ -170,9 +173,35 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
|
170 | 173 | // Add the BDAP operation output
|
171 | 174 | CTxOut outOP(depositFee, scriptPubKey);
|
172 | 175 | rawTx.vout.push_back(outOP);
|
173 |
| - // Add the BDAP link funds output |
174 |
| - CAmount nLinkAmount(0.0400004 * COIN); // enough for 4 links |
175 |
| - CTxOut outLinkFunds(nLinkAmount, stealtDestination); |
| 176 | + |
| 177 | + // Get fees for 10 link request transactions |
| 178 | + if (!GetBDAPFees(OP_BDAP_NEW, OP_BDAP_LINK_REQUEST, BDAP::ObjectType::BDAP_LINK_REQUEST, 0, monthlyFee, oneTimeFee, depositFee)) |
| 179 | + throw JSONRPCError(RPC_BDAP_FEE_UNKNOWN, strprintf("Error calculating BDAP link fees.")); |
| 180 | + |
| 181 | + CAmount nLinkRequestAmount((oneTimeFee + depositFee + monthlyFee) * 10); // enough for 10 link requests |
| 182 | + |
| 183 | + // Get fees for 10 link accept transactions |
| 184 | + if (!GetBDAPFees(OP_BDAP_NEW, OP_BDAP_LINK_ACCEPT, BDAP::ObjectType::BDAP_LINK_ACCEPT, 0, monthlyFee, oneTimeFee, depositFee)) |
| 185 | + throw JSONRPCError(RPC_BDAP_FEE_UNKNOWN, strprintf("Error calculating BDAP link fees.")); |
| 186 | + |
| 187 | + CAmount nLinkAcceptAmount((oneTimeFee + depositFee + monthlyFee) * 10); // enough for 10 link accepts |
| 188 | + // Get total amount need for 10 link request and 10 link accept transactions |
| 189 | + CAmount nTotalLinkAmount = (nLinkRequestAmount + nLinkAcceptAmount); |
| 190 | + LogPrintf("%s -- nLinkRequestAmount %d, nLinkAcceptAmount %d, Total %d\n", __func__, |
| 191 | + FormatMoney(nLinkRequestAmount), FormatMoney(nLinkAcceptAmount), FormatMoney(nTotalLinkAmount)); |
| 192 | + |
| 193 | + // Create BDAP credits operation script |
| 194 | + std::vector<unsigned char> vchMoveSource = vchFromString(std::string("DYN")); |
| 195 | + std::vector<unsigned char> vchMoveDestination = vchFromString(std::string("BDAP")); |
| 196 | + CScript scriptBdapCredits; |
| 197 | + scriptBdapCredits << CScript::EncodeOP_N(OP_BDAP_MOVE) << CScript::EncodeOP_N(OP_BDAP_ASSET) |
| 198 | + << vchMoveSource << vchMoveDestination << OP_2DROP << OP_2DROP; |
| 199 | + |
| 200 | + // Add stealth link destination address to credits |
| 201 | + scriptBdapCredits += stealtDestination; |
| 202 | + |
| 203 | + // Add the BDAP link with credit funds output |
| 204 | + CTxOut outLinkFunds(nTotalLinkAmount, scriptBdapCredits); |
176 | 205 | rawTx.vout.push_back(outLinkFunds);
|
177 | 206 |
|
178 | 207 | return EncodeHexTx(rawTx);
|
|
0 commit comments