5
5
#include " bdap/bdap.h"
6
6
#include " bdap/domainentry.h"
7
7
#include " bdap/domainentrydb.h"
8
+ #include " bdap/fees.h"
8
9
#include " bdap/vgp/include/encryption.h" // for VGP E2E encryption
9
10
#include " bdap/linking.h"
10
11
#include " bdap/linkingdb.h"
@@ -102,7 +103,7 @@ static bool BuildJsonLinkAcceptInfo(const CLinkAccept& link, const CDomainEntry&
102
103
103
104
static UniValue SendLinkRequest (const JSONRPCRequest& request)
104
105
{
105
- if (request.fHelp || request.params .size () < 4 || request. params . size () > 5 )
106
+ if (request.fHelp || request.params .size () != 4 )
106
107
throw std::runtime_error (
107
108
" link request userid-from userid-to message\n "
108
109
" Creates a link request transaction on the blockchain."
@@ -111,7 +112,6 @@ static UniValue SendLinkRequest(const JSONRPCRequest& request)
111
112
" 1. requestor (string) BDAP account requesting the link\n "
112
113
" 2. recipient (string) Link recipient's BDAP account.\n "
113
114
" 3. invite message (string) Message from requestor to recipient.\n "
114
- " 4. registration days (int, optional) Number of days to keep the link request on the blockchain before pruning.\n "
115
115
" \n Result:\n "
116
116
" {(json object)\n "
117
117
" \" Requestor FQDN\" (string) Requestor's BDAP full path\n "
@@ -196,14 +196,7 @@ static UniValue SendLinkRequest(const JSONRPCRequest& request)
196
196
if (!CreateSignatureProof (key, strRecipientFQDN, txLink.SignatureProof ))
197
197
throw std::runtime_error (" BDAP_SEND_LINK_RPC_ERROR: ERRCODE: 4008 - Error signing " + strRequestorFQDN + _ (" 's signature proof." ));
198
198
199
- int64_t nDays = DEFAULT_REGISTRATION_DAYS; // default to 4 years.
200
- if (request.params .size () > 4 ) {
201
- if (!ParseInt64 (request.params [4 ].get_str (), &nDays))
202
- throw std::runtime_error (" BDAP_SEND_LINK_RPC_ERROR: ERRCODE: 4009 - Error parsing registration days parameter = " + request.params [4 ].get_str ());
203
- }
204
-
205
- int64_t nSeconds = nDays * SECONDS_PER_DAY;
206
- txLink.nExpireTime = chainActive.Tip ()->GetMedianTimePast () + nSeconds;
199
+ txLink.nExpireTime = DEFAULT_LINK_EXPIRE_TIME;
207
200
CKeyEd25519 dhtKey;
208
201
std::vector<unsigned char > vchSharedPubKey = GetLinkSharedPubKey (privReqDHTKey, entryRecipient.DHTPublicKey );
209
202
txLink.SharedPubKey = vchSharedPubKey;
@@ -265,14 +258,18 @@ static UniValue SendLinkRequest(const JSONRPCRequest& request)
265
258
CScript scriptData;
266
259
scriptData << OP_RETURN << dataEncrypted;
267
260
261
+ // Get BDAP fees
262
+ BDAP::ObjectType bdapType = ObjectType::BDAP_LINK_REQUEST;
263
+ int32_t nMonths = 0 ; // Links do not expire
264
+ CAmount monthlyFee, oneTimeFee, depositFee;
265
+ if (!GetBDAPFees (OP_BDAP_NEW, OP_BDAP_LINK_REQUEST, bdapType, nMonths, monthlyFee, oneTimeFee, depositFee))
266
+ throw JSONRPCError (RPC_BDAP_FEE_UNKNOWN, strprintf (" Error calculating BDAP fees." ));
267
+ LogPrintf (" %s -- monthlyFee %d, oneTimeFee %d, depositFee %d\n " , __func__, monthlyFee, oneTimeFee, depositFee);
268
268
// Send the transaction
269
269
CWalletTx wtx;
270
- float fYears = ((float )nDays/365.25 );
271
- CAmount nOperationFee = GetBDAPFee (scriptPubKey) * powf (3.1 , fYears );
272
- CAmount nDataFee = (GetBDAPFee (scriptData) * powf (3.1 , fYears )) + (GetBDAPFee (stealthScript) * powf (3.1 , fYears ));
273
-
274
270
bool fUseInstantSend = false ;
275
- SendLinkingTransaction (scriptData, scriptPubKey, stealthScript, wtx, nOperationFee, nDataFee, fUseInstantSend );
271
+ SendLinkingTransaction (scriptData, scriptPubKey, stealthScript, wtx, oneTimeFee, depositFee, fUseInstantSend );
272
+
276
273
txLink.txHash = wtx.GetHash ();
277
274
278
275
UniValue oLink (UniValue::VOBJ);
@@ -284,15 +281,14 @@ static UniValue SendLinkRequest(const JSONRPCRequest& request)
284
281
285
282
static UniValue SendLinkAccept (const JSONRPCRequest& request)
286
283
{
287
- if (request.fHelp || request.params .size () < 3 || request. params . size () > 4 )
284
+ if (request.fHelp || request.params .size () != 3 )
288
285
throw std::runtime_error (
289
286
" link accept userid-from userid-to\n "
290
287
" Creates a link accept transaction on the blockchain."
291
288
+ HelpRequiringPassphrase () +
292
289
" \n Link Send Arguments:\n "
293
290
" 1. accept account (string) BDAP account accepting the link\n "
294
291
" 2. requestor account (string) Link requestor's BDAP account.\n "
295
- " 3. registration days (int, optional) Number of days to keep the link accept on the blockchain before pruning.\n "
296
292
" \n Result:\n "
297
293
" {(json object)\n "
298
294
" \" Requestor FQDN\" (string) Requestor's BDAP full path\n "
@@ -377,13 +373,7 @@ static UniValue SendLinkAccept(const JSONRPCRequest& request)
377
373
if (!CreateSignatureProof (key, strRequestorFQDN, txLinkAccept.SignatureProof ))
378
374
throw std::runtime_error (" BDAP_ACCEPT_LINK_RPC_ERROR: ERRCODE: 4110 - Error signing " + strRequestorFQDN + _ (" 's signature proof." ));
379
375
380
- int64_t nDays = DEFAULT_REGISTRATION_DAYS; // default to 4 years.
381
- if (request.params .size () > 3 ) {
382
- if (!ParseInt64 (request.params [3 ].get_str (), &nDays))
383
- throw std::runtime_error (" BDAP_SEND_LINK_RPC_ERROR: ERRCODE: 4111 - Error parsing registration days parameter = " + request.params [3 ].get_str ());
384
- }
385
- int64_t nSeconds = nDays * SECONDS_PER_DAY;
386
- txLinkAccept.nExpireTime = chainActive.Tip ()->GetMedianTimePast () + nSeconds;
376
+ txLinkAccept.nExpireTime = DEFAULT_LINK_EXPIRE_TIME;
387
377
CKeyEd25519 dhtKey;
388
378
std::vector<unsigned char > vchSharedPubKey = GetLinkSharedPubKey (privAcceptDHTKey, entryRequestor.DHTPublicKey );
389
379
txLinkAccept.SharedPubKey = vchSharedPubKey;
@@ -443,13 +433,17 @@ static UniValue SendLinkAccept(const JSONRPCRequest& request)
443
433
CScript scriptData;
444
434
scriptData << OP_RETURN << dataEncrypted;
445
435
436
+ // Get BDAP fees
437
+ BDAP::ObjectType bdapType = ObjectType::BDAP_LINK_ACCEPT;
438
+ int32_t nMonths = 0 ; // Links do not expire
439
+ CAmount monthlyFee, oneTimeFee, depositFee;
440
+ if (!GetBDAPFees (OP_BDAP_NEW, OP_BDAP_LINK_ACCEPT, bdapType, nMonths, monthlyFee, oneTimeFee, depositFee))
441
+ throw JSONRPCError (RPC_BDAP_FEE_UNKNOWN, strprintf (" Error calculating BDAP fees." ));
442
+
446
443
// Send the transaction
447
444
CWalletTx wtx;
448
- float fYears = ((float )nDays/365.25 );
449
- CAmount nOperationFee = GetBDAPFee (scriptPubKey) * powf (3.1 , fYears );
450
- CAmount nDataFee = (GetBDAPFee (scriptData) * powf (3.1 , fYears )) + (GetBDAPFee (stealthScript) * powf (3.1 , fYears ));
451
445
bool fUseInstantSend = false ;
452
- SendLinkingTransaction (scriptData, scriptPubKey, stealthScript, wtx, nOperationFee, nDataFee , fUseInstantSend );
446
+ SendLinkingTransaction (scriptData, scriptPubKey, stealthScript, wtx, oneTimeFee, depositFee , fUseInstantSend );
453
447
txLinkAccept.txHash = wtx.GetHash ();
454
448
455
449
UniValue oLink (UniValue::VOBJ);
@@ -912,10 +906,10 @@ static UniValue DenyLink(const JSONRPCRequest& request)
912
906
oLink.push_back (Pair (" list_data_size" , (int )vchSerializedList.size ()));
913
907
oLink.push_back (Pair (" list_records" , nRecords));
914
908
uint16_t nVersion = 1 ; // VGP encryption version 1
915
- uint32_t nExpire = 0 ; // Does not expire.
909
+ uint64_t nExpire = DEFAULT_LINK_EXPIRE_TIME ; // Does not expire.
916
910
std::vector<std::vector<unsigned char >> vvchPubKeys;
917
911
vvchPubKeys.push_back (getKey.GetPubKeyBytes ());
918
- CDataRecord newRecord (strOperationType, nTotalSlots, vvchPubKeys, vchSerializedList, nVersion, nExpire, DHT::DataFormat::BinaryBlob);
912
+ CDataRecord newRecord (strOperationType, nTotalSlots, vvchPubKeys, vchSerializedList, nVersion, ( uint32_t ) nExpire, DHT::DataFormat::BinaryBlob);
919
913
if (newRecord.HasError ())
920
914
throw std::runtime_error (" BDAP_DENY_LINK_RPC_ERROR: ERRCODE: 4245 - Error creating DHT data entry. " + newRecord.ErrorMessage () + _ (" \n " ));
921
915
0 commit comments