Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for CAP-33 #372

Merged
merged 13 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/en/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,36 @@ ClaimClaimableBalance
.. autoclass:: stellar_sdk.operation.ClaimClaimableBalance
:members: to_xdr_object, from_xdr_object

BeginSponsoringFutureReserves
-----------------------------
.. autoclass:: stellar_sdk.operation.BeginSponsoringFutureReserves
:members: to_xdr_object, from_xdr_object

EndSponsoringFutureReserves
---------------------------
.. autoclass:: stellar_sdk.operation.EndSponsoringFutureReserves
:members: to_xdr_object, from_xdr_object

RevokeSponsorship
-----------------
.. autoclass:: stellar_sdk.operation.RevokeSponsorship
:members: to_xdr_object, from_xdr_object

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.RevokeSponsorshipType
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.TrustLine
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.Offer
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.Data
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.Signer
:members:

Price
^^^^^

Expand All @@ -465,6 +495,13 @@ Signer
:members:
:inherited-members:

SignerKey
^^^^^^^^^

.. autoclass:: stellar_sdk.signer_key.SignerKey
:members:
:inherited-members:

TimeBounds
^^^^^^^^^^

Expand Down
37 changes: 37 additions & 0 deletions docs/zh_CN/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,36 @@ ClaimClaimableBalance
.. autoclass:: stellar_sdk.operation.ClaimClaimableBalance
:members: to_xdr_object, from_xdr_object

BeginSponsoringFutureReserves
-----------------------------
.. autoclass:: stellar_sdk.operation.BeginSponsoringFutureReserves
:members: to_xdr_object, from_xdr_object

EndSponsoringFutureReserves
---------------------------
.. autoclass:: stellar_sdk.operation.EndSponsoringFutureReserves
:members: to_xdr_object, from_xdr_object

RevokeSponsorship
-----------------
.. autoclass:: stellar_sdk.operation.RevokeSponsorship
:members: to_xdr_object, from_xdr_object

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.RevokeSponsorshipType
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.TrustLine
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.Offer
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.Data
:members:

.. autoclass:: stellar_sdk.operation.revoke_sponsorship.Signer
:members:

Price
^^^^^

Expand All @@ -465,6 +495,13 @@ Signer
:members:
:inherited-members:

SignerKey
^^^^^^^^^

.. autoclass:: stellar_sdk.signer_key.SignerKey
:members:
:inherited-members:

TimeBounds
^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions stellar_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .price import Price
from .server import Server
from .signer import Signer
from .signer_key import SignerKey
from .time_bounds import TimeBounds
from .transaction import Transaction
from .transaction_builder import TransactionBuilder
Expand Down Expand Up @@ -53,6 +54,7 @@
"Price",
"Server",
"Signer",
"SignerKey",
"TimeBounds",
"Transaction",
"TransactionBuilder",
Expand Down
6 changes: 6 additions & 0 deletions stellar_sdk/operation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from .account_merge import AccountMerge
from .allow_trust import AllowTrust, TrustLineEntryFlag
from .begin_sponsoring_future_reserves import BeginSponsoringFutureReserves
from .bump_sequence import BumpSequence
from .change_trust import ChangeTrust
from .claim_claimable_balance import ClaimClaimableBalance
from .create_account import CreateAccount
from .create_claimable_balance import CreateClaimableBalance, Claimant, ClaimPredicate
from .create_passive_sell_offer import CreatePassiveSellOffer
from .end_sponsoring_future_reserves import EndSponsoringFutureReserves
from .inflation import Inflation
from .manage_buy_offer import ManageBuyOffer
from .manage_data import ManageData
Expand All @@ -15,6 +17,7 @@
from .path_payment_strict_receive import PathPaymentStrictReceive
from .path_payment_strict_send import PathPaymentStrictSend
from .payment import Payment
from .revoke_sponsorship import RevokeSponsorship
from .set_options import SetOptions, Flag

