Skip to content

Commit

Permalink
Remove tx_endpoint from select_coins (#16325)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quexington authored Sep 14, 2023
1 parent 19e03f0 commit fc66f43
Showing 1 changed file with 17 additions and 5 deletions.
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

0 comments on commit fc66f43

Please sign in to comment.