Merge pull request #6503 from sellout/wallet_tx_builder/remove-wallet

Remove CWallet member from WalletTxBuilder
This commit is contained in:
Kris Nuttycombe 2023-03-28 20:01:57 -06:00 committed by GitHub
commit 2fe569ec45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 14 deletions

View File

@ -138,9 +138,10 @@ void AsyncRPCOperation_sendmany::main() {
// //
// At least #4 differs from the Rust transaction builder. // At least #4 differs from the Rust transaction builder.
uint256 AsyncRPCOperation_sendmany::main_impl() { uint256 AsyncRPCOperation_sendmany::main_impl() {
auto spendable = builder_.FindAllSpendableInputs(ztxoSelector_, mindepth_); auto spendable = builder_.FindAllSpendableInputs(*pwalletMain, ztxoSelector_, mindepth_);
auto preparedTx = builder_.PrepareTransaction( auto preparedTx = builder_.PrepareTransaction(
*pwalletMain,
ztxoSelector_, ztxoSelector_,
spendable, spendable,
recipients_, recipients_,

View File

@ -284,7 +284,7 @@ TEST(WalletRPCTests, RPCZsendmanyTaddrToSapling)
pwalletMain->LoadWalletTx(wtx); pwalletMain->LoadWalletTx(wtx);
// Context that z_sendmany requires // Context that z_sendmany requires
auto builder = WalletTxBuilder(Params(), *pwalletMain, minRelayTxFee); auto builder = WalletTxBuilder(Params(), minRelayTxFee);
mtx = CreateNewContextualCMutableTransaction(consensusParams, nextBlockHeight, false); mtx = CreateNewContextualCMutableTransaction(consensusParams, nextBlockHeight, false);
// we need AllowFullyTransparent because the transaction will result // we need AllowFullyTransparent because the transaction will result

View File

@ -5016,7 +5016,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
// Create operation and add to global queue // Create operation and add to global queue
auto nAnchorDepth = std::min((unsigned int) nMinDepth, nAnchorConfirmations); auto nAnchorDepth = std::min((unsigned int) nMinDepth, nAnchorConfirmations);
WalletTxBuilder builder(Params(), *pwalletMain, minRelayTxFee); WalletTxBuilder builder(Params(), minRelayTxFee);
std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue(); std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
std::shared_ptr<AsyncRPCOperation> operation( std::shared_ptr<AsyncRPCOperation> operation(

View File

@ -1248,7 +1248,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
// confirm this. // confirm this.
TransparentCoinbasePolicy::Allow, TransparentCoinbasePolicy::Allow,
false).value(); false).value();
WalletTxBuilder builder(Params(), *pwalletMain, minRelayTxFee); WalletTxBuilder builder(Params(), minRelayTxFee);
std::vector<Payment> recipients = { Payment(zaddr1, 100*COIN, Memo::FromHexOrThrow("DEADBEEF")) }; std::vector<Payment> recipients = { Payment(zaddr1, 100*COIN, Memo::FromHexOrThrow("DEADBEEF")) };
TransactionStrategy strategy(PrivacyPolicy::AllowRevealedSenders); TransactionStrategy strategy(PrivacyPolicy::AllowRevealedSenders);
std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sendmany(std::move(builder), selector, recipients, 1, 1, strategy)); std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sendmany(std::move(builder), selector, recipients, 1, 1, strategy));
@ -1265,7 +1265,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
true, true,
TransparentCoinbasePolicy::Disallow, TransparentCoinbasePolicy::Disallow,
false).value(); false).value();
WalletTxBuilder builder(Params(), *pwalletMain, minRelayTxFee); WalletTxBuilder builder(Params(), minRelayTxFee);
std::vector<Payment> recipients = { Payment(taddr1, 100*COIN, Memo::FromHexOrThrow("DEADBEEF")) }; std::vector<Payment> recipients = { Payment(taddr1, 100*COIN, Memo::FromHexOrThrow("DEADBEEF")) };
TransactionStrategy strategy(PrivacyPolicy::AllowRevealedRecipients); TransactionStrategy strategy(PrivacyPolicy::AllowRevealedRecipients);
std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sendmany(std::move(builder), selector, recipients, 1, 1, strategy)); std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sendmany(std::move(builder), selector, recipients, 1, 1, strategy));

View File

