Skip to content
Draft
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,16 @@ async def create_new_wallet(
main_wallet = wallet_state_manager.main_wallet
fee = uint64(request.get("fee", 0))

transaction_records: List[TransactionRecord] = []

if request["wallet_type"] == "cat_wallet":
# If not provided, the name will be autogenerated based on the tail hash.
name = request.get("name", None)
if request["mode"] == "new":
if request.get("test", False):
async with self.service.wallet_state_manager.lock:
cat_wallet: CATWallet = await CATWallet.create_new_cat_wallet(
# TODO: use the transaction record
cat_wallet, transaction_record = await CATWallet.create_new_cat_wallet(
wallet_state_manager,
main_wallet,
{"identifier": "genesis_by_id"},
Expand All @@ -687,9 +690,15 @@ async def create_new_wallet(
fee,
name,
)
transaction_records.append(transaction_record)
asset_id = cat_wallet.get_asset_id()
self.service.wallet_state_manager.state_changed("wallet_created")
return {"type": cat_wallet.type(), "asset_id": asset_id, "wallet_id": cat_wallet.id()}
return {
"type": cat_wallet.type(),
"asset_id": asset_id,
"wallet_id": cat_wallet.id(),
"txs": transaction_records,
}
else:
raise ValueError(
"Support for this RPC mode has been dropped."
Expand Down Expand Up @@ -790,7 +799,7 @@ async def create_new_wallet(
else:
raise ValueError("DAO rules must be specified for wallet creation")
async with self.service.wallet_state_manager.lock:
dao_wallet = await DAOWallet.create_new_dao_and_wallet(
dao_wallet, dao_wallet_transaction_records = await DAOWallet.create_new_dao_and_wallet(
wallet_state_manager,
main_wallet,
uint64(request.get("amount_of_cats", None)),
Expand All @@ -801,6 +810,7 @@ async def create_new_wallet(
uint64(request.get("fee", 0)),
uint64(request.get("fee_for_cat", 0)),
)
transaction_records.extend(dao_wallet_transaction_records)
elif mode == "existing":
# async with self.service.wallet_state_manager.lock:
dao_wallet = await DAOWallet.create_new_dao_wallet_for_existing_dao(
Expand All @@ -817,6 +827,7 @@ async def create_new_wallet(
"treasury_id": dao_wallet.dao_info.treasury_id,
"cat_wallet_id": dao_wallet.dao_info.cat_wallet_id,
"dao_cat_wallet_id": dao_wallet.dao_info.dao_cat_wallet_id,
"txs": transaction_records,
}
elif request["wallet_type"] == "nft_wallet":
for wallet in self.service.wallet_state_manager.wallets.values():
Expand Down
4 changes: 2 additions & 2 deletions chia/simulator/full_node_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ async def wallet_is_synced(self, wallet_node: WalletNode) -> bool:
async def wait_for_wallet_synced(
self,
wallet_node: WalletNode,
timeout: Optional[float] = 5,
timeout: Optional[float] = 10,
) -> None:
with anyio.fail_after(delay=adjusted_timeout(timeout)):
for backoff_time in backoff_times():
Expand All @@ -683,7 +683,7 @@ async def wallets_are_synced(self, wallet_nodes: List[WalletNode]) -> bool:
async def wait_for_wallets_synced(
self,
wallet_nodes: List[WalletNode],
timeout: Optional[float] = 5,
timeout: Optional[float] = 10,
) -> None:
with anyio.fail_after(delay=adjusted_timeout(timeout)):
for backoff_time in backoff_times():
Expand Down
5 changes: 3 additions & 2 deletions chia/wallet/cat_wallet/cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ async def create_new_cat_wallet(
tx_config: TXConfig,
fee: uint64 = uint64(0),
name: Optional[str] = None,
) -> CATWallet:
) -> Tuple[CATWallet, TransactionRecord]:
# TODO: nope, no. red light. stop. (with the tuple, that is)
self = CATWallet()
self.standard_wallet = wallet
self.log = logging.getLogger(__name__)
Expand Down Expand Up @@ -175,7 +176,7 @@ async def create_new_cat_wallet(
chia_tx = dataclasses.replace(chia_tx, spend_bundle=spend_bundle)
await self.standard_wallet.push_transaction(chia_tx)
await self.standard_wallet.push_transaction(cat_record)
return self
return self, cat_record

@staticmethod
async def get_or_create_wallet_for_cat(
Expand Down
24 changes: 16 additions & 8 deletions chia/wallet/dao_wallet/dao_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ async def create_new_dao_and_wallet(
name: Optional[str] = None,
fee: uint64 = uint64(0),
fee_for_cat: uint64 = uint64(0),
) -> DAOWallet:
) -> Tuple[DAOWallet, List[TransactionRecord]]:
# TODO: auauaghhhhh not a tuple
"""
Create a brand new DAO wallet
This must be called under the wallet state manager lock
Expand Down Expand Up @@ -177,7 +178,7 @@ async def create_new_dao_and_wallet(
std_wallet_id = self.standard_wallet.wallet_id

try:
await self.generate_new_dao(
transaction_records = await self.generate_new_dao(
amount_of_cats,
tx_config,
fee=fee,
Expand All @@ -202,7 +203,7 @@ async def create_new_dao_and_wallet(
)
await self.save_info(dao_info)

return self
return self, transaction_records

@staticmethod
async def create_new_dao_wallet_for_existing_dao(
Expand Down Expand Up @@ -612,7 +613,7 @@ async def generate_new_dao(
fee: uint64 = uint64(0),
fee_for_cat: uint64 = uint64(0),
extra_conditions: Tuple[Condition, ...] = tuple(),
) -> Optional[SpendBundle]:
) -> List[TransactionRecord]:
"""
Create a new DAO treasury using the dao_rules object. This does the first spend to create the launcher
and eve coins.
Expand All @@ -621,6 +622,8 @@ async def generate_new_dao(
This must be called under the wallet state manager lock
"""

transaction_records: List[TransactionRecord] = []

if amount_of_cats_to_create is not None and amount_of_cats_to_create < 0: # pragma: no cover
raise ValueError("amount_of_cats must be >= 0, or None")
if (
Expand All @@ -643,7 +646,8 @@ async def generate_new_dao(
coins = await self.standard_wallet.select_coins(uint64(fee + 1), tx_config.coin_selection_config)

if coins is None: # pragma: no cover
return None
# TODO: review for raising a real exception
raise Exception("")
# origin is normal coin which creates launcher coin
origin = coins.copy().pop()

Expand Down Expand Up @@ -688,7 +692,7 @@ async def generate_new_dao(
"treasury_id": launcher_coin.name(),
"coins": different_coins,
}
new_cat_wallet = await CATWallet.create_new_cat_wallet(
new_cat_wallet, cat_wallet_transaction_record = await CATWallet.create_new_cat_wallet(
self.wallet_state_manager,
self.standard_wallet,
cat_tail_info,
Expand All @@ -697,6 +701,7 @@ async def generate_new_dao(
fee=fee_for_cat,
)
assert new_cat_wallet is not None
transaction_records.append(cat_wallet_transaction_record)
else: # pragma: no cover
for wallet in self.wallet_state_manager.wallets:
if self.wallet_state_manager.wallets[wallet].type() == WalletType.CAT:
Expand Down Expand Up @@ -756,7 +761,8 @@ async def generate_new_dao(
await self.add_parent(launcher_coin.name(), launcher_proof)

if tx_record is None or tx_record.spend_bundle is None: # pragma: no cover
return None
# TODO: review for raising a real exception
raise Exception("")

eve_coin = Coin(launcher_coin.name(), full_treasury_puzzle_hash, uint64(1))
dao_info = DAOInfo(
Expand Down Expand Up @@ -799,14 +805,16 @@ async def generate_new_dao(
regular_record = dataclasses.replace(tx_record, spend_bundle=None)
await self.wallet_state_manager.add_pending_transaction(regular_record)
await self.wallet_state_manager.add_pending_transaction(treasury_record)
transaction_records.append(treasury_record)

funding_inner_puzhash = get_p2_singleton_puzhash(self.dao_info.treasury_id)
await self.wallet_state_manager.add_interested_puzzle_hashes([funding_inner_puzhash], [self.id()])
await self.wallet_state_manager.add_interested_puzzle_hashes([launcher_coin.name()], [self.id()])
await self.wallet_state_manager.add_interested_coin_ids([launcher_coin.name()], [self.wallet_id])

await self.wallet_state_manager.add_interested_coin_ids([eve_coin.name()], [self.wallet_id])
return full_spend
# TODO: any more transaction records needed?
return transaction_records

async def generate_treasury_eve_spend(
self, inner_puz: Program, eve_coin: Coin, fee: uint64 = uint64(0)
Expand Down
2 changes: 1 addition & 1 deletion chia/wallet/vc_wallet/cr_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def create_new_cat_wallet(
tx_config: TXConfig,
fee: uint64 = uint64(0),
name: Optional[str] = None,
) -> CATWallet: # pragma: no cover
) -> Tuple[CATWallet, TransactionRecord]: # pragma: no cover
raise NotImplementedError("create_new_cat_wallet is a legacy method and is not available on CR-CAT wallets")

@staticmethod
Expand Down
6 changes: 4 additions & 2 deletions tests/wallet/cat_wallet/test_trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ async def test_cat_trades(
await time_out_assert_not_none(5, full_node.full_node.mempool_manager.get_spendbundle, spend_bundle.name())
else:
async with wallet_node_maker.wallet_state_manager.lock:
cat_wallet_maker = await CATWallet.create_new_cat_wallet(
# TODO: use the transaction record
cat_wallet_maker, _ = await CATWallet.create_new_cat_wallet(
wallet_node_maker.wallet_state_manager,
wallet_maker,
{"identifier": "genesis_by_id"},
Expand All @@ -218,7 +219,8 @@ async def test_cat_trades(
)

async with wallet_node_taker.wallet_state_manager.lock:
new_cat_wallet_taker = await CATWallet.create_new_cat_wallet(
# TODO: use the transaction record
new_cat_wallet_taker, _ = await CATWallet.create_new_cat_wallet(
wallet_node_taker.wallet_state_manager,
wallet_taker,
{"identifier": "genesis_by_id"},
Expand Down
Loading