Source code for digital_world_sdk.operation.clawback_claimable_balance

import base64
import binascii
from typing import ClassVar

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

__all__ = ["ClawbackClaimableBalance"]


[docs] class ClawbackClaimableBalance(Operation): """The :class:`ClawbackClaimableBalance` object, which represents a ClawbackClaimableBalance operation on Digital World's network. Claws back a claimable balance Threshold: Medium See `Clawback Claimable Balance <https://docs.digitalworld.global/docs/learn/fundamentals/transactions/list-of-operations#clawback-claimable-balance>`_ for more information. :param balance_id: The claimable balance ID to be clawed back. :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.CLAWBACK_CLAIMABLE_BALANCE ) def __init__( self, balance_id: str, source: MuxedAccount | str | None = None ) -> None: super().__init__(source) self.balance_id: str = balance_id raise_if_not_valid_balance_id(self.balance_id, "balance_id") def _to_operation_body(self) -> dw_xdr.OperationBody: balance_id_bytes: bytes = binascii.unhexlify(self.balance_id) balance_id = dw_xdr.ClaimableBalanceID.from_xdr_bytes(balance_id_bytes) clawback_claimable_balance_op = dw_xdr.ClawbackClaimableBalanceOp( balance_id=balance_id ) body = dw_xdr.OperationBody( type=self._XDR_OPERATION_TYPE, clawback_claimable_balance_op=clawback_claimable_balance_op, ) return body
[docs] @classmethod def from_xdr_object( cls, xdr_object: dw_xdr.Operation ) -> "ClawbackClaimableBalance": """Creates a :class:`ClawbackClaimableBalance` object from an XDR Operation object. """ source = Operation.get_source_from_xdr_obj(xdr_object) assert xdr_object.body.clawback_claimable_balance_op is not None balance_id_bytes = base64.b64decode( xdr_object.body.clawback_claimable_balance_op.to_xdr() ) balance_id = binascii.hexlify(balance_id_bytes).decode() op = cls(balance_id=balance_id, source=source) return op
def __repr__(self): return f"<ClawbackClaimableBalance [balance_id={self.balance_id}, source={self.source}]>"