@ -13,6 +13,7 @@ int GetAnchorHeight(const CChain& chain, uint32_t anchorConfirmations)
} }
PrepareTransactionResult WalletTxBuilder::PrepareTransaction( PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
SpendableInputs& spendable, SpendableInputs& spendable,
const std::vector<Payment>& payments, const std::vector<Payment>& payments,
@ -24,7 +25,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
assert(fee < MAX_MONEY); assert(fee < MAX_MONEY);
int anchorHeight = GetAnchorHeight(chain, anchorConfirmations); int anchorHeight = GetAnchorHeight(chain, anchorConfirmations);
auto selected = ResolveInputsAndPayments(selector, spendable, payments, chain, strategy, fee, anchorHeight); auto selected = ResolveInputsAndPayments(wallet, selector, spendable, payments, chain, strategy, fee, anchorHeight);
if (std::holds_alternative<InputSelectionError>(selected)) { if (std::holds_alternative<InputSelectionError>(selected)) {
return std::get<InputSelectionError>(selected); return std::get<InputSelectionError>(selected);
} }
@ -81,7 +82,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
auto changeAddressForTransparentSelector = [&](const std::set<ReceiverType>& receiverTypes) { auto changeAddressForTransparentSelector = [&](const std::set<ReceiverType>& receiverTypes) {
return addChangePayment( return addChangePayment(
pwalletMain->GenerateChangeAddressForAccount( wallet.GenerateChangeAddressForAccount(
sendFromAccount, sendFromAccount,
getAllowedChangePools(receiverTypes))); getAllowedChangePools(receiverTypes)));
}; };
@ -93,7 +94,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
return addChangePayment( return addChangePayment(
sendFromAccount == ZCASH_LEGACY_ACCOUNT sendFromAccount == ZCASH_LEGACY_ACCOUNT
? addr ? addr
: pwalletMain->GenerateChangeAddressForAccount( : wallet.GenerateChangeAddressForAccount(
sendFromAccount, sendFromAccount,
getAllowedChangePools({ReceiverType::Sapling}))); getAllowedChangePools({ReceiverType::Sapling})));
}; };
@ -126,7 +127,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
return changeAddressForSaplingAddress(fvk.DefaultAddress()); return changeAddressForSaplingAddress(fvk.DefaultAddress());
}, },
[&](const libzcash::UnifiedAddress& ua) -> ChangeAddress { [&](const libzcash::UnifiedAddress& ua) -> ChangeAddress {
auto zufvk = pwalletMain->GetUFVKForAddress(ua); auto zufvk = wallet.GetUFVKForAddress(ua);
assert(zufvk.has_value()); assert(zufvk.has_value());
return changeAddressForZUFVK(zufvk.value(), ua.GetKnownReceiverTypes()); return changeAddressForZUFVK(zufvk.value(), ua.GetKnownReceiverTypes());
}, },
@ -137,14 +138,14 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
}, },
[&](const AccountZTXOPattern& acct) -> ChangeAddress { [&](const AccountZTXOPattern& acct) -> ChangeAddress {
return addChangePayment( return addChangePayment(
pwalletMain->GenerateChangeAddressForAccount( wallet.GenerateChangeAddressForAccount(
acct.GetAccountId(), acct.GetAccountId(),
getAllowedChangePools(acct.GetReceiverTypes()))); getAllowedChangePools(acct.GetReceiverTypes())));
} }
}, selector.GetPattern()); }, selector.GetPattern());
} }
auto ovks = SelectOVKs(selector, spendable); auto ovks = SelectOVKs(wallet, selector, spendable);
return TransactionEffects( return TransactionEffects(
anchorConfirmations, anchorConfirmations,
@ -169,6 +170,7 @@ CAmount WalletTxBuilder::DefaultDustThreshold() const {
} }
SpendableInputs WalletTxBuilder::FindAllSpendableInputs( SpendableInputs WalletTxBuilder::FindAllSpendableInputs(
const CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
int32_t minDepth) const int32_t minDepth) const
{ {
@ -177,6 +179,7 @@ SpendableInputs WalletTxBuilder::FindAllSpendableInputs(
} }
InputSelectionResult WalletTxBuilder::ResolveInputsAndPayments( InputSelectionResult WalletTxBuilder::ResolveInputsAndPayments(
const CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
SpendableInputs& spendableMut, SpendableInputs& spendableMut,
const std::vector<Payment>& payments, const std::vector<Payment>& payments,
@ -370,6 +373,7 @@ GetOVKsForUFVK(const UnifiedFullViewingKey& ufvk, const SpendableInputs& spendab
} }
std::pair<uint256, uint256> WalletTxBuilder::SelectOVKs( std::pair<uint256, uint256> WalletTxBuilder::SelectOVKs(
const CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
const SpendableInputs& spendable) const const SpendableInputs& spendable) const
{ {

View File

@ -305,7 +305,6 @@ typedef std::variant<
class WalletTxBuilder { class WalletTxBuilder {
private: private:
const CChainParams& params; const CChainParams& params;
const CWallet& wallet;
CFeeRate minRelayFee; CFeeRate minRelayFee;
uint32_t maxOrchardActions; uint32_t maxOrchardActions;
@ -320,6 +319,7 @@ private:
* and the requested transaction strategy. * and the requested transaction strategy.
*/ */
InputSelectionResult ResolveInputsAndPayments( InputSelectionResult ResolveInputsAndPayments(
const CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
SpendableInputs& spendable, SpendableInputs& spendable,
const std::vector<Payment>& payments, const std::vector<Payment>& payments,
@ -332,18 +332,21 @@ private:
* the spendable inputs. * the spendable inputs.
*/ */
std::pair<uint256, uint256> SelectOVKs( std::pair<uint256, uint256> SelectOVKs(
const CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
const SpendableInputs& spendable) const; const SpendableInputs& spendable) const;
public: public:
WalletTxBuilder(const CChainParams& params, const CWallet& wallet, CFeeRate minRelayFee): WalletTxBuilder(const CChainParams& params, CFeeRate minRelayFee):
params(params), wallet(wallet), minRelayFee(minRelayFee), maxOrchardActions(nOrchardActionLimit) {} params(params), minRelayFee(minRelayFee), maxOrchardActions(nOrchardActionLimit) {}
SpendableInputs FindAllSpendableInputs( SpendableInputs FindAllSpendableInputs(
const CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
int32_t minDepth) const; int32_t minDepth) const;
PrepareTransactionResult PrepareTransaction( PrepareTransactionResult PrepareTransaction(
CWallet& wallet,
const ZTXOSelector& selector, const ZTXOSelector& selector,
SpendableInputs& spendable, SpendableInputs& spendable,
const std::vector<Payment>& payments, const std::vector<Payment>& payments,