Skip to content

Commit

Permalink
Add generate_signed_transaction to WalletProtocol (#19244)
Browse files Browse the repository at this point in the history
This PR adds the `generate_signed_transaction` method to the
`WalletProtocol`. This will help enforce that any new wallets or general
uses of wallets must follow the same API for the key transaction method.
  • Loading branch information
pmaslana authored Feb 12, 2025
2 parents 3bc3325 + ebef33e commit 9842b8c
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 deletions.
4 changes: 2 additions & 2 deletions chia/data_layer/data_layer_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ async def generate_signed_transaction(
puzzle_hashes: list[bytes32],
action_scope: WalletActionScope,
fee: uint64 = uint64(0),
coins: set[Coin] = set(),
coins: Optional[set[Coin]] = None,
memos: Optional[list[list[bytes]]] = None, # ignored
extra_conditions: tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
Expand All @@ -601,7 +601,7 @@ async def generate_signed_transaction(
new_root_hash: Optional[bytes32] = kwargs.get("new_root_hash", None)
announce_new_state: bool = kwargs.get("announce_new_state", False)
# Figure out the launcher ID
if len(coins) == 0:
if coins is None or len(coins) == 0:
if launcher_id is None:
raise ValueError("Not enough info to know which DL coin to send")
else:
Expand Down
16 changes: 15 additions & 1 deletion chia/pools/pool_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast

from chia_rs import G1Element, G2Element, PrivateKey
from typing_extensions import final
from typing_extensions import Unpack, final

from chia.pools.pool_config import PoolWalletConfig, load_pool_config, update_pool_config
from chia.pools.pool_puzzles import (
Expand Down Expand Up @@ -53,6 +53,7 @@
from chia.wallet.wallet_action_scope import WalletActionScope
from chia.wallet.wallet_coin_record import WalletCoinRecord
from chia.wallet.wallet_info import WalletInfo
from chia.wallet.wallet_protocol import GSTOptionalArgs
from chia.wallet.wallet_spend_bundle import WalletSpendBundle

if TYPE_CHECKING:
Expand Down Expand Up @@ -930,3 +931,16 @@ def get_name(self) -> str:

async def match_hinted_coin(self, coin: Coin, hint: bytes32) -> bool: # pragma: no cover
return False # PoolWallet pre-dates hints

async def generate_signed_transaction(
self,
amounts: list[uint64],
puzzle_hashes: list[bytes32],
action_scope: WalletActionScope,
fee: uint64 = uint64(0),
coins: Optional[set[Coin]] = None,
memos: Optional[list[list[bytes]]] = None,
extra_conditions: tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
) -> None:
raise NotImplementedError("Pool Wallet does not implement `generate_signed_transaction`")
15 changes: 15 additions & 0 deletions chia/wallet/cat_wallet/dao_cat_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast

from chia_rs import G1Element
from typing_extensions import Unpack

from chia.server.ws_connection import WSChiaConnection
from chia.types.blockchain_format.coin import Coin
Expand Down Expand Up @@ -39,6 +40,7 @@
from chia.wallet.wallet_action_scope import WalletActionScope
from chia.wallet.wallet_coin_record import WalletCoinRecord
from chia.wallet.wallet_info import WalletInfo
from chia.wallet.wallet_protocol import GSTOptionalArgs
from chia.wallet.wallet_spend_bundle import WalletSpendBundle

if TYPE_CHECKING:
Expand Down Expand Up @@ -661,3 +663,16 @@ async def save_info(self, dao_cat_info: DAOCATInfo) -> None:

def get_name(self) -> str:
return self.wallet_info.name

async def generate_signed_transaction(
self,
amounts: list[uint64],
puzzle_hashes: list[bytes32],
action_scope: WalletActionScope,
fee: uint64 = uint64(0),
coins: Optional[set[Coin]] = None,
memos: Optional[list[list[bytes]]] = None,
extra_conditions: tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
) -> None:
raise NotImplementedError("DAOCATWallet does not implement `generate_signed_transaction`")
15 changes: 15 additions & 0 deletions chia/wallet/dao_wallet/dao_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from chia_rs import AugSchemeMPL, G1Element, G2Element
from clvm.casts import int_from_bytes
from typing_extensions import Unpack

from chia.full_node.full_node_api import FullNodeAPI
from chia.protocols.wallet_protocol import CoinState, RequestBlockHeader, RespondBlockHeader
Expand Down Expand Up @@ -78,6 +79,7 @@
from chia.wallet.wallet_action_scope import WalletActionScope
from chia.wallet.wallet_coin_record import WalletCoinRecord
from chia.wallet.wallet_info import WalletInfo
from chia.wallet.wallet_protocol import GSTOptionalArgs
from chia.wallet.wallet_spend_bundle import WalletSpendBundle


Expand Down Expand Up @@ -2105,3 +2107,16 @@ async def apply_state_transition(self, new_state: CoinSpend, block_height: uint3
raise ValueError(f"Unsupported spend in DAO Wallet: {self.id()}")

return True

async def generate_signed_transaction(
self,
amounts: list[uint64],
puzzle_hashes: list[bytes32],
action_scope: WalletActionScope,
fee: uint64 = uint64(0),
coins: Optional[set[Coin]] = None,
memos: Optional[list[list[bytes]]] = None,
extra_conditions: tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
) -> None:
raise NotImplementedError("DAOWallet does not implement `generate_signed_transaction`")
16 changes: 15 additions & 1 deletion chia/wallet/did_wallet/did_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import TYPE_CHECKING, Any, ClassVar, Optional, cast

from chia_rs import AugSchemeMPL, G1Element, G2Element
from typing_extensions import Unpack

from chia.protocols.wallet_protocol import CoinState
from chia.server.ws_connection import WSChiaConnection
Expand Down Expand Up @@ -53,7 +54,7 @@
from chia.wallet.wallet_action_scope import WalletActionScope
from chia.wallet.wallet_coin_record import WalletCoinRecord
from chia.wallet.wallet_info import WalletInfo
from chia.wallet.wallet_protocol import WalletProtocol
from chia.wallet.wallet_protocol import GSTOptionalArgs, WalletProtocol
from chia.wallet.wallet_spend_bundle import WalletSpendBundle


Expand Down Expand Up @@ -1499,3 +1500,16 @@ async def match_hinted_coin(self, coin: Coin, hint: bytes32) -> bool:
).get_tree_hash_precalc(hint)
== coin.puzzle_hash
)

async def generate_signed_transaction(
self,
amounts: list[uint64],
puzzle_hashes: list[bytes32],
action_scope: WalletActionScope,
fee: uint64 = uint64(0),
coins: Optional[set[Coin]] = None,
memos: Optional[list[list[bytes]]] = None,
extra_conditions: tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
) -> None:
raise NotImplementedError("DIDWallet does not implement `generate_signed_transaction`")
2 changes: 1 addition & 1 deletion chia/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ async def generate_signed_transaction(
fee: uint64 = uint64(0),
coins: Optional[set[Coin]] = None,
memos: Optional[list[list[bytes]]] = None,
puzzle_decorator_override: Optional[list[dict[str, Any]]] = None,
extra_conditions: tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
) -> None:
origin_id: Optional[bytes32] = kwargs.get("origin_id", None)
negative_change_allowed: bool = kwargs.get("negative_change_allowed", False)
puzzle_decorator_override: Optional[list[dict[str, Any]]] = kwargs.get("puzzle_decorator_override", None)
"""
Use this to generate transaction.
Note: this must be called under a wallet state manager lock
Expand Down
18 changes: 16 additions & 2 deletions chia/wallet/wallet_protocol.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Optional, TypeVar
from typing import TYPE_CHECKING, Any, Optional, TypeVar

from chia_rs import G1Element
from typing_extensions import NotRequired, Protocol, TypedDict
from typing_extensions import NotRequired, Protocol, TypedDict, Unpack

from chia.server.ws_connection import WSChiaConnection
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.ints import uint32, uint64, uint128
from chia.wallet.conditions import Condition
from chia.wallet.nft_wallet.nft_info import NFTCoinInfo
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_action_scope import WalletActionScope
Expand Down Expand Up @@ -59,6 +60,18 @@ def get_name(self) -> str: ...

async def match_hinted_coin(self, coin: Coin, hint: bytes32) -> bool: ...

async def generate_signed_transaction(
self,
amounts: list[uint64],
puzzle_hashes: list[bytes32],
action_scope: WalletActionScope,
fee: uint64 = uint64(0),
coins: Optional[set[Coin]] = None,
memos: Optional[list[list[bytes]]] = None,
extra_conditions: tuple[Condition, ...] = tuple(),
**kwargs: Unpack[GSTOptionalArgs],
) -> None: ...

wallet_info: WalletInfo
wallet_state_manager: WalletStateManager

Expand Down Expand Up @@ -88,3 +101,4 @@ class GSTOptionalArgs(TypedDict):
# Wallet
origin_id: NotRequired[Optional[bytes32]]
negative_change_allowed: NotRequired[bool]
puzzle_decorator_override: NotRequired[Optional[list[dict[str, Any]]]]

0 comments on commit 9842b8c

Please sign in to comment.