Skip to content

Commit

Permalink
[CHIA-432] Port chia dao ... to @tx_out_cmd (and exclude DL and poo…
Browse files Browse the repository at this point in the history
…ling) (#18065)

This brings another set of commands to the @tx_out_cmd decorator which
gives it the capability to optionally push a transaction and export the
transactions to a local file.

This PR being the last in a chain of similar PRs, I have included some
comments explaining that DL and pooling endpoints will not be ported to
the decorator at this time. Didn't think that necessitated its own PR
and CI run :)
  • Loading branch information
Quexington committed May 23, 2024
2 parents a7a0cc8 + 1ba3b3a commit 7424942
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 99 deletions.
8 changes: 8 additions & 0 deletions chia/_tests/cmds/wallet/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def create_new_dao_wallet(
name: Optional[str] = None,
fee: uint64 = uint64(0),
fee_for_cat: uint64 = uint64(0),
push: bool = True,
) -> CreateNewDAOWalletResponse:
if not treasury_id:
treasury_id = bytes32(token_bytes(32))
Expand Down Expand Up @@ -140,6 +141,7 @@ async def dao_add_funds_to_treasury(
tx_config: TXConfig,
fee: uint64 = uint64(0),
reuse_puzhash: Optional[bool] = None,
push: bool = True,
) -> DAOAddFundsToTreasuryResponse:
return DAOAddFundsToTreasuryResponse([STD_UTX], [STD_TX], STD_TX.name, STD_TX)

Expand Down Expand Up @@ -278,6 +280,7 @@ async def dao_vote_on_proposal(
tx_config: TXConfig,
is_yes_vote: bool,
fee: uint64 = uint64(0),
push: bool = True,
) -> DAOVoteOnProposalResponse:
return DAOVoteOnProposalResponse([STD_UTX], [STD_TX], STD_TX.name, STD_TX)

Expand All @@ -289,6 +292,7 @@ async def dao_close_proposal(
fee: uint64 = uint64(0),
self_destruct: bool = False,
reuse_puzhash: Optional[bool] = None,
push: bool = True,
) -> DAOCloseProposalResponse:
return DAOCloseProposalResponse([STD_UTX], [STD_TX], STD_TX.name, STD_TX)

Expand All @@ -306,6 +310,7 @@ async def dao_create_proposal(
new_dao_rules: Optional[Dict[str, uint64]] = None,
fee: uint64 = uint64(0),
reuse_puzhash: Optional[bool] = None,
push: bool = True,
) -> DAOCreateProposalResponse:
return DAOCreateProposalResponse([STD_UTX], [STD_TX], bytes32([0] * 32), STD_TX.name, STD_TX)

Expand Down Expand Up @@ -489,6 +494,7 @@ async def dao_send_to_lockup(
tx_config: TXConfig,
fee: uint64 = uint64(0),
reuse_puzhash: Optional[bool] = None,
push: bool = True,
) -> DAOSendToLockupResponse:
return DAOSendToLockupResponse([STD_UTX], [STD_TX], STD_TX.name, [STD_TX])

Expand All @@ -498,6 +504,7 @@ async def dao_free_coins_from_finished_proposals(
tx_config: TXConfig,
fee: uint64 = uint64(0),
reuse_puzhash: Optional[bool] = None,
push: bool = True,
) -> DAOFreeCoinsFromFinishedProposalsResponse:
return DAOFreeCoinsFromFinishedProposalsResponse([STD_UTX], [STD_TX], STD_TX.name, STD_TX)

Expand All @@ -508,6 +515,7 @@ async def dao_exit_lockup(
coins: Optional[List[Dict[str, Union[str, int]]]] = None,
fee: uint64 = uint64(0),
reuse_puzhash: Optional[bool] = None,
push: bool = True,
) -> DAOExitLockupResponse:
return DAOExitLockupResponse([STD_UTX], [STD_TX], STD_TX.name, STD_TX)

Expand Down
75 changes: 53 additions & 22 deletions chia/cmds/dao.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

import asyncio
from typing import Optional, Sequence
from typing import List, Optional, Sequence

import click

from chia.cmds.cmds_util import tx_config_args
from chia.cmds.cmds_util import tx_config_args, tx_out_cmd
from chia.cmds.plotnft import validate_fee
from chia.wallet.transaction_record import TransactionRecord


@click.group("dao", short_help="Create, manage or show state of DAOs", no_args_is_help=True)
Expand Down Expand Up @@ -155,6 +156,7 @@ def dao_add_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_create_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -175,7 +177,8 @@ def dao_create_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import create_dao_wallet

if self_destruct == proposal_timelock:
Expand All @@ -201,8 +204,9 @@ def dao_create_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(create_dao_wallet(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(create_dao_wallet(extra_params, wallet_rpc_port, fingerprint))


# ----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -266,6 +270,7 @@ def dao_get_id_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_add_funds_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -278,7 +283,8 @@ def dao_add_funds_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import add_funds_to_treasury

extra_params = {
Expand All @@ -291,8 +297,9 @@ def dao_add_funds_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(add_funds_to_treasury(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(add_funds_to_treasury(extra_params, wallet_rpc_port, fingerprint))


@dao_cmd.command("balance", short_help="Get the asset balances for a DAO treasury", no_args_is_help=True)
Expand Down Expand Up @@ -455,6 +462,7 @@ def dao_show_proposal_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_vote_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -468,7 +476,8 @@ def dao_vote_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import vote_on_proposal

is_yes_vote = False if vote_no else True
Expand All @@ -484,8 +493,9 @@ def dao_vote_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(vote_on_proposal(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(vote_on_proposal(extra_params, wallet_rpc_port, fingerprint))


# ----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -526,6 +536,7 @@ def dao_vote_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_close_proposal_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -538,7 +549,8 @@ def dao_close_proposal_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import close_proposal

extra_params = {
Expand All @@ -551,8 +563,9 @@ def dao_close_proposal_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(close_proposal(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(close_proposal(extra_params, wallet_rpc_port, fingerprint))


# ----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -586,6 +599,7 @@ def dao_close_proposal_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_lockup_coins_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -597,7 +611,8 @@ def dao_lockup_coins_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import lockup_coins

extra_params = {
Expand All @@ -609,8 +624,9 @@ def dao_lockup_coins_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(lockup_coins(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(lockup_coins(extra_params, wallet_rpc_port, fingerprint))


@dao_cmd.command("release_coins", short_help="Release closed proposals from DAO CATs", no_args_is_help=True)
Expand All @@ -633,6 +649,7 @@ def dao_lockup_coins_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_release_coins_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -643,7 +660,8 @@ def dao_release_coins_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool = True,
) -> List[TransactionRecord]:
from .dao_funcs import release_coins

extra_params = {
Expand All @@ -654,8 +672,9 @@ def dao_release_coins_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(release_coins(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(release_coins(extra_params, wallet_rpc_port, fingerprint))


@dao_cmd.command("exit_lockup", short_help="Release DAO CATs from voting mode", no_args_is_help=True)
Expand All @@ -678,6 +697,7 @@ def dao_release_coins_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_exit_lockup_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -688,7 +708,8 @@ def dao_exit_lockup_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import exit_lockup

extra_params = {
Expand All @@ -699,8 +720,9 @@ def dao_exit_lockup_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(exit_lockup(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(exit_lockup(extra_params, wallet_rpc_port, fingerprint))


# ----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -772,6 +794,7 @@ def dao_proposal(ctx: click.Context) -> None:
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_create_spend_proposal_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -787,7 +810,8 @@ def dao_create_spend_proposal_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import create_spend_proposal

extra_params = {
Expand All @@ -803,8 +827,9 @@ def dao_create_spend_proposal_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(create_spend_proposal(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(create_spend_proposal(extra_params, wallet_rpc_port, fingerprint))


@dao_proposal.command("update", short_help="Create a proposal to change the DAO rules", no_args_is_help=True)
Expand Down Expand Up @@ -877,6 +902,7 @@ def dao_create_spend_proposal_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_create_update_proposal_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -894,7 +920,8 @@ def dao_create_update_proposal_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import create_update_proposal

extra_params = {
Expand All @@ -912,8 +939,9 @@ def dao_create_update_proposal_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(create_update_proposal(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(create_update_proposal(extra_params, wallet_rpc_port, fingerprint))


@dao_proposal.command("mint", short_help="Create a proposal to mint new DAO CATs", no_args_is_help=True)
Expand Down Expand Up @@ -959,6 +987,7 @@ def dao_create_update_proposal_cmd(
callback=validate_fee,
)
@tx_config_args
@tx_out_cmd
def dao_create_mint_proposal_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -972,7 +1001,8 @@ def dao_create_mint_proposal_cmd(
coins_to_exclude: Sequence[str],
amounts_to_exclude: Sequence[str],
reuse: Optional[bool],
) -> None:
push: bool,
) -> List[TransactionRecord]:
from .dao_funcs import create_mint_proposal

extra_params = {
Expand All @@ -986,8 +1016,9 @@ def dao_create_mint_proposal_cmd(
"coins_to_exclude": coins_to_exclude,
"amounts_to_exclude": amounts_to_exclude,
"reuse_puzhash": reuse,
"push": push,
}
asyncio.run(create_mint_proposal(extra_params, wallet_rpc_port, fingerprint))
return asyncio.run(create_mint_proposal(extra_params, wallet_rpc_port, fingerprint))


# ----------------------------------------------------------------------------------------
Expand Down

0 comments on commit 7424942

Please sign in to comment.