Module jumpscale.clients.stellar.wrapped
Expand source code
# some wrapped stellar_sdk objects to modify the behavior
import stellar_sdk
from stellar_sdk import Account as stellarAccount
from stellar_sdk import Server as stellarServer
import time
from .exceptions import NoTrustLine, TooLate, UnAuthorized
class Account(stellarAccount):
def __init__(self, account_id: str, sequence: int, wallet) -> None:
stellarAccount.__init__(self, account_id, sequence)
self.wallet = wallet
def increment_sequence_number(self):
"""
Increments sequence number in this object by one.
"""
stellarAccount.increment_sequence_number(self)
self.wallet.sequence = self.sequence
self.wallet.sequencedate = int(time.time())
@property
def last_created_sequence_is_used(self):
return self.wallet.sequence <= self.sequence
class Server(stellarServer):
def __init__(self, horizon_url):
super().__init__(horizon_url)
def submit_transaction(self, transaction_envelope):
try:
return super().submit_transaction(transaction_envelope)
except stellar_sdk.exceptions.BadRequestError as e:
if e.status == 400:
resultcodes = e.extras["result_codes"]
if resultcodes["transaction"] == "tx_too_late":
raise TooLate()
if resultcodes["transaction"] == "tx_bad_auth":
raise UnAuthorized(e.extras["envelope_xdr"])
if resultcodes["transaction"] == "tx_failed":
if "op_no_trust" in resultcodes["operations"]:
raise NoTrustLine()
if "op_bad_auth" in resultcodes["operations"]:
raise UnAuthorized(e.extras["envelope_xdr"])
raise e
Classes
class Account (account_id: str, sequence: int, wallet)
-
The :class:
Account
object represents a single account on the Stellar network and its sequence number.Account tracks the sequence number as it is used by :class:
TransactionBuilder <stellar_sdk.transaction_builder.TransactionBuilder>
.Normally, you can get an :class:
Account
instance through :func:stellar_sdk.server.Server.load_account
or :func:stellar_sdk.server_async.ServerAsync.load_account
.An example::
from stellar_sdk import Keypair, Server server = Server(horizon_url="https://horizon-testnet.stellar.org") source = Keypair.from_secret("SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD") # <code>account</code> can also be a muxed account source_account = server.load_account(account=source.public_key)
See
Accounts <https://developers.stellar.org/docs/glossary/accounts/>
__ for more information.:param account: Account Id of the account (ex.
"GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA"
) or muxed account (ex."MBZSQ3YZMZEWL5ZRCEQ5CCSOTXCFCMKDGFFP4IEQN2KN6LCHCLI46AAAAAAAAAAE2L2QE"
) :param sequence: Current sequence number of the account. :param raw_data: Raw horizon response data.Expand source code
class Account(stellarAccount): def __init__(self, account_id: str, sequence: int, wallet) -> None: stellarAccount.__init__(self, account_id, sequence) self.wallet = wallet def increment_sequence_number(self): """ Increments sequence number in this object by one. """ stellarAccount.increment_sequence_number(self) self.wallet.sequence = self.sequence self.wallet.sequencedate = int(time.time()) @property def last_created_sequence_is_used(self): return self.wallet.sequence <= self.sequence
Ancestors
- stellar_sdk.account.Account
Instance variables
var last_created_sequence_is_used
-
Expand source code
@property def last_created_sequence_is_used(self): return self.wallet.sequence <= self.sequence
Methods
def increment_sequence_number(self)
-
Increments sequence number in this object by one.
Expand source code
def increment_sequence_number(self): """ Increments sequence number in this object by one. """ stellarAccount.increment_sequence_number(self) self.wallet.sequence = self.sequence self.wallet.sequencedate = int(time.time())
class Server (horizon_url)
-
Server handles the network connection to a
Horizon <https://developers.stellar.org/api/introduction/>
_ instance and exposes an interface for requests to that instance.An example::
from stellar_sdk import Server server = Server("https://horizon-testnet.stellar.org") resp = server.transactions().limit(10).order(desc=True).call() print(resp)
:param horizon_url: Horizon Server URL (ex.
"https://horizon-testnet.stellar.org"
for test network,"https://horizon.stellar.org"
for public network) :param client: Http client used to send the requestExpand source code
class Server(stellarServer): def __init__(self, horizon_url): super().__init__(horizon_url) def submit_transaction(self, transaction_envelope): try: return super().submit_transaction(transaction_envelope) except stellar_sdk.exceptions.BadRequestError as e: if e.status == 400: resultcodes = e.extras["result_codes"] if resultcodes["transaction"] == "tx_too_late": raise TooLate() if resultcodes["transaction"] == "tx_bad_auth": raise UnAuthorized(e.extras["envelope_xdr"]) if resultcodes["transaction"] == "tx_failed": if "op_no_trust" in resultcodes["operations"]: raise NoTrustLine() if "op_bad_auth" in resultcodes["operations"]: raise UnAuthorized(e.extras["envelope_xdr"]) raise e
Ancestors
- stellar_sdk.server.Server
- stellar_sdk.base_server.BaseServer
Methods
def submit_transaction(self, transaction_envelope)
-
Submits a transaction to the network.
:param transaction_envelope: :class:
stellar_sdk.transaction_envelope.TransactionEnvelope
object or base64 encoded xdr :param skip_memo_required_check: Allow skipping memo :return: the response from horizon :raises: :exc:ConnectionError <stellar_sdk.exceptions.ConnectionError>
:exc:NotFoundError <stellar_sdk.exceptions.NotFoundError>
:exc:BadRequestError <stellar_sdk.exceptions.BadRequestError>
:exc:BadResponseError <stellar_sdk.exceptions.BadResponseError>
:exc:UnknownRequestError <stellar_sdk.exceptions.UnknownRequestError>
:exc:AccountRequiresMemoError <stellar_sdk.sep.exceptions.AccountRequiresMemoError>
Expand source code
def submit_transaction(self, transaction_envelope): try: return super().submit_transaction(transaction_envelope) except stellar_sdk.exceptions.BadRequestError as e: if e.status == 400: resultcodes = e.extras["result_codes"] if resultcodes["transaction"] == "tx_too_late": raise TooLate() if resultcodes["transaction"] == "tx_bad_auth": raise UnAuthorized(e.extras["envelope_xdr"]) if resultcodes["transaction"] == "tx_failed": if "op_no_trust" in resultcodes["operations"]: raise NoTrustLine() if "op_bad_auth" in resultcodes["operations"]: raise UnAuthorized(e.extras["envelope_xdr"]) raise e