Skip to content

Commit

Permalink
Add flags to CR-CAT offer summary (#16131)
Browse files Browse the repository at this point in the history
* Add flags to CR-CAT Offer Summary

* Fix typo
  • Loading branch information
Quexington authored Aug 25, 2023
1 parent 0c525f6 commit 988d3bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
31 changes: 29 additions & 2 deletions chia/rpc/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Any, ClassVar, Dict, List, Optional, Set, Tuple, Union

from blspy import AugSchemeMPL, G1Element, G2Element, PrivateKey
from clvm_tools.binutils import assemble

from chia.consensus.block_rewards import calculate_base_farmer_reward
from chia.data_layer.data_layer_errors import LauncherCoinNotFoundError
Expand Down Expand Up @@ -82,6 +83,7 @@
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG, 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
from chia.wallet.vc_wallet.cr_cat_wallet import CRCATWallet
from chia.wallet.vc_wallet.vc_store import VCProofs
from chia.wallet.vc_wallet.vc_wallet import VCWallet
Expand Down Expand Up @@ -1699,16 +1701,41 @@ async def get_offer_summary(self, request: Dict[str, Any]) -> EndpointResult:
offered, requested, infos = offer.summary()

if request.get("advanced", False):
return {
response = {
"summary": {"offered": offered, "requested": requested, "fees": offer.fees(), "infos": infos},
"id": offer.name(),
}
else:
return {
response = {
"summary": await self.service.wallet_state_manager.trade_manager.get_offer_summary(offer),
"id": offer.name(),
}

# This is a bit of a hack in favor of returning some more manageable information about CR-CATs
# A more general solution surely exists, but I'm not sure what it is right now
return {
**response,
"summary": {
**response["summary"], # type: ignore[dict-item]
"infos": {
key: {
**info,
"also": {
**info["also"],
"flags": ProofsChecker.from_program(
uncurry_puzzle(
Program(assemble(info["also"]["proofs_checker"])) # type: ignore[no-untyped-call]
)
).flags,
},
}
if "also" in info and "proofs_checker" in info["also"]
else info
for key, info in response["summary"]["infos"].items() # type: ignore[index]
},
},
}

async def check_offer_validity(self, request: Dict[str, Any]) -> EndpointResult:
offer_hex: str = request["offer"]

Expand Down
8 changes: 7 additions & 1 deletion tests/wallet/cat_wallet/test_trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from chia.wallet.trading.offer import Offer
from chia.wallet.trading.trade_status import TradeStatus
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.uncurried_puzzle import uncurry_puzzle
from chia.wallet.util.transaction_type import TransactionType
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG, TXConfig
from chia.wallet.vc_wallet.cr_cat_drivers import ProofsChecker
Expand Down Expand Up @@ -346,15 +347,20 @@ async def test_cat_trades(
assert trade_make is not None

peer = wallet_node_taker.get_full_node_peer()
maker_offer: Offer = Offer.from_bytes(trade_make.offer)
trade_take, tx_records = await trade_manager_taker.respond_to_offer(
Offer.from_bytes(trade_make.offer),
maker_offer,
peer,
tx_config,
fee=uint64(1),
)
assert trade_take is not None
assert tx_records is not None

if credential_restricted:
assert (await client_maker.get_offer_summary(maker_offer))[1]["infos"][
bytes.fromhex(new_cat_wallet_maker.get_asset_id()).hex()
]["also"]["flags"] == ProofsChecker.from_program(uncurry_puzzle(proofs_checker_taker.as_program())).flags
if test_aggregation:
first_offer = Offer.from_bytes(trade_take.offer)

Expand Down

0 comments on commit 988d3bb

Please sign in to comment.