Exemple #1
0
def sync_input(handle, next_revoke_secret_hash, client_pubkey,
               payments, commit, revokes):
    connection = hub_connection(handle)
    validate.hash160(next_revoke_secret_hash)
    _channel_client(handle, client_pubkey)

    if revokes:
        jsonschema.validate(revokes, REVOKES_SCHEMA)
        # TODO check revokes match commits?

    if commit:
        jsonschema.validate(commit, COMMIT_SCHEMA)
        c2h_commit(handle, commit["rawtx"], commit["script"])

    payments = copy.deepcopy(payments) or []
    connection_terms = db.terms(id=connection["terms_id"])
    payments.insert(0, {
        "payee_handle": None,  # to hub
        "amount": connection_terms["sync_fee"],
        "token": "deadbeef"  # sync_fee
    })
    jsonschema.validate(payments, PAYMENT_SCHEMA)
    payer = _check_payment_payer(handle, payments, commit, revokes)
    for payment in payments:
        validate.is_hex(payment["token"])
        validate.is_quantity(payment["amount"])
        if payment["payee_handle"] is not None:
            validate.is_hex(payment["payee_handle"])
        _check_payment_payee(payer, payment)
Exemple #2
0
def sync_input(handle, next_revoke_secret_hash, client_pubkey, payments,
               commit, revokes):
    connection = hub_connection(handle)
    validate.hash160(next_revoke_secret_hash)
    _channel_client(handle, client_pubkey)

    if revokes:
        jsonschema.validate(revokes, REVOKES_SCHEMA)
        # TODO check revokes match commits?

    if commit:
        jsonschema.validate(commit, COMMIT_SCHEMA)
        c2h_commit(handle, commit["rawtx"], commit["script"])

    payments = copy.deepcopy(payments) or []
    connection_terms = db.terms(id=connection["terms_id"])
    payments.insert(
        0,
        {
            "payee_handle": None,  # to hub
            "amount": connection_terms["sync_fee"],
            "token": "deadbeef"  # sync_fee
        })
    jsonschema.validate(payments, PAYMENT_SCHEMA)
    payer = _check_payment_payer(handle, payments, commit, revokes)
    for payment in payments:
        validate.is_hex(payment["token"])
        validate.is_quantity(payment["amount"])
        if payment["payee_handle"] is not None:
            validate.is_hex(payment["payee_handle"])
        _check_payment_payee(payer, payment)
Exemple #3
0
def request_input(asset, pubkey, spend_secret_hash, hub_rpc_url):
    validate.pubkey(pubkey)
    validate.hash160(spend_secret_hash)
    asset_exists(asset)
    if hub_rpc_url:
        is_url(hub_rpc_url)

    # asset must be in terms
    terms = lib.terms().get(asset)
    if terms is None:
        raise err.AssetNotInTerms(asset)
Exemple #4
0
def request_input(asset, pubkey, spend_secret_hash, hub_rpc_url):
    validate.pubkey(pubkey)
    validate.hash160(spend_secret_hash)
    asset_exists(asset)
    if hub_rpc_url:
        is_url(hub_rpc_url)

    # asset must be in terms
    terms = lib.get_terms().get(asset)
    if terms is None:
        raise err.AssetNotInTerms(asset)
Exemple #5
0
def deposit_input(handle, deposit_script, next_revoke_secret_hash,
                  client_pubkey):

    connection = hub_connection(handle)
    if connection["complete"]:
        raise err.DepositAlreadyGiven(handle)

    # FIXME validate terms["expire_max"] >= expire time >= terms["expire_min"]
    validate.hash160(next_revoke_secret_hash)
    c2h_channel = _channel_client(handle, client_pubkey)
    expected_payee_pubkey = c2h_channel["payee_pubkey"]
    expected_spend_secret_hash = c2h_channel["spend_secret_hash"]
    validate.deposit_script(deposit_script, expected_payee_pubkey,
                            expected_spend_secret_hash)
Exemple #6
0
def deposit_input(handle, deposit_script,
                  next_revoke_secret_hash, client_pubkey):

    connection = hub_connection(handle)
    if connection["complete"]:
        raise err.DepositAlreadyGiven(handle)

    # TODO validate terms["expire_max"] >= expire time >= terms["expire_min"]
    validate.hash160(next_revoke_secret_hash)
    c2h_channel = _channel_client(handle, client_pubkey)
    expected_payee_pubkey = c2h_channel["payee_pubkey"]
    expected_spend_secret_hash = c2h_channel["spend_secret_hash"]
    validate.deposit_script(deposit_script, expected_payee_pubkey,
                            expected_spend_secret_hash)
Exemple #7
0
def sync_input(handle, next_revoke_secret_hash, client_pubkey, payments,
               commit, revokes):
    hub_connection(handle)
    validate.hash160(next_revoke_secret_hash)
    _channel_client(handle, client_pubkey)

    handles = []
    if payments:
        jsonschema.validate(payments, PAYMENT_SCHEMA)
        for payment in payments:
            validate.is_hex(payment["token"])
            validate.is_hex(payment["payee_handle"])
            validate.is_quantity(payment["amount"])
            handles.append(payment["payee_handle"])

    handles_exist(handles)

    if revokes:
        jsonschema.validate(revokes, REVOKES_SCHEMA)
        # FIXME check revokes match commits?

    if commit:
        jsonschema.validate(commit, COMMIT_SCHEMA)
        c2h_commit(handle, commit["rawtx"], commit["script"])