Skip to content

Commit

Permalink
docs: Transaction and TransactionEnvelope
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Aug 10, 2019
1 parent a2d068a commit c5f3de7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
12 changes: 12 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,18 @@ TimeBounds
:members:
:inherited-members:

Transaction
^^^^^^^^^^^

.. autoclass:: stellar_sdk.transaction.Transaction
:members:

TransactionEnvelope
^^^^^^^^^^^^^^^^^^^

.. autoclass:: stellar_sdk.transaction_envelope.TransactionEnvelope
:members:

TransactionBuilder
^^^^^^^^^^^^^^^^^^

Expand Down
46 changes: 44 additions & 2 deletions stellar_sdk/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@


class Transaction:
"""The :class:`Transaction` object, which represents a transaction
on Stellar's network.
A transaction contains a list of operations, which are all executed
in order as one ACID transaction, along with an
associated source account, fee, account sequence number, list of
signatures, both an optional memo and an optional TimeBounds. Typically a
:class:`Transaction` is placed in a :class:`TransactionEnvelope
<stellar_sdk.transaction_envelope.TransactionEnvelope>` which is
then signed before being sent over the network.
For more information on Transactions in Stellar, see `Stellar's guide
on transactions`_.
.. _Stellar's guide on transactions:
https://www.stellar.org/developers/guides/concepts/transactions.html
:param source: the source account for the transaction.
:param sequence: The sequence number for the transaction.
:param fee: The fee amount for the transaction, which should equal
FEE (currently 100 stroops) multiplied by the number of
operations in the transaction. See `Stellar's latest documentation
on fees
<https://www.stellar.org/developers/guides/concepts/fees.html#transaction-fee>`_
for more information.
:param operations: A list of operations objects (typically its
subclasses as defined in :mod:`stellar_sdk.operation.Operation`.
:param time_bounds: The timebounds for the validity of this transaction.
:param memo: The memo being sent with the transaction, being
represented as one of the subclasses of the
:class:`Memo <stellar_sdk.memo.Memo>` object.
"""
def __init__(
self,
source: Keypair,
Expand All @@ -34,7 +66,11 @@ def __init__(
self.fee = fee
self.time_bounds = time_bounds

def to_xdr_object(self):
def to_xdr_object(self) -> Xdr.types.Transaction:
"""Get an XDR object representation of this :class:`Transaction`.
:return: XDR Transaction object
"""
source_account = self.source.xdr_account_id()
memo = self.memo.to_xdr_object()
operations = [operation.to_xdr_object() for operation in self.operations]
Expand All @@ -48,7 +84,13 @@ def to_xdr_object(self):
)

@classmethod
def from_xdr_object(cls, tx_xdr_object):
def from_xdr_object(cls, tx_xdr_object) -> 'Transaction':
"""Create a new :class:`Transaction` from an XDR object.
:param tx_xdr_object: The XDR object that represents a transaction.
:return: A new :class:`Transaction` object from the given XDR Transaction object.
"""
source = Keypair.from_public_key(
StrKey.encode_ed25519_public_key(tx_xdr_object.sourceAccount.ed25519)
)
Expand Down
4 changes: 1 addition & 3 deletions stellar_sdk/transaction_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ def sign(self, signer: Keypair) -> None:
:param signer: The keypair to use for signing this transaction
envelope.
:raises: :exc:`SignatureExistError
<stellar_sdk.exception.SignatureExistError>`
:raise: :exc:`SignatureExistError <stellar_sdk.exception.SignatureExistError>`
"""
# TODO: raise
tx_hash = self.hash()
sig = signer.sign_decorated(tx_hash)
sig_dict = [signature.__dict__ for signature in self.signatures]
Expand Down

0 comments on commit c5f3de7

Please sign in to comment.