Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/long_lived/vault' into quex.all_…
Browse files Browse the repository at this point in the history
…tx_pushing_optional
  • Loading branch information
Quexington committed Nov 2, 2023
2 parents 8ae964d + 188bb20 commit 83e980e
Show file tree
Hide file tree
Showing 36 changed files with 512 additions and 661 deletions.
8 changes: 6 additions & 2 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.bech32m import bech32_decode, decode_puzzle_hash, encode_puzzle_hash
from chia.util.byte_types import hexstr_to_bytes
from chia.util.config import selected_network_address_prefix
from chia.util.ints import uint16, uint32, uint64
from chia.wallet.conditions import CreateCoinAnnouncement, CreatePuzzleAnnouncement
from chia.wallet.nft_wallet.nft_info import NFTInfo
from chia.wallet.outer_puzzles import AssetType
from chia.wallet.puzzle_drivers import PuzzleInfo
Expand Down Expand Up @@ -982,9 +984,11 @@ async def did_message_spend(
try:
response = await wallet_client.did_message_spend(
did_wallet_id,
puzzle_announcements,
coin_announcements,
CMDTXConfigLoader().to_tx_config(units["chia"], config, fingerprint),
extra_conditions=(
*(CreateCoinAnnouncement(hexstr_to_bytes(ca)) for ca in coin_announcements),
*(CreatePuzzleAnnouncement(hexstr_to_bytes(pa)) for pa in puzzle_announcements),
),
)
print(f"Message Spend Bundle: {response['spend_bundle']}")
except Exception as e:
Expand Down
55 changes: 20 additions & 35 deletions chia/data_layer/data_layer_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from chia.data_layer.data_layer_util import OfferStore, ProofOfInclusion, ProofOfInclusionLayer, StoreProofs, leaf_hash
from chia.protocols.wallet_protocol import CoinState
from chia.server.ws_connection import WSChiaConnection
from chia.types.announcement import Announcement
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.serialized_program import SerializedProgram
Expand All @@ -25,7 +24,15 @@
from chia.types.spend_bundle import SpendBundle
from chia.util.ints import uint8, uint32, uint64, uint128
from chia.util.streamable import Streamable, streamable
from chia.wallet.conditions import Condition, UnknownCondition, parse_timelock_info
from chia.wallet.conditions import (
AssertAnnouncement,
AssertCoinAnnouncement,
AssertPuzzleAnnouncement,
Condition,
CreateCoinAnnouncement,
UnknownCondition,
parse_timelock_info,
)
from chia.wallet.db_wallet.db_wallet_puzzles import (
ACS_MU,
ACS_MU_PH,
Expand Down Expand Up @@ -313,7 +320,7 @@ async def generate_new_reporter(
[full_puzzle.get_tree_hash(), 1, [initial_root, inner_puzzle.get_tree_hash()]]
)
announcement_message: bytes32 = genesis_launcher_solution.get_tree_hash()
announcement = Announcement(launcher_coin.name(), announcement_message)
announcement = AssertCoinAnnouncement(asserted_id=launcher_coin.name(), asserted_msg=announcement_message)
[create_launcher_tx_record] = await self.standard_wallet.generate_signed_transaction(
amount=uint64(1),
puzzle_hash=SINGLETON_LAUNCHER.get_tree_hash(),
Expand All @@ -322,9 +329,7 @@ async def generate_new_reporter(
origin_id=launcher_parent.name(),
coins=coins,
primaries=None,
ignore_max_send_amount=False,
coin_announcements_to_consume={announcement},
extra_conditions=extra_conditions,
extra_conditions=(*extra_conditions, announcement),
)
assert create_launcher_tx_record is not None and create_launcher_tx_record.spend_bundle is not None

Expand Down Expand Up @@ -381,18 +386,16 @@ async def generate_new_reporter(
async def create_tandem_xch_tx(
self,
fee: uint64,
announcement_to_assert: Announcement,
announcement_to_assert: AssertAnnouncement,
tx_config: TXConfig,
coin_announcement: bool = True,
) -> TransactionRecord:
[chia_tx] = await self.standard_wallet.generate_signed_transaction(
amount=uint64(0),
puzzle_hash=await self.standard_wallet.get_puzzle_hash(new=not tx_config.reuse_puzhash),
tx_config=tx_config,
fee=fee,
negative_change_allowed=False,
coin_announcements_to_consume={announcement_to_assert} if coin_announcement else None,
puzzle_announcements_to_consume=None if coin_announcement else {announcement_to_assert},
extra_conditions=(announcement_to_assert,),
)
assert chia_tx.spend_bundle is not None
return chia_tx
Expand All @@ -405,8 +408,6 @@ async def create_update_state_spend(
new_puz_hash: Optional[bytes32] = None,
new_amount: Optional[uint64] = None,
fee: uint64 = uint64(0),
coin_announcements_to_consume: Optional[Set[Announcement]] = None,
puzzle_announcements_to_consume: Optional[Set[Announcement]] = None,
sign: bool = True,
add_pending_singleton: bool = True,
announce_new_state: bool = False,
Expand Down Expand Up @@ -503,11 +504,9 @@ async def create_update_state_spend(
]
),
)
root_announce = Announcement(second_full_puz.get_tree_hash(), b"$")
if puzzle_announcements_to_consume is None:
puzzle_announcements_to_consume = set((root_announce,))
else:
puzzle_announcements_to_consume.add(root_announce)
extra_conditions += (
AssertPuzzleAnnouncement(asserted_ph=second_full_puz.get_tree_hash(), asserted_msg=b"$"),
)
second_singleton_record = SingletonRecord(
coin_id=second_coin.name(),
launcher_id=launcher_id,
Expand Down Expand Up @@ -559,14 +558,7 @@ async def create_update_state_spend(
)
inner_sol: Program = self.standard_wallet.make_solution(
primaries=primaries,
coin_announcements={b"$"} if fee > 0 else None,
coin_announcements_to_assert={a.name() for a in coin_announcements_to_consume}
if coin_announcements_to_consume is not None
else None,
puzzle_announcements_to_assert={a.name() for a in puzzle_announcements_to_consume}
if puzzle_announcements_to_consume is not None
else None,
conditions=extra_conditions,
conditions=(*extra_conditions, CreateCoinAnnouncement(b"$")) if fee > 0 else extra_conditions,
)
db_layer_sol = Program.to([inner_sol])
full_sol = Program.to(
Expand Down Expand Up @@ -614,7 +606,7 @@ async def create_update_state_spend(
assert dl_tx.spend_bundle is not None
if fee > 0:
chia_tx = await self.create_tandem_xch_tx(
fee, Announcement(current_coin.name(), b"$"), tx_config, coin_announcement=True
fee, AssertAnnouncement(True, asserted_origin_id=current_coin.name(), asserted_msg=b"$"), tx_config
)
assert chia_tx.spend_bundle is not None
aggregate_bundle = SpendBundle.aggregate([dl_tx.spend_bundle, chia_tx.spend_bundle])
Expand Down Expand Up @@ -643,9 +635,6 @@ async def generate_signed_transaction(
fee: uint64 = uint64(0),
coins: Set[Coin] = set(),
memos: Optional[List[List[bytes]]] = None, # ignored
coin_announcements_to_consume: Optional[Set[Announcement]] = None,
puzzle_announcements_to_consume: Optional[Set[Announcement]] = None,
ignore_max_send_amount: bool = False, # ignored
extra_conditions: Tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
) -> List[TransactionRecord]:
Expand Down Expand Up @@ -680,8 +669,6 @@ async def generate_signed_transaction(
puzzle_hashes[0],
amounts[0],
fee,
coin_announcements_to_consume,
puzzle_announcements_to_consume,
sign,
add_pending_singleton,
announce_new_state,
Expand Down Expand Up @@ -758,7 +745,6 @@ async def create_new_mirror(
fee=fee,
primaries=[],
memos=[launcher_id, *(url for url in urls)],
ignore_max_send_amount=False,
extra_conditions=extra_conditions,
)
assert create_mirror_tx_record.spend_bundle is not None
Expand Down Expand Up @@ -790,8 +776,7 @@ async def delete_mirror(
excess_fee: int = fee - mirror_coin.amount
inner_sol: Program = self.standard_wallet.make_solution(
primaries=[Payment(new_puzhash, uint64(mirror_coin.amount - fee))] if excess_fee < 0 else [],
coin_announcements={b"$"} if excess_fee > 0 else None,
conditions=extra_conditions,
conditions=(*extra_conditions, CreateCoinAnnouncement(b"$")) if excess_fee > 0 else extra_conditions,
)
mirror_spend = CoinSpend(
mirror_coin,
Expand Down Expand Up @@ -834,7 +819,7 @@ async def delete_mirror(
new_puzhash,
tx_config,
fee=uint64(excess_fee),
coin_announcements_to_consume={Announcement(mirror_coin.name(), b"$")},
extra_conditions=(AssertCoinAnnouncement(asserted_id=mirror_coin.name(), asserted_msg=b"$"),),
)
assert txs[0].spend_bundle is not None
assert chia_tx.spend_bundle is not None
Expand Down
27 changes: 14 additions & 13 deletions chia/pools/pool_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@
)
from chia.protocols.pool_protocol import POOL_PROTOCOL_VERSION
from chia.server.ws_connection import WSChiaConnection
from chia.types.announcement import Announcement
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.serialized_program import SerializedProgram
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_spend import CoinSpend, compute_additions
from chia.types.spend_bundle import SpendBundle
from chia.util.ints import uint32, uint64, uint128
from chia.wallet.conditions import Condition, ConditionValidTimes, parse_timelock_info
from chia.wallet.conditions import AssertCoinAnnouncement, Condition, ConditionValidTimes, parse_timelock_info
from chia.wallet.derive_keys import find_owner_sk
from chia.wallet.puzzles.p2_delegated_puzzle_or_hidden_puzzle import puzzle_hash_for_synthetic_public_key
from chia.wallet.sign_coin_spends import sign_coin_spends
Expand Down Expand Up @@ -514,7 +513,7 @@ async def generate_fee_transaction(
self,
fee: uint64,
tx_config: TXConfig,
coin_announcements: Optional[Set[Announcement]] = None,
extra_conditions: Tuple[Condition, ...] = tuple(),
) -> TransactionRecord:
[fee_tx] = await self.standard_wallet.generate_signed_transaction(
uint64(0),
Expand All @@ -524,8 +523,7 @@ async def generate_fee_transaction(
origin_id=None,
coins=None,
primaries=None,
ignore_max_send_amount=False,
coin_announcements_to_consume=coin_announcements,
extra_conditions=extra_conditions,
)
return fee_tx

Expand Down Expand Up @@ -691,9 +689,7 @@ async def generate_launcher_spend(

puzzle_hash: bytes32 = full_pooling_puzzle.get_tree_hash()
pool_state_bytes = Program.to([("p", bytes(initial_target_state)), ("t", delay_time), ("h", delay_ph)])
announcement_set: Set[Announcement] = set()
announcement_message = Program.to([puzzle_hash, amount, pool_state_bytes]).get_tree_hash()
announcement_set.add(Announcement(launcher_coin.name(), announcement_message))

[create_launcher_tx_record] = await standard_wallet.generate_signed_transaction(
amount,
Expand All @@ -702,10 +698,11 @@ async def generate_launcher_spend(
fee,
coins,
None,
False,
announcement_set,
origin_id=launcher_parent.name(),
extra_conditions=extra_conditions,
extra_conditions=(
*extra_conditions,
AssertCoinAnnouncement(asserted_id=launcher_coin.name(), asserted_msg=announcement_message),
),
)
assert create_launcher_tx_record.spend_bundle is not None

Expand Down Expand Up @@ -884,9 +881,13 @@ async def claim_pool_rewards(

fee_tx = None
if fee > 0:
absorb_announce = Announcement(first_coin_record.coin.name(), b"$")
assert absorb_announce is not None
fee_tx = await self.generate_fee_transaction(fee, tx_config, coin_announcements={absorb_announce})
fee_tx = await self.generate_fee_transaction(
fee,
tx_config,
extra_conditions=(
AssertCoinAnnouncement(asserted_id=first_coin_record.coin.name(), asserted_msg=b"$"),
),
)
assert fee_tx.spend_bundle is not None
full_spend = SpendBundle.aggregate([fee_tx.spend_bundle, claim_spend])

Expand Down
Loading

0 comments on commit 83e980e

Please sign in to comment.