Merge pull request #6503 from sellout/wallet_tx_builder/remove-wallet
Remove CWallet member from WalletTxBuilder
This commit is contained in:
commit
2fe569ec45
|
@ -138,9 +138,10 @@ void AsyncRPCOperation_sendmany::main() {
|
|||
//
|
||||
// At least #4 differs from the Rust transaction builder.
|
||||
uint256 AsyncRPCOperation_sendmany::main_impl() {
|
||||
auto spendable = builder_.FindAllSpendableInputs(ztxoSelector_, mindepth_);
|
||||
auto spendable = builder_.FindAllSpendableInputs(*pwalletMain, ztxoSelector_, mindepth_);
|
||||
|
||||
auto preparedTx = builder_.PrepareTransaction(
|
||||
*pwalletMain,
|
||||
ztxoSelector_,
|
||||
spendable,
|
||||
recipients_,
|
||||
|
|
|
@ -284,7 +284,7 @@ TEST(WalletRPCTests, RPCZsendmanyTaddrToSapling)
|
|||
pwalletMain->LoadWalletTx(wtx);
|
||||
|
||||
// Context that z_sendmany requires
|
||||
auto builder = WalletTxBuilder(Params(), *pwalletMain, minRelayTxFee);
|
||||
auto builder = WalletTxBuilder(Params(), minRelayTxFee);
|
||||
mtx = CreateNewContextualCMutableTransaction(consensusParams, nextBlockHeight, false);
|
||||
|
||||
// we need AllowFullyTransparent because the transaction will result
|
||||
|
|
|
@ -5016,7 +5016,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
|
|||
|
||||
// Create operation and add to global queue
|
||||
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<AsyncRPCOperation> operation(
|
||||
|
|
|
@ -1248,7 +1248,7 @@ BOOST_AUTO_TEST_CASE(rpc_z_sendmany_internals)
|
|||
// confirm this.
|
||||
TransparentCoinbasePolicy::Allow,
|
||||
false).value();
|
||||
WalletTxBuilder builder(Params(), *pwalletMain, minRelayTxFee);
|
||||
WalletTxBuilder builder(Params(), minRelayTxFee);
|
||||
std::vector<Payment> recipients = { Payment(zaddr1, 100*COIN, Memo::FromHexOrThrow("DEADBEEF")) };
|
||||
TransactionStrategy strategy(PrivacyPolicy::AllowRevealedSenders);
|
||||
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,
|
||||
TransparentCoinbasePolicy::Disallow,
|
||||
false).value();
|
||||
WalletTxBuilder builder(Params(), *pwalletMain, minRelayTxFee);
|
||||
WalletTxBuilder builder(Params(), minRelayTxFee);
|
||||
std::vector<Payment> recipients = { Payment(taddr1, 100*COIN, Memo::FromHexOrThrow("DEADBEEF")) };
|
||||
TransactionStrategy strategy(PrivacyPolicy::AllowRevealedRecipients);
|
||||
std::shared_ptr<AsyncRPCOperation> operation(new AsyncRPCOperation_sendmany(std::move(builder), selector, recipients, 1, 1, strategy));
|
||||
|
|
|
@ -13,6 +13,7 @@ int GetAnchorHeight(const CChain& chain, uint32_t anchorConfirmations)
|
|||
}
|
||||
|
||||
PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
|
||||
CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
SpendableInputs& spendable,
|
||||
const std::vector<Payment>& payments,
|
||||
|
@ -24,7 +25,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
|
|||
assert(fee < MAX_MONEY);
|
||||
|
||||
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)) {
|
||||
return std::get<InputSelectionError>(selected);
|
||||
}
|
||||
|
@ -81,7 +82,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
|
|||
|
||||
auto changeAddressForTransparentSelector = [&](const std::set<ReceiverType>& receiverTypes) {
|
||||
return addChangePayment(
|
||||
pwalletMain->GenerateChangeAddressForAccount(
|
||||
wallet.GenerateChangeAddressForAccount(
|
||||
sendFromAccount,
|
||||
getAllowedChangePools(receiverTypes)));
|
||||
};
|
||||
|
@ -93,7 +94,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
|
|||
return addChangePayment(
|
||||
sendFromAccount == ZCASH_LEGACY_ACCOUNT
|
||||
? addr
|
||||
: pwalletMain->GenerateChangeAddressForAccount(
|
||||
: wallet.GenerateChangeAddressForAccount(
|
||||
sendFromAccount,
|
||||
getAllowedChangePools({ReceiverType::Sapling})));
|
||||
};
|
||||
|
@ -126,7 +127,7 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
|
|||
return changeAddressForSaplingAddress(fvk.DefaultAddress());
|
||||
},
|
||||
[&](const libzcash::UnifiedAddress& ua) -> ChangeAddress {
|
||||
auto zufvk = pwalletMain->GetUFVKForAddress(ua);
|
||||
auto zufvk = wallet.GetUFVKForAddress(ua);
|
||||
assert(zufvk.has_value());
|
||||
return changeAddressForZUFVK(zufvk.value(), ua.GetKnownReceiverTypes());
|
||||
},
|
||||
|
@ -137,14 +138,14 @@ PrepareTransactionResult WalletTxBuilder::PrepareTransaction(
|
|||
},
|
||||
[&](const AccountZTXOPattern& acct) -> ChangeAddress {
|
||||
return addChangePayment(
|
||||
pwalletMain->GenerateChangeAddressForAccount(
|
||||
wallet.GenerateChangeAddressForAccount(
|
||||
acct.GetAccountId(),
|
||||
getAllowedChangePools(acct.GetReceiverTypes())));
|
||||
}
|
||||
}, selector.GetPattern());
|
||||
}
|
||||
|
||||
auto ovks = SelectOVKs(selector, spendable);
|
||||
auto ovks = SelectOVKs(wallet, selector, spendable);
|
||||
|
||||
return TransactionEffects(
|
||||
anchorConfirmations,
|
||||
|
@ -169,6 +170,7 @@ CAmount WalletTxBuilder::DefaultDustThreshold() const {
|
|||
}
|
||||
|
||||
SpendableInputs WalletTxBuilder::FindAllSpendableInputs(
|
||||
const CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
int32_t minDepth) const
|
||||
{
|
||||
|
@ -177,6 +179,7 @@ SpendableInputs WalletTxBuilder::FindAllSpendableInputs(
|
|||
}
|
||||
|
||||
InputSelectionResult WalletTxBuilder::ResolveInputsAndPayments(
|
||||
const CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
SpendableInputs& spendableMut,
|
||||
const std::vector<Payment>& payments,
|
||||
|
@ -370,6 +373,7 @@ GetOVKsForUFVK(const UnifiedFullViewingKey& ufvk, const SpendableInputs& spendab
|
|||
}
|
||||
|
||||
std::pair<uint256, uint256> WalletTxBuilder::SelectOVKs(
|
||||
const CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
const SpendableInputs& spendable) const
|
||||
{
|
||||
|
|
|
@ -305,7 +305,6 @@ typedef std::variant<
|
|||
class WalletTxBuilder {
|
||||
private:
|
||||
const CChainParams& params;
|
||||
const CWallet& wallet;
|
||||
CFeeRate minRelayFee;
|
||||
uint32_t maxOrchardActions;
|
||||
|
||||
|
@ -320,6 +319,7 @@ private:
|
|||
* and the requested transaction strategy.
|
||||
*/
|
||||
InputSelectionResult ResolveInputsAndPayments(
|
||||
const CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
SpendableInputs& spendable,
|
||||
const std::vector<Payment>& payments,
|
||||
|
@ -332,18 +332,21 @@ private:
|
|||
* the spendable inputs.
|
||||
*/
|
||||
std::pair<uint256, uint256> SelectOVKs(
|
||||
const CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
const SpendableInputs& spendable) const;
|
||||
|
||||
public:
|
||||
WalletTxBuilder(const CChainParams& params, const CWallet& wallet, CFeeRate minRelayFee):
|
||||
params(params), wallet(wallet), minRelayFee(minRelayFee), maxOrchardActions(nOrchardActionLimit) {}
|
||||
WalletTxBuilder(const CChainParams& params, CFeeRate minRelayFee):
|
||||
params(params), minRelayFee(minRelayFee), maxOrchardActions(nOrchardActionLimit) {}
|
||||
|
||||
SpendableInputs FindAllSpendableInputs(
|
||||
const CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
int32_t minDepth) const;
|
||||
|
||||
PrepareTransactionResult PrepareTransaction(
|
||||
CWallet& wallet,
|
||||
const ZTXOSelector& selector,
|
||||
SpendableInputs& spendable,
|
||||
const std::vector<Payment>& payments,
|
||||
|
|
Loading…
Reference in New Issue