Integrations¶
Polaris does most of the work implementing SEP-24. However, Polaris simply
doesn’t have the information it needs to interface with an anchor’s partner
financial entities. This is where DepositIntegration
and
WithdrawalIntegration
come in.
Polaris expects developers to override these base class methods and register
them using register_integrations()
. The code will
be executed from inside Polaris Django Commands, which should be run in a
separate process from the web server running Polaris. See the
stellar-anchor-server project, specifically the docker-compose.yml
,
for an example on how to run the Polaris web server and management commands.
-
class
polaris.integrations.transactions.
DepositIntegration
[source]¶ The container class for deposit integration functions.
Subclasses must be registered with Polaris by passing it to
polaris.integrations.register_integrations()
.-
classmethod
after_deposit
(transaction: polaris.models.Transaction)[source]¶ Use this function to perform any post-processing of transaction after its been executed on the Stellar network. This could include actions such as updating other django models in your project or emailing users about completed deposits. Overriding this function is not required.
Parameters: transaction – a polaris.models.Transaction
that was executed on the Stellar network
-
classmethod
poll_pending_deposits
(pending_deposits: django.db.models.query.QuerySet) → List[polaris.models.Transaction][source]¶ OVERRIDE REQUIRED
This function should poll the financial entity for the state of all pending_deposits transactions and return the ones ready to be executed on the Stellar network.
For every transaction that is returned, Polaris will submit it to the Stellar network. If a transaction was completed on the network, the overridable
after_deposit()
function will be called, however overriding this function is optional.If the Stellar network is unable to execute a transaction returned from this function, it’s status will be marked as
pending_stellar
and itsstatus_message
attribute will be assigned a description of the problem that occurred.pending_deposits is a QuerySet of the form
Transactions.object.filter( kind=Transaction.KIND.deposit, status=Transaction.STATUS.pending_user_transfer_start )
If you have many pending deposits, you may way want to batch the retrieval of these objects to improve query performance and memory usage.
Parameters: pending_deposits – a django Queryset for pending Transactions
-
classmethod
-
class
polaris.integrations.transactions.
WithdrawalIntegration
[source]¶ The container class for withdrawal integration functions
Subclasses must be registered with Polaris by passing it to
polaris.integrations.register_integrations()
.-
classmethod
process_withdrawal
(response: Dict[KT, VT], transaction: polaris.models.Transaction)[source]¶ OVERRIDE REQUIRED
This method should implement the transfer of the amount of the anchored asset specified by transaction to the user who requested the withdrawal.
If an error is raised from this function, the transaction’s status will be changed to
error
and itsstatus_message
will be assigned to the message raised with the exception.Parameters: - response – a response body returned from Horizon for the transactions for account endpoint
- transaction – a
polaris.models.Transaction
instance to process
-
classmethod
-
polaris.integrations.
register_integrations
(deposit: polaris.integrations.transactions.DepositIntegration = None, withdrawal: polaris.integrations.transactions.WithdrawalIntegration = None)[source]¶ Registers user-defined subclasses of
WithdrawalIntegration
andDepositIntegration
with Polaris.Run this function in the relevant Django AppConfig.ready() function:
from django.apps import AppConfig class PolarisIntegrationApp(AppConfig): name = 'Polaris Integration' verbose_name = name def ready(self): from polaris.integrations import register_integrations from myapp.integrations import (MyDepositIntegration, MyWithdrawalIntegration) register_integrations( deposit=MyDepositIntegration(), withdrawal=MyWithdrawalIntegration() )
These integration classes provide a structured interface for implementing user-defined logic used by Polaris, specifically for deposit and withdrawal flows. See the integration classes for more information on implementation.
Parameters: - deposit – a
DepositIntegration
subclass object to be used by Polaris - withdrawal – a
WithdrawalIntegration
subclass object to be used by Polaris
Raises: - ValueError – missing argument(s)
- TypeError – arguments are not subclasses of DepositIntegration or Withdrawal
- deposit – a