Skip to content

Commit

Permalink
Allow flag to disable wallet ownership checks (#2953)
Browse files Browse the repository at this point in the history
* Allow flag to disable wallet ownership checks

* Remove redundant header

* fmt
  • Loading branch information
prasannavl authored Jun 28, 2024
1 parent c2ce89a commit 46174c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/dfi/rpc_accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <ffi/ffihelpers.h>
#include <boost/asio.hpp>

static bool DEFAULT_DVM_OWNERSHIP_CHECK = true;

std::string tokenAmountString(const CTokenAmount &amount, AmountFormat format = AmountFormat::Symbol) {
const auto token = pcustomcsview->GetToken(amount.nTokenId);
const auto amountString = ValueFromAmount(amount.nValue).getValStr();
Expand Down Expand Up @@ -265,9 +267,14 @@ static UniValue DecodeRecipientsGetRecipients(const UniValue &values) {
return recipients;
}

static CAccounts DecodeRecipientsDefaultInternal(CWallet *const pwallet, const UniValue &values) {
static CAccounts DecodeRecipientsDefaultInternal(CWallet *const pwallet,
const UniValue &values,
bool checkOwnership = true) {
const auto recipients = DecodeRecipientsGetRecipients(values);
auto accounts = DecodeRecipients(pwallet->chain(), recipients);
if (!checkOwnership) {
return accounts;
}
for (const auto &account : accounts) {
if (IsMineCached(*pwallet, account.first) != ISMINE_SPENDABLE &&
account.second.balances.find(DCT_ID{0}) != account.second.balances.end()) {
Expand Down Expand Up @@ -750,7 +757,8 @@ UniValue utxostoaccount(const JSONRPCRequest &request) {

// decode recipients
CUtxosToAccountMessage msg{};
msg.to = DecodeRecipientsDefaultInternal(pwallet, request.params[0].get_obj());
auto ownershipCheck = gArgs.GetBoolArg("-dvmownershipcheck", DEFAULT_DVM_OWNERSHIP_CHECK);
msg.to = DecodeRecipientsDefaultInternal(pwallet, request.params[0].get_obj(), ownershipCheck);

for (const auto &[to, amount] : msg.to) {
RejectErc55Address(to);
Expand Down Expand Up @@ -915,7 +923,8 @@ UniValue accounttoaccount(const JSONRPCRequest &request) {

// decode sender and recipients
CAccountToAccountMessage msg{};
msg.to = DecodeRecipientsDefaultInternal(pwallet, request.params[1].get_obj());
auto ownershipCheck = gArgs.GetBoolArg("-dvmownershipcheck", DEFAULT_DVM_OWNERSHIP_CHECK);
msg.to = DecodeRecipientsDefaultInternal(pwallet, request.params[1].get_obj(), ownershipCheck);

if (SumAllTransfers(msg.to).balances.empty()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "zero amounts");
Expand Down Expand Up @@ -2045,7 +2054,8 @@ UniValue sendtokenstoaddress(const JSONRPCRequest &request) {
RPCTypeCheck(request.params, {UniValue::VOBJ, UniValue::VOBJ, UniValue::VSTR}, false);

CAnyAccountsToAccountsMessage msg;
msg.to = DecodeRecipientsDefaultInternal(pwallet, request.params[1].get_obj());
auto ownershipCheck = gArgs.GetBoolArg("-dvmownershipcheck", DEFAULT_DVM_OWNERSHIP_CHECK);
msg.to = DecodeRecipientsDefaultInternal(pwallet, request.params[1].get_obj(), ownershipCheck);

const CBalances sumTransfersTo = SumAllTransfers(msg.to);
if (sumTransfersTo.balances.empty()) {
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ void SetupServerArgs()
gArgs.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -daemon. To disable logging to file, set -nodebuglogfile)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-tdsinglekeycheck", "Set the single key check flag for transferdomain RPC. If enabled, transfers between domain are only allowed if the addresses specified corresponds to the same key (default: true)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-dvmownershipcheck", "If enabled, utxostoaccount, sendtokenstoaddress and accounttoaccount APIs enforce a check to only allow to owned addresses (default: true)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-evmtxpriorityfeepercentile", strprintf("Set the suggested priority fee for EVM transactions (default: %u)", DEFAULT_SUGGESTED_PRIORITY_FEE_PERCENTILE), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-evmestimategaserrorratio", strprintf("Set the gas estimation error ratio for eth_estimateGas RPC (default: %u)", DEFAULT_ESTIMATE_GAS_ERROR_RATIO), ArgsManager::ALLOW_ANY, OptionsCategory::RPC);
gArgs.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
Expand Down

0 comments on commit 46174c4

Please sign in to comment.