Skip to content

Commit

Permalink
Add the is_uma flag to payments. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jklein24 authored Jan 11, 2024
2 parents a4c16c9 + 9d1dd53 commit c6cdd88
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 167 deletions.
2 changes: 2 additions & 0 deletions lightspark/objects/Account.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ def get_transactions(
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
incoming_payment_transaction_hash: transaction_hash
incoming_payment_is_uma: is_uma
incoming_payment_destination: destination {
id
}
Expand Down Expand Up @@ -933,6 +934,7 @@ def get_transactions(
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
outgoing_payment_transaction_hash: transaction_hash
outgoing_payment_is_uma: is_uma
outgoing_payment_origin: origin {
id
}
Expand Down
2 changes: 2 additions & 0 deletions lightspark/objects/CancelInvoiceInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

@dataclass
class CancelInvoiceInput:
"""The unique identifier of the Invoice that should be cancelled. The invoice is supposed to be open, not settled and not expired."""

invoice_id: str

def to_json(self) -> Mapping[str, Any]:
Expand Down
2 changes: 2 additions & 0 deletions lightspark/objects/CancelInvoiceOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

@dataclass
class CancelInvoiceOutput:
"""The Invoice that was cancelled. If the invoice was already cancelled, the same invoice is returned."""

requester: Requester

invoice_id: str
Expand Down
71 changes: 47 additions & 24 deletions lightspark/objects/ChannelSnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,70 @@

from .CurrencyAmount import CurrencyAmount
from .CurrencyAmount import from_json as CurrencyAmount_from_json
from .Entity import Entity


@dataclass
class ChannelSnapshot:
class ChannelSnapshot(Entity):
requester: Requester

channel_id: str
id: str
"""The unique identifier of this entity across all Lightspark systems. Should be treated as an opaque string."""

timestamp: datetime
created_at: datetime
"""The date and time when the entity was first created."""

updated_at: datetime
"""The date and time when the entity was last updated."""

local_balance: Optional[CurrencyAmount]

local_unsettled_balance: Optional[CurrencyAmount]

local_channel_reserve: Optional[CurrencyAmount]

remote_balance: Optional[CurrencyAmount]

remote_unsettled_balance: Optional[CurrencyAmount]

channel_id: str

local_channel_reserve: Optional[CurrencyAmount]

timestamp: datetime
"""The timestamp that was used to query the snapshot of the channel"""
typename: str

def to_json(self) -> Mapping[str, Any]:
return {
"channel_snapshot_channel": {"id": self.channel_id},
"channel_snapshot_timestamp": self.timestamp.isoformat(),
"__typename": "ChannelSnapshot",
"channel_snapshot_id": self.id,
"channel_snapshot_created_at": self.created_at.isoformat(),
"channel_snapshot_updated_at": self.updated_at.isoformat(),
"channel_snapshot_local_balance": self.local_balance.to_json()
if self.local_balance
else None,
"channel_snapshot_local_unsettled_balance": self.local_unsettled_balance.to_json()
if self.local_unsettled_balance
else None,
"channel_snapshot_local_channel_reserve": self.local_channel_reserve.to_json()
if self.local_channel_reserve
else None,
"channel_snapshot_remote_balance": self.remote_balance.to_json()
if self.remote_balance
else None,
"channel_snapshot_remote_unsettled_balance": self.remote_unsettled_balance.to_json()
if self.remote_unsettled_balance
else None,
"channel_snapshot_channel": {"id": self.channel_id},
"channel_snapshot_local_channel_reserve": self.local_channel_reserve.to_json()
if self.local_channel_reserve
else None,
"channel_snapshot_timestamp": self.timestamp.isoformat(),
}


FRAGMENT = """
fragment ChannelSnapshotFragment on ChannelSnapshot {
__typename
channel_snapshot_channel: channel {
id
}
channel_snapshot_timestamp: timestamp
channel_snapshot_id: id
channel_snapshot_created_at: created_at
channel_snapshot_updated_at: updated_at
channel_snapshot_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
Expand All @@ -73,39 +88,45 @@ def to_json(self) -> Mapping[str, Any]:
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_local_channel_reserve: local_channel_reserve {
channel_snapshot_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_balance: remote_balance {
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
channel_snapshot_channel: channel {
id
}
channel_snapshot_local_channel_reserve: local_channel_reserve {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_timestamp: timestamp
}
"""


def from_json(requester: Requester, obj: Mapping[str, Any]) -> ChannelSnapshot:
return ChannelSnapshot(
requester=requester,
channel_id=obj["channel_snapshot_channel"]["id"],
timestamp=datetime.fromisoformat(obj["channel_snapshot_timestamp"]),
typename="ChannelSnapshot",
id=obj["channel_snapshot_id"],
created_at=datetime.fromisoformat(obj["channel_snapshot_created_at"]),
updated_at=datetime.fromisoformat(obj["channel_snapshot_updated_at"]),
local_balance=CurrencyAmount_from_json(
requester, obj["channel_snapshot_local_balance"]
)
Expand All @@ -116,11 +137,6 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> ChannelSnapshot:
)
if obj["channel_snapshot_local_unsettled_balance"]
else None,
local_channel_reserve=CurrencyAmount_from_json(
requester, obj["channel_snapshot_local_channel_reserve"]
)
if obj["channel_snapshot_local_channel_reserve"]
else None,
remote_balance=CurrencyAmount_from_json(
requester, obj["channel_snapshot_remote_balance"]
)
Expand All @@ -131,4 +147,11 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> ChannelSnapshot:
)
if obj["channel_snapshot_remote_unsettled_balance"]
else None,
channel_id=obj["channel_snapshot_channel"]["id"],
local_channel_reserve=CurrencyAmount_from_json(
requester, obj["channel_snapshot_local_channel_reserve"]
)
if obj["channel_snapshot_local_channel_reserve"]
else None,
timestamp=datetime.fromisoformat(obj["channel_snapshot_timestamp"]),
)
98 changes: 53 additions & 45 deletions lightspark/objects/Entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,56 @@ class Entity:
id
}
}
... on ChannelSnapshot {
__typename
channel_snapshot_id: id
channel_snapshot_created_at: created_at
channel_snapshot_updated_at: updated_at
channel_snapshot_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_channel: channel {
id
}
channel_snapshot_local_channel_reserve: local_channel_reserve {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_timestamp: timestamp
}
... on Deposit {
__typename
deposit_id: id
Expand Down Expand Up @@ -288,6 +338,7 @@ class Entity:
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
incoming_payment_transaction_hash: transaction_hash
incoming_payment_is_uma: is_uma
incoming_payment_destination: destination {
id
}
Expand Down Expand Up @@ -907,6 +958,7 @@ class Entity:
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
outgoing_payment_transaction_hash: transaction_hash
outgoing_payment_is_uma: is_uma
outgoing_payment_origin: origin {
id
}
Expand Down Expand Up @@ -1264,51 +1316,7 @@ class Entity:
id
}
outgoing_payment_attempt_channel_snapshot: channel_snapshot {
__typename
channel_snapshot_channel: channel {
id
}
channel_snapshot_timestamp: timestamp
channel_snapshot_local_balance: local_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_local_unsettled_balance: local_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_local_channel_reserve: local_channel_reserve {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_balance: remote_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
channel_snapshot_remote_unsettled_balance: remote_unsettled_balance {
__typename
currency_amount_original_value: original_value
currency_amount_original_unit: original_unit
currency_amount_preferred_currency_unit: preferred_currency_unit
currency_amount_preferred_currency_value_rounded: preferred_currency_value_rounded
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
id
}
}
... on RoutingTransaction {
Expand Down
6 changes: 6 additions & 0 deletions lightspark/objects/IncomingPayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class IncomingPayment(LightningTransaction, Transaction, Entity):
transaction_hash: Optional[str]
"""The hash of this transaction, so it can be uniquely identified on the Lightning Network."""

is_uma: bool
"""Whether this payment is an UMA payment or not. NOTE: this field is only set if the invoice that is being paid has been created using the recommended `create_uma_invoice` function."""

destination_id: str
"""The recipient Lightspark node this payment was sent to."""

Expand Down Expand Up @@ -127,6 +130,7 @@ def to_json(self) -> Mapping[str, Any]:
else None,
"incoming_payment_amount": self.amount.to_json(),
"incoming_payment_transaction_hash": self.transaction_hash,
"incoming_payment_is_uma": self.is_uma,
"incoming_payment_destination": {"id": self.destination_id},
"incoming_payment_payment_request": {"id": self.payment_request_id}
if self.payment_request_id
Expand Down Expand Up @@ -156,6 +160,7 @@ def to_json(self) -> Mapping[str, Any]:
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
incoming_payment_transaction_hash: transaction_hash
incoming_payment_is_uma: is_uma
incoming_payment_destination: destination {
id
}
Expand Down Expand Up @@ -191,6 +196,7 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> IncomingPayment:
else None,
amount=CurrencyAmount_from_json(requester, obj["incoming_payment_amount"]),
transaction_hash=obj["incoming_payment_transaction_hash"],
is_uma=obj["incoming_payment_is_uma"],
destination_id=obj["incoming_payment_destination"]["id"],
payment_request_id=obj["incoming_payment_payment_request"]["id"]
if obj["incoming_payment_payment_request"]
Expand Down
4 changes: 4 additions & 0 deletions lightspark/objects/LightningTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def to_json(self) -> Mapping[str, Any]:
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
incoming_payment_transaction_hash: transaction_hash
incoming_payment_is_uma: is_uma
incoming_payment_destination: destination {
id
}
Expand Down Expand Up @@ -120,6 +121,7 @@ def to_json(self) -> Mapping[str, Any]:
currency_amount_preferred_currency_value_approx: preferred_currency_value_approx
}
outgoing_payment_transaction_hash: transaction_hash
outgoing_payment_is_uma: is_uma
outgoing_payment_origin: origin {
id
}
Expand Down Expand Up @@ -504,6 +506,7 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> LightningTransact
else None,
amount=CurrencyAmount_from_json(requester, obj["incoming_payment_amount"]),
transaction_hash=obj["incoming_payment_transaction_hash"],
is_uma=obj["incoming_payment_is_uma"],
destination_id=obj["incoming_payment_destination"]["id"],
payment_request_id=obj["incoming_payment_payment_request"]["id"]
if obj["incoming_payment_payment_request"]
Expand Down Expand Up @@ -534,6 +537,7 @@ def from_json(requester: Requester, obj: Mapping[str, Any]) -> LightningTransact
else None,
amount=CurrencyAmount_from_json(requester, obj["outgoing_payment_amount"]),
transaction_hash=obj["outgoing_payment_transaction_hash"],
is_uma=obj["outgoing_payment_is_uma"],
origin_id=obj["outgoing_payment_origin"]["id"],
destination_id=obj["outgoing_payment_destination"]["id"]
if obj["outgoing_payment_destination"]
Expand Down
Loading

0 comments on commit c6cdd88

Please sign in to comment.