Exemplo n.º 1
0
def test_validate_deposit_not_already_given():
    try:
        asset = "XCP"
        client_key = lib.create_key(asset, netcode="XTN")
        client_pubkey = client_key["pubkey"]

        h2c_spend_secret = util.b2h(os.urandom(32))
        h2c_spend_secret_hash = util.hash160hex(
            h2c_spend_secret
        )

        params = {
            "asset": asset,
            "spend_secret_hash": h2c_spend_secret_hash
        }
        params = auth.sign_json(params, client_key["wif"])
        result = api.mph_request(**params)

        handle = result["handle"]
        hub_pubkey = result["pubkey"]
        c2h_spend_secret_hash = result["spend_secret_hash"]

        c2h_deposit_script = compile_deposit_script(
            client_pubkey, hub_pubkey, c2h_spend_secret_hash, 1337
        )

        # submit deposit
        next_revoke_secret_hash = util.hash160hex(util.b2h(os.urandom(32)))

        params = {
            "handle": handle,
            "deposit_script": c2h_deposit_script,
            "next_revoke_secret_hash": next_revoke_secret_hash
        }
        params = auth.sign_json(params, client_key["wif"])
        result = api.mph_deposit(**params)
        assert result is not None
        jsonschema.validate(result, DEPOSIT_RESULT_SCHEMA)

        # resubmit deposit
        next_revoke_secret_hash = util.hash160hex(util.b2h(os.urandom(32)))
        params = {
            "handle": handle,
            "deposit_script": c2h_deposit_script,
            "next_revoke_secret_hash": next_revoke_secret_hash
        }
        params = auth.sign_json(params, client_key["wif"])
        result = api.mph_deposit(**params)

        assert False
    except err.DepositAlreadyGiven:
        assert True
def test_validate_deposit_not_already_given():
    try:
        asset = "XCP"
        client_key = lib.create_key(asset, netcode="XTN")
        client_pubkey = client_key["pubkey"]

        h2c_spend_secret = util.b2h(os.urandom(32))
        h2c_spend_secret_hash = util.hash160hex(h2c_spend_secret)

        params = {"asset": asset, "spend_secret_hash": h2c_spend_secret_hash}
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        result = api.mph_request(**params)

        handle = result["handle"]
        hub_pubkey = result["pubkey"]
        c2h_spend_secret_hash = result["spend_secret_hash"]

        c2h_deposit_script = compile_deposit_script(client_pubkey, hub_pubkey,
                                                    c2h_spend_secret_hash,
                                                    1337)

        # submit deposit
        next_revoke_secret_hash = util.hash160hex(util.b2h(os.urandom(32)))

        params = {
            "handle": handle,
            "deposit_script": c2h_deposit_script,
            "next_revoke_secret_hash": next_revoke_secret_hash
        }
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        result = api.mph_deposit(**params)
        assert result is not None
        jsonschema.validate(result, DEPOSIT_RESULT_SCHEMA)

        # resubmit deposit
        next_revoke_secret_hash = util.hash160hex(util.b2h(os.urandom(32)))
        params = {
            "handle": handle,
            "deposit_script": c2h_deposit_script,
            "next_revoke_secret_hash": next_revoke_secret_hash
        }
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        result = api.mph_deposit(**params)

        assert False
    except err.DepositAlreadyGiven:
        assert True
Exemplo n.º 3
0
def complete_connection(handle, c2h_deposit_script,
                        next_revoke_secret_hash):

    hub_conn, h2c, expire_time, hub_wif = _load_incomplete_connection(
        handle, c2h_deposit_script
    )

    h2c_deposit_script = scripts.compile_deposit_script(
        h2c["payer_pubkey"], h2c["payee_pubkey"],
        h2c["spend_secret_hash"], expire_time
    )

    data = {
        "handle": handle,
        "expire_time": expire_time,
        "c2h_channel_id": hub_conn["c2h_channel_id"],
        "c2h_deposit_script": c2h_deposit_script,
        "c2h_deposit_address": util.script_address(
            c2h_deposit_script, netcode=etc.netcode
        ),
        "h2c_channel_id": hub_conn["h2c_channel_id"],
        "h2c_deposit_script": h2c_deposit_script,
        "h2c_deposit_address": util.script_address(
            h2c_deposit_script, netcode=etc.netcode
        ),
        "next_revoke_secret_hash": next_revoke_secret_hash,
    }

    data.update(create_secret())  # revoke secret

    db.complete_hub_connection(data)
    return (
        {
            "deposit_script": h2c_deposit_script,
            "next_revoke_secret_hash": data["secret_hash"]
        },
        hub_wif
    )
Exemplo n.º 4
0
def complete_connection(handle, c2h_deposit_script, next_revoke_secret_hash):

    hub_conn, h2c, expire_time, hub_key = _load_incomplete_connection(
        handle, c2h_deposit_script)

    h2c_deposit_script = scripts.compile_deposit_script(
        h2c["payer_pubkey"], h2c["payee_pubkey"], h2c["spend_secret_hash"],
        expire_time)

    data = {
        "handle":
        handle,
        "expire_time":
        expire_time,
        "c2h_channel_id":
        hub_conn["c2h_channel_id"],
        "c2h_deposit_script":
        c2h_deposit_script,
        "c2h_deposit_address":
        util.script_address(c2h_deposit_script, netcode=etc.netcode),
        "h2c_channel_id":
        hub_conn["h2c_channel_id"],
        "h2c_deposit_script":
        h2c_deposit_script,
        "h2c_deposit_address":
        util.script_address(h2c_deposit_script, netcode=etc.netcode),
        "next_revoke_secret_hash":
        next_revoke_secret_hash,
    }

    data.update(create_secret())  # revoke secret

    db.complete_hub_connection(data)
    return ({
        "deposit_script": h2c_deposit_script,
        "next_revoke_secret_hash": data["secret_hash"]
    }, hub_key["wif"])