Exemplo n.º 1
0
def connect(asset, quantity, expire_time=1024, delay_time=2):
    """ Create micropayment connection with hub.

    Args:
        asset (str): Asset to exchange in connection.
        quantity (str): Quantity to be bound in the deposit, this determins
                        the maximum amount that can bet transferred.
        expire_time (int, default=1024): Time in blocks after which the
                                         deposit expires and can be recovered.
        delay_time (int, default=2): Blocks hub must wait before payout,
                                     protects against publish revoked commits.

    Returns:
        {
            "send_deposit_txid": "published bitcoin transaction id",
            "handle": "handle for created connection"
        }
    """

    # connect to hub
    client = Mph(_hub_api())
    send_deposit_txid = client.connect(quantity,
                                       expire_time=expire_time,
                                       asset=asset,
                                       delay_time=delay_time)

    # save to data
    data = _load_data()
    data["connections"][client.handle] = client.serialize()
    _save_data(data)

    return {"send_deposit_txid": send_deposit_txid, "handle": client.handle}
def test_serialization():
    auth_wif = util.gen_funded_wif("XCP", 1000000, 1000000)

    hub_api = util.MockAPI(auth_wif=auth_wif)
    client_alpha = Mph(hub_api)
    serialized_alpha = client_alpha.serialize()

    client_beta = Mph.deserialize(api=hub_api, data=serialized_alpha)
    serialized_beta = client_beta.serialize()

    assert serialized_alpha == serialized_beta
Exemplo n.º 3
0
def connect(asset, quantity, expire_time=1024, delay_time=2):
    """ Create micropayment connection with hub.

    Args:
        asset (str): Asset to exchange in connection.
        quantity (str): Quantity to be bound in the deposit, this determins
                        the maximum amount that can bet transferred.
        expire_time (int, default=1024): Time in blocks after which the
                                         deposit expires and can be recovered.
        delay_time (int, default=2): Blocks hub must wait before payout,
                                     protects against publish revoked commits.

    Returns:
        {
            "send_deposit_txid": "published bitcoin transaction id",
            "handle": "handle for created connection"
        }
    """

    # check if funds available
    _status = status()
    _quantity = _status["wallet"]["balances"].get(asset, 0)
    err_msg = "Insufficient {0}: {1} required, {2} available!"
    assert _quantity > quantity, err_msg.format(asset, quantity, _quantity)

    # connect to hub
    client = Mph(_hub_api())
    send_deposit_txid = client.connect(quantity, expire_time=expire_time,
                                       asset=asset, delay_time=delay_time)

    # save to data
    data = _load_data()
    data["connections"][client.handle] = client.serialize()
    _save_data(data)

    return {
        "send_deposit_txid": send_deposit_txid,
        "handle": client.handle
    }