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

Make the project packageable #59

Merged
merged 14 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,41 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install pip
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with black
- name: Lint all code with black
run: |
pip install black
# stop the build if the code was not reformatted by black
black . --check
- name: Lint with flake8
- name: Lint all code with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
# stop the build if there are syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --ignore=E203,E221,E261,E731,W503 --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
# exit-zero treats all errors as warnings
flake8 . --count --exit-zero --ignore=E203,E221,E261,E731,W503 --max-complexity=10 --max-line-length=88 --statistics
- name: Install the poetry tool
run: |
pip install pytest
cd ..
python -m pytest ./tinydecred/tests/unit/
pip install poetry
- name: Install the decred package and its dependencies (including pytest)
working-directory: ./decred/
run: |
poetry install
- name: Test the decred package with pytest
working-directory: ./decred/
run: |
poetry run pytest ./tests/unit/
- name: Build the decred package
working-directory: ./decred/
run: |
poetry build
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
examples/testnet
decred/dist
tinywallet/dist
decred/poetry.lock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you're not ignoring the tinywallet/poetry.lock. Is that intentional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, well spotted. tinywallet/poetry.lock is indeed committed, decred/poetry.lock is not. The idea is to commit lock files for applications, but not for libraries.

You want to commit the lock file for apps so that a build always uses the same versions of the dependencies (and their dependencies), and therefore is reproducible.

You don't want to commit the lock file for libraries because then you would have multiple lock files for different libraries and for the app that uses them, potentially conflicting among them.

The libraries will specify the version intervals for their dependencies in their pyproject.toml or requirements.txt files; Poetry will respect those intervals, but will disregard any libraries' lock files. The only lock file that counts is the app one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably nothing, but using the provided tinywallet/poetry.lock file threw an error at me:

[joe@hyrule tinywallet]$ poetry install
Installing dependencies from lock file
Warning: The lock file is not up to date with the latest changes in pyproject.toml. You may be getting outdated dependencies. Run update to update them.

[SolverProblemError]
Because tinywallet depends on pyqt5 (=5.12.3) which doesn't match any versions, version solving failed.

Running poetry update solved the problem, but it gave me a rather large diff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, forgot to update the dependencies and the lock file. Thanks.

__pycache__/
.pytest_cache
.coverage
.venv
*.egg-info
*.sublime-project
*.sublime-workspace
examples/testnet
.coverage
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Contribution guidelines

