Skip to content

Commit

Permalink
add XChainAddAttestation model(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Jul 18, 2022
1 parent fc4501b commit db2fe0d
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
2 changes: 2 additions & 0 deletions xrpl/models/transactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
TrustSetFlag,
TrustSetFlagInterface,
)
from xrpl.models.transactions.xchain_add_attestation import XChainAddAttestation
from xrpl.models.transactions.xchain_claim import XChainClaim
from xrpl.models.transactions.xchain_commit import XChainCommit
from xrpl.models.transactions.xchain_create_bridge import XChainCreateBridge
Expand Down Expand Up @@ -102,6 +103,7 @@
"TrustSet",
"TrustSetFlag",
"TrustSetFlagInterface",
"XChainAddAttestation",
"XChainClaim",
"XChainCommit",
"XChainCreateBridge",
Expand Down
2 changes: 1 addition & 1 deletion xrpl/models/transactions/types/transaction_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TransactionType(str, Enum):
SIGNER_LIST_SET = "SignerListSet"
TICKET_CREATE = "TicketCreate"
TRUST_SET = "TrustSet"
# XCHAIN_ADD_ATTESTATION = "XChainAddAttestation"
XCHAIN_ADD_ATTESTATION = "XChainAddAttestation"
XCHAIN_CLAIM = "XChainClaim"
XCHAIN_COMMIT = "XChainCommit"
# XCHAIN_CREATE_ACCOUNT_COMMIT = "XChainCreateAccountCommit"
Expand Down
127 changes: 127 additions & 0 deletions xrpl/models/transactions/xchain_add_attestation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""Model for a XChainAddAttestation transaction type."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any, Dict, List, Literal, Optional, Type, Union

from xrpl.models.amounts import Amount
from xrpl.models.base_model import BaseModel
from xrpl.models.required import REQUIRED
from xrpl.models.transactions.transaction import Transaction
from xrpl.models.transactions.types import TransactionType
from xrpl.models.utils import require_kwargs_on_init
from xrpl.models.xchain_bridge import XChainBridge


@require_kwargs_on_init
@dataclass(frozen=True)
class XChainClaimAttestationBatchElement(BaseModel):
"""Represents a single claim attestation."""

account: str = REQUIRED # type: ignore

amount: Amount = REQUIRED # type: ignore

attestation_reward_account: str = REQUIRED # type: ignore

destination: str = REQUIRED # type: ignore

public_key: str = REQUIRED # type: ignore

signature: str = REQUIRED # type: ignore

was_locking_chain_send: Union[Literal[0, 1]] = REQUIRED # type: ignore

xchain_claim_id: str = REQUIRED # type: ignore

@classmethod
def is_dict_of_model(
cls: Type[XChainClaimAttestationBatchElement], dictionary: Dict[str, Any]
) -> bool:
"""
Returns True if the input dictionary was derived by the `to_dict`
method of an instance of this class. In other words, True if this is
a dictionary representation of an instance of this class.
NOTE: does not account for model inheritance, IE will only return True
if dictionary represents an instance of this class, but not if
dictionary represents an instance of a subclass of this class.
Args:
dictionary: The dictionary to check.
Returns:
True if dictionary is a dict representation of an instance of this
class.
"""
return (
isinstance(dictionary, dict)
and "xchain_claim_attestation_batch_element" in dictionary
and super().is_dict_of_model(
dictionary["xchain_claim_attestation_batch_element"]
)
)

@classmethod
def from_dict(
cls: Type[XChainClaimAttestationBatchElement], value: Dict[str, Any]
) -> XChainClaimAttestationBatchElement:
"""
Construct a new XChainClaimAttestationBatchElement from a dictionary of
parameters.
Args:
value: The value to construct the XChainClaimAttestationBatchElement from.
Returns:
A new XChainClaimAttestationBatchElement object, constructed using the
given parameters.
"""
if len(value) == 1 and "xchain_claim_attestation_batch_element" in value:
return super(XChainClaimAttestationBatchElement, cls).from_dict(
value["xchain_claim_attestation_batch_element"]
)
return super(XChainClaimAttestationBatchElement, cls).from_dict(value)

def to_dict(self: XChainClaimAttestationBatchElement) -> Dict[str, Any]:
"""
Returns the dictionary representation of a XChainClaimAttestationBatchElement.
Returns:
The dictionary representation of a XChainClaimAttestationBatchElement.
"""
return {"xchain_claim_attestation_batch_element": super().to_dict()}


@require_kwargs_on_init
@dataclass(frozen=True)
class XChainAttestationBatch(BaseModel):
"""Represents a set of attestations from a single witness server."""

xchain_bridge: XChainBridge = REQUIRED # type: ignore

xchain_claim_attestation_batch: List[
XChainClaimAttestationBatchElement
] = REQUIRED # type: ignore

xchain_create_account_attestation_batch: List[
XChainClaimAttestationBatchElement
] = REQUIRED # type: ignore


@require_kwargs_on_init
@dataclass(frozen=True)
class XChainAddAttestation(Transaction):
"""Represents a XChainAddAttestation transaction."""

xchain_bridge: XChainBridge = REQUIRED # type: ignore

signature_reward: Amount = REQUIRED # type: ignore

min_account_create_amount: Optional[Amount] = None

transaction_type: TransactionType = field(
default=TransactionType.XCHAIN_ADD_ATTESTATION,
init=False,
)

0 comments on commit db2fe0d

Please sign in to comment.