From 07715fdab23f031a84623184a7556a9b2c44dc2f Mon Sep 17 00:00:00 2001 From: kuegi <29012906+kuegi@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:21:24 +0200 Subject: [PATCH 1/3] accounts: improved utxosToAccount selecting inputs from to address if own address and only one target --- src/dfi/rpc_accounts.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 4550f708145..5769cb778f6 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -783,9 +783,31 @@ UniValue utxostoaccount(const JSONRPCRequest &request) { } } + const UniValue &txInputs = request.params[2]; + bool funded= false; + if (msg.to.size() == 1) { + CCoinControl coinControl; + //try to fill inputs from target address and use it as change + const auto &target = msg.to.begin()->first; + CTxDestination dest; + ExtractDestination(target, dest); + if (IsMineCached(*pwallet, target) == ISMINE_SPENDABLE) { + if (IsValidDestination(dest)) { + coinControl.destChange = dest; + coinControl.matchDestination = dest; + try { + fund(rawTx, pwallet, {}, &coinControl, request.metadata.coinSelectOpts); + funded= true; + } catch(const UniValue &e) { + //likely not enough utxos, silent catch and try again outside + } + } + } + } // fund - fund(rawTx, pwallet, {}, nullptr, request.metadata.coinSelectOpts); - + if(!funded) { + fund(rawTx, pwallet, {}, nullptr, request.metadata.coinSelectOpts); + } // check execution execTestTx(CTransaction(rawTx), targetHeight); From 40afa9b437ec1cec9c8cf0717dc0026e0494d2ce Mon Sep 17 00:00:00 2001 From: kuegi <29012906+kuegi@users.noreply.github.com> Date: Tue, 25 Jun 2024 07:40:24 +0200 Subject: [PATCH 2/3] fmt --- src/dfi/rpc_accounts.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 5769cb778f6..6d2041e329b 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -784,10 +784,10 @@ UniValue utxostoaccount(const JSONRPCRequest &request) { } const UniValue &txInputs = request.params[2]; - bool funded= false; + bool funded = false; if (msg.to.size() == 1) { CCoinControl coinControl; - //try to fill inputs from target address and use it as change + // try to fill inputs from target address and use it as change const auto &target = msg.to.begin()->first; CTxDestination dest; ExtractDestination(target, dest); @@ -797,15 +797,15 @@ UniValue utxostoaccount(const JSONRPCRequest &request) { coinControl.matchDestination = dest; try { fund(rawTx, pwallet, {}, &coinControl, request.metadata.coinSelectOpts); - funded= true; - } catch(const UniValue &e) { - //likely not enough utxos, silent catch and try again outside + funded = true; + } catch (const UniValue &e) { + // likely not enough utxos, silent catch and try again outside } } } } // fund - if(!funded) { + if (!funded) { fund(rawTx, pwallet, {}, nullptr, request.metadata.coinSelectOpts); } // check execution From ff4d668cba8d3974000af9b063577d547e724c0c Mon Sep 17 00:00:00 2001 From: kuegi <29012906+kuegi@users.noreply.github.com> Date: Mon, 1 Jul 2024 08:30:04 +0200 Subject: [PATCH 3/3] remove unused txInputs not used in this rpc right now --- src/dfi/rpc_accounts.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dfi/rpc_accounts.cpp b/src/dfi/rpc_accounts.cpp index 6d2041e329b..906ee57ad68 100644 --- a/src/dfi/rpc_accounts.cpp +++ b/src/dfi/rpc_accounts.cpp @@ -783,7 +783,6 @@ UniValue utxostoaccount(const JSONRPCRequest &request) { } } - const UniValue &txInputs = request.params[2]; bool funded = false; if (msg.to.size() == 1) { CCoinControl coinControl;