Thank you for contributing to this project! The developers are part of the
[Decred community](https://decred.org/community/) and coordinate in a
[chat](https://chat.decred.org/#/room/#tinydecred:decred.org) on the
[Matrix](https://matrix.org/) platform, you'll need a (free) account to access
it.

## Bugs and new features

If you found a bug, before creating an issue please search among the
[open ones](https://github.com/decred/tinydecred/issues). Please add as many
useful details as you can.

If you'd like to request a new feature, either create an issue (again, after
searching first) or chat with us on Matrix (see above).

## Development

The [Poetry](https://python-poetry.org/) tool is used for dependency management
and packaging. You'll reformat your changes with the
[Black](https://black.readthedocs.io/) tool and run tests using
[pytest](https://www.pytest.org/).

Before each pull request is merged, a Github workflow action is run to make
sure that the changes meet some minimum requirements. The action definition
[file](./.github/workflows/python.yml) is a useful summary of the commands
you'll run while developing.

## More information

Please find more information in the dcrd
[contribution guidelines](https://github.com/decred/dcrd/blob/master/docs/code_contribution_guidelines.md).
88 changes: 14 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,23 @@
tinydecred
==========
# tinydecred

[![Build Status](https://github.com/decred/tinydecred/workflows/Build%20and%20Test/badge.svg)](https://github.com/decred/tinydecred/actions)
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](https://copyfree.org/)

## Overview
TinyDecred is a Python 3 toolkit that can be used to integrate
[Decred](https://decred.org/) into Python projects.

A Python 3 Decred toolkit. The modules in TinyDecred can be used to integrate
Decred into Python projects. Everything needed to create wallets to send and
receive DCR.
The [`decred`](./decred) package contains everything needed to create wallets
to send and receive DCR.

## Features
The [`tinywallet`](./tinywallet) package contains a wallet based on the
`decred` toolkit.

1. Pure-Python secp256k1 elliptic curve.

1. Serializable and de-serializable python versions of important types
from the dcrd/wire package: `MsgTx`, `BlockHeader`, `OutPoint`, etc.

1. BIP-0044 keys. Account creation and management. PGP mnemonic seeds.

1. Network parameters for mainnet, testnet3, and simnet.

1. Clients for the dcrdata block explorer API (websockets, pubsub, HTTP).

1. Experimental PyQt5 light wallet.

## Installation

Install by cloning the git repo.
The parent directory of *tinydecred* will need to be in `sys.path`.
You can add it by setting the `PYTHONPATH` environment variable.
Alternatively, you can put a symlink to the *tinydecred* directory in your
Python installation's *lib/site-packages/* directory or other `sys.path`
directory.

All dependencies are available through PyPi.

```
pip3 install -r requirements.txt
```

though depending on your setup, you may need `sudo`, and `pip3` might be `pip`.

You're probably okay to use newer versions of PyQt5, but `5.9.2` has been
remarkably stable.

## Examples

In the examples directory, there are scripts for creating and using wallets,
and for using dcrdata and matplotlib to plot Decred network data.

## TinyDecred GUI Wallet

TinyDecred is the name of the package as well as the experimental light wallet
GUI application.
**The light wallet is experimental, and should not be used on mainnet.**

To start the wallet, navigate to the `tinydecred` package directory, and run

```
python app.py --testnet
```

The wallet runs as a system-tray application, of which the major difference is
that "closing" the wallet actually just removes the entry from the taskbar and
minimizes the window "to the system tray".
The wallet can then be "opened" again through the icon in the system tray.

![alt text][screenshot]

TinyDecred is pretty small.
Like Decred, it's meant to be an omnipresent yet largely invisible and
unobtrusive part of your digital environment.
The small dialog size keeps user interactions focused.
Bells and whistles are minimized in favor of simplicity whenever possible.
Blockchain mechanics are invisible.
The goal is to make using Decred easier than pulling change out of your pocket.
Each package may be installed from the [Python Package Index](https://pypi.org/)
using the [`pip`](https://pip.pypa.io/) command as usual.

## Roadmap

In no particular order
In no particular order:

- Staking
- Schnorr signatures and Edwards curve
Expand All @@ -88,4 +26,6 @@ In no particular order
- Decred DEX integration
- Lightning network

[screenshot]: https://user-images.githubusercontent.com/6109680/62095772-08b4ce80-b247-11e9-81ae-66931ebb07be.png
## Contributing

See the [contribution guidelines](./CONTRIBUTING.md).
File renamed without changes.
36 changes: 23 additions & 13 deletions pydecred/README.md → decred/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
## PyDecred
# decred

PyDecred is a set of modules that enable Decred-compatible blockchain
applications. The **dcrdata** module contains a dcrdata client and a TinyDecred
*Blockchain API* implementation.
The `decred` package contains everything needed to create
[Decred](https://decred.org/) applications in Python.

The **wire** module mirrors it's dcrd golang counterpart, providing serializable
transactions and blocks.
## Features

Network parameters are implemented as modules **mainnet**, **testnet**, and
**simnet**.
1. Pure-Python secp256k1 elliptic curve.

1. Serializable and de-serializable python versions of important types
from the `dcrd/wire` package: `MsgTx`, `BlockHeader`, `OutPoint`, etc.

1. BIP-0044 keys. Account creation and management. PGP mnemonic seeds.

1. Network parameters for mainnet, testnet3, and simnet.

1. Clients for the dcrdata block explorer API (websockets, pubsub, HTTP).

## DcrdataClient

DcrdataClient is a dcrdata API client written in Python 3.

The constructor takes a single argument, which is the path to a dcrdata server,
including protocol, e.g. `https://explorer.dcrdata.org`. The available endpoints
are gathered from the server when the client is created.
including protocol, e.g. `https://explorer.dcrdata.org/`. The available
endpoints are gathered from the server when the client is created.

```
from tinydecred.pydecred.dcrdata import DcrdataClient
from decred.dcr.dcrdata import DcrdataClient
import json

client = DcrdataClient("https://explorer.dcrdata.org")
Expand All @@ -33,13 +39,17 @@ The acquired list does not include some endpoints, particularly the Insight API
endpoints.

You can print an endpoint guide to the console with `client.endpointGuide()`,

or a Python list of URLs is returned from `client.endpointList()`.

Depending on the version of dcrdata they are running, different servers might
have different sets of endpoints.

### Examples
## Examples

In the [`examples`](./examples) directory there are scripts for creating and
using wallets, and for using dcrdata and matplotlib to plot Decred network data.

Here are some more examples:

```
def dumpResponse(obj):
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions config.py → decred/decred/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

from appdirs import AppDirs

from tinydecred.pydecred import nets
from tinydecred.util import helpers
from decred.dcr import nets
from decred.util import helpers


# Set the data directory in a OS-appropriate location.
_ad = AppDirs("TinyDecred", False)
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions crypto/crypto.py → decred/decred/crypto/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from blake256.blake256 import blake_hash
import nacl.secret

from tinydecred.util.encode import ByteArray
from tinydecred.crypto import rando
from tinydecred.crypto.secp256k1.curve import curve as Curve, PublicKey, PrivateKey
from tinydecred.util import encode
from decred.util import encode
from decred.util.encode import ByteArray
from . import rando
teknico marked this conversation as resolved.
Show resolved Hide resolved
from .secp256k1.curve import curve as Curve, PublicKey, PrivateKey


KEY_SIZE = 32
Expand Down
5 changes: 3 additions & 2 deletions crypto/mnemonic.py → decred/decred/crypto/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
PGP-based mnemonic seed generation.
"""

from tinydecred.util.encode import ByteArray
from tinydecred.crypto.crypto import sha256ChecksumByte
from decred.util.encode import ByteArray
from .crypto import sha256ChecksumByte


alternatingWords = """aardvark
adroitness
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
dcrd golang version.
"""

from tinydecred.util.encode import ByteArray
from tinydecred.crypto.rando import generateSeed
from tinydecred.crypto.secp256k1.field import FieldVal, BytePoints
from decred.util.encode import ByteArray
from decred.crypto.rando import generateSeed
from .field import BytePoints, FieldVal


COORDINATE_LEN = 32
PUBKEY_COMPRESSED_LEN = COORDINATE_LEN + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from base64 import b64decode
from zlib import decompress as zdecompress

from tinydecred.util.encode import ByteArray
from tinydecred.crypto.secp256k1.bytepoints import secp256k1BytePoints
from decred.util.encode import ByteArray
from .bytepoints import secp256k1BytePoints


# Constants used to make the code more readable.
twoBitsMask = 0x03
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions pydecred/account.py → decred/decred/dcr/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
See LICENSE for details
"""

from tinydecred.util import helpers, encode
from tinydecred.crypto import opcode, crypto
from tinydecred.pydecred import txscript
from tinydecred.pydecred.vsp import VotingServiceProvider
from tinydecred.pydecred import nets
from decred.crypto import opcode, crypto
from decred.util import encode, helpers
from . import nets, txscript
from .vsp import VotingServiceProvider


log = helpers.getLogger("DCRACCT")

Expand Down
9 changes: 6 additions & 3 deletions pydecred/calc.py → decred/decred/dcr/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

Some network math.
"""
import math

import bisect
from tinydecred.util import helpers
from tinydecred.pydecred import constants as C, mainnet
import math

from decred.util import helpers
from . import constants as C, mainnet


NETWORK = mainnet
MODEL_DEVICE = {
Expand Down
2 changes: 2 additions & 0 deletions pydecred/constants.py → decred/decred/dcr/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

Just some constants.
"""

import os


PYDECRED_PACKAGEDIR = os.path.dirname(os.path.realpath(__file__))
FAVICON = os.path.join(PYDECRED_PACKAGEDIR, "favicon-32x32.png")
LOGO = os.path.join(PYDECRED_PACKAGEDIR, "logo.svg")
Expand Down
Loading