wallet: refactor GetNewDestination, use BResult

This commit is contained in:
furszy committed 2022-07-08 11:18:35 -03:00
1 parent 22351725bc
commit 111ea3ab71
13 files changed
+72 -86

No files matched your search

+3 -5
View File
@@ -74,11 +74,9 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
tx.vout.resize(nInput + 1);
tx.vout[nInput].nValue = nValue;
if (spendable) {
CTxDestination dest;
bilingual_str error;
const bool destination_ok = wallet.GetNewDestination(OutputType::BECH32, "", dest, error);
assert(destination_ok);
tx.vout[nInput].scriptPubKey = GetScriptForDestination(dest);
auto op_dest = wallet.GetNewDestination(OutputType::BECH32, "");
assert(op_dest.HasRes());
tx.vout[nInput].scriptPubKey = GetScriptForDestination(op_dest.GetObj());
}
uint256 txid = tx.GetHash();
+5 -6
View File
@@ -69,15 +69,14 @@ struct FuzzedWallet {
CScript GetScriptPubKey(FuzzedDataProvider& fuzzed_data_provider)
{
auto type{fuzzed_data_provider.PickValueInArray(OUTPUT_TYPES)};
CTxDestination dest;
bilingual_str error;
BResult<CTxDestination> op_dest;
if (fuzzed_data_provider.ConsumeBool()) {
assert(wallet->GetNewDestination(type, "", dest, error));
op_dest = wallet->GetNewDestination(type, "");
} else {
assert(wallet->GetNewChangeDestination(type, dest, error));
op_dest = wallet->GetNewChangeDestination(type);
}
assert(error.empty());
return GetScriptForDestination(dest);
assert(op_dest.HasRes());
return GetScriptForDestination(op_dest.GetObj());
}
};
+2 -6
View File
@@ -610,9 +610,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
wallet->SetMinVersion(FEATURE_LATEST);
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
BOOST_CHECK(!wallet->TopUpKeyPool(1000));
CTxDestination dest;
bilingual_str error;
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, ""));
}
{
const std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase());
@@ -620,9 +618,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
wallet->SetMinVersion(FEATURE_LATEST);
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
CTxDestination dest;
bilingual_str error;
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, "", dest, error));
BOOST_CHECK(!wallet->GetNewDestination(OutputType::BECH32, ""));
}
}