Source code for digital_world_sdk.operation.account_merge

from typing import ClassVar

from .. import xdr as dw_xdr
from ..muxed_account import MuxedAccount
from .operation import Operation

__all__ = ["AccountMerge"]


[docs] class AccountMerge(Operation): """The :class:`AccountMerge` object, which represents a AccountMerge operation on the Digital World network. Transfers the native balance (the amount of XLM an account holds) to another account and removes the source account from the ledger. Threshold: High See `Account Merge <https://docs.digitalworld.global/docs/learn/fundamentals/transactions/list-of-operations#account-merge>`_ for more information. :param destination: Destination to merge the source account into. :param source: The source account for the operation. Defaults to the transaction's source account. """ _XDR_OPERATION_TYPE: ClassVar[dw_xdr.OperationType] = ( dw_xdr.OperationType.ACCOUNT_MERGE ) def __init__( self, destination: MuxedAccount | str, source: MuxedAccount | str | None = None, ) -> None: super().__init__(source) if isinstance(destination, str): destination = MuxedAccount.from_account(destination) self.destination: MuxedAccount = destination def _to_operation_body(self) -> dw_xdr.OperationBody: destination = self.destination.to_xdr_object() body = dw_xdr.OperationBody( type=self._XDR_OPERATION_TYPE, destination=destination ) return body
[docs] @classmethod def from_xdr_object(cls, xdr_object: dw_xdr.Operation) -> "AccountMerge": """Creates a :class:`AccountMerge` object from an XDR Operation object. """ source = Operation.get_source_from_xdr_obj(xdr_object) assert xdr_object.body.destination is not None destination = MuxedAccount.from_xdr_object(xdr_object.body.destination) op = cls(source=source, destination=destination) return op
def __repr__(self): return f"<AccountMerge [destination={self.destination}, source={self.source}]>"