Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Api framework #1232

Merged
merged 57 commits into from
Jul 8, 2021
Merged

Feature: Api framework #1232

merged 57 commits into from
Jul 8, 2021

Conversation

k9ert
Copy link
Contributor

@k9ert k9ert commented Jun 14, 2021

This is a continuation of the PR #713 but moving the code to a non-master branch on my remote.
Will close the original PR. With this PR, Specter gets an API. The documentation is in the docs-folder.

The API is only activated if:

export SPECTER_API_ACTIVE=true

It's also active by default in Dev-Mode.

Apart from this new feature:

  • The test-framework needed some refactoring. Better some bug-fixing. The biggest change is that the bitcoin_regtest fixture changed scope from module to session. This means that the regtest-node is only be spun up exactly once for the tests.
  • Made an update of a bunch of dependecies
  • One of the dependencies (cryptography) needed a newer OS-version but the used cypress-image was based on an old debian-image. So i've created a new base-image docker/cypress-base-ubuntu-focal/Dockerfile which is ubuntu based and what is from now on the new base for docker/cypress-python/Dockerfile
  • The user.password is now a property which will automatically detect a plain-password and will do the necessary salted hashing
  • The wallet-enpoint for creating PSBT's got a refactoring and now we have psbt_creator.py very similiar to the wallet_imported.py. There are people calling that a "command-pattern".
  • The wallet_importer.py got some improvements as well
  • The wallet.py has a change where we're rather throwing an error than returning 0-balances. We should have more courage to raise SpecterErrors
  • I've changed the port-numbers of adhoc-bitcoind-nodes spun up in tests and i've wrapped them in try/raise to make sure that they will shutdown in any case of result of the tests (several tests).
  • Finally there is also a small bugfix for this:
    k9ert, [21.06.21 14:26]
[2021-06-18 14:36:39,975] INFO in wallet_manager: Wallet already in Specter, updating wallet: testwallet_ghost
[2021-06-18 14:36:40,107] ERROR in controller: Uncaught exception: 'dict object' has no attribute 'devices_signed'
[2021-06-18 14:36:40,108] ERROR in controller: Traceback (most recent call last):
  File "/tmp/cirrus-ci-build/.env/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/tmp/cirrus-ci-build/.env/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/tmp/cirrus-ci-build/.env/lib/python3.8/site-packages/flask_login/utils.py", line 269, in decorated_view
    return func(*args, **kwargs)
  File "/tmp/cirrus-ci-build/src/cryptoadvance/specter/server_endpoints/wallets.py", line 683, in send_new
    return render_template(
  File "/tmp/cirrus-ci-build/.env/lib/python3.8/site-packages/flask/templating.py", line 137, in render_template
    return _render(
  File "/tmp/cirrus-ci-build/.env/lib/python3.8/site-packages/flask/templating.py", line 120, in _render
    rv = template.render(context)
  File "/tmp/cirrus-ci-build/.env/lib/python3.8/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/tmp/cirrus-ci-build/.env/lib/python3.8/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/tmp/cirrus-ci-build/src/cryptoadvance/specter/templates/wallet/send/sign/wallet_send_sign_psbt.jinja", line 2, in top-level template code
    {% set tab = 'send' %}
  File "/tmp/cirrus-ci-build/src/cryptoadvance/specter/templates/wallet/components/wallet_tab.jinja", line 1, in top-level template code
    {% extends "base.jinja" %}
  File "/tmp/cirrus-ci-build/src/cryptoadvance/specter/templates/base.jinja", line 62, in top-level template code
    {% block main %}
  File "/tmp/cirrus-ci-build/src/cryptoadvance/specter/templates/wallet/components/wallet_tab.jinja", line 12, in block 'main'
    {% block content %}
  File "/tmp/cirrus-ci-build/src/cryptoadvance/specter/templates/wallet/send/sign/wallet_send_sign_psbt.jinja", line 199, in block 'content'
    <button type="button" class="btn signing-column-btn" id="{{ device.alias }}_tx_sign_btn" {{ 'disabled style=background-color:#303c49;' if device.alias in psbt["devices_signed"] else '' }}>
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'devices_signed'
[2021-06-18 14:36:40,149] INFO in wallet_manager: Finished updating wallet:  testwallet_ghost
[2021-06-18 14:36:40,149] INFO in wallet_manager: Wallet already in Specter, updating wallet:

pxsocs and others added 13 commits November 28, 2020 14:17
Included 3 API end points:

###/api/specter ["GET"]
Basic Specter info from app.specter class

###/api/full_txlist/ ["GET"]
Full Transaction list for all wallets

###"/api/wallet_info/<wallet_alias>/ ["GET"]
More detailed wallet info and transactions from the app.specter.wallet_manager class
Include `wallet.check_unused()`

Co-authored-by: benk10 <ben.kaufman10@gmail.com>
Made a few changes:
- Flattened the wallet list to be similar to full transaction list
- included versioning on url `/v1alpha/`
- Included `wallet.utxo` data
- Improved `safe_serialize` for better json output

Pending Updates:
- Create a separate file for API (as a blueprint)
- Explore using Flask-restful for improved authentication (downside is that it is another dependency - not sure if already a requirement for specter)
implementing Flask-Restful
@k9ert k9ert marked this pull request as draft June 14, 2021 10:29
@k9ert k9ert mentioned this pull request Jun 14, 2021
@k9ert k9ert requested a review from stepansnigirev June 30, 2021 16:43
@k9ert k9ert requested a review from ben-kaufman July 7, 2021 15:31
@ben-kaufman ben-kaufman merged commit e10cea0 into cryptoadvance:master Jul 8, 2021
@k9ert k9ert deleted the api_features branch February 22, 2023 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants