Skip to content

Commit 8c2741b

Browse files
committed
[BDAP] Update createrawbdapaccount to send credits for links
1 parent faef8bd commit 8c2741b

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/bdap/rpcrawbdap.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "rpcserver.h"
1313
#include "policy/policy.h"
1414
#include "primitives/transaction.h"
15+
#include "utilmoneystr.h"
1516
#include "utilstrencodings.h"
1617
#include "dynode-sync.h"
1718
#include "spork.h"
@@ -126,8 +127,10 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
126127
// Get BDAP fees
127128
CAmount monthlyFee, oneTimeFee, depositFee;
128129
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+
131134
// Create BDAP operation script
132135
CScript scriptPubKey;
133136
std::vector<unsigned char> vchFullObjectPath = txDomainEntry.vchFullObjectPath();
@@ -170,9 +173,35 @@ UniValue createrawbdapaccount(const JSONRPCRequest& request)
170173
// Add the BDAP operation output
171174
CTxOut outOP(depositFee, scriptPubKey);
172175
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);
176205
rawTx.vout.push_back(outLinkFunds);
177206

178207
return EncodeHexTx(rawTx);

0 commit comments

Comments
 (0)