-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from overcat/v2
v2
- Loading branch information
Showing
32 changed files
with
649 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,6 +303,8 @@ Network | |
:members: | ||
:inherited-members: | ||
|
||
.. _operation_list_archor: | ||
|
||
Operation | ||
^^^^^^^^^ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. _assets: | ||
|
||
|
||
****** | ||
Assets | ||
****** | ||
|
||
Object of the :py:class:`Asset <stellar_sdk.asset.Asset>` | ||
class represents an asset in the Stellar network. Right now there are 3 possible types of assets in the Stellar network: | ||
|
||
|
||
* native **XLM** asset (**ASSET_TYPE_NATIVE**), | ||
* issued assets with asset code of maximum 4 characters (**ASSET_TYPE_CREDIT_ALPHANUM4**), | ||
* issued assets with asset code of maximum 12 characters (**ASSET_TYPE_CREDIT_ALPHANUM12**). | ||
|
||
To create a new native asset representation use static :py:meth:`native() <stellar_sdk.asset.Asset.native>` method: | ||
|
||
.. code-block:: python | ||
:linenos: | ||
from stellar_sdk import Asset | ||
native = Asset.native() | ||
To represent an issued asset you need to create a new object of type :py:class:`Asset <stellar_sdk.asset.Asset>` with an asset code and issuer: | ||
|
||
.. code-block:: python | ||
:linenos: | ||
from stellar_sdk import Asset | ||
# Creates TEST asset issued by GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB | ||
test_asset = Asset("TEST", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB") | ||
is_native = test_asset.is_native() # False | ||
# Creates Google stock asset issued by GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB | ||
google_stock_asset = Asset('US38259P7069', 'GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB') | ||
google_stock_asset_type = google_stock_asset.type # credit_alphanum12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
.. _building_transactions: | ||
|
||
|
||
********************* | ||
Building Transactions | ||
********************* | ||
|
||
`Transactions <https://stellar.org/developers/learn/concepts/transactions.html>`_ are the commands that modify the state of the ledger. | ||
They include sending payments, creating offers, making account configuration changes, etc. | ||
|
||
Every transaction has a source `account <https://stellar.org/developers/learn/concepts/accounts.html>`__. This is the account | ||
that pays the `fee <https://stellar.org/developers/learn/concepts/fees.html>`_ and uses up a sequence number for the transaction. | ||
|
||
Transactions are made up of one or more `operations <https://stellar.org/developers/learn/concepts/operations.html>`_. | ||
Each operation also has a source account, which defaults to the transaction's source account. | ||
|
||
`TransactionBuilder <https://github.com/stellar/js-stellar-base/blob/master/src/transaction_builder.js>`_ | ||
------------------------------------------------------------------------------------------------------------- | ||
|
||
The :py:class:`TransactionBuilder <stellar_sdk.transaction_builder.TransactionBuilder>` class is used to construct new transactions. | ||
TransactionBuilder is given an account that is used as transaction's **source account**. | ||
The transaction will use the current sequence number of the given :py:class:`Account <stellar_sdk.account.Account>` | ||
object as its sequence number and increments the given account's sequence number | ||
when :py:meth:`build() <stellar_sdk.transaction_builder.TransactionBuilder.build>` is called on the TransactionBuilder. | ||
|
||
Operations can be added to the transaction calling | ||
:py:meth:`append_operation <stellar_sdk.transaction_builder.TransactionBuilder.append_operation>` for | ||
each operation you wish to add to the transaction. | ||
See :ref:`operation_list_archor` for a list of possible operations you can add. | ||
:py:meth:`append_operation <stellar_sdk.transaction_builder.TransactionBuilder.append_operation>` | ||
returns the current :py:class:`TransactionBuilder <stellar_sdk.transaction_builder.TransactionBuilder>` | ||
object so you can chain multiple calls. But you don't need to call it directly, | ||
we have prepared a lot of easy-to-use functions for you, such as | ||
:py:meth:`append_payment_op <stellar_sdk.transaction_builder.TransactionBuilder.append_payment_op>` | ||
can add a payment operation to the :py:class:`TransactionBuilder <stellar_sdk.transaction_builder.TransactionBuilder>`. | ||
|
||
After adding the desired operations, call the :py:meth:`build() <stellar_sdk.transaction_builder.TransactionBuilder.build>` | ||
method on the :py:class:`TransactionBuilder <stellar_sdk.transaction_builder.TransactionBuilder>`. | ||
This will return a fully constructed :py:class:`TransactionEnvelope <stellar_sdk.transaction_envelop.TransactionEnvelope>`. | ||
The transaction object is wrapped in an object called a :py:class:`TransactionEnvelope <stellar_sdk.transaction_envelope.TransactionEnvelope>`, | ||
the returned transaction will contain | ||
the sequence number of the source account. This transaction is unsigned. | ||
You must sign it before it will be accepted by the Stellar network. | ||
|
||
.. literalinclude:: ../examples/transaction_builder.py | ||
:language: python | ||
:linenos: | ||
|
||
Sequence Numbers | ||
---------------- | ||
|
||
The sequence number of a transaction has to match the sequence number stored by the source account or else the transaction is invalid. | ||
After the transaction is submitted and applied to the ledger, the source account's sequence number increases by 1. | ||
|
||
There are two ways to ensure correct sequence numbers: | ||
|
||
|
||
#. Read the source account's sequence number before submitting a transaction | ||
#. Manage the sequence number locally | ||
|
||
During periods of high transaction throughput, fetching a source account's sequence number from the network may not return | ||
the correct value. So, if you're submitting many transactions quickly, you will want to keep track of the sequence number locally. | ||
|
||
Adding Memos | ||
------------ | ||
|
||
Transactions can contain a **memo** field you can use to attach additional information to the transaction. You can do this | ||
by passing a :py:class:`Memo <stellar_sdk.memo.Memo>` object when you construct the TransactionBuilder. | ||
|
||
There are 5 types of memos: | ||
|
||
* :py:class:`stellar_sdk.memo.NoneMemo` - empty memo, | ||
* :py:class:`stellar_sdk.memo.TextMemo`` - 28-byte ascii encoded string memo, | ||
* :py:class:`stellar_sdk.memo.IdMemo`- 64-bit number memo, | ||
* :py:class:`stellar_sdk.memo.HashMemo` - 32-byte hash - ex. hash of an item in a content server, | ||
* :py:class:`stellar_sdk.memo.ReturnHashMemo` - 32-byte hash used for returning payments - contains hash of the transaction being rejected. | ||
|
||
.. literalinclude:: ../examples/transaction_builder_with_memo.py | ||
:language: python | ||
:linenos: | ||
|
||
|
||
Transaction and TransactionEnvelope | ||
----------------------------------- | ||
These two concepts may make the novices unclear, but the official has given a good explanation. | ||
|
||
Transactions are commands that modify the ledger state. Among other things, Transactions are used to send payments, | ||
enter orders into the distributed exchange, change settings on accounts, and authorize another account to hold your | ||
currency. If you think of the ledger as a database, then transactions are SQL commands. | ||
|
||
Once a transaction is ready to be signed, the transaction object is wrapped in an object called a Transaction Envelope, | ||
which contains the transaction as well as a set of signatures. Most transaction envelopes only contain a single | ||
signature along with the transaction, but in multi-signature setups it can contain many signatures. Ultimately, | ||
transaction envelopes are passed around the network and are included in transaction sets, | ||
as opposed to raw Transaction objects. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.. _create_account: | ||
|
||
|
||
************** | ||
Create Account | ||
************** | ||
|
||
Now, in order to create an account, you need to run a :py:class:`CreateAccount | ||
<stellar_sdk.operation.CreateAccount>` operation with your new account ID. | ||
Due to `Stellar's account minimums | ||
<https://www.stellar.org/developers/guides/concepts/fees.html#minimum-account-balance>`_, | ||
you'll need to transfer the minimum account balance from another account with | ||
the create account operation. As of this writing, minimum balance is **1 XLM (2 | ||
x 0.5 Base Reserve)**, and is subject to change. | ||
|
||
Using The SDF Testnet | ||
===================== | ||
If you want to play in the Stellar test network, you can ask our `Friendbot | ||
<https://www.stellar.org/developers/guides/get-started/create-account.html>`_ | ||
to create an account for you as shown below: | ||
|
||
.. literalinclude:: ../examples/create_account_friendbot.py | ||
:language: python | ||
:linenos: | ||
|
||
Using The Stellar Live Network | ||
============================== | ||
On the other hand, if you would like to create an account on the live network, | ||
you should buy some Stellar Lumens from an exchange. When you withdraw the | ||
Lumens into your new account, the exchange will automatically create the | ||
account for you. However, if you want to create an account from another | ||
account of your own, here's an example of how to do so: | ||
|
||
|
||
.. literalinclude:: ../examples/create_account.py | ||
:language: python | ||
:linenos: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.. _generate_keypair: | ||
|
||
|
||
**************** | ||
Generate Keypair | ||
**************** | ||
|
||
:py:class:`Keypair <stellar_sdk.keypair.Keypair>` object represents key pair used to | ||
sign transactions in Stellar network. :py:class:`Keypair <stellar_sdk.keypair.Keypair>` | ||
object can contain both a public and private key, or only a public key. | ||
|
||
If :py:class:`Keypair <stellar_sdk.keypair.Keypair>` object does not contain private | ||
key it can't be used to sign transactions. The most convenient method of | ||
creating new keypair is by passing the account's secret seed: | ||
|
||
.. code-block:: python | ||
:linenos: | ||
from stellar_sdk import Keypair | ||
keypair = Keypair.from_secret("SBK2VIYYSVG76E7VC3QHYARNFLY2EAQXDHRC7BMXBBGIFG74ARPRMNQM") | ||
public_key = keypair.public_key() # GDHMW6QZOL73SHKG2JA3YHXFDHM46SS5ZRWEYF5BCYHX2C5TVO6KZBYL | ||
can_sign = keypair.can_sign() # True | ||
You can create a keypair from public key, but its function is limited: | ||
|
||
.. code-block:: python | ||
:linenos: | ||
from stellar_sdk import Keypair | ||
keypair = Keypair.from_public_key("GDHMW6QZOL73SHKG2JA3YHXFDHM46SS5ZRWEYF5BCYHX2C5TVO6KZBYL") | ||
can_sign = keypair.can_sign() # False | ||
You can also create a randomly generated keypair: | ||
|
||
.. code-block:: python | ||
:linenos: | ||
from stellar_sdk import Keypair | ||
keypair = Keypair.random() | ||
print("Public Key: " + keypair.public_key()) | ||
print("Secret Seed: " + keypair.secret()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.