Skip to content

Commit 61034b5

Browse files
authored
[CHIA-3602] Port wallet coin endpoints to @marshal (#19966)
* Port `spend_clawback_coins` to `@marshal` * fix tests * fix test again * how do I keep missing these? * Port `select_coins` to `@marshal` * fix tests * fix test * Port `get_spendable_coins` * Port `get_coin_records_by_names` * bad port of `include_spent_coins` * Less bad replace logic * Actually autofill the CoinSelectionConfigLoader in `get_spendable_coins` * Comments by @altendky
1 parent 23ad961 commit 61034b5

File tree

8 files changed

+333
-266
lines changed

8 files changed

+333
-266
lines changed

chia/_tests/cmds/cmd_test_utils.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from chia.full_node.full_node_rpc_client import FullNodeRpcClient
2323
from chia.rpc.rpc_client import RpcClient
2424
from chia.simulator.simulator_full_node_rpc_client import SimulatorFullNodeRpcClient
25-
from chia.types.coin_record import CoinRecord
2625
from chia.types.signing_mode import SigningMode
2726
from chia.util.bech32m import encode_puzzle_hash
2827
from chia.util.config import load_config
@@ -31,7 +30,7 @@
3130
from chia.wallet.nft_wallet.nft_wallet import NFTWallet
3231
from chia.wallet.transaction_record import TransactionRecord
3332
from chia.wallet.util.transaction_type import TransactionType
34-
from chia.wallet.util.tx_config import CoinSelectionConfig, TXConfig
33+
from chia.wallet.util.tx_config import TXConfig
3534
from chia.wallet.util.wallet_types import WalletType
3635
from chia.wallet.wallet_request_types import (
3736
GetSyncStatusResponse,
@@ -232,46 +231,6 @@ async def nft_calculate_royalties(
232231
)
233232
)
234233

235-
async def get_spendable_coins(
236-
self,
237-
wallet_id: int,
238-
coin_selection_config: CoinSelectionConfig,
239-
) -> tuple[list[CoinRecord], list[CoinRecord], list[Coin]]:
240-
"""
241-
We return a tuple containing: (confirmed records, unconfirmed removals, unconfirmed additions)
242-
"""
243-
self.add_to_log(
244-
"get_spendable_coins",
245-
(wallet_id, coin_selection_config),
246-
)
247-
confirmed_records = [
248-
CoinRecord(
249-
Coin(bytes32([1] * 32), bytes32([2] * 32), uint64(1234560000)),
250-
uint32(123456),
251-
uint32(0),
252-
False,
253-
uint64(0),
254-
),
255-
CoinRecord(
256-
Coin(bytes32([3] * 32), bytes32([4] * 32), uint64(1234560000)),
257-
uint32(123456),
258-
uint32(0),
259-
False,
260-
uint64(0),
261-
),
262-
]
263-
unconfirmed_removals = [
264-
CoinRecord(
265-
Coin(bytes32([5] * 32), bytes32([6] * 32), uint64(1234570000)),
266-
uint32(123457),
267-
uint32(0),
268-
True,
269-
uint64(0),
270-
)
271-
]
272-
unconfirmed_additions = [Coin(bytes32([7] * 32), bytes32([8] * 32), uint64(1234580000))]
273-
return confirmed_records, unconfirmed_removals, unconfirmed_additions
274-
275234
async def send_transaction_multi(
276235
self,
277236
wallet_id: int,

chia/_tests/wallet/nft_wallet/test_nft_bulk_mint.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from chia.wallet.nft_wallet.uncurry_nft import UncurriedNFT
1616
from chia.wallet.transaction_record import TransactionRecord
1717
from chia.wallet.util.address_type import AddressType
18-
from chia.wallet.wallet_request_types import NFTGetNFTs, NFTMintBulk, NFTMintMetadata, PushTransactions
18+
from chia.wallet.wallet_request_types import NFTGetNFTs, NFTMintBulk, NFTMintMetadata, PushTransactions, SelectCoins
1919

2020

2121
async def nft_count(wallet: NFTWallet) -> int:
@@ -291,22 +291,25 @@ async def test_nft_mint_rpc(wallet_environments: WalletTestFramework, zero_royal
291291
fee = 100
292292
num_chunks = int(n / chunk) + (1 if n % chunk > 0 else 0)
293293
required_amount = n + (fee * num_chunks)
294-
xch_coins = await env_0.rpc_client.select_coins(
295-
amount=required_amount,
296-
coin_selection_config=wallet_environments.tx_config.coin_selection_config,
297-
wallet_id=wallet_0.id(),
294+
select_coins_response = await env_0.rpc_client.select_coins(
295+
SelectCoins.from_coin_selection_config(
296+
amount=uint64(required_amount),
297+
coin_selection_config=wallet_environments.tx_config.coin_selection_config,
298+
wallet_id=wallet_0.id(),
299+
)
298300
)
299-
funding_coin = xch_coins[0]
301+
funding_coin = select_coins_response.coins[0]
300302
assert funding_coin.amount >= required_amount
301-
funding_coin_dict = xch_coins[0].to_json_dict()
302303
next_coin = funding_coin
303304
did_coin = (
304305
await env_0.rpc_client.select_coins(
305-
amount=1,
306-
coin_selection_config=wallet_environments.tx_config.coin_selection_config,
307-
wallet_id=env_0.wallet_aliases["did"],
306+
SelectCoins.from_coin_selection_config(
307+
amount=uint64(1),
308+
coin_selection_config=wallet_environments.tx_config.coin_selection_config,
309+
wallet_id=uint32(env_0.wallet_aliases["did"]),
310+
)
308311
)
309-
)[0]
312+
).coins[0]
310313
did_lineage_parent: Optional[bytes32] = None
311314
txs: list[TransactionRecord] = []
312315
nft_ids = set()
@@ -321,7 +324,7 @@ async def test_nft_mint_rpc(wallet_environments: WalletTestFramework, zero_royal
321324
mint_number_start=uint16(i + 1),
322325
mint_total=uint16(n),
323326
xch_coins=[next_coin],
324-
xch_change_target=funding_coin_dict["puzzle_hash"],
327+
xch_change_target=funding_coin.puzzle_hash.hex(),
325328
did_coin=did_coin if with_did else None,
326329
did_lineage_parent=did_lineage_parent if with_did else None,
327330
mint_from_did=with_did,

0 commit comments

Comments
 (0)