__all__ = [
Expand All @@ -38,6 +41,9 @@
"PathPaymentStrictSend",
"Payment",
"SetOptions",
"BeginSponsoringFutureReserves",
"EndSponsoringFutureReserves",
"RevokeSponsorship",
"TrustLineEntryFlag",
"Flag", # TODO: act like TrustLineEntryFlag
]
57 changes: 57 additions & 0 deletions stellar_sdk/operation/begin_sponsoring_future_reserves.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from .operation import Operation
from .utils import check_ed25519_public_key
from ..keypair import Keypair
from ..strkey import StrKey
from ..xdr import Xdr


class BeginSponsoringFutureReserves(Operation):
"""The :class:`BeginSponsoringFutureReserves` object, which represents a BeginSponsoringFutureReserves
operation on Stellar's network.

Establishes the is-sponsoring-future-reserves-for relationship between the source account and sponsoredID.
See `Sponsored Reserves <https://developers.stellar.org/docs/glossary/sponsored-reserves/>_` for more information.

See `Begin Sponsoring Future Reserves
<https://developers.stellar.org/docs/start/list-of-operations/#begin-sponsoring-future-reserves>_`.

Threshold: Medium

:param sponsored_id: The sponsored account id.
:param source: The source account (defaults to transaction source).
"""

def __init__(self, sponsored_id: str, source: str = None) -> None:
super().__init__(source)
check_ed25519_public_key(sponsored_id)
self.sponsored_id: str = sponsored_id

@classmethod
def type_code(cls) -> int:
return Xdr.const.BEGIN_SPONSORING_FUTURE_RESERVES

def _to_operation_body(self) -> Xdr.nullclass:
sponsored_id = Keypair.from_public_key(self.sponsored_id).xdr_account_id()
begin_sponsoring_future_reserves_op = Xdr.types.BeginSponsoringFutureReservesOp(
sponsoredID=sponsored_id
)
body = Xdr.nullclass()
body.type = Xdr.const.BEGIN_SPONSORING_FUTURE_RESERVES
body.beginSponsoringFutureReservesOp = begin_sponsoring_future_reserves_op
return body

@classmethod
def from_xdr_object(
cls, operation_xdr_object: Xdr.types.Operation
) -> "BeginSponsoringFutureReserves":
"""Creates a :class:`BeginSponsoringFutureReserves` object from an XDR Operation
object.
"""
source = Operation.get_source_from_xdr_obj(operation_xdr_object)

sponsored_id = StrKey.encode_ed25519_public_key(
operation_xdr_object.body.beginSponsoringFutureReservesOp.sponsoredID.ed25519
)
op = cls(source=source, sponsored_id=sponsored_id)
op._source_muxed = Operation.get_source_muxed_from_xdr_obj(operation_xdr_object)
return op
43 changes: 43 additions & 0 deletions stellar_sdk/operation/end_sponsoring_future_reserves.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from .operation import Operation
from ..xdr import Xdr


class EndSponsoringFutureReserves(Operation):
"""The :class:`EndSponsoringFutureReserves` object, which represents a EndSponsoringFutureReserves
operation on Stellar's network.

Terminates the current is-sponsoring-future-reserves-for relationship in which the source account is sponsored.
See `Sponsored Reserves <https://developers.stellar.org/docs/glossary/sponsored-reserves/>_` for more information.

See `End Sponsoring Future Reserves
<https://developers.stellar.org/docs/start/list-of-operations/#end-sponsoring-future-reserves>_`.

Threshold: Medium

:param sponsored_id: The sponsored account id.
:param source: The source account (defaults to transaction source).
"""

def __init__(self, source: str = None) -> None:
super().__init__(source)

@classmethod
def type_code(cls) -> int:
return Xdr.const.END_SPONSORING_FUTURE_RESERVES

def _to_operation_body(self) -> Xdr.nullclass:
body = Xdr.nullclass()
body.type = Xdr.const.END_SPONSORING_FUTURE_RESERVES
return body

@classmethod
def from_xdr_object(
cls, operation_xdr_object: Xdr.types.Operation
) -> "EndSponsoringFutureReserves":
"""Creates a :class:`EndSponsoringFutureReserves` object from an XDR Operation
object.
"""
source = Operation.get_source_from_xdr_obj(operation_xdr_object)
op = cls(source=source,)
op._source_muxed = Operation.get_source_muxed_from_xdr_obj(operation_xdr_object)
return op
Loading