Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tx_endpoint from select_coins #16325

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
from chia.wallet.util.compute_memos import compute_memos
from chia.wallet.util.query_filter import HashFilter, TransactionTypeFilter
from chia.wallet.util.transaction_type import CLAWBACK_INCOMING_TRANSACTION_TYPES, TransactionType
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG, TXConfig
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG, CoinSelectionConfig, CoinSelectionConfigLoader, TXConfig
from chia.wallet.util.wallet_sync_utils import fetch_coin_spend_for_coin_state
from chia.wallet.util.wallet_types import CoinType, WalletType
from chia.wallet.vc_wallet.cr_cat_drivers import ProofsChecker
Expand Down Expand Up @@ -1155,13 +1155,25 @@ async def delete_unconfirmed_transactions(self, request: Dict[str, Any]) -> Endp
wallet.target_state = None
return {}

@tx_endpoint
async def select_coins(
self,
request: Dict[str, Any],
tx_config: TXConfig = DEFAULT_TX_CONFIG,
extra_conditions: Tuple[Condition, ...] = tuple(),
) -> EndpointResult:
assert self.service.logged_in_fingerprint is not None
cs_config_loader: CoinSelectionConfigLoader = CoinSelectionConfigLoader.from_json_dict(request)

# Some backwards compat fill-ins
if cs_config_loader.excluded_coin_ids is None:
excluded_coins: Optional[List[Coin]] = request.get("excluded_coins", request.get("exclude_coins"))
if excluded_coins is not None:
cs_config_loader = cs_config_loader.override(
excluded_coin_ids=[Coin.from_json_dict(c).name() for c in excluded_coins],
)

cs_config: CoinSelectionConfig = cs_config_loader.autofill(
constants=self.service.wallet_state_manager.constants,
)

if await self.service.wallet_state_manager.synced() is False:
raise ValueError("Wallet needs to be fully synced before selecting coins")

Expand All @@ -1170,7 +1182,7 @@ async def select_coins(

wallet = self.service.wallet_state_manager.wallets[wallet_id]
async with self.service.wallet_state_manager.lock:
selected_coins = await wallet.select_coins(amount, tx_config.coin_selection_config)
selected_coins = await wallet.select_coins(amount, cs_config)

return {"coins": [coin.to_json_dict() for coin in selected_coins]}

Expand Down
Loading