manta.wallet

Library with a basic implementation of a Manta Wallet.

This module implements a basic Manta Wallet. An usage example of this class can be found in module manta.testing.wallet.

The API is implemented in the Wallet class and specifically by the Wallet.get_payment_request() and Wallet.send_payment() methods. The former requests the payment details to the Payment Processor while the latter creates an PaymentMessage and sends it to the Payment Processor that is managing the payment process in order to complete the payment process.

To work as expected, an object of the Wallet is created using the Wallet.factory() classmethod from a Manta URL:

import asyncio

from manta.wallet import Wallet

wallet = Wallet.factory("manta://developer.mantaproto.com/774747")

All the other operations are implemented as coroutines and so they need an asyncio loop to work correctly. The first operation needed is to retrieve the payment details:

loop = asyncio.get_event_loop()

envelope = loop.run_until_complete(wallet.get_payment_request())
payment_req = envelope.unpack()

…then a concrete wallet implementation is supposed to add the transaction on the block chain and then send these informations back to the Payment Processor. We here simulate it with:

loop.run_until_complete(wallet.send_payment(transaction_hash=block, crypto_currency='NANO'))

Like what happens with the Store class, the progress of the payment session can be monitored by looking into the AckMessage instances collected by the wallet.acks queue. The payment is considered complete when a received ack has status == PAID:

from manta.messages import Status

async def wait_for_complete(wallet):
    while True:
        ack = await wallet.acks.get()
        if ack.status is Status.PAID:
            break
    return ack

final_ack = loop.run_until_complete(wait_for_complete(wallet))

Reference

class manta.wallet.Wallet(url, session_id, host='localhost', port=1883)[source]

Implements a Manta Wallet. This class needs an asyncio loop to run correctly as some of its features are implemented as coroutines.

This is usually instantiated from a Manta URL using the factory() classmethod.

Parameters:
  • url (str) – a string containing a Manta URL
  • session_id (str) – a session_id
  • host (str) – MQTT broker IP addresses
  • port (int) – optional port number of the broker service
Attributes:
  • acks – queue of AckMessage instances
  • loop – the asyncio loop that manages the asynchronous parts of this object
  • session_idsession_id of the ongoing session, if any
close()[source]

Disconnect and stop MQTT client’s processing loop.

coroutine connect()[source]

Connect to the MQTT broker and wait for the connection confirmation.

This is a coroutine.

classmethod factory(url)[source]

This creates an instance from a Manta URL. Can be None if the URL is invalid.

Parameters:url (str) – manta url (ex. manta://developer.mantaproto.com/2848839943)
Return type:Optional[Wallet]
Returns:a new configured but unconnected instance
coroutine get_certificate(self)[source]

Get Payment Processor’s certificate retained by the MQTT broker service.

This is a coroutine

Return type:Certificate
coroutine get_payment_request(self, crypto_currency='all')[source]

Get the PaymentRequestMessage for specific crypto currency, or all to obtain informations about all the supported crypto currencies.

Parameters:crypto_currency (str) – crypto to request payment for (ex. ‘NANO’)
Return type:PaymentRequestEnvelope
Returns:The Payment Request Envelope. It’s all by default

This is a coroutine

static parse_url(url)[source]

Convenience method to check if Manta url is valid :type url: str :param url: manta url (ex. manta://developer.mantaproto.com/2848839943)

Return type:Optional[Match[AnyStr]]
Returns:A match object
coroutine send_payment(self, transaction_hash, crypto_currency)[source]

Send payment info

Parameters:
  • transaction_hash (str) – the hash of transaction sent to blockchain
  • crypto_currency (str) – the crypto currency used for transaction

This is a coroutine