Stellar Python SDK¶
注解
此页面呈现的是 V2 版本,如果你想使用 V1 版本请点击 这里。
py-stellar-sdk 是用于开发 Stellar 应用程序的 Python 库。它目前支持 Python 3.6+ 和 PyPy3.6+。
它提供了:
完全访问 Horizon 各个接口的能力
快速的构建与签署事务,并将它提交到 Stellar 网络
入门¶
我强烈推荐你阅读官方的 开发者文档 , 其中介绍了诸多基础的概念,能帮助你快速的了解 Stellar 网络中的各种概念。
安装¶
通过 pipenv 或 pip 安装¶
通过 pipenv 来安装 Stellar Python SDK :
pipenv install stellar-sdk==2.13.0
我们推荐你使用 pipenv 来安装这个模块。当然你也可以使用 pip。 想要更多的了解如何安装依赖,请参阅 Hitchhiker’s Guide to Python。
通过源码安装¶
请尽可能使用上述方法安装。最新的代码可能不稳定。
你可以先克隆 这个仓库,然后通过源码安装 SDK:
git clone https://github.com/StellarCN/py-stellar-base.git
cd py-stellar-base
git checkout 2.13.0
pip install .
生成 Keypair¶
在 Stellar 网络中,Keypair
用来给事务签名,
Keypair
可以包含公钥与密钥,当然也可以只包含公钥。
如果 Keypair
中没有包含密钥,那么它不能用来签署事务。
我们可以使用密钥来创建一个 Keypair:
1 2 3 4 5 | from stellar_sdk import Keypair
keypair = Keypair.from_secret("SBK2VIYYSVG76E7VC3QHYARNFLY2EAQXDHRC7BMXBBGIFG74ARPRMNQM")
public_key = keypair.public_key # GDHMW6QZOL73SHKG2JA3YHXFDHM46SS5ZRWEYF5BCYHX2C5TVO6KZBYL
can_sign = keypair.can_sign() # True
|
我们也可以用公钥来创建一个功能有限的 Keypair:
1 2 3 4 | from stellar_sdk import Keypair
keypair = Keypair.from_public_key("GDHMW6QZOL73SHKG2JA3YHXFDHM46SS5ZRWEYF5BCYHX2C5TVO6KZBYL")
can_sign = keypair.can_sign() # False
|
还可以生成一个随机的 Keypair:
1 2 3 4 5 | from stellar_sdk import Keypair
keypair = Keypair.random()
print("Public Key: " + keypair.public_key)
print("Secret Seed: " + keypair.secret)
|
创建账户¶
你需要通过 CreateAccount
操作来创建 Stellar 中的账户。
由于 恒星网络对账户有着最低持币要求,
所以你需要给待激活账户发送一定数量的 XLM。当前这个数量是 1 XLM (2
x 0.5 Base Reserve),它可能会变化,但是通常很长时间才会变动一次,所以你可以将它视为一个固定值。
使用测试网络¶
如果你想在测试网络中进行测试,你可以通过 Friendbot 来激活你的帐号。
1 2 3 4 5 6 7 8 9 10 11 12 | import requests
from stellar_sdk import Keypair
keypair = Keypair.random()
print("Public Key: " + keypair.public_key)
print("Secret Seed: " + keypair.secret)
url = 'https://friendbot.stellar.org'
response = requests.get(url, params={'addr': keypair.public_key})
print(response)
|
使用公共网络¶
如果你想在公共网络中创建一个账户的话,你可以让你的朋友给你发送一些 XLM,也可以在交易所购买一些, 当你从交易所提取 XLM 到一个新账户时,交易所一般会帮你创建好这个账户。如果你想使用你的账户创建另外一个账户的话,可以参考下面的代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | from stellar_sdk import TransactionBuilder, Server, Network, Keypair
server = Server(horizon_url="https://horizon-testnet.stellar.org")
source = Keypair.from_secret("SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD")
destination = Keypair.random()
source_account = server.load_account(account_id=source.public_key)
transaction = TransactionBuilder(
source_account=source_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100) \
.append_create_account_op(destination=destination.public_key, starting_balance="12.25") \
.build()
transaction.sign(source)
response = server.submit_transaction(transaction)
print("Transaction hash: {}".format(response["hash"]))
print("New Keypair: \n\taccount id: {account_id}\n\tsecret seed: {secret_seed}".format(
account_id=destination.public_key, secret_seed=destination.secret))
|
通过 Horizon 查询数据¶
通过 Stellar Python SDK 你可以访问 Horizon 的各个接口。
构建请求¶
SDK 使用 建造者模式 来创建请求。通过 Server
,我们可以链式的构建一个请求。
(请参阅 Horizon 文档 来了解有哪些方法是可用的。)
1 2 3 4 5 6 7 8 9 10 11 12 13 | from stellar_sdk import Server
server = Server(horizon_url="https://horizon-testnet.stellar.org")
# get a list of transactions that occurred in ledger 1400
transactions = server.transactions().for_ledger(1400).call()
print(transactions)
# get a list of transactions submitted by a particular account
transactions = server.transactions() \
.for_account(account_id="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW") \
.call()
print(transactions)
|
当请求构建完成之后,我们可以通过调用 call()
以向 Horizon 发起请求。
call()
将会立即返回一个响应。
构建流式(Stream)请求¶
很多接口都能通过 stream()
调用。
与 call()
不同,它不立刻返回结果,
而是会返回一个 EventSource。
Horizon 将会实时的返回从当前时间开始产生的数据,当然你也可以通过 cursor()
指定一个时间点。
(请参阅 Horizon 文档 了解有哪些接口支持 Stream。)
下面这个示例将会实时打印这个账户提交的事务。
1 2 3 4 5 6 7 8 9 10 11 12 13 | from stellar_sdk import Server
server = Server(horizon_url="https://horizon-testnet.stellar.org")
account_id = "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW"
last_cursor = 'now' # or load where you left off
def tx_handler(tx_response):
print(tx_response)
for tx in server.transactions().for_account(account_id).cursor(last_cursor).stream():
tx_handler(tx)
|
资产¶
Asset
的实例代表着 Stellar 网络中的资产。目前 Stellar 网络中有着三种类型的资产:
原生资产 XLM (ASSET_TYPE_NATIVE),
资产代码长度最长为 4 位的资产 (ASSET_TYPE_CREDIT_ALPHANUM4),
资产代码长度最长为 12 位的资产 (ASSET_TYPE_CREDIT_ALPHANUM12).
你可以通过 native()
来创建原生资产:
1 2 | from stellar_sdk import Asset
native = Asset.native()
|
你也可以通过 Asset
来创建一个自发行资产,它应该包含资产代码与发行账户:
1 2 3 4 5 6 7 | from stellar_sdk import Asset
# 创建资产代码为 TEST,发行方为 GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB 的资产
test_asset = Asset("TEST", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB")
is_native = test_asset.is_native() # False
# 创建由 GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB 发行的 Google 股票资产
google_stock_asset = Asset('US38259P7069', 'GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB')
google_stock_asset_type = google_stock_asset.type # credit_alphanum12
|
构建事务¶
事务 是修改账本的命令,事务中一般包含了付款、创建订单、配置账户等操作。
每个事务都有一个源 账户,这个帐号将会为这笔事务支付 手续费,且这个事务会使用源账户的序列号。
事务由一个或多个 操作组成, 每个操作都有一个源账户,如果一个账户没有设置源账户的话,那么它将使用事务的源账户作为它的源账户。
TransactionBuilder¶
我们可以通过 TransactionBuilder
来构建一个新的事务。
你需要在 TransactionBuilder 中配置事务的 源账户。这个事务会使用给定账户(Account
)的序列号,
当你调用 build()
生成一个事务时,该账户的序列号会加 1.
事务中的操作可以通过调用 append_operation
来添加。
你可以阅读 Operation 来了解 Stellar 网络中有哪些类型的操作。
append_operation
会返回当前的 TransactionBuilder
示例,所以你可以链式的调用它。一般来说你并不需要直接调用它,我们提供了一系列便捷的函数,我更推荐你使用这些函数,比如你可以通过
append_payment_op
向
TransactionBuilder
中添加一个付款操作。
当你添加完操作之后,你可以调用 build()
,
它会返回一个 TransactionEnvelope
。
整个事务都被包装在 TransactionEnvelope
当中,
随后你需要使用密钥对它进行签名,只有经过正确签名的事务才会被 Stellar 网络所接受。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from stellar_sdk import TransactionBuilder, Network, Keypair, Account
root_keypair = Keypair.from_secret("SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC")
# Create an Account object from an address and sequence number.
root_account = Account(account_id=root_keypair.public_key, sequence=1)
transaction = TransactionBuilder(
source_account=root_account,
# If you want to submit to pubnet, you need to change `network_passphrase` to `Network.PUBLIC_NETWORK_PASSPHRASE`
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100) \
.append_payment_op( # add a payment operation to the transaction
destination="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW",
asset_code="XLM",
amount="125.5") \
.append_set_options_op( # add a set options operation to the transaction
home_domain="overcat.me") \
.set_timeout(30) \
.build() # mark this transaction as valid only for the next 30 seconds
|
序列号¶
事务的序列号必须与源帐户的序列号匹配,如果不匹配的话该事务会被 Stellar 网络拒绝。当一个事务生效之后,源账户的序列号会加 1。
有两种方法可以确保使用的序列号是正确的:
在提交事务前从 Horizon 获取账户的序列号
在本地管理事务的序列号
当你尝试快速的向 Stellar 网络提交大量事务时,从网络中获取到的序列号可能是不正确的,你应该在本地对序列号进行管理。
添加备注(Memo)¶
事务可以包含一个用于附加额外信息的 memo,当前有 5 种类型的 memo:
stellar_sdk.memo.NoneMemo
- 空 memo,stellar_sdk.memo.TextMemo`
- 28-字节的 Ascii 编码的字符型 memo,stellar_sdk.memo.IdMemo
- 64-位的数字型 memo,stellar_sdk.memo.HashMemo
- 32-字节的 hash 编码的 memo,stellar_sdk.memo.ReturnHashMemo
- 32-字节的 hash 编码的 memo,用与包含退款事务的 ID.
1 2 3 4 5 6 7 8 9 10 | from stellar_sdk import TransactionBuilder, Network, Keypair, Account
root_keypair = Keypair.from_secret("SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC")
# Create an Account object from an address and sequence number.
root_account = Account(account_id=root_keypair.public_key, sequence=1)
transaction = TransactionBuilder(source_account=root_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100).add_text_memo("Happy birthday!").append_payment_op(
destination="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", amount="2000",
asset_code="XLM").set_timeout(30).build()
|
事务(Transaction)与事务信封(TransactionEnvelope)¶
人们常常对这两个概念感到困惑,但是官方已经给出了非常好的解释。
事务可以视为修改账本状态的命令,事务可以被用来发送付款,创建订单、修改事务或授权其他账户持有你发行的资产。 如果将账本视为一个数据库,那么事务就是 SQL 命令。
当一个事务构建好了之后,它需要被包装到事务信封当中,事务信封可以包含事务以及签名。大多数的事务信封都只包含一个签名,但是如果用户启用了多重签名的话, 事务信封便会包含多个签名了。最终在 Stellar 网络中留存的是事务信封。
构建一个付款事务¶
付款¶
在下面这个示例中,你需要先确保收款账户已经在 Stellar 网络中激活了。 你可以使用同步方法在此处提交这个事务,也可以使用异步方法提交这个事务。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """
Create, sign, and submit a transaction using Python Stellar SDK.
Assumes that you have the following items:
1. Secret key of a funded account to be the source account
2. Public key of an existing account as a recipient
These two keys can be created and funded by the friendbot at
https://www.stellar.org/laboratory/ under the heading "Quick Start: Test Account"
3. Access to Python Stellar SDK (https://github.com/StellarCN/py-stellar-base) through Python shell.
"""
from stellar_sdk import Server, Keypair, TransactionBuilder, Network
# The source account is the account we will be signing and sending from.
source_secret_key = "SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD"
# Derive Keypair object and public key (that starts with a G) from the secret
source_keypair = Keypair.from_secret(source_secret_key)
source_public_key = source_keypair.public_key
receiver_public_key = "GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOPVH"
# Configure StellarSdk to talk to the horizon instance hosted by Stellar.org
# To use the live network, set the hostname to 'horizon.stellar.org'
server = Server(horizon_url="https://horizon-testnet.stellar.org")
# Transactions require a valid sequence number that is specific to this account.
# We can fetch the current sequence number for the source account from Horizon.
source_account = server.load_account(source_public_key)
base_fee = server.fetch_base_fee()
# we are going to submit the transaction to the test network,
# so network_passphrase is `Network.TESTNET_NETWORK_PASSPHRASE`,
# if you want to submit to the public network, please use `Network.PUBLIC_NETWORK_PASSPHRASE`.
transaction = (
TransactionBuilder(
source_account=source_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=base_fee,
)
.add_text_memo("Hello, Stellar!") # Add a memo
# Add a payment operation to the transaction
# Send 350.1234567 XLM to receiver
# Specify 350.1234567 lumens. Lumens are divisible to seven digits past the decimal.
.append_payment_op(receiver_public_key, "350.1234567", "XLM")
.set_timeout(30) # Make this transaction valid for the next 30 seconds only
.build()
)
# Sign this transaction with the secret key
# NOTE: signing is transaction is network specific. Test network transactions
# won't work in the public network. To switch networks, use the Network object
# as explained above (look for stellar_sdk.network.Network).
transaction.sign(source_keypair)
# Let's see the XDR (encoded in base64) of the transaction we just built
print(transaction.to_xdr())
# Submit the transaction to the Horizon server.
# The Horizon server will then submit the transaction into the network for us.
response = server.submit_transaction(transaction)
print(response)
|
路径付款(Path Payment)¶
在下面这个示例中,我们将使用付款账户 GABJLI6IVBKJ7HIC5NN7HHDCIEW3CMWQ2DWYHREQQUFWSWZ2CDAMZZX4 向 GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB 发送 5.5 个由 GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW 发行的 GBP,而付款账户最多会扣除 1000 XLM。以下示例资产经过了 三轮交换:XLM->USD, USD->EUR, EUR->GBP。
USD 由 GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB 发行
EUR 由 GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL 发行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from stellar_sdk import Keypair, Server, TransactionBuilder, Network, Asset
server = Server(horizon_url="https://horizon-testnet.stellar.org")
source_keypair = Keypair.from_secret("SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC")
source_account = server.load_account(account_id=source_keypair.public_key)
path = [
Asset("USD", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"),
Asset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL")
]
transaction = TransactionBuilder(
source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100) \
.append_path_payment_strict_receive_op(destination="GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB",
send_code="XLM", send_issuer=None, send_max="1000", dest_code="GBP",
dest_issuer="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW",
dest_amount="5.50", path=path) \
.set_timeout(30) \
.build()
transaction.sign(source_keypair)
response = server.submit_transaction(transaction)
|
异步请求¶
现在我们支持通过异步请求来提交事务了,当然我们不会强迫你使用异步,毕竟同步代码更容易编写,也有着更多的开发库可以选择。
Server
有一个参数是 client,在这里我们有必要提及一下它,如果你不明确的设置这个参数,
那么 SDK 将默认使用 RequestsClient
的实例,它是一个同步的客户端;
当然,你也可以指定一个异步的 HTTP 客户端,例如: AiohttpClient
。
如果你设置了一个异步的客户端,那么所有的请求都是异步的,反之则是同步的。
下面这个示例演示了如何通过异步请求发起一笔付款,你可以与 这个示例 进行对比, 它们的功能是完全相同的,只是后者发起的是同步请求。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | """
The effect of this example is the same as `payment.py`, but this example is asynchronous.
Create, sign, and submit a transaction using Python Stellar SDK.
Assumes that you have the following items:
1. Secret key of a funded account to be the source account
2. Public key of an existing account as a recipient
These two keys can be created and funded by the friendbot at
https://www.stellar.org/laboratory/ under the heading "Quick Start: Test Account"
3. Access to Python Stellar SDK (https://github.com/StellarCN/py-stellar-base) through Python shell.
"""
import asyncio
from stellar_sdk import Server, Keypair, TransactionBuilder, Network, AiohttpClient
# The source account is the account we will be signing and sending from.
source_secret_key = "SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD"
# Derive Keypair object and public key (that starts with a G) from the secret
source_keypair = Keypair.from_secret(source_secret_key)
source_public_key = source_keypair.public_key
receiver_public_key = "GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOPVH"
async def main():
# Configure StellarSdk to talk to the horizon instance hosted by Stellar.org
# To use the live network, set the hostname to 'horizon.stellar.org'
# When we use the `with` syntax, it automatically releases the resources it occupies.
async with Server(
horizon_url="https://horizon-testnet.stellar.org", client=AiohttpClient()
) as server:
# Transactions require a valid sequence number that is specific to this account.
# We can fetch the current sequence number for the source account from Horizon.
source_account = await server.load_account(source_public_key)
base_fee = await server.fetch_base_fee()
# we are going to submit the transaction to the test network,
# so network_passphrase is `Network.TESTNET_NETWORK_PASSPHRASE`,
# if you want to submit to the public network, please use `Network.PUBLIC_NETWORK_PASSPHRASE`.
transaction = (
TransactionBuilder(
source_account=source_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=base_fee,
)
.add_text_memo("Hello, Stellar!") # Add a memo
# Add a payment operation to the transaction
# Send 350.1234567 XLM to receiver
# Specify 350.1234567 lumens. Lumens are divisible to seven digits past the decimal.
.append_payment_op(receiver_public_key, "350.1234567", "XLM")
.set_timeout(30) # Make this transaction valid for the next 30 seconds only
.build()
)
# Sign this transaction with the secret key
# NOTE: signing is transaction is network specific. Test network transactions
# won't work in the public network. To switch networks, use the Network object
# as explained above (look for stellar_sdk.network.Network).
transaction.sign(source_keypair)
# Let's see the XDR (encoded in base64) of the transaction we just built
print(transaction.to_xdr())
# Submit the transaction to the Horizon server.
# The Horizon server will then submit the transaction into the network for us.
response = await server.submit_transaction(transaction)
print(response)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
# asyncio.run(main()) # Python 3.7+
|
下面这个示例演示了如何通过异步的监听多个端点。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import asyncio
from stellar_sdk import AiohttpClient, Server
HORIZON_URL = "https://horizon.stellar.org"
async def payments():
async with Server(HORIZON_URL, AiohttpClient()) as server:
async for payment in server.payments().cursor(cursor="now").stream():
print(f"Payment: {payment}")
async def effects():
async with Server(HORIZON_URL, AiohttpClient()) as server:
async for effect in server.effects().cursor(cursor="now").stream():
print(f"Effect: {effect}")
async def operations():
async with Server(HORIZON_URL, AiohttpClient()) as server:
async for operation in server.operations().cursor(cursor="now").stream():
print(f"Operation: {operation}")
async def transactions():
async with Server(HORIZON_URL, AiohttpClient()) as server:
async for transaction in server.transactions().cursor(cursor="now").stream():
print(f"Transaction: {transaction}")
async def listen():
await asyncio.gather(
payments(),
effects(),
operations(),
transactions()
)
if __name__ == '__main__':
asyncio.run(listen())
|
多重签名账户¶
通过为账户启用 多重签名 ,你可以使这个账户创建的事务需要 经过多个公钥的签名才能生效。首先你需要为账户配置 阈值(threshold),在 Stellar 网络中,每个操作都有着自己的权限等级,这个等级分为高、中、低三等, 你可以为每个等级配置一个阈值,这个值可以在 1-255 之间。你可以为你的账户添加多个签名者,每个签名者都有着自己的权重,这个权重可以在 1-255 之间,如果你想 从账户中删除一个签名者,那么你只需要将这个签名者的权重设置为 0。任何事务得到的签名权重必须大于或等于它所需要的阈值才能生效。
首先,我们来设置账户的阈值等级,我们将低级权限操作的阈值设为 1,中级权限操作的阈值设置为 2,高级权限操作的阈值设置为 3。付款操作是一个中级权限的操作。 如果你的主公钥权重为 1,那么你需要使用另外一个公钥进行签名,使它获得的权重大于等于 2 才行。
在下面这个示例中,我们将做以下几件事情:
向账户中添加第二个签名账户
为我们的主公钥设置权重,并设置阈值等级
创建一个需要多重签名的付款事务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | from stellar_sdk import Server, TransactionBuilder, Signer, Network, Keypair
server = Server(horizon_url="https://horizon-testnet.stellar.org")
root_keypair = Keypair.from_secret("SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC")
root_account = server.load_account(account_id=root_keypair.public_key)
secondary_keypair = Keypair.from_secret("SAMZUAAPLRUH62HH3XE7NVD6ZSMTWPWGM6DS4X47HLVRHEBKP4U2H5E7")
secondary_signer = Signer.ed25519_public_key(account_id=secondary_keypair.public_key, weight=1)
transaction = TransactionBuilder(
source_account=root_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100) \
.append_set_options_op(
master_weight=1, # set master key weight
low_threshold=1,
med_threshold=2, # a payment is medium threshold
high_threshold=2, # make sure to have enough weight to add up to the high threshold!
signer=secondary_signer) \
.set_timeout(30) \
.build()
# only need to sign with the root signer as the 2nd signer won't
# be added to the account till after this transaction completes
transaction.sign(root_keypair)
response = server.submit_transaction(transaction)
print(response)
# now create a payment with the account that has two signers
destination = "GBA5SMM5OYAOOPL6R773MV7O3CCLUDVLCWHIVVL3W4XTD3DA5FJ4JSEZ"
transaction = TransactionBuilder(
source_account=root_account,
network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE,
base_fee=100) \
.append_payment_op(
destination=destination,
amount="2000",
asset_code="XLM") \
.set_timeout(30) \
.build()
# now we need to sign the transaction with both the root and the secondary_keypair
transaction.sign(root_keypair)
transaction.sign(secondary_keypair)
response = server.submit_transaction(transaction)
print(response)
|
API 文档¶
Here you’ll find detailed documentation on specific functions, classes, and methods.
API 文档¶
Account¶
-
class
stellar_sdk.account.
Account
(account_id, sequence)[源代码]¶ The
Account
object represents a single account on the Stellar network and its sequence number.Account tracks the sequence number as it is used by
TransactionBuilder
See Accounts For more information about the formats used for asset codes and how issuers work on Stellar,
- 参数
- Raises
Ed25519PublicKeyInvalidError
: ifaccount_id
is not a valid ed25519 public key.
Asset¶
-
class
stellar_sdk.asset.
Asset
(code, issuer=None)[源代码]¶ The
Asset
object, which represents an asset and its corresponding issuer on the Stellar network.For more information about the formats used for asset codes and how issuers work on Stellar’s network, see Stellar’s guide on assets.
- 参数
code (
str
) – The asset code, in the formats specified in Stellar’s guide on assets.issuer (
Optional
[str
]) – The account ID of the issuer. Note if the currency is the native currency (XLM (Lumens)), no issuer is necessary.
- Raises
AssetCodeInvalidError
: ifcode
is invalid.AssetIssuerInvalidError
: ifissuer
is not a valid ed25519 public key.
-
guess_asset_type
()[源代码]¶ Return the type of the asset, Can be one of following types: native, credit_alphanum4 or credit_alphanum12
- 返回类型
- 返回
The type of the asset.
-
is_native
()[源代码]¶ Return true if the
Asset
is the native asset.- 返回类型
- 返回
True if the Asset is native, False otherwise.
-
static
native
()[源代码]¶ Returns an asset object for the native asset.
- 返回类型
- 返回
An asset object for the native asset.
Call Builder¶
BaseCallBuilder¶
-
class
stellar_sdk.call_builder.
BaseCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
BaseCallBuilder
pointed to server defined by horizon_url.This is an abstract class. Do not create this object directly, use
stellar_sdk.server.Server
class.- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()[源代码]¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)[源代码]¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)[源代码]¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)[源代码]¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()[源代码]¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
AccountsCallBuilder¶
-
class
stellar_sdk.call_builder.
AccountsCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
AccountsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.accounts()
.- 参数
horizon_url – Horizon server URL.
client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
account_id
(account_id)[源代码]¶ Returns information and links relating to a single account. The balances section in the returned JSON will also list all the trust lines this account has set up.
See Account Details
- 参数
account_id (
str
) – account id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
AccountsCallBuilder
- 返回
current AccountCallBuilder instance
-
asset
(asset)[源代码]¶ Filtering accounts who have a trustline to an asset. The result is a list of accounts.
See Account Details
- 参数
asset (
Asset
) – an issued asset- 返回类型
AccountsCallBuilder
- 返回
current AccountCallBuilder instance
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_asset
(asset)[源代码]¶ Filtering accounts who have a trustline to an asset. The result is a list of accounts.
See Account Details
- 参数
asset (
Asset
) – an issued asset- 返回类型
AccountsCallBuilder
- 返回
current AccountCallBuilder instance
-
for_signer
(signer)[源代码]¶ Filtering accounts who have a given signer. The result is a list of accounts.
See Account Details
- 参数
signer (
str
) – signer’s account id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
AccountsCallBuilder
- 返回
current AccountCallBuilder instance
-
for_sponsor
(sponsor)[源代码]¶ Filtering accounts where the given account is sponsoring the account or any of its sub-entries.
See Account Details
- 参数
sponsor (
str
) – the sponsor id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
AccountsCallBuilder
- 返回
current AccountCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
signer
(signer)[源代码]¶ Filtering accounts who have a given signer. The result is a list of accounts.
See Account Details
- 参数
signer (
str
) – signer’s account id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
AccountsCallBuilder
- 返回
current AccountCallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
AssetsCallBuilder¶
-
class
stellar_sdk.call_builder.
AssetsCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
AssetsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.assets()
.See All Assets
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_code
(asset_code)[源代码]¶ This endpoint filters all assets by the asset code.
- 参数
asset_code (
str
) – asset code, for example: USD- 返回类型
AssetsCallBuilder
- 返回
current AssetCallBuilder instance
-
for_issuer
(asset_issuer)[源代码]¶ This endpoint filters all assets by the asset issuer.
- 参数
asset_issuer (
str
) – asset issuer, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
AssetsCallBuilder
- 返回
current AssetCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
ClaimableBalancesCallBuilder¶
-
class
stellar_sdk.call_builder.
ClaimableBalancesCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
ClaimableBalancesCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.claimable_balance()
.- 参数
horizon_url – Horizon server URL.
client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
claimable_balance
(claimable_balance_id)[源代码]¶ Returns information and links relating to a single claimable balance.
- 参数
claimable_balance_id (
str
) – claimable balance id- 返回类型
ClaimableBalancesCallBuilder
- 返回
current AccountCallBuilder instance
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_asset
(asset)[源代码]¶ Returns all claimable balances which provide a balance for the given asset.
See Account Details
- 参数
asset (
Asset
) – an asset- 返回类型
ClaimableBalancesCallBuilder
- 返回
current ClaimableBalancesCallBuilder instance
-
for_claimant
(claimant)[源代码]¶ Returns all claimable balances which can be claimed by the given account ID.
See Account Details
- 参数
claimant (
str
) – the account id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
ClaimableBalancesCallBuilder
- 返回
current ClaimableBalancesCallBuilder instance
-
for_sponsor
(sponsor)[源代码]¶ Returns all claimable balances which are sponsored by the given account ID.
- 参数
sponsor (
str
) – the sponsor id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
ClaimableBalancesCallBuilder
- 返回
current ClaimableBalancesCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
DataCallBuilder¶
-
class
stellar_sdk.call_builder.
DataCallBuilder
(horizon_url, client, account_id, data_name)[源代码]¶ Creates a new
DataCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.data()
.See Data for Account
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.account_id (
str
) – account id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDDdata_name (
str
) – Key name
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
EffectsCallBuilder¶
-
class
stellar_sdk.call_builder.
EffectsCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
EffectsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.effects()
.See All Effects
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_account
(account_id)[源代码]¶ This endpoint represents all effects that changed a given account. It will return relevant effects from the creation of the account to the current ledger.
- 参数
account_id (
str
) – account id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
EffectsCallBuilder
- 返回
this EffectCallBuilder instance
-
for_ledger
(sequence)[源代码]¶ Effects are the specific ways that the ledger was changed by any operation. This endpoint represents all effects that occurred in the given ledger.
-
for_operation
(operation_id)[源代码]¶ This endpoint represents all effects that occurred as a result of a given operation.
-
for_transaction
(transaction_hash)[源代码]¶ This endpoint represents all effects that occurred as a result of a given transaction.
- 参数
transaction_hash (
str
) – transaction hash- 返回类型
EffectsCallBuilder
- 返回
this EffectCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
FeeStatsCallBuilder¶
-
class
stellar_sdk.call_builder.
FeeStatsCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
FeeStatsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.fee_stats()
.See Fee Stats
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
LedgersCallBuilder¶
-
class
stellar_sdk.call_builder.
LedgersCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
LedgersCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.ledgers()
.See All Ledgers
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
ledger
(sequence)[源代码]¶ Provides information on a single ledger.
See Ledger Details
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
OffersCallBuilder¶
-
class
stellar_sdk.call_builder.
OffersCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
OffersCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.offers()
.See Offer Details See Offers
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
account
(account_id)[源代码]¶ Returns all offers where the given account is the seller.
- 参数
account_id – Account ID
- 返回
this OffersCallBuilder instance
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_buying
(buying)[源代码]¶ Returns all offers buying an asset.
People on the Stellar network can make offers to buy or sell assets. This endpoint represents all the current offers, allowing filtering by seller, selling_asset or buying_asset.
See Offers
- 参数
buying (
Asset
) – The asset being bought.- 返回
this OffersCallBuilder instance
-
for_seller
(seller)[源代码]¶ Returns all offers where the given account is the seller.
People on the Stellar network can make offers to buy or sell assets. This endpoint represents all the current offers, allowing filtering by seller, selling_asset or buying_asset.
See Offers
- 参数
seller (
str
) – Account ID of the offer creator- 返回
this OffersCallBuilder instance
-
for_selling
(selling)[源代码]¶ Returns all offers selling an asset.
People on the Stellar network can make offers to buy or sell assets. This endpoint represents all the current offers, allowing filtering by seller, selling_asset or buying_asset.
See Offers
- 参数
selling (
Asset
) – The asset being sold.- 返回
this OffersCallBuilder instance
-
for_sponsor
(sponsor)[源代码]¶ Filtering offers where the given account is sponsoring the offer entry.
See Offer Details
- 参数
sponsor (
str
) – the sponsor id, for example: GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD- 返回类型
OffersCallBuilder
- 返回
current OffersCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
offer
(offer_id)[源代码]¶ Returns information and links relating to a single offer.
See Offer Details
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
OperationsCallBuilder¶
-
class
stellar_sdk.call_builder.
OperationsCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
OperationsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.operations()
.See All Operations
- 参数
horizon_url – Horizon server URL.
client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_account
(account_id)[源代码]¶ This endpoint represents all operations that were included in valid transactions that affected a particular account.
- 参数
account_id (
str
) – Account ID- 返回类型
OperationsCallBuilder
- 返回
this OperationCallBuilder instance
-
for_transaction
(transaction_hash)[源代码]¶ This endpoint represents all operations that are part of a given transaction.
See Operations for Transaction
- 参数
transaction_hash (
str
) –- 返回类型
OperationsCallBuilder
- 返回
this OperationCallBuilder instance
-
include_failed
(include_failed)[源代码]¶ Adds a parameter defining whether to include failed transactions. By default only operations of successful transactions are returned.
- 参数
include_failed (
bool
) – Set to True to include operations of failed transactions.- 返回类型
OperationsCallBuilder
- 返回
current OperationsCallBuilder instance
-
join
(join)[源代码]¶ join represents join param in queries, currently only supports transactions
- 参数
join (
str
) – join represents join param in queries, currently only supports transactions- 返回类型
OperationsCallBuilder
- 返回
current OperationsCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
operation
(operation_id)[源代码]¶ The operation details endpoint provides information on a single operation. The operation ID provided in the id argument specifies which operation to load.
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
OrderbookCallBuilder¶
-
class
stellar_sdk.call_builder.
OrderbookCallBuilder
(horizon_url, client, selling, buying)[源代码]¶ Creates a new
OrderbookCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.orderbook()
.- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.selling (
Asset
) – Asset being soldbuying (
Asset
) – Asset being bought
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
PathsCallBuilder¶
-
class
stellar_sdk.call_builder.
PathsCallBuilder
(horizon_url, client, source_account, destination_account, destination_asset, destination_amount)[源代码]¶ Creates a new
PathsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.paths()
.The Stellar Network allows payments to be made across assets through path payments. A path payment specifies a series of assets to route a payment through, from source asset (the asset debited from the payer) to destination asset (the asset credited to the payee).
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.source_account (
str
) – The sender’s account ID. Any returned path must use a source that the sender can hold.destination_account (
str
) – The destination account ID that any returned path should use.destination_asset (
Asset
) – The destination asset.destination_amount (
str
) – The amount, denominated in the destination asset, that any returned path should be able to satisfy.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
PaymentsCallBuilder¶
-
class
stellar_sdk.call_builder.
PaymentsCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
PaymentsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.payments()
.See All Payments
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_account
(account_id)[源代码]¶ This endpoint responds with a collection of Payment operations where the given account was either the sender or receiver.
- 参数
account_id (
str
) – Account ID- 返回类型
PaymentsCallBuilder
- 返回
current PaymentsCallBuilder instance
-
for_ledger
(sequence)[源代码]¶ This endpoint represents all payment operations that are part of a valid transactions in a given ledger.
-
for_transaction
(transaction_hash)[源代码]¶ This endpoint represents all payment operations that are part of a given transaction.
- 参数
transaction_hash (
str
) – Transaction hash- 返回类型
PaymentsCallBuilder
- 返回
current PaymentsCallBuilder instance
-
include_failed
(include_failed)[源代码]¶ Adds a parameter defining whether to include failed transactions. By default only payments of successful transactions are returned.
- 参数
include_failed (
bool
) – Set toTrue
to include payments of failed transactions.- 返回类型
PaymentsCallBuilder
- 返回
current PaymentsCallBuilder instance
-
join
(join)[源代码]¶ join represents join param in queries, currently only supports transactions
- 参数
join (
str
) – join represents join param in queries, currently only supports transactions- 返回类型
PaymentsCallBuilder
- 返回
current OperationsCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
RootCallBuilder¶
-
class
stellar_sdk.call_builder.
RootCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
RootCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.root()
.- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
StrictReceivePathsCallBuilder¶
-
class
stellar_sdk.call_builder.
StrictReceivePathsCallBuilder
(horizon_url, client, source, destination_asset, destination_amount)[源代码]¶ Creates a new
StrictReceivePathsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.strict_receive_paths()
.The Stellar Network allows payments to be made across assets through path payments. A path payment specifies a series of assets to route a payment through, from source asset (the asset debited from the payer) to destination asset (the asset credited to the payee).
A path search is specified using:
The source address or source assets.
The asset and amount that the destination account should receive.
As part of the search, horizon will load a list of assets available to the source address and will find any payment paths from those source assets to the desired destination asset. The search’s amount parameter will be used to determine if there a given path can satisfy a payment of the desired amount.
If a list of assets is passed as the source, horizon will find any payment paths from those source assets to the desired destination asset.
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.source (
Union
[str
,List
[Asset
]]) – The sender’s account ID or a list of Assets. Any returned path must use a source that the sender can hold.destination_asset (
Asset
) – The destination asset.destination_amount (
str
) – The amount, denominated in the destination asset, that any returned path should be able to satisfy.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
StrictSendPathsCallBuilder¶
-
class
stellar_sdk.call_builder.
StrictSendPathsCallBuilder
(horizon_url, client, source_asset, source_amount, destination)[源代码]¶ Creates a new
StrictSendPathsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.strict_send_paths()
.The Stellar Network allows payments to be made across assets through path payments. A strict send path payment specifies a series of assets to route a payment through, from source asset (the asset debited from the payer) to destination asset (the asset credited to the payee).
A strict send path search is specified using:
The source asset
The source amount
The destination assets or destination account.
As part of the search, horizon will load a list of assets available to the source address and will find any payment paths from those source assets to the desired destination asset. The search’s source_amount parameter will be used to determine if there a given path can satisfy a payment of the desired amount.
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.source_asset (
Asset
) – The asset to be sent.source_amount (
str
) – The amount, denominated in the source asset, that any returned path should be able to satisfy.destination (
Union
[str
,List
[Asset
]]) – The destination account or the destination assets.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
TradeAggregationsCallBuilder¶
-
class
stellar_sdk.call_builder.
TradeAggregationsCallBuilder
(horizon_url, client, base, counter, resolution, start_time=None, end_time=None, offset=None)[源代码]¶ Creates a new
TradeAggregationsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.trade_aggregations()
.Trade Aggregations facilitate efficient gathering of historical trade data.
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.base (
Asset
) – base assetcounter (
Asset
) – counter assetresolution (
int
) – segment duration as millis since epoch. Supported values are 1 minute (60000), 5 minutes (300000), 15 minutes (900000), 1 hour (3600000), 1 day (86400000) and 1 week (604800000).start_time (
Optional
[int
]) – lower time boundary represented as millis since epochend_time (
Optional
[int
]) – upper time boundary represented as millis since epochoffset (
Optional
[int
]) – segments can be offset using this parameter. Expressed in milliseconds. Can only be used if the resolution is greater than 1 hour. Value must be in whole hours, less than the provided resolution, and less than 24 hours.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
TradesCallBuilder¶
-
class
stellar_sdk.call_builder.
TradesCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
TradesCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.trades()
.See Trades
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_account
(account_id)[源代码]¶ Filter trades for a specific account
- 参数
account_id (
str
) – account id- 返回类型
TradesCallBuilder
- 返回
current TradesCallBuilder instance
-
for_offer
(offer_id)[源代码]¶ Filter trades for a specific offer
See Trades for Offer
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
TransactionsCallBuilder¶
-
class
stellar_sdk.call_builder.
TransactionsCallBuilder
(horizon_url, client)[源代码]¶ Creates a new
TransactionsCallBuilder
pointed to server defined by horizon_url. Do not create this object directly, usestellar_sdk.server.Server.transactions()
.See All Transactions
- 参数
horizon_url (
str
) – Horizon server URL.client (
Union
[BaseAsyncClient
,BaseSyncClient
]) – The client instance used to send request.
-
call
()¶ Triggers a HTTP request using this builder’s current configuration.
- 返回类型
- 返回
If it is called synchronous, the response will be returned. If it is called asynchronously, it will return Coroutine.
- Raises
ConnectionError
: if you have not successfully connected to the server.NotFoundError
: if status_code == 404BadRequestError
: if 400 <= status_code < 500 and status_code != 404BadResponseError
: if 500 <= status_code < 600UnknownRequestError
: if an unknown error occurs, please submit an issue
-
cursor
(cursor)¶ Sets
cursor
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
cursor (
Union
) – A cursor is a value that points to a specific location in a collection of resources.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
for_account
(account_id)[源代码]¶ This endpoint represents all transactions that affected a given account.
- 参数
account_id (
str
) – account id- 返回类型
TransactionsCallBuilder
- 返回
current TransactionsCallBuilder instance
-
include_failed
(include_failed)[源代码]¶ Adds a parameter defining whether to include failed transactions. By default only transactions of successful transactions are returned.
- 参数
include_failed (
bool
) – Set to True to include failed transactions.- 返回类型
TransactionsCallBuilder
- 返回
current TransactionsCallBuilder instance
-
limit
(limit)¶ Sets
limit
parameter for the current call. Returns the CallBuilder object on which this method has been called.See Paging
- 参数
limit (
int
) – Number of records the server should return.- 返回类型
BaseCallBuilder
- 返回
-
order
(desc=True)¶ Sets
order
parameter for the current call. Returns the CallBuilder object on which this method has been called.- 参数
desc (
bool
) – Sort direction,True
to get desc sort direction, the default setting isTrue
.- 返回类型
BaseCallBuilder
- 返回
current CallBuilder instance
-
stream
()¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
-
transaction
(transaction_hash)[源代码]¶ The transaction details endpoint provides information on a single transaction. The transaction hash provided in the hash argument specifies which transaction to load.
- 参数
transaction_hash (
str
) – transaction hash- 返回类型
TransactionsCallBuilder
- 返回
current TransactionsCallBuilder instance
Client¶
BaseAsyncClient¶
-
class
stellar_sdk.client.base_async_client.
BaseAsyncClient
[源代码]¶ This is an abstract class, and if you want to implement your own asynchronous client, you must implement this class.
-
abstract async
stream
(url, params=None)[源代码]¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
-
abstract async
BaseSyncClient¶
-
class
stellar_sdk.client.base_sync_client.
BaseSyncClient
[源代码]¶ This is an abstract class, and if you want to implement your own synchronous client, you must implement this class.
-
abstract
stream
(url, params=None)[源代码]¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
-
abstract
AiohttpClient¶
-
class
stellar_sdk.client.aiohttp_client.
AiohttpClient
(pool_size=None, request_timeout=11, post_timeout=33.0, backoff_factor=0.5, user_agent=None, **kwargs)[源代码]¶ The
AiohttpClient
object is a asynchronous http client, which represents the interface for making requests to a server instance.- 参数
pool_size (
Optional
[int
]) – persistent connection to Horizon and connection poolrequest_timeout (
float
) – the timeout for all GET requestspost_timeout (
float
) – the timeout for all POST requestsbackoff_factor (
Optional
[float
]) – a backoff factor to apply between attempts after the second tryuser_agent (
Optional
[str
]) – the server can use it to identify you
RequestsClient¶
-
class
stellar_sdk.client.requests_client.
RequestsClient
(pool_size=10, num_retries=3, request_timeout=11, post_timeout=33.0, backoff_factor=0.5, session=None, stream_session=None)[源代码]¶ The
RequestsClient
object is a synchronous http client, which represents the interface for making requests to a server instance.- 参数
pool_size (
int
) – persistent connection to Horizon and connection poolnum_retries (
int
) – configurable request retry functionalityrequest_timeout (
int
) – the timeout for all GET requestspost_timeout (
float
) – the timeout for all POST requestsbackoff_factor (
float
) – a backoff factor to apply between attempts after the second trysession (
Optional
[Session
]) – the request sessionstream_session (
Optional
[Session
]) – the stream request session
-
stream
(url, params=None)[源代码]¶ Creates an EventSource that listens for incoming messages from the server.
See MDN EventSource
SimpleRequestsClient¶
-
class
stellar_sdk.client.simple_requests_client.
SimpleRequestsClient
[源代码]¶ The
SimpleRequestsClient
object is a synchronous http client, which represents the interface for making requests to a server instance.This client is to guide you in writing a client that suits your needs. I don’t recommend that you actually use it.
Response¶
Exceptions¶
SdkError¶
ValueError¶
TypeError¶
BadSignatureError¶
Ed25519PublicKeyInvalidError¶
Ed25519SecretSeedInvalidError¶
MissingEd25519SecretSeedError¶
MemoInvalidException¶
AssetCodeInvalidError¶
AssetIssuerInvalidError¶
NoApproximationError¶
SignatureExistError¶
BaseRequestError¶
ConnectionError¶
BaseHorizonError¶
NotFoundError¶
BadRequestError¶
BadResponseError¶
Keypair¶
-
class
stellar_sdk.keypair.
Keypair
(verify_key, signing_key=None)[源代码]¶ The
Keypair
object, which represents a signing and verifying key for use with the Stellar network.Instead of instantiating the class directly, we recommend using one of several class methods:
- 参数
verify_key (
VerifyKey
) – The verifying (public) Ed25519 key in the keypair.signing_key (
Optional
[SigningKey
]) – The signing (private) Ed25519 key in the keypair.
-
classmethod
from_mnemonic_phrase
(mnemonic_phrase, language=<Language.ENGLISH: 'english'>, passphrase='', index=0)[源代码]¶ Generate a
Keypair
object via a mnemonic phrase.- 参数
mnemonic_phrase (
str
) – A unique string used to deterministically generate keypairs.language (
Union
[Language
,str
]) – The language of the mnemonic phrase, defaults to english.passphrase (
str
) – An optional passphrase used as part of the salt during PBKDF2 rounds when generating the seed from the mnemonic.index (
int
) –The index of the keypair generated by the mnemonic. This allows for multiple Keypairs to be derived from the same mnemonic, such as:
>>> from stellar_sdk.keypair import Keypair >>> mnemonic = 'update hello cry airport drive chunk elite boat shaft sea describe number' # Don't use this mnemonic in practice. >>> kp1 = Keypair.from_mnemonic_phrase(mnemonic, index=0) >>> kp2 = Keypair.from_mnemonic_phrase(mnemonic, index=1) >>> kp3 = Keypair.from_mnemonic_phrase(mnemonic, index=2)
- 返回
A new
Keypair
instance derived from the mnemonic.
-
classmethod
from_public_key
(public_key)[源代码]¶ Generate a
Keypair
object from a public key.- 参数
public_key (
str
) – strkey ed25519 public key, for example: GATPGGOIE6VWADVKD3ER3IFO2IH6DTOA5G535ITB3TT66FZFSIZEAU2B- 返回类型
- 返回
A new
Keypair
instance derived by the public key.- Raise
Ed25519PublicKeyInvalidError
: ifpublic_key
is not a valid ed25519 public key.
-
classmethod
from_raw_ed25519_public_key
(raw_public_key)[源代码]¶ Generate a
Keypair
object from ed25519 public key raw bytes.
-
classmethod
from_raw_ed25519_seed
(raw_seed)[源代码]¶ Generate a
Keypair
object from ed25519 secret key seed raw bytes.
-
classmethod
from_secret
(secret)[源代码]¶ Generate a
Keypair
object from a secret seed.- 参数
secret (
str
) – strkey ed25519 seed, for example: SB2LHKBL24ITV2Y346BU46XPEL45BDAFOOJLZ6SESCJZ6V5JMP7D6G5X- 返回类型
- 返回
A new
Keypair
instance derived by the secret.- Raise
Ed25519SecretSeedInvalidError
: ifsecret
is not a valid ed25519 secret seed.
-
static
generate_mnemonic_phrase
(language=<Language.ENGLISH: 'english'>, strength=128)[源代码]¶ Generate a mnemonic phrase.
-
property
secret
¶ Returns secret key associated with this
Keypair
instance- 返回类型
- 返回
secret key
- Raise
MissingEd25519SecretSeedError
TheKeypair
does not contain secret seed
-
sign
(data)[源代码]¶ Sign the provided data with the keypair’s private key.
- 参数
data (
bytes
) – The data to sign.- 返回类型
- 返回
signed bytes
- Raise
MissingEd25519SecretSeedError
: ifKeypair
does not contain secret seed.
-
sign_decorated
(data)[源代码]¶ Sign the provided data with the keypair’s private key and returns DecoratedSignature.
- 参数
data – signed bytes
- 返回类型
DecoratedSignature
- 返回
sign decorated
-
signature_hint
()[源代码]¶ Returns signature hint associated with this
Keypair
instance- 返回类型
- 返回
signature hint
-
verify
(data, signature)[源代码]¶ Verify the provided data and signature match this keypair’s public key.
- 参数
- Raise
BadSignatureError
: if the verification failed and the signature was incorrect.- 返回类型
Memo¶
Memo¶
-
class
stellar_sdk.memo.
Memo
[源代码]¶ The
Memo
object, which represents the base class for memos for use with Stellar transactions.The memo for a transaction contains optional extra information about the transaction taking place. It is the responsibility of the client to interpret this value.
See the following implementations that serve a more practical use with the library:
NoneMemo
- No memo.TextMemo
- A string encoded using either ASCII or UTF-8, up to 28-bytes long.IdMemo
- A 64 bit unsigned integer.HashMemo
- A 32 byte hash.RetHashMemo
- A 32 byte hash intended to be interpreted as the hash of the transaction the sender is refunding.
See Stellar’s documentation on Transactions for more information on how memos are used within transactions, as well as information on the available types of memos.
NoneMemo¶
TextMemo¶
-
class
stellar_sdk.memo.
TextMemo
(text)[源代码]¶ The
TextMemo
, which represents MEMO_TEXT in a transaction.- 参数
text (str, bytes) – A string encoded using either ASCII or UTF-8, up to 28-bytes long.
- Raises
MemoInvalidException
: iftext
is not a valid text memo.
IdMemo¶
HashMemo¶
-
class
stellar_sdk.memo.
HashMemo
(memo_hash)[源代码]¶ The
HashMemo
which represents MEMO_HASH in a transaction.- 参数
memo_hash (
Union
[bytes
,str
]) – A 32 byte hash hex encoded string.- Raises
MemoInvalidException
: ifmemo_hash
is not a valid hash memo.
ReturnHashMemo¶
-
class
stellar_sdk.memo.
ReturnHashMemo
(memo_return)[源代码]¶ The
ReturnHashMemo
which represents MEMO_RETURN in a transaction.MEMO_RETURN is typically used with refunds/returns over the network - it is a 32 byte hash intended to be interpreted as the hash of the transaction the sender is refunding.
- 参数
memo_return (
Union
[bytes
,str
]) – A 32 byte hash or hex encoded string intended to be interpreted as the hash of the transaction the sender is refunding.- Raises
MemoInvalidException
: ifmemo_return
is not a valid return hash memo.
-
classmethod
from_xdr_object
(xdr_obj)[源代码]¶ Returns an
ReturnHashMemo
object from XDR memo object.- 返回类型
-
to_xdr_object
()[源代码]¶ Creates an XDR Memo object that represents this
ReturnHashMemo
.- 返回类型
Memo
Network¶
-
class
stellar_sdk.network.
Network
(network_passphrase)[源代码]¶ The
Network
object, which represents a Stellar network.This class represents such a stellar network such as the Public network and the Test network.
- 参数
network_passphrase (str) – The passphrase for the network. (ex. ‘Public Global Stellar Network ; September 2015’)
-
PUBLIC_NETWORK_PASSPHRASE
: str = 'Public Global Stellar Network ; September 2015'¶ Get the Public network passphrase.
-
TESTNET_NETWORK_PASSPHRASE
: str = 'Test SDF Network ; September 2015'¶ Get the Test network passphrase.
-
network_id
()[源代码]¶ Get the network ID of the network, which is an XDR hash of the passphrase.
- 返回类型
- 返回
The network ID of the network.
Operation¶
Operation¶
-
class
stellar_sdk.operation.
Operation
(source=None)[源代码]¶ The
Operation
object, which represents an operation on Stellar’s network.An operation is an individual command that mutates Stellar’s ledger. It is typically rolled up into a transaction (a transaction is a list of operations with additional metadata).
Operations are executed on behalf of the source account specified in the transaction, unless there is an override defined for the operation.
For more on operations, see Stellar’s documentation on operations as well as Stellar’s List of Operations, which includes information such as the security necessary for a given operation, as well as information about when validity checks occur on the network.
The
Operation
class is typically not used, but rather one of its subclasses is typically included in transactions.- 参数
source (
Optional
[str
]) – The source account for the payment. Defaults to the transaction’s source account.
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Create the appropriate
Operation
subclass from the XDR object.- 参数
operation_xdr_object (
Operation
) – The XDR object to create anOperation
(or subclass) instance from.- 返回类型
Operation
-
static
get_source_from_xdr_obj
(xdr_object)[源代码]¶ Get the source account from account the operation xdr object.
-
static
get_source_muxed_from_xdr_obj
(xdr_object)[源代码]¶ Get the source account from account the operation xdr object.
- 参数
xdr_object (
Operation
) – the operation xdr object.- 返回类型
Optional
[MuxedAccount
]- 返回
The source account from account the operation xdr object.
-
static
to_xdr_amount
(value)[源代码]¶ Converts an amount to the appropriate value to send over the network as a part of an XDR object.
Each asset amount is encoded as a signed 64-bit integer in the XDR structures. An asset amount unit (that which is seen by end users) is scaled down by a factor of ten million (10,000,000) to arrive at the native 64-bit integer representation. For example, the integer amount value 25,123,456 equals 2.5123456 units of the asset. This scaling allows for seven decimal places of precision in human-friendly amount units.
This static method correctly multiplies the value by the scaling factor in order to come to the integer value used in XDR structures.
See Stellar’s documentation on Asset Precision for more information.
AccountMerge¶
-
class
stellar_sdk.operation.
AccountMerge
(destination, source=None)[源代码]¶ The
AccountMerge
object, which represents a AccountMerge operation on Stellar’s network.Transfers the native balance (the amount of XLM an account holds) to another account and removes the source account from the ledger.
Threshold: High
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
AccountMerge
object from an XDR Operation object.- 返回类型
AccountMerge
AllowTrust¶
-
class
stellar_sdk.operation.
AllowTrust
(trustor, asset_code, authorize, source=None)[源代码]¶ The
AllowTrust
object, which represents a AllowTrust operation on Stellar’s network.Updates the authorized flag of an existing trustline. This can only be called by the issuer of a trustline’s asset.
The issuer can only clear the authorized flag if the issuer has the AUTH_REVOCABLE_FLAG set. Otherwise, the issuer can only set the authorized flag.
Threshold: Low
- 参数
trustor (
str
) – The trusting account (the one being authorized).asset_code (
str
) – The asset code being authorized.authorize (
Union
[TrustLineEntryFlag
,bool
]) – True to authorize the line, False to deauthorize,if you need further control, you can also usestellar_sdk.operation.allow_trust.TrustLineEntryFlag
.source (
Optional
[str
]) – The source account (defaults to transaction source).
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
AllowTrust
object from an XDR Operation object.- 返回类型
AllowTrust
-
class
stellar_sdk.operation.allow_trust.
TrustLineEntryFlag
(value)[源代码]¶ Indicates which flags to set. For details about the flags, please refer to the CAP-0018.
UNAUTHORIZED_FLAG: The account can hold a balance but cannot receive payments, send payments, maintain offers or manage offers
AUTHORIZED_FLAG: The account can hold a balance, receive payments, send payments, maintain offers or manage offers
AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG: The account can hold a balance and maintain offers but cannot receive payments, send payments or manage offers
BumpSequence¶
-
class
stellar_sdk.operation.
BumpSequence
(bump_to, source=None)[源代码]¶ The
BumpSequence
object, which represents a BumpSequence operation on Stellar’s network.Bump sequence allows to bump forward the sequence number of the source account of the operation, allowing to invalidate any transactions with a smaller sequence number. If the specified bumpTo sequence number is greater than the source account’s sequence number, the account’s sequence number is updated with that value, otherwise it’s not modified.
Threshold: Low
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
BumpSequence
object from an XDR Operation object.- 返回类型
BumpSequence
ChangeTrust¶
-
class
stellar_sdk.operation.
ChangeTrust
(asset, limit=None, source=None)[源代码]¶ The
ChangeTrust
object, which represents a ChangeTrust operation on Stellar’s network.Creates, updates, or deletes a trustline. For more on trustlines, please refer to the assets documentation <https://www.stellar.org/developers/guides/concepts/assets.html>_.
Threshold: Medium
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
ChangeTrust
object from an XDR Operation object.- 返回类型
ChangeTrust
CreateAccount¶
-
class
stellar_sdk.operation.
CreateAccount
(destination, starting_balance, source=None)[源代码]¶ The
CreateAccount
object, which represents a Create Account operation on Stellar’s network.This operation creates and funds a new account with the specified starting balance.
Threshold: Medium
- 参数
destination (
str
) – Destination account ID to create an account for.starting_balance (
Union
[str
,Decimal
]) – Amount in XLM the account should be funded for. Must be greater than the reserve balance amount.source (
Optional
[str
]) – The source account for the payment. Defaults to the transaction’s source account.
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
CreateAccount
object from an XDR Operation object.- 返回类型
CreateAccount
CreatePassiveSellOffer¶
-
class
stellar_sdk.operation.
CreatePassiveSellOffer
(selling, buying, amount, price, source=None)[源代码]¶ The
CreatePassiveSellOffer
object, which represents a CreatePassiveSellOffer operation on Stellar’s network.A passive sell offer is an offer that does not act on and take a reverse offer of equal price. Instead, they only take offers of lesser price. For example, if an offer exists to buy 5 BTC for 30 XLM, and you make a passive sell offer to buy 30 XLM for 5 BTC, your passive sell offer does not take the first offer.
Note that regular offers made later than your passive sell offer can act on and take your passive sell offer, even if the regular offer is of the same price as your passive sell offer.
Passive sell offers allow market makers to have zero spread. If you want to trade EUR for USD at 1:1 price and USD for EUR also at 1:1, you can create two passive sell offers so the two offers don’t immediately act on each other.
Once the passive sell offer is created, you can manage it like any other offer using the manage offer operation - see
ManageOffer
for more details.- 参数
selling (
Asset
) – What you’re selling.buying (
Asset
) – What you’re buying.amount (
Union
[str
,Decimal
]) – The total amount you’re selling. If 0, deletes the offer.price (
Union
[Price
,str
,Decimal
]) – Price of 1 unit of selling in terms of buying.source (
Optional
[str
]) – The source account (defaults to transaction source).
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
CreatePassiveSellOffer
object from an XDR Operation object.- 返回类型
CreatePassiveSellOffer
Inflation¶
-
class
stellar_sdk.operation.
Inflation
(source=None)[源代码]¶ The
Inflation
object, which represents a Inflation operation on Stellar’s network.This operation runs inflation.
Threshold: Low
- 参数
source (str) – The source account (defaults to transaction source).
ManageBuyOffer¶
-
class
stellar_sdk.operation.
ManageBuyOffer
(selling, buying, amount, price, offer_id=0, source=None)[源代码]¶ The
ManageBuyOffer
object, which represents a ManageBuyOffer operation on Stellar’s network.Creates, updates, or deletes an buy offer.
If you want to create a new offer set Offer ID to 0.
If you want to update an existing offer set Offer ID to existing offer ID.
If you want to delete an existing offer set Offer ID to existing offer ID and set Amount to 0.
Threshold: Medium
- 参数
selling (
Asset
) – What you’re selling.buying (
Asset
) – What you’re buying.amount (
Union
[str
,Decimal
]) – Amount being bought. if set to 0, delete the offer.price (
Union
[Price
,str
,Decimal
]) – Price of thing being bought in terms of what you are selling.offer_id (
int
) – If 0, will create a new offer (default). Otherwise, edits an existing offer.source (
Optional
[str
]) – The source account (defaults to transaction source).
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
ManageBuyOffer
object from an XDR Operation object.- 返回类型
ManageBuyOffer
ManageData¶
-
class
stellar_sdk.operation.
ManageData
(data_name, data_value, source=None)[源代码]¶ The
ManageData
object, which represents a ManageData operation on Stellar’s network.Allows you to set, modify or delete a Data Entry (name/value pair) that is attached to a particular account. An account can have an arbitrary amount of DataEntries attached to it. Each DataEntry increases the minimum balance needed to be held by the account.
DataEntries can be used for application specific things. They are not used by the core Stellar protocol.
Threshold: Medium
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
ManageData
object from an XDR Operation object.- 返回类型
ManageData
ManageSellOffer¶
-
class
stellar_sdk.operation.
ManageSellOffer
(selling, buying, amount, price, offer_id=0, source=None)[源代码]¶ The
ManageSellOffer
object, which represents a ManageSellOffer operation on Stellar’s network.Creates, updates, or deletes an sell offer.
If you want to create a new offer set Offer ID to 0.
If you want to update an existing offer set Offer ID to existing offer ID.
If you want to delete an existing offer set Offer ID to existing offer ID and set Amount to 0.
Threshold: Medium
- 参数
selling (
Asset
) – What you’re selling.buying (
Asset
) – What you’re buying.amount (
Union
[str
,Decimal
]) – The total amount you’re selling. If 0, deletes the offer.price (
Union
[Price
,str
,Decimal
]) – Price of 1 unit of selling in terms of buying.offer_id (
int
) – If 0, will create a new offer (default). Otherwise, edits an existing offer.source (
Optional
[str
]) – The source account (defaults to transaction source).
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
ManageSellOffer
object from an XDR Operation object.- 返回类型
ManageSellOffer
PathPayment¶
-
class
stellar_sdk.operation.
PathPayment
(destination, send_asset, send_max, dest_asset, dest_amount, path, source=None)[源代码]¶ The
PathPayment
object, which represents a PathPayment operation on Stellar’s network.Sends an amount in a specific asset to a destination account through a path of offers. This allows the asset sent (e.g. 450 XLM) to be different from the asset received (e.g. 6 BTC).
Threshold: Medium
- 参数
destination (
str
) – The destination account to send to.send_asset (
Asset
) – The asset to pay with.send_max (
Union
[str
,Decimal
]) – The maximum amount of send_asset to send.dest_asset (
Asset
) – The asset the destination will receive.dest_amount (
Union
[str
,Decimal
]) – The amount the destination receives.path (
List
[Asset
]) – A list of Asset objects to use as the path.source (
Optional
[str
]) – The source account for the payment. Defaults to the transaction’s source account.
-
classmethod
from_xdr_object
(operation_xdr_object)¶ Creates a
PathPaymentStrictReceive
object from an XDR Operation object.- 返回类型
PathPaymentStrictReceive
PathPaymentStrictReceive¶
-
class
stellar_sdk.operation.
PathPaymentStrictReceive
(destination, send_asset, send_max, dest_asset, dest_amount, path, source=None)[源代码]¶ The
PathPaymentStrictReceive
object, which represents a PathPaymentStrictReceive operation on Stellar’s network.Sends an amount in a specific asset to a destination account through a path of offers. This allows the asset sent (e.g. 450 XLM) to be different from the asset received (e.g. 6 BTC).
Threshold: Medium
- 参数
destination (
str
) – The destination account to send to.send_asset (
Asset
) – The asset to pay with.send_max (
Union
[str
,Decimal
]) – The maximum amount of send_asset to send.dest_asset (
Asset
) – The asset the destination will receive.dest_amount (
Union
[str
,Decimal
]) – The amount the destination receives.path (
List
[Asset
]) – A list of Asset objects to use as the path.source (
Optional
[str
]) – The source account for the payment. Defaults to the transaction’s source account.
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
PathPaymentStrictReceive
object from an XDR Operation object.- 返回类型
PathPaymentStrictReceive
PathPaymentStrictSend¶
-
class
stellar_sdk.operation.
PathPaymentStrictSend
(destination, send_asset, send_amount, dest_asset, dest_min, path, source=None)[源代码]¶ The
PathPaymentStrictSend
object, which represents a PathPaymentStrictSend operation on Stellar’s network.Sends an amount in a specific asset to a destination account through a path of offers. This allows the asset sent (e.g, 450 XLM) to be different from the asset received (e.g, 6 BTC).
Threshold: Medium
- 参数
destination (
str
) – The destination account to send to.send_asset (
Asset
) – The asset to pay with.send_amount (
Union
[str
,Decimal
]) – Amount of send_asset to send.dest_asset (
Asset
) – The asset the destination will receive.dest_min (
Union
[str
,Decimal
]) – The minimum amount of dest_asset to be received.path (
List
[Asset
]) – A list of Asset objects to use as the path.source (
Optional
[str
]) – The source account for the payment. Defaults to the transaction’s source account.
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
PathPaymentStrictSend
object from an XDR Operation object.- 返回类型
PathPaymentStrictSend
Payment¶
-
class
stellar_sdk.operation.
Payment
(destination, asset, amount, source=None)[源代码]¶ The
Payment
object, which represents a Payment operation on Stellar’s network.Sends an amount in a specific asset to a destination account.
Threshold: Medium
- 参数
SetOptions¶
-
class
stellar_sdk.operation.
SetOptions
(inflation_dest=None, clear_flags=None, set_flags=None, master_weight=None, low_threshold=None, med_threshold=None, high_threshold=None, signer=None, home_domain=None, source=None)[源代码]¶ The
SetOptions
object, which represents a SetOptions operation on Stellar’s network.This operation sets the options for an account.
For more information on the signing options, please refer to the multi-sig doc.
When updating signers or other thresholds, the threshold of this operation is high.
Threshold: Medium or High
- 参数
inflation_dest (
Optional
[str
]) – Account of the inflation destination.clear_flags (
Union
[int
,Flag
,None
]) – Indicates which flags to clear. For details about the flags, please refer to the accounts doc. The bit mask integer subtracts from the existing flags of the account. This allows for setting specific bits without knowledge of existing flags, you can also usestellar_sdk.operation.set_options.Flag
- AUTHORIZATION_REQUIRED = 1 - AUTHORIZATION_REVOCABLE = 2 - AUTHORIZATION_IMMUTABLE = 4 - AUTHORIZATION_CLAWBACK_ENABLED = 8set_flags (
Union
[int
,Flag
,None
]) –Indicates which flags to set. For details about the flags, please refer to the accounts doc. The bit mask integer adds onto the existing flags of the account. This allows for setting specific bits without knowledge of existing flags, you can also use
stellar_sdk.operation.set_options.Flag
- AUTHORIZATION_REQUIRED = 1 - AUTHORIZATION_REVOCABLE = 2 - AUTHORIZATION_IMMUTABLE = 4 - AUTHORIZATION_CLAWBACK_ENABLED = 8master_weight (
Optional
[int
]) – A number from 0-255 (inclusive) representing the weight of the master key. If the weight of the master key is updated to 0, it is effectively disabled.low_threshold (
Optional
[int
]) – A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have a low threshold.med_threshold (
Optional
[int
]) – A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have a medium threshold.high_threshold (
Optional
[int
]) – A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have a high threshold.home_domain (
Optional
[str
]) – sets the home domain used for reverse federation lookup.signer (
Optional
[Signer
]) – Add, update, or remove a signer from the account.source (
Optional
[str
]) – The source account (defaults to transaction source).
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
SetOptions
object from an XDR Operation object.- 返回类型
SetOptions
-
class
stellar_sdk.operation.set_options.
Flag
(value)[源代码]¶ Indicates which flags to set. For details about the flags, please refer to the accounts doc. The bit mask integer adds onto the existing flags of the account.
CreateClaimableBalance¶
-
class
stellar_sdk.operation.
CreateClaimableBalance
(asset, amount, claimants, source=None)[源代码]¶ The
CreateClaimableBalance
object, which represents a CreateClaimableBalance operation on Stellar’s network.Creates a ClaimableBalanceEntry. See Claimable Balance <https://developers.stellar.org/docs/glossary/claimable-balance/>_ for more information on parameters and usage.
See Create Claimable Balance <https://developers.stellar.org/docs/start/list-of-operations/#create-claimable-balance>_.
Threshold: Medium
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
CreateClaimableBalance
object from an XDR Operation object.- 返回类型
CreateClaimableBalance
-
class
stellar_sdk.operation.
Claimant
(destination, predicate=None)[源代码]¶ The
Claimant
object represents a claimable balance claimant.
-
class
stellar_sdk.operation.
ClaimPredicate
(claim_predicate_type, and_predicates, or_predicates, not_predicate, abs_before, rel_before)[源代码]¶ The
ClaimPredicate
object, which represents a ClaimPredicate on Stellar’s network.We do not recommend that you build it through the constructor, please use the helper function.
- 参数
claim_predicate_type (
ClaimPredicateType
) – Type of ClaimPredicate.and_predicates (
Optional
[ClaimPredicateGroup
]) – The ClaimPredicates.or_predicates (
Optional
[ClaimPredicateGroup
]) – The ClaimPredicates.not_predicate (
Optional
[ClaimPredicate
]) – The ClaimPredicate.rel_before (
Optional
[int
]) – seconds since closeTime of the ledger in which the ClaimableBalanceEntry was created.
-
classmethod
predicate_and
(left, right)[源代码]¶ Returns an and claim predicate
- 参数
left (
ClaimPredicate
) – a ClaimPredicate.right (
ClaimPredicate
) – a ClaimPredicate.
- 返回类型
ClaimPredicate
- 返回
an and claim predicate.
-
classmethod
predicate_before_absolute_time
(abs_before)[源代码]¶ Returns a before_absolute_time claim predicate.
This predicate will be fulfilled if the closing time of the ledger that includes the
CreateClaimableBalance
operation is less than this (absolute) Unix timestamp.- 参数
abs_before (
int
) – Unix epoch.- 返回类型
ClaimPredicate
- 返回
a before_absolute_time claim predicate.
-
classmethod
predicate_before_relative_time
(seconds)[源代码]¶ Returns a before_relative_time claim predicate.
This predicate will be fulfilled if the closing time of the ledger that includes the
CreateClaimableBalance
operation plus this relative time delta (in seconds) is less than the current time.- 参数
seconds (
int
) – seconds since closeTime of the ledger in which the ClaimableBalanceEntry was created.- 返回类型
ClaimPredicate
- 返回
a before_relative_time claim predicate.
-
classmethod
predicate_not
(predicate)[源代码]¶ Returns a not claim predicate.
- 参数
predicate (
ClaimPredicate
) – a ClaimPredicate.- 返回类型
ClaimPredicate
- 返回
a not claim predicate.
ClaimClaimableBalance¶
-
class
stellar_sdk.operation.
ClaimClaimableBalance
(balance_id, source=None)[源代码]¶ The
ClaimClaimableBalance
object, which represents a ClaimClaimableBalance operation on Stellar’s network.Claims a ClaimableBalanceEntry and adds the amount of asset on the entry to the source account.
See Claim Claimable Balance Documentation <https://developers.stellar.org/docs/start/list-of-operations/#claim-claimable-balance>_.
Threshold: Low
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
ClaimClaimableBalance
object from an XDR Operation object.- 返回类型
ClaimClaimableBalance
BeginSponsoringFutureReserves¶
-
class
stellar_sdk.operation.
BeginSponsoringFutureReserves
(sponsored_id, source=None)[源代码]¶ The
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
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
BeginSponsoringFutureReserves
object from an XDR Operation object.- 返回类型
BeginSponsoringFutureReserves
EndSponsoringFutureReserves¶
-
class
stellar_sdk.operation.
EndSponsoringFutureReserves
(source=None)[源代码]¶ The
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
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
EndSponsoringFutureReserves
object from an XDR Operation object.- 返回类型
EndSponsoringFutureReserves
-
classmethod
RevokeSponsorship¶
-
class
stellar_sdk.operation.
RevokeSponsorship
(revoke_sponsorship_type, account_id, trustline, offer, data, claimable_balance_id, signer, source=None)[源代码]¶ The
RevokeSponsorship
object, which represents a RevokeSponsorship operation on Stellar’s network.The logic of this operation depends on the state of the source account.
If the source account is not sponsored or is sponsored by the owner of the specified entry or sub-entry, then attempt to revoke the sponsorship. If the source account is sponsored, the next step depends on whether the entry is sponsored or not. If it is sponsored, attempt to transfer the sponsorship to the sponsor of the source account. If the entry is not sponsored, then establish the sponsorship. See Sponsored Reserves <https://developers.stellar.org/docs/glossary/sponsored-reserves/>_ for more information.
See Revoke Sponsorship <https://developers.stellar.org/docs/start/list-of-operations/#revoke-sponsorship>_.
Threshold: Medium
- 参数
revoke_sponsorship_type (
RevokeSponsorshipType
) – The sponsored account id.claimable_balance_id (
Optional
[str
]) – The sponsored claimable balance.source (
Optional
[str
]) – The source account (defaults to transaction source).
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
RevokeSponsorship
object from an XDR Operation object.- 返回类型
RevokeSponsorship
Clawback¶
-
class
stellar_sdk.operation.
Clawback
(asset, from_, amount, source=None)[源代码]¶ The
Clawback
object, which represents a Clawback operation on Stellar’s network.Claws back an amount of an asset from an account.
Threshold: Medium
- 参数
ClawbackClaimableBalance¶
-
class
stellar_sdk.operation.
ClawbackClaimableBalance
(balance_id, source=None)[源代码]¶ The
ClawbackClaimableBalance
object, which represents a ClawbackClaimableBalance operation on Stellar’s network.Claws back a claimable balance
Threshold: Medium
- 参数
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
ClawbackClaimableBalance
object from an XDR Operation object.- 返回类型
ClawbackClaimableBalance
SetTrustLineFlags¶
-
class
stellar_sdk.operation.
SetTrustLineFlags
(trustor, asset, clear_flags=None, set_flags=None, source=None)[源代码]¶ The
SetTrustLineFlags
object, which represents a SetTrustLineFlags operation on Stellar’s network.Updates the flags of an existing trust line. This is called by the issuer of the related asset.
Threshold: Low
- 参数
trustor (
str
) – The account whose trustline this is.asset (
Asset
) – The asset on the trustline.clear_flags (
Optional
[TrustLineFlags
]) – The flags to clear.set_flags (
Optional
[TrustLineFlags
]) – The flags to set.source (
Optional
[str
]) – The source account for the operation. Defaults to the transaction’s source account.
-
classmethod
from_xdr_object
(operation_xdr_object)[源代码]¶ Creates a
SetTrustLineFlags
object from an XDR Operation object.- 返回类型
SetTrustLineFlags
-
class
stellar_sdk.operation.set_trust_line_flags.
TrustLineFlags
(value)[源代码]¶ Indicates which flags to set. For details about the flags, please refer to the CAP-0035.
AUTHORIZED_FLAG: issuer has authorized account to perform transactions with its credit
AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG: issuer has authorized account to maintain and reduce liabilities for its credit
TRUSTLINE_CLAWBACK_ENABLED_FLAG: issuer has specified that it may clawback its credit, and that claimable balances created with its credit may also be clawed back
Price¶
-
class
stellar_sdk.price.
Price
(n, d)[源代码]¶ Create a new price. Price in Stellar is represented as a fraction.
-
classmethod
from_raw_price
(price)[源代码]¶ Create a
Price
from the given str price.- 参数
price (
str
) – the str price. (ex. ‘0.125’)- 返回类型
- 返回
A new
Price
object from the given str price.- Raises
NoApproximationError
: if the approximation could not not be found.
-
classmethod
Server¶
-
class
stellar_sdk.server.
Server
(horizon_url='https://horizon-testnet.stellar.org/', client=None)[源代码]¶ Server handles the network connection to a Horizon instance and exposes an interface for requests to that instance.
Here we need to talk about the client parameter, if you do not specify the client, we will use the
stellar_sdk.client.requests_client.RequestsClient
instance by default, it is a synchronous HTTPClient, you can also specify an asynchronous HTTP Client, for example:stellar_sdk.client.aiohttp_client.AiohttpClient
. If you use a synchronous client, then all requests are synchronous. If you use an asynchronous client, then all requests are asynchronous. The choice is in your hands.- 参数
horizon_url (
str
) – Horizon Server URL (ex. https://horizon-testnet.stellar.org)client (
Union
[BaseAsyncClient
,BaseSyncClient
,None
]) – Http Client used to send the request
- Raises
TypeError
: if theclient
does not meet the standard.
-
accounts
()[源代码]¶ - 返回类型
AccountsCallBuilder
- 返回
New
stellar_sdk.call_builder.AccountsCallBuilder
object configured by a current Horizon server configuration.
-
assets
()[源代码]¶ - 返回类型
AssetsCallBuilder
- 返回
New
stellar_sdk.call_builder.AssetsCallBuilder
object configured by a current Horizon server configuration.
-
claimable_balances
()[源代码]¶ - 返回类型
ClaimableBalancesCallBuilder
- 返回
New
stellar_sdk.call_builder.ClaimableBalancesCallBuilder
object configured by a current Horizon server configuration.
-
data
(account_id, data_name)[源代码]¶ - 返回
New
stellar_sdk.call_builder.DataCallBuilder
object configured by a current Horizon server configuration.
-
effects
()[源代码]¶ - 返回类型
EffectsCallBuilder
- 返回
New
stellar_sdk.call_builder.EffectsCallBuilder
object configured by a current Horizon server configuration.
-
fee_stats
()[源代码]¶ - 返回类型
FeeStatsCallBuilder
- 返回
New
stellar_sdk.call_builder.FeeStatsCallBuilder
object configured by a current Horizon server configuration.
-
fetch_base_fee
()[源代码]¶ Fetch the base fee. Since this hits the server, if the server call fails, you might get an error. You should be prepared to use a default value if that happens.
- 返回类型
- 返回
the base fee
- Raises
ConnectionError
NotFoundError
BadRequestError
BadResponseError
UnknownRequestError
-
ledgers
()[源代码]¶ - 返回类型
LedgersCallBuilder
- 返回
New
stellar_sdk.call_builder.LedgersCallBuilder
object configured by a current Horizon server configuration.
-
load_account
(account_id)[源代码]¶ Fetches an account’s most current state in the ledger and then creates and returns an
stellar_sdk.account.Account
object.- 参数
- 返回类型
- 返回
an
stellar_sdk.account.Account
object.- Raises
ConnectionError
NotFoundError
BadRequestError
BadResponseError
UnknownRequestError
-
offers
()[源代码]¶ - 返回类型
OffersCallBuilder
- 返回
New
stellar_sdk.call_builder.OffersCallBuilder
object configured by a current Horizon server configuration.
-
operations
()[源代码]¶ - 返回类型
OperationsCallBuilder
- 返回
New
stellar_sdk.call_builder.OperationsCallBuilder
object configured by a current Horizon server configuration.
-
orderbook
(selling, buying)[源代码]¶ - 参数
- 返回类型
OrderbookCallBuilder
- 返回
New
stellar_sdk.call_builder.OrderbookCallBuilder
object configured by a current Horizon server configuration.
-
paths
(source_account, destination_account, destination_asset, destination_amount)[源代码]¶ - 参数
source_account (
str
) – The sender’s account ID. Any returned path must use a source that the sender can hold.destination_account (
str
) – The destination account ID that any returned path should use.destination_asset (
Asset
) – The destination asset.destination_amount (
str
) – The amount, denominated in the destination asset, that any returned path should be able to satisfy.
- 返回类型
PathsCallBuilder
- 返回
New
stellar_sdk.call_builder.PathsCallBuilder
object configured by a current Horizon server configuration.
-
payments
()[源代码]¶ - 返回类型
PaymentsCallBuilder
- 返回
New
stellar_sdk.call_builder.PaymentsCallBuilder
object configured by a current Horizon server configuration.
-
root
()[源代码]¶ - 返回类型
RootCallBuilder
- 返回
New
stellar_sdk.call_builder.RootCallBuilder
object configured by a current Horizon server configuration.
-
strict_receive_paths
(source, destination_asset, destination_amount)[源代码]¶ - 参数
source (
Union
[str
,List
[Asset
]]) – The sender’s account ID or a list of Assets. Any returned path must use a source that the sender can hold.destination_asset (
Asset
) – The destination asset.destination_amount (
str
) – The amount, denominated in the destination asset, that any returned path should be able to satisfy.
- 返回
New
stellar_sdk.call_builder.StrictReceivePathsCallBuilder
object configured by a current Horizon server configuration.
-
strict_send_paths
(source_asset, source_amount, destination)[源代码]¶ - 参数
- 返回
New
stellar_sdk.call_builder.StrictReceivePathsCallBuilder
object configured by a current Horizon server configuration.
-
submit_transaction
(transaction_envelope, skip_memo_required_check=False)[源代码]¶ Submits a transaction to the network.
- 参数
transaction_envelope (
Union
[TransactionEnvelope
,FeeBumpTransactionEnvelope
,str
]) –stellar_sdk.transaction_envelope.TransactionEnvelope
object or base64 encoded xdr- 返回类型
- 返回
the response from horizon
- Raises
ConnectionError
NotFoundError
BadRequestError
BadResponseError
UnknownRequestError
AccountRequiresMemoError
-
trade_aggregations
(base, counter, resolution, start_time=None, end_time=None, offset=None)[源代码]¶ - 参数
base (
Asset
) – base assetcounter (
Asset
) – counter assetresolution (
int
) – segment duration as millis since epoch. Supported values are 1 minute (60000), 5 minutes (300000), 15 minutes (900000), 1 hour (3600000), 1 day (86400000) and 1 week (604800000).start_time (
Optional
[int
]) – lower time boundary represented as millis since epochend_time (
Optional
[int
]) – upper time boundary represented as millis since epochoffset (
Optional
[int
]) – segments can be offset using this parameter. Expressed in milliseconds. Can only be used if the resolution is greater than 1 hour. Value must be in whole hours, less than the provided resolution, and less than 24 hours.
- 返回类型
TradeAggregationsCallBuilder
- 返回
New
stellar_sdk.call_builder.TradeAggregationsCallBuilder
object configured by a current Horizon server configuration.
-
trades
()[源代码]¶ - 返回类型
TradesCallBuilder
- 返回
New
stellar_sdk.call_builder.TradesCallBuilder
object configured by a current Horizon server configuration.
-
transactions
()[源代码]¶ - 返回类型
TransactionsCallBuilder
- 返回
New
stellar_sdk.call_builder.TransactionsCallBuilder
object configured by a current Horizon server configuration.
Signer¶
-
class
stellar_sdk.signer.
Signer
(signer_key, weight)[源代码]¶ The
Signer
object, which represents an account signer on Stellar’s network.- 参数
signer_key (
SignerKey
) – The signer objectweight – The weight of the key
-
classmethod
ed25519_public_key
(account_id, weight)[源代码]¶ Create ED25519 PUBLIC KEY Signer from account id.
- 参数
- 返回类型
- 返回
ED25519 PUBLIC KEY Signer
- Raises
Ed25519PublicKeyInvalidError
: ifaccount_id
is not a valid ed25519 public key.
-
classmethod
pre_auth_tx
(pre_auth_tx_hash, weight)[源代码]¶ Create Pre AUTH TX Signer from the sha256 hash of a transaction, click here for more information.
SignerKey¶
-
class
stellar_sdk.signer_key.
SignerKey
(signer_key)[源代码]¶ The
SignerKey
object, which represents an account signer key on Stellar’s network.- 参数
signer_key (
SignerKey
) – The XDR signer object
-
classmethod
ed25519_public_key
(account_id)[源代码]¶ Create ED25519 PUBLIC KEY Signer from account id.
- 参数
account_id (
str
) – account id- 返回类型
- 返回
ED25519 PUBLIC KEY Signer
- Raises
Ed25519PublicKeyInvalidError
: ifaccount_id
is not a valid ed25519 public key.
-
classmethod
from_xdr_object
(signer_xdr_object)[源代码]¶ Create a
SignerKey
from an XDR SignerKey object.
-
classmethod
pre_auth_tx
(pre_auth_tx_hash)[源代码]¶ Create Pre AUTH TX Signer from the sha256 hash of a transaction, click here for more information.
TimeBounds¶
-
class
stellar_sdk.time_bounds.
TimeBounds
(min_time, max_time)[源代码]¶ TimeBounds represents the time interval that a transaction is valid.
The UNIX timestamp (in seconds), determined by ledger time, of a lower and upper bound of when this transaction will be valid. If a transaction is submitted too early or too late, it will fail to make it into the transaction set. max_time equal 0 means that it’s not set.
See Stellar’s documentation on Transactions for more information on how TimeBounds are used within transactions.
- 参数
- Raises
ValueError
: ifmax_time
less thanmin_time
.
-
classmethod
from_xdr_object
(time_bounds_xdr_object)[源代码]¶ Create a
TimeBounds
from an XDR TimeBounds object.- 参数
time_bounds_xdr_object (
TimeBounds
) – The XDR TimeBounds object.- 返回类型
- 返回
A new
TimeBounds
object from the given XDR TimeBounds object.
Transaction¶
-
class
stellar_sdk.transaction.
Transaction
(source, sequence, fee, operations, memo=None, time_bounds=None, v1=True)[源代码]¶ The
Transaction
object, which represents a transaction(Transaction or TransactionV0) 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
Transaction
is placed in aTransactionEnvelope
which is then signed before being sent over the network.For more information on Transactions in Stellar, see Stellar’s guide on transactions.
- 参数
source (
Union
[Keypair
,str
]) – the source account for the transaction.sequence (
int
) – The sequence number for the transaction.fee (
int
) – 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 for more information.operations (
List
[Operation
]) – A list of operations objects (typically its subclasses as defined instellar_sdk.operation.Operation
.time_bounds (
Optional
[TimeBounds
]) – The timebounds for the validity of this transaction.memo (
Optional
[Memo
]) – The memo being sent with the transaction, being represented as one of the subclasses of theMemo
object.v1 (
bool
) – When this value is set to True, V1 transactions will be generated, otherwise V0 transactions will be generated. See CAP-0015 for more information.
-
classmethod
from_xdr
(xdr, v1=False)[源代码]¶ Create a new
Transaction
from an XDR string.- 参数
- 返回类型
- 返回
A new
Transaction
object from the given XDR Transaction base64 string object.
-
classmethod
from_xdr_object
(tx_xdr_object, v1=False)[源代码]¶ Create a new
Transaction
from an XDR object.- 参数
- 返回类型
- 返回
A new
Transaction
object from the given XDR Transaction object.
-
to_xdr_object
()[源代码]¶ Get an XDR object representation of this
Transaction
.- 返回类型
Union
[Transaction
,TransactionV0
]- 返回
XDR Transaction object
TransactionEnvelope¶
-
class
stellar_sdk.transaction_envelope.
TransactionEnvelope
(transaction, network_passphrase, signatures=None)[源代码]¶ The
TransactionEnvelope
object, which represents a transaction envelope ready to sign and submit to send over the network.When a transaction is ready to be prepared for sending over the network, it must be put into a
TransactionEnvelope
, which includes additional metadata such as the signers for a given transaction. Ultimately, this class handles signing and conversion to and from XDR for usage on Stellar’s network.- 参数
transaction (
Transaction
) – The transaction that is encapsulated in this envelope.signatures (list) – which contains a list of signatures that have already been created.
network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from.
-
classmethod
from_xdr
(xdr, network_passphrase)¶ Create a new
BaseTransactionEnvelope
from an XDR string.
-
classmethod
from_xdr_object
(te_xdr_object, network_passphrase)[源代码]¶ Create a new
TransactionEnvelope
from an XDR object.- 参数
te_xdr_object (
TransactionEnvelope
) – The XDR object that represents a transaction envelope.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from.
- 返回类型
- 返回
A new
TransactionEnvelope
object from the given XDR TransactionEnvelope object.
-
hash
()¶ Get the XDR Hash of the signature base.
This hash is ultimately what is signed before transactions are sent over the network. See
signature_base()
for more details about this process.- 返回类型
- 返回
The XDR Hash of this transaction envelope’s signature base.
-
hash_hex
()¶ Return a hex encoded hash for this transaction envelope.
- 返回类型
- 返回
A hex encoded hash for this transaction envelope.
-
sign
(signer)¶ Sign this transaction envelope with a given keypair.
Note that the signature must not already be in this instance’s list of signatures.
-
sign_hashx
(preimage)¶ Sign this transaction envelope with a Hash(x) signature.
See Stellar’s documentation on Multi-Sig for more details on Hash(x) signatures.
-
signature_base
()[源代码]¶ Get the signature base of this transaction envelope.
Return the “signature base” of this transaction, which is the value that, when hashed, should be signed to create a signature that validators on the Stellar Network will accept.
It is composed of a 4 prefix bytes followed by the xdr-encoded form of this transaction.
- 返回类型
- 返回
The signature base of this transaction envelope.
-
to_transaction_envelope_v1
()[源代码]¶ Create a new
TransactionEnvelope
, if the internal tx is not v1, we will convert it to v1.- 返回类型
-
to_xdr
()¶ Get the base64 encoded XDR string representing this
BaseTransactionEnvelope
.- 返回类型
- 返回
XDR TransactionEnvelope base64 string object
-
to_xdr_object
()[源代码]¶ Get an XDR object representation of this
TransactionEnvelope
.- 返回类型
TransactionEnvelope
- 返回
XDR TransactionEnvelope object
FeeBumpTransaction¶
-
class
stellar_sdk.fee_bump_transaction.
FeeBumpTransaction
(fee_source, base_fee, inner_transaction_envelope)[源代码]¶ The
FeeBumpTransaction
object, which represents a fee bump transaction on Stellar’s network.See CAP-0015 for more information.
- 参数
fee_source (
Union
[Keypair
,str
]) – The account paying for the transaction.base_fee (
int
) – The max fee willing to pay per operation in inner transaction (in stroops).inner_transaction_envelope (
TransactionEnvelope
) – The TransactionEnvelope to be bumped by the fee bump transaction.
-
classmethod
from_xdr
(xdr, network_passphrase)[源代码]¶ Create a new
FeeBumpTransaction
from an XDR string.- 参数
- 返回类型
- 返回
A new
FeeBumpTransaction
object from the given XDR FeeBumpTransaction base64 string object.
-
classmethod
from_xdr_object
(tx_xdr_object, network_passphrase)[源代码]¶ Create a new
FeeBumpTransaction
from an XDR object.- 参数
tx_xdr_object (
FeeBumpTransaction
) – The XDR object that represents a fee bump transaction.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from.
- 返回类型
- 返回
A new
FeeBumpTransaction
object from the given XDR Transaction object.
-
to_xdr_object
()[源代码]¶ Get an XDR object representation of this
FeeBumpTransaction
.- 返回类型
FeeBumpTransaction
- 返回
XDR Transaction object
FeeBumpTransactionEnvelope¶
-
class
stellar_sdk.fee_bump_transaction_envelope.
FeeBumpTransactionEnvelope
(transaction, network_passphrase, signatures=None)[源代码]¶ The
FeeBumpTransactionEnvelope
object, which represents a transaction envelope ready to sign and submit to send over the network.When a transaction is ready to be prepared for sending over the network, it must be put into a
FeeBumpTransactionEnvelope
, which includes additional metadata such as the signers for a given transaction. Ultimately, this class handles signing and conversion to and from XDR for usage on Stellar’s network.- 参数
transaction (
FeeBumpTransaction
) – The fee bump transaction that is encapsulated in this envelope.signatures (list) – which contains a list of signatures that have already been created.
network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from.
-
classmethod
from_xdr
(xdr, network_passphrase)¶ Create a new
BaseTransactionEnvelope
from an XDR string.
-
classmethod
from_xdr_object
(te_xdr_object, network_passphrase)[源代码]¶ Create a new
FeeBumpTransactionEnvelope
from an XDR object.- 参数
te_xdr_object (
TransactionEnvelope
) – The XDR object that represents a fee bump transaction envelope.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from.
- 返回类型
- 返回
A new
FeeBumpTransactionEnvelope
object from the given XDR TransactionEnvelope object.
-
hash
()¶ Get the XDR Hash of the signature base.
This hash is ultimately what is signed before transactions are sent over the network. See
signature_base()
for more details about this process.- 返回类型
- 返回
The XDR Hash of this transaction envelope’s signature base.
-
hash_hex
()¶ Return a hex encoded hash for this transaction envelope.
- 返回类型
- 返回
A hex encoded hash for this transaction envelope.
-
sign
(signer)¶ Sign this transaction envelope with a given keypair.
Note that the signature must not already be in this instance’s list of signatures.
-
sign_hashx
(preimage)¶ Sign this transaction envelope with a Hash(x) signature.
See Stellar’s documentation on Multi-Sig for more details on Hash(x) signatures.
-
signature_base
()[源代码]¶ Get the signature base of this transaction envelope.
Return the “signature base” of this transaction, which is the value that, when hashed, should be signed to create a signature that validators on the Stellar Network will accept.
It is composed of a 4 prefix bytes followed by the xdr-encoded form of this transaction.
- 返回类型
- 返回
The signature base of this transaction envelope.
-
to_xdr
()¶ Get the base64 encoded XDR string representing this
BaseTransactionEnvelope
.- 返回类型
- 返回
XDR TransactionEnvelope base64 string object
TransactionBuilder¶
-
class
stellar_sdk.transaction_builder.
TransactionBuilder
(source_account, network_passphrase='Test SDF Network ; September 2015', base_fee=100, v1=True)[源代码]¶ Transaction builder helps constructs a new
TransactionEnvelope
using the givenAccount
as the transaction’s “source account”. The transaction will use the current sequence number of the given account as its sequence number and increment the given account’s sequence number by one. The given source account must include a private key for signing the transaction or an error will be thrown.Be careful about unsubmitted transactions! When you build a transaction, stellar-sdk automatically increments the source account’s sequence number. If you end up not submitting this transaction and submitting another one instead, it’ll fail due to the sequence number being wrong. So if you decide not to use a built transaction, make sure to update the source account’s sequence number with
stellar_sdk.Server.load_account()
before creating another transaction.- 参数
source_account (
Account
) – The source account for this transaction.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from. Defaults to Test SDF Network ; September 2015.base_fee (
int
) – Base fee in stroops. The network base fee is obtained by default from the latest ledger. Transaction fee is equal to base fee times number of operations in this transaction.v1 (
bool
) –When this value is set to True, V1 transactions will be generated, otherwise V0 transactions will be generated. See CAP-0015 for more information.
-
add_hash_memo
(memo_hash)[源代码]¶ Set the memo for the transaction to a new
HashMemo
.- 参数
memo_hash (
Union
[bytes
,str
]) – A 32 byte hash or hex encoded string to use as the memo.- 返回类型
- 返回
This builder instance.
- Raises
MemoInvalidException
: ifmemo_hash
is not a valid hash memo.
-
add_id_memo
(memo_id)[源代码]¶ Set the memo for the transaction to a new
IdMemo
.- 参数
memo_id (
int
) – A 64 bit unsigned integer to set as the memo.- 返回类型
- 返回
This builder instance.
- Raises
MemoInvalidException
: ifmemo_id
is not a valid id memo.
-
add_memo
(memo)[源代码]¶ Set the memo for the transaction build by this
Builder
.- 参数
memo (
Memo
) – A memo to add to this transaction.- 返回类型
- 返回
This builder instance.
-
add_return_hash_memo
(memo_return)[源代码]¶ Set the memo for the transaction to a new
RetHashMemo
.- 参数
memo_return (
Union
[bytes
,str
]) – A 32 byte hash or hex encoded string intended to be interpreted as the hash of the transaction the sender is refunding.- 返回类型
- 返回
This builder instance.
- Raises
MemoInvalidException
: ifmemo_return
is not a valid return hash memo.
-
add_text_memo
(memo_text)[源代码]¶ Set the memo for the transaction to a new
TextMemo
.- 参数
memo_text (
Union
[str
,bytes
]) – The text for the memo to add.- 返回类型
- 返回
This builder instance.
- Raises
MemoInvalidException
: ifmemo_text
is not a valid text memo.
-
add_time_bounds
(min_time, max_time)[源代码]¶ Add a time bound to this transaction.
Add a UNIX timestamp, determined by ledger time, of a lower and upper bound of when this transaction will be valid. If a transaction is submitted too early or too late, it will fail to make it into the transaction set. maxTime equal 0 means that it’s not set.
- 参数
- 返回类型
- 返回
This builder instance.
-
append_account_merge_op
(destination, source=None)[源代码]¶ Append a
AccountMerge
operation to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_allow_trust_op
(trustor, asset_code, authorize, source=None)[源代码]¶ Append an
AllowTrust
operation to the list of operations.- 参数
trustor (
str
) – The account of the recipient of the trustline.asset_code (
str
) – The asset of the trustline the source account is authorizing. For example, if an anchor wants to allow another account to hold its USD credit, the type is USD:anchor.authorize (
Union
[TrustLineEntryFlag
,bool
]) – True to authorize the line, False to deauthorize,if you need further control, you can also usestellar_sdk.operation.allow_trust.TrustLineEntryFlag
.source (
Optional
[str
]) – The source address that is establishing the trust in the allow trust operation.
- 返回类型
- 返回
This builder instance.
-
append_begin_sponsoring_future_reserves_op
(sponsored_id, source=None)[源代码]¶ Append a
BeginSponsoringFutureReserves
operation to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_bump_sequence_op
(bump_to, source=None)[源代码]¶ Append a
BumpSequence
operation to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_change_trust_op
(asset_code, asset_issuer, limit=None, source=None)[源代码]¶ Append a
ChangeTrust
operation to the list of operations.
-
append_claim_claimable_balance_op
(balance_id, source=None)[源代码]¶ Append a
ClaimClaimableBalance
operation to the list of operations.- 参数
- 返回类型
-
append_clawback_claimable_balance_op
(balance_id, source=None)[源代码]¶ Append an
ClawbackClaimableBalance
operation to the list of operations.
-
append_clawback_op
(asset, from_, amount, source=None)[源代码]¶ Append an
Clawback
operation to the list of operations.
-
append_create_account_op
(destination, starting_balance, source=None)[源代码]¶ Append a
CreateAccount
operation to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_create_claimable_balance_op
(asset, amount, claimants, source=None)[源代码]¶ Append a
CreateClaimableBalance
operation to the list of operations.
-
append_create_passive_sell_offer_op
(selling_code, selling_issuer, buying_code, buying_issuer, amount, price, source=None)[源代码]¶ Append a
CreatePassiveSellOffer
operation to the list of operations.- 参数
selling_code (
str
) – The asset code for the asset the offer creator is selling.selling_issuer (
Optional
[str
]) – The issuing address for the asset the offer creator is selling.buying_code (
str
) – The asset code for the asset the offer creator is buying.buying_issuer (
Optional
[str
]) – The issuing address for the asset the offer creator is buying.amount (
Union
[str
,Decimal
]) – Amount of the asset being sold. Set to 0 if you want to delete an existing offer.price (
Union
[str
,Price
,Decimal
]) – Price of 1 unit of selling in terms of buying.source (
Optional
[str
]) – The source address that is creating a passive offer on Stellar’s distributed exchange.
- 返回类型
- 返回
This builder instance.
-
append_ed25519_public_key_signer
(account_id, weight, source=None)[源代码]¶ Add a ed25519 public key signer to an account.
Add a ed25519 public key signer to an account via a
SetOptions <stellar_sdk.operation.SetOptions
operation. This is a helper function forappend_set_options_op()
.- 参数
- 返回类型
- 返回
This builder instance.
-
append_end_sponsoring_future_reserves_op
(source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation to the list of operations.
-
append_hashx_signer
(sha256_hash, weight, source=None)[源代码]¶ Add a sha256 hash(HashX) signer to an account.
Add a HashX signer to an account via a
SetOptions <stellar_sdk.operation.SetOptions
operation. This is a helper function forappend_set_options_op()
.- 参数
- 返回类型
- 返回
This builder instance.
-
append_inflation_op
(source=None)[源代码]¶ Append a
Inflation
operation to the list of operations.
-
append_manage_buy_offer_op
(selling_code, selling_issuer, buying_code, buying_issuer, amount, price, offer_id=0, source=None)[源代码]¶ Append a
ManageBuyOffer
operation to the list of operations.- 参数
selling_code (
str
) – The asset code for the asset the offer creator is selling.selling_issuer (
Optional
[str
]) – The issuing address for the asset the offer creator is selling.buying_code (
str
) – The asset code for the asset the offer creator is buying.buying_issuer (
Optional
[str
]) – The issuing address for the asset the offer creator is buying.amount (
Union
[str
,Decimal
]) – Amount being bought. if set to. Set to 0 if you want to delete an existing offer.price (
Union
[str
,Decimal
,Price
]) – Price of thing being bought in terms of what you are selling.offer_id (
int
) – The ID of the offer. 0 for new offer. Set to existing offer ID to update or delete.source (
Optional
[str
]) – The source address that is managing a buying offer on Stellar’s distributed exchange.
- 返回类型
- 返回
This builder instance.
-
append_manage_data_op
(data_name, data_value, source=None)[源代码]¶ Append a
ManageData
operation to the list of operations.- 参数
data_name (
str
) – String up to 64 bytes long. If this is a new Name it will add the given name/value pair to the account. If this Name is already present then the associated value will be modified.data_value (
Union
[str
,bytes
,None
]) – If not present then the existing Name will be deleted. If present then this value will be set in the DataEntry. Up to 64 bytes long.source (
Optional
[str
]) – The source account on which data is being managed. operation.
- 返回类型
- 返回
This builder instance.
-
append_manage_sell_offer_op
(selling_code, selling_issuer, buying_code, buying_issuer, amount, price, offer_id=0, source=None)[源代码]¶ Append a
ManageSellOffer
operation to the list of operations.- 参数
selling_code (
str
) – The asset code for the asset the offer creator is selling.selling_issuer (
Optional
[str
]) – The issuing address for the asset the offer creator is selling.buying_code (
str
) – The asset code for the asset the offer creator is buying.buying_issuer (
Optional
[str
]) – The issuing address for the asset the offer creator is buying.amount (
Union
[str
,Decimal
]) – Amount of the asset being sold. Set to 0 if you want to delete an existing offer.price (
Union
[str
,Price
,Decimal
]) – Price of 1 unit of selling in terms of buying.offer_id (
int
) – The ID of the offer. 0 for new offer. Set to existing offer ID to update or delete.source (
Optional
[str
]) – The source address that is managing an offer on Stellar’s distributed exchange.
- 返回类型
- 返回
This builder instance.
-
append_operation
(operation)[源代码]¶ Add an operation to the builder instance
- 参数
operation (
Operation
) – an operation- 返回类型
- 返回
This builder instance.
-
append_path_payment_op
(destination, send_code, send_issuer, send_max, dest_code, dest_issuer, dest_amount, path, source=None)[源代码]¶ Append a
PathPayment
operation to the list of operations.- 参数
destination (
str
) – The destination address (Account ID) for the payment.send_code (
str
) – The asset code for the source asset deducted from the source account.send_issuer (
Optional
[str
]) – The address of the issuer of the source asset.send_max (
Union
[str
,Decimal
]) – The maximum amount of send asset to deduct (excluding fees).dest_code (
str
) – The asset code for the final destination asset sent to the recipient.dest_issuer (
Optional
[str
]) – Account address that receives the payment.dest_amount (
Union
[str
,Decimal
]) – The amount of destination asset the destination account receives.path (
List
[Asset
]) – A list of Asset objects to use as the path.source (
Optional
[str
]) – The source address of the path payment.
- 返回类型
- 返回
This builder instance.
-
append_path_payment_strict_receive_op
(destination, send_code, send_issuer, send_max, dest_code, dest_issuer, dest_amount, path, source=None)[源代码]¶ Append a
PathPaymentStrictReceive
operation to the list of operations.- 参数
destination (
str
) – The destination address (Account ID) for the payment.send_code (
str
) – The asset code for the source asset deducted from the source account.send_issuer (
Optional
[str
]) – The address of the issuer of the source asset.send_max (
Union
[str
,Decimal
]) – The maximum amount of send asset to deduct (excluding fees).dest_code (
str
) – The asset code for the final destination asset sent to the recipient.dest_issuer (
Optional
[str
]) – Account address that receives the payment.dest_amount (
Union
[str
,Decimal
]) – The amount of destination asset the destination account receives.path (
List
[Asset
]) – A list of Asset objects to use as the path.source (
Optional
[str
]) – The source address of the path payment.
- 返回类型
- 返回
This builder instance.
-
append_path_payment_strict_send_op
(destination, send_code, send_issuer, send_amount, dest_code, dest_issuer, dest_min, path, source=None)[源代码]¶ Append a
PathPaymentStrictSend
operation to the list of operations.- 参数
destination (
str
) – The destination address (Account ID) for the payment.send_code (
str
) – The asset code for the source asset deducted from the source account.send_issuer (
Optional
[str
]) – The address of the issuer of the source asset.send_amount (
Union
[str
,Decimal
]) – Amount of send_asset to send.dest_code (
str
) – The asset code for the final destination asset sent to the recipient.dest_issuer (
Optional
[str
]) – Account address that receives the payment.dest_min (
Union
[str
,Decimal
]) – The minimum amount of dest_asset to be received.path (
List
[Asset
]) – A list of Asset objects to use as the path.source (
Optional
[str
]) – The source address of the path payment.
- 返回类型
- 返回
This builder instance.
-
append_payment_op
(destination, amount, asset_code='XLM', asset_issuer=None, source=None)[源代码]¶ Append a
Payment
operation to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_pre_auth_tx_signer
(pre_auth_tx_hash, weight, source=None)[源代码]¶ Add a PreAuthTx signer to an account.
Add a PreAuthTx signer to an account via a
SetOptions <stellar_sdk.operation.SetOptions
operation. This is a helper function forappend_set_options_op()
.- 参数
pre_auth_tx_hash (
Union
[str
,bytes
]) – The address of the new preAuthTx signer - obtained by callinghash
on theTransactionEnvelope
, a 32 byte hash or hex encoded string.weight (
int
) – The weight of the new signer.source – The source account that is adding a signer to its list of signers.
- 返回类型
- 返回
This builder instance.
-
append_revoke_account_sponsorship_op
(account_id, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for an account to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_revoke_claimable_balance_sponsorship_op
(claimable_balance_id, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for a claimable to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_revoke_data_sponsorship_op
(account_id, data_name, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for a data entry to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_revoke_ed25519_public_key_signer_sponsorship_op
(account_id, signer_key, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for a ed25519_public_key signer to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_revoke_hashx_signer_sponsorship_op
(account_id, signer_key, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for a hashx signer to the list of operations.
-
append_revoke_offer_sponsorship_op
(seller_id, offer_id, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for an offer to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_revoke_pre_auth_tx_signer_sponsorship_op
(account_id, signer_key, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for a pre_auth_tx signer to the list of operations.
-
append_revoke_trustline_sponsorship_op
(account_id, asset, source=None)[源代码]¶ Append a
EndSponsoringFutureReserves
operation for a trustline to the list of operations.- 参数
- 返回类型
- 返回
This builder instance.
-
append_set_options_op
(inflation_dest=None, clear_flags=None, set_flags=None, master_weight=None, low_threshold=None, med_threshold=None, high_threshold=None, home_domain=None, signer=None, source=None)[源代码]¶ Append a
SetOptions
operation to the list of operations.- 参数
inflation_dest (
Optional
[str
]) – Account of the inflation destination.clear_flags (
Union
[int
,Flag
,None
]) –Indicates which flags to clear. For details about the flags, please refer to the accounts doc. The bit mask integer subtracts from the existing flags of the account. This allows for setting specific bits without knowledge of existing flags, you can also use
stellar_sdk.operation.set_options.Flag
- AUTHORIZATION_REQUIRED = 1 - AUTHORIZATION_REVOCABLE = 2 - AUTHORIZATION_IMMUTABLE = 4 - AUTHORIZATION_CLAWBACK_ENABLED = 8set_flags (
Union
[int
,Flag
,None
]) – Indicates which flags to set. For details about the flags, please refer to the accounts doc. The bit mask integer adds onto the existing flags of the account. This allows for setting specific bits without knowledge of existing flags, you can also usestellar_sdk.operation.set_options.Flag
- AUTHORIZATION_REQUIRED = 1 - AUTHORIZATION_REVOCABLE = 2 - AUTHORIZATION_IMMUTABLE = 4 - AUTHORIZATION_CLAWBACK_ENABLED = 8master_weight (
Optional
[int
]) – A number from 0-255 (inclusive) representing the weight of the master key. If the weight of the master key is updated to 0, it is effectively disabled.low_threshold (
Optional
[int
]) –A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have a low threshold.
med_threshold (
Optional
[int
]) –A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have a medium threshold.
high_threshold (
Optional
[int
]) –A number from 0-255 (inclusive) representing the threshold this account sets on all operations it performs that have a high threshold.
sets the home domain used for reverse federation lookup.
signer (
Optional
[Signer
]) – Add, update, or remove a signer from the account.source (
Optional
[str
]) – The source account (defaults to transaction source).
- 返回类型
- 返回
This builder instance.
-
append_set_trust_line_flags_op
(trustor, asset, clear_flags=None, set_flags=None, source=None)[源代码]¶ Append an
SetTrustLineFlags
operation to the list of operations.- 参数
trustor (
str
) – The account whose trustline this is.asset (
Asset
) – The asset on the trustline.clear_flags (
Optional
[TrustLineFlags
]) – The flags to clear.set_flags (
Optional
[TrustLineFlags
]) – The flags to set.source (
Optional
[str
]) – The source account for the operation. Defaults to the transaction’s source account.
- 返回
This builder instance.
-
build
()[源代码]¶ This will build the transaction envelope. It will also increment the source account’s sequence number by 1.
- 返回类型
- 返回
The transaction envelope.
-
static
build_fee_bump_transaction
(fee_source, base_fee, inner_transaction_envelope, network_passphrase='Test SDF Network ; September 2015')[源代码]¶ Create a
FeeBumpTransactionEnvelope
object.See CAP-0015 for more information.
- 参数
fee_source (
Union
[Keypair
,str
]) – The account paying for the transaction.base_fee (
int
) – The max fee willing to pay per operation in inner transaction (in stroops).inner_transaction_envelope (
TransactionEnvelope
) – The TransactionEnvelope to be bumped by the fee bump transaction.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from.
- 返回类型
- 返回
a
TransactionBuilder
via the XDR object.
-
static
from_xdr
(xdr, network_passphrase)[源代码]¶ Create a
TransactionBuilder
orFeeBumpTransactionEnvelope
via an XDR object.In addition, if xdr is not of
TransactionEnvelope
, it sets the fields of this builder (the transaction envelope, transaction, operations, source, etc.) to all of the fields in the provided XDR transaction envelope, but the signature will not be added to it.- 参数
- 返回类型
- 返回
a
TransactionBuilder
orFeeBumpTransactionEnvelope
via the XDR object.
-
set_timeout
(timeout)[源代码]¶ Set timeout for the transaction, actually set a TimeBounds.
- 参数
timeout (
int
) – timeout in second.- 返回类型
- 返回
This builder instance.
- Raises
ValueError
: if time_bound is already set.
Helpers¶
-
stellar_sdk.helpers.
parse_transaction_envelope_from_xdr
(xdr, network_passphrase)[源代码]¶ - When you are not sure whether your XDR belongs to
TransactionEnvelope
orFeeBumpTransactionEnvelope
, you can use this helper function.
- 参数
- Raises
ValueError
- XDR is neitherTransactionEnvelope
norFeeBumpTransactionEnvelope
- 返回类型
Stellar Ecosystem Proposals¶
SEP 0001: stellar.toml¶
-
stellar_sdk.sep.stellar_toml.
fetch_stellar_toml
(domain, client=None, use_http=False)[源代码]¶ Retrieve the stellar.toml file from a given domain.
Retrieve the stellar.toml file for information about interacting with Stellar’s federation protocol for a given Stellar Anchor (specified by a domain).
- 参数
domain (
str
) – The domain the .toml file is hosted at.use_http (
bool
) – Specifies whether the request should go over plain HTTP vs HTTPS. Note it is recommend that you always use HTTPS.client (
Union
[BaseAsyncClient
,BaseSyncClient
,None
]) – Http Client used to send the request.
- 返回类型
- 返回
The stellar.toml file as a an object via
toml.loads()
.- Raises
StellarTomlNotFoundError
: if the Stellar toml file could not not be found.
SEP 0002: Federation protocol¶
-
stellar_sdk.sep.federation.
resolve_stellar_address
(stellar_address, client=None, federation_url=None, use_http=False)[源代码]¶ Get the federation record if the user was found for a given Stellar address.
- 参数
stellar_address (
str
) – address Stellar address (ex. bob*stellar.org).client (
Union
[BaseAsyncClient
,BaseSyncClient
,None
]) – Http Client used to send the request.federation_url (
Optional
[str
]) – The federation server URL (ex. https://stellar.org/federation), if you don’t set this value, we will try to get it fromstellar_address
.use_http (
bool
) – Specifies whether the request should go over plain HTTP vs HTTPS. Note it is recommend that you always use HTTPS.
- 返回类型
Union
[Coroutine
[Any
,Any
,FederationRecord
],FederationRecord
]- 返回
Federation record.
-
stellar_sdk.sep.federation.
resolve_account_id
(account_id, domain=None, federation_url=None, client=None, use_http=False)[源代码]¶ Given an account ID, get their federation record if the user was found
- 参数
account_id (
str
) – Account ID (ex. GBYNR2QJXLBCBTRN44MRORCMI4YO7FZPFBCNOKTOBCAAFC7KC3LNPRYS)domain (
Optional
[str
]) – Getfederation_url
from the domain, you don’t need to set this value iffederation_url
is set.federation_url (
Optional
[str
]) – The federation server URL (ex. https://stellar.org/federation).client (
Union
[BaseAsyncClient
,BaseSyncClient
,None
]) – Http Client used to send the request.use_http (
bool
) – Specifies whether the request should go over plain HTTP vs HTTPS. Note it is recommend that you always use HTTPS.
- 返回类型
Union
[Coroutine
[Any
,Any
,FederationRecord
],FederationRecord
]- 返回
Federation record.
SEP 0005: Key Derivation Methods for Stellar Accounts¶
-
class
stellar_sdk.sep.mnemonic.
StellarMnemonic
(language=<Language.ENGLISH: 'english'>)[源代码]¶ Please use
Keypair.generate_mnemonic_phrase()
andKeypair.from_mnemonic_phrase()
-
class
stellar_sdk.sep.mnemonic.
Language
(value)[源代码]¶ The type of language supported by the mnemonic.
-
CHINESE_SIMPLIFIED
= 'chinese_simplified'¶
-
CHINESE_TRADITIONAL
= 'chinese_traditional'¶
-
ENGLISH
= 'english'¶
-
FRENCH
= 'french'¶
-
ITALIAN
= 'italian'¶
-
JAPANESE
= 'japanese'¶
-
KOREAN
= 'korean'¶
-
SPANISH
= 'spanish'¶
-
SEP 0007: URI Scheme to facilitate delegated signing¶
-
class
stellar_sdk.sep.stellar_uri.
PayStellarUri
(destination, amount=None, asset=None, memo=None, callback=None, message=None, network_passphrase=None, origin_domain=None, signature=None)[源代码]¶ A request for a payment to be signed.
See SEP-0007
- 参数
destination (
str
) – A valid account ID or payment address.amount (
Optional
[str
]) – Amount that destination will receive.memo (
Optional
[Memo
]) – A memo to attach to the transaction.callback (
Optional
[str
]) – The uri to post the transaction to after signing.message (
Optional
[str
]) – An message for displaying to the user.network_passphrase (
Optional
[str
]) – The passphrase of the target network.origin_domain (
Optional
[str
]) – A fully qualified domain name that specifies the originating domain of the URI request.signature (
Optional
[str
]) – A base64 encode signature of the hash of the URI request.
-
classmethod
from_uri
(uri)[源代码]¶ Parse Stellar Pay URI and generate
PayStellarUri
object.- 参数
uri (
str
) – Stellar Pay URI.- 返回类型
- 返回
PayStellarUri
object from uri.
-
sign
(signer)¶ Sign the URI.
-
class
stellar_sdk.sep.stellar_uri.
TransactionStellarUri
(transaction_envelope, replace=None, callback=None, pubkey=None, message=None, network_passphrase=None, origin_domain=None, signature=None)[源代码]¶ A request for a transaction to be signed.
See SEP-0007
- 参数
transaction_envelope (
TransactionEnvelope
) – Transaction waiting to be signed.replace (
Optional
[List
[Replacement
]]) – A value that identifies the fields to be replaced in the xdr using the Txrep (SEP-0011) representation.callback (
Optional
[str
]) – The uri to post the transaction to after signing.pubkey (
Optional
[str
]) – Specify which public key you want the URI handler to sign for.message (
Optional
[str
]) – An message for displaying to the user.network_passphrase (
Optional
[str
]) – The passphrase of the target network.origin_domain (
Optional
[str
]) – A fully qualified domain name that specifies the originating domain of the URI request.signature (
Optional
[str
]) – A base64 encode signature of the hash of the URI request.
-
classmethod
from_uri
(uri, network_passphrase)[源代码]¶ Parse Stellar Transaction URI and generate
TransactionStellarUri
object.- 参数
- 返回类型
- 返回
TransactionStellarUri
object from uri.
-
sign
(signer)¶ Sign the URI.
SEP 0010: Stellar Web Authentication¶
-
stellar_sdk.sep.stellar_web_authentication.
build_challenge_transaction
(server_secret, client_account_id, home_domain, web_auth_domain, network_passphrase, timeout=900, client_domain=None, client_signing_key=None)[源代码]¶ Returns a valid SEP0010 challenge transaction which you can use for Stellar Web Authentication.
- 参数
server_secret (
str
) – secret key for server’s stellar.toml SIGNING_KEY.client_account_id (
str
) – The stellar account that the wallet wishes to authenticate with the server.home_domain (
str
) – The fully qualified domain name of the service requiring authentication, for example: example.com.web_auth_domain (
str
) – The fully qualified domain name of the service issuing the challenge.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from. (ex. ‘Public Global Stellar Network ; September 2015’)timeout (
int
) – Challenge duration in seconds (default to 15 minutes).client_domain (
Optional
[str
]) – The domain of the client application requesting authenticationclient_signing_key (
Optional
[str
]) – The stellar account listed as the SIGNING_KEY on the client domain’s TOML file
- 返回类型
- 返回
A base64 encoded string of the raw TransactionEnvelope xdr struct for the transaction.
-
stellar_sdk.sep.stellar_web_authentication.
read_challenge_transaction
(challenge_transaction, server_account_id, home_domains, web_auth_domain, network_passphrase)[源代码]¶ Reads a SEP 10 challenge transaction and returns the decoded transaction envelope and client account ID contained within.
It also verifies that transaction is signed by the server.
It does not verify that the transaction has been signed by the client or that any signatures other than the servers on the transaction are valid. Use one of the following functions to completely verify the transaction:
- 参数
challenge_transaction (
str
) – SEP0010 transaction challenge transaction in base64.server_account_id (
str
) – public key for server’s account.home_domains (
Union
[str
,Iterable
[str
]]) – The home domain that is expected to be included in the first Manage Data operation’s string key. If a list is provided, one of the domain names in the array must match.web_auth_domain (
str
) – The home domain that is expected to be included as the value of the Manage Data operation with the ‘web_auth_domain’ key. If no such operation is included, this parameter is not used.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from. (ex. ‘Public Global Stellar Network ; September 2015’)
- Raises
InvalidSep10ChallengeError
- if the validation fails, the exception will be thrown.- 返回类型
-
stellar_sdk.sep.stellar_web_authentication.
verify_challenge_transaction_threshold
(challenge_transaction, server_account_id, home_domains, web_auth_domain, network_passphrase, threshold, signers)[源代码]¶ Verifies that for a SEP 10 challenge transaction all signatures on the transaction are accounted for and that the signatures meet a threshold on an account. A transaction is verified if it is signed by the server account, and all other signatures match a signer that has been provided as an argument, and those signatures meet a threshold on the account.
- 参数
challenge_transaction (
str
) – SEP0010 transaction challenge transaction in base64.server_account_id (
str
) – public key for server’s account.home_domains (
Union
[str
,Iterable
[str
]]) – The home domain that is expected to be included in the first Manage Data operation’s string key. If a list is provided, one of the domain names in the array must match.web_auth_domain (
str
) – The home domain that is expected to be included as the value of the Manage Data operation with the ‘web_auth_domain’ key. If no such operation is included, this parameter is not used.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from. (ex. ‘Public Global Stellar Network ; September 2015’)threshold (
int
) – The medThreshold on the client account.signers (
List
[Ed25519PublicKeySigner
]) – The signers of client account.
- Raises
InvalidSep10ChallengeError
: - The transaction is invalid according tostellar_sdk.sep.stellar_web_authentication.read_challenge_transaction()
. - One or more signatures in the transaction are not identifiable as the server account or one of the signers provided in the arguments. - The signatures are all valid but do not meet the threshold.- 返回类型
List
[Ed25519PublicKeySigner
]
-
stellar_sdk.sep.stellar_web_authentication.
verify_challenge_transaction_signed_by_client_master_key
(challenge_transaction, server_account_id, home_domains, web_auth_domain, network_passphrase)[源代码]¶ An alias for
stellar_sdk.sep.stellar_web_authentication.verify_challenge_transaction()
.- 参数
challenge_transaction (
str
) – SEP0010 transaction challenge transaction in base64.server_account_id (
str
) – public key for server’s account.home_domains (
Union
[str
,Iterable
[str
]]) – The home domain that is expected to be included in the first Manage Data operation’s string key. If a list is provided, one of the domain names in the array must match.web_auth_domain (
str
) – The home domain that is expected to be included as the value of the Manage Data operation with the ‘web_auth_domain’ key. If no such operation is included, this parameter is not used.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from. (ex. ‘Public Global Stellar Network ; September 2015’)
- Raises
InvalidSep10ChallengeError
- if the validation fails, the exception will be thrown.- 返回类型
-
stellar_sdk.sep.stellar_web_authentication.
verify_challenge_transaction_signers
(challenge_transaction, server_account_id, home_domains, web_auth_domain, network_passphrase, signers)[源代码]¶ Verifies that for a SEP 10 challenge transaction all signatures on the transaction are accounted for. A transaction is verified if it is signed by the server account, and all other signatures match a signer that has been provided as an argument. Additional signers can be provided that do not have a signature, but all signatures must be matched to a signer for verification to succeed. If verification succeeds a list of signers that were found is returned, excluding the server account ID.
- 参数
challenge_transaction (
str
) – SEP0010 transaction challenge transaction in base64.server_account_id (
str
) – public key for server’s account.home_domains (
Union
[str
,Iterable
[str
]]) – The home domain that is expected to be included in the first Manage Data operation’s string key. If a list is provided, one of the domain names in the array must match.web_auth_domain (
str
) – The home domain that is expected to be included as the value of the Manage Data operation with the ‘web_auth_domain’ key, if present.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from. (ex. ‘Public Global Stellar Network ; September 2015’)signers (
List
[Ed25519PublicKeySigner
]) – The signers of client account.
- Raises
InvalidSep10ChallengeError
: - The transaction is invalid according tostellar_sdk.sep.stellar_web_authentication.read_challenge_transaction()
. - One or more signatures in the transaction are not identifiable as the server account or one of the signers provided in the arguments.- 返回类型
List
[Ed25519PublicKeySigner
]
-
stellar_sdk.sep.stellar_web_authentication.
verify_challenge_transaction
(challenge_transaction, server_account_id, home_domains, web_auth_domain, network_passphrase)[源代码]¶ Verifies if a transaction is a valid SEP0010 v1.2 challenge transaction, if the validation fails, an exception will be thrown.
This function performs the following checks:
verify that transaction sequenceNumber is equal to zero;
verify that transaction source account is equal to the server’s signing key;
verify that transaction has time bounds set, and that current time is between the minimum and maximum bounds;
verify that transaction contains a single Manage Data operation and it’s source account is not null;
verify that transaction envelope has a correct signature by server’s signing key;
verify that transaction envelope has a correct signature by the operation’s source account;
- 参数
challenge_transaction (
str
) – SEP0010 transaction challenge transaction in base64.server_account_id (
str
) – public key for server’s account.home_domains (
Union
[str
,Iterable
[str
]]) – The home domain that is expected to be included in the first Manage Data operation’s string key. If a list is provided, one of the domain names in the array must match.web_auth_domain (
str
) – The home domain that is expected to be included as the value of the Manage Data operation with the ‘web_auth_domain’ key, if present.network_passphrase (
str
) – The network to connect to for verifying and retrieving additional attributes from. (ex. ‘Public Global Stellar Network ; September 2015’)
- Raises
InvalidSep10ChallengeError
- if the validation fails, the exception will be thrown.- 返回类型
SEP 0011: Txrep: human-readable low-level representation of Stellar transactions¶
-
stellar_sdk.sep.txrep.
to_txrep
(transaction_envelope)[源代码]¶ Generate a human-readable format for Stellar transactions.
MuxAccount is currently not supported.
Txrep is a human-readable representation of Stellar transactions that functions like an assembly language for XDR.
See SEP-0011
- 参数
transaction_envelope (
Union
[TransactionEnvelope
,FeeBumpTransactionEnvelope
]) – Transaction envelope object.- 返回类型
- 返回
A human-readable format for Stellar transactions.
-
stellar_sdk.sep.txrep.
from_txrep
(txrep, network_passphrase)[源代码]¶ Parse txrep and generate transaction envelope object.
MuxAccount is currently not supported.
Txrep is a human-readable representation of Stellar transactions that functions like an assembly language for XDR.
See SEP-0011
- 参数
- 返回类型
- 返回
A human-readable format for Stellar transactions.
Exceptions¶
-
class
stellar_sdk.sep.exceptions.
StellarTomlNotFoundError
[源代码]¶ If the SEP 0010 toml file not found, the exception will be thrown.
-
class
stellar_sdk.sep.exceptions.
InvalidFederationAddress
[源代码]¶ If the federation address is invalid, the exception will be thrown.
-
class
stellar_sdk.sep.exceptions.
FederationServerNotFoundError
[源代码]¶ If the federation address is invalid, the exception will be thrown.
-
class
stellar_sdk.sep.exceptions.
BadFederationResponseError
(response)[源代码]¶ If the federation address is invalid, the exception will be thrown.
- 参数
response – client response
-
class
stellar_sdk.sep.exceptions.
InvalidSep10ChallengeError
[源代码]¶ If the SEP 0010 validation fails, the exception will be thrown.
-
class
stellar_sdk.sep.exceptions.
AccountRequiresMemoError
(message, account_id, operation_index)[源代码]¶ AccountRequiresMemoError is raised when a transaction is trying to submit an operation to an account which requires a memo.
This error contains two attributes to help you identify the account requiring the memo and the operation where the account is the destination.
See SEP-0029 for more information.
资源¶
致谢¶
这份文档是在 Stellar JavaScript SDK 文档的基础上完成的。在此感谢所有向 Stellar 生态贡献过自己的一份力量的同学。