Skip to content

Commit

Permalink
Fix rpc util
Browse files Browse the repository at this point in the history
  • Loading branch information
Quexington committed May 23, 2024
1 parent 8b7d391 commit a12341b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 5 additions & 1 deletion chia/_tests/wallet/rpc/test_wallet_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
from chia.wallet.transaction_sorting import SortKey
from chia.wallet.uncurried_puzzle import uncurry_puzzle
from chia.wallet.util.address_type import AddressType
from chia.wallet.util.blind_signer_tl import BLIND_SIGNER_TRANSLATION
from chia.wallet.util.clvm_streamable import byte_deserialize_clvm_streamable
from chia.wallet.util.compute_memos import compute_memos
from chia.wallet.util.query_filter import AmountFilter, HashFilter, TransactionTypeFilter
Expand Down Expand Up @@ -341,13 +342,16 @@ async def test_send_transaction(wallet_rpc_environment: WalletRpcTestEnvironment
"exclude_coins": [non_existent_coin.to_json_dict()],
"reuse_puzhash": True,
"CHIP-0029": True,
"translation": "CHIP-0028",
"push": True,
},
)
assert response["success"]
tx = TransactionRecord.from_json_dict_convenience(response["transactions"][0])
[
byte_deserialize_clvm_streamable(bytes.fromhex(utx), UnsignedTransaction)
byte_deserialize_clvm_streamable(
bytes.fromhex(utx), UnsignedTransaction, translation_layer=BLIND_SIGNER_TRANSLATION
)
for utx in response["unsigned_transactions"]
]
assert tx == dataclasses.replace(tx_no_push, created_at_time=tx.created_at_time)
Expand Down
26 changes: 24 additions & 2 deletions chia/rpc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,36 @@ async def rpc_endpoint(self, request: Dict[str, Any], *args, **kwargs) -> Dict[s
]
unsigned_txs = await self.service.wallet_state_manager.gather_signing_info_for_txs(tx_records)

response["unsigned_transactions"] = unsigned_txs
if request.get("CHIP-0029", False):
response["unsigned_transactions"] = [
json_serialize_with_clvm_streamable(
tx,
translation_layer=(
ALL_TRANSLATION_LAYERS[request["translation"]] if "translation" in request else None
),
)
for tx in unsigned_txs
]
else:
response["unsigned_transactions"] = [tx.to_json_dict() for tx in unsigned_txs]

new_txs: List[TransactionRecord] = []
if request.get("sign", self.service.config.get("auto_sign_txs", True)):
new_txs, signing_responses = await self.service.wallet_state_manager.sign_transactions(
tx_records, response.get("signing_responses", []), "signing_responses" in response
)
response["signing_responses"] = signing_responses
if request.get("CHIP-0029", False):
response["signing_responses"] = [
json_serialize_with_clvm_streamable(
sr,
translation_layer=(
ALL_TRANSLATION_LAYERS[request["translation"]] if "translation" in request else None
),
)
for sr in signing_responses
]
else:
response["signing_responses"] = [sr.to_json_dict() for sr in signing_responses]
else:
new_txs = tx_records # pragma: no cover

Expand Down

0 comments on commit a12341b

Please sign in to comment.