|
22 | 22 |
|
23 | 23 | if TYPE_CHECKING:
|
24 | 24 | from bittensor_wallet import Wallet
|
| 25 | + from bittensor.utils.balance import Balance |
25 | 26 |
|
26 | 27 | BT_DOCS_LINK = "https://docs.bittensor.com"
|
27 | 28 |
|
@@ -445,3 +446,34 @@ def deprecated_message(message: str) -> None:
|
445 | 446 | """Shows a deprecation warning message with the given message."""
|
446 | 447 | warnings.simplefilter("default", DeprecationWarning)
|
447 | 448 | warnings.warn(message=message, category=DeprecationWarning, stacklevel=2)
|
| 449 | + |
| 450 | + |
| 451 | +def get_transfer_fn_params( |
| 452 | + amount: Optional["Balance"], destination: str, keep_alive: bool |
| 453 | +) -> tuple[str, dict[str, Union[str, int, bool]]]: |
| 454 | + """ |
| 455 | + Helper function to get the transfer call function and call params, depending on the value and keep_alive flag |
| 456 | + provided |
| 457 | +
|
| 458 | + Args: |
| 459 | + amount: the amount of Tao to transfer. `None` if transferring all. |
| 460 | + destination: the destination SS58 of the transfer |
| 461 | + keep_alive: whether to enforce a retention of the existential deposit in the account after transfer. |
| 462 | +
|
| 463 | + Returns: |
| 464 | + tuple[call function, call params] |
| 465 | + """ |
| 466 | + call_params = {"dest": destination} |
| 467 | + if amount is None: |
| 468 | + call_function = "transfer_all" |
| 469 | + if keep_alive: |
| 470 | + call_params["keep_alive"] = True |
| 471 | + else: |
| 472 | + call_params["keep_alive"] = False |
| 473 | + else: |
| 474 | + call_params["value"] = amount.rao |
| 475 | + if keep_alive: |
| 476 | + call_function = "transfer_keep_alive" |
| 477 | + else: |
| 478 | + call_function = "transfer_allow_death" |
| 479 | + return call_function, call_params |
0 commit comments