Browse Source

0.7.2: --version, cashaddr support

tags/0.7.2
Teran McKinney 2 years ago
parent
commit
a7294c375e
5 changed files with 33 additions and 15 deletions
  1. +1
    -0
      .gitignore
  2. +2
    -2
      README.md
  3. +1
    -1
      sporestack/__init__.py
  4. +22
    -12
      sporestack/cli.py
  5. +7
    -0
      test_cli.py

+ 1
- 0
.gitignore View File

@@ -4,3 +4,4 @@ build
dist
*.egg-info
.eggs
__pycache__

+ 2
- 2
README.md View File

@@ -2,7 +2,7 @@

## Installation

Python 3 is recommended.
Python 3 is recommended, Python 2 support will be removed entirely.

* `pip3 install sporestack || pip install sporestack`

@@ -24,7 +24,7 @@ Spawn a tor relay for 28 days:
$ sporestack spawn --launch tor_relay
```

Spawn and pay with Bitcoin Cash:
Spawn and pay with Bitcoin Cash (the default):

```
$ sporestack spawn --currency bch


+ 1
- 1
sporestack/__init__.py View File

@@ -15,7 +15,7 @@ try:
except ImportError:
from urllib2 import urlopen, HTTPError

__version__ = '0.7.1'
__version__ = '0.7.2'

DEFAULT_ENDPOINT = 'https://sporestack.com'



+ 22
- 12
sporestack/cli.py View File

@@ -36,6 +36,25 @@ def stderr(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)


def payment_uri(currency, address, satoshis):
"""
Returns a payment URI from the currency, address, and satoshis.
"""
amount = "{0:.8f}".format(satoshis *
0.00000001)
if currency == 'btc':
uri = 'bitcoin:{}?amount={}'.format(address, amount)
elif currency == 'bch':
# Add support for legacy address format and new cashaddr format.
if ':' in address:
uri = '{}?amount={}'.format(address, amount)
else:
uri = 'bitcoincash:{}?amount={}'.format(address, amount)
else:
raise ValueError('Currency must be one of: btc, bch')
return uri


def ttl(end_of_life):
"""
Human readable time remaining.
@@ -103,19 +122,10 @@ def handle_payment(uuid, address, satoshis, wallet_command, currency):
if os.system(full_wallet_command) != 0:
raise
return True
amount = "{0:.8f}".format(satoshis *
0.00000001)
if currency == 'btc':
uri = 'bitcoin:{}?amount={}'.format(address, amount)
elif currency == 'bch':
uri = 'bitcoincash:{}?amount={}'.format(address, amount)
else:
raise ValueError('Currency must be one of: btc, bch')
uri = payment_uri(currency, address, satoshis)
premessage = '''UUID: {}
Bitcoin URI: {}
Pay with Bitcoin *within an hour*. QR code will change every so often but the
current and previous QR codes are both valid for about an hour. The faster you
make payment, the better. Pay *exactly* the specified amount. No more, no less.
Payment URI: {}
Pay *exactly* the specified amount. No more, no less.
Resize your terminal and try again if QR code above is not readable.
Press ctrl+c to abort.'''
message = premessage.format(uuid, uri)


+ 7
- 0
test_cli.py View File

@@ -0,0 +1,7 @@
import sporestack.cli as cli


def test_payment_uri():
assert cli.payment_uri('btc', '13i2BNi49URkZXgVwkoA7nKT1TSE97uWyY', 10000) == 'bitcoin:13i2BNi49URkZXgVwkoA7nKT1TSE97uWyY?amount=0.00010000'
assert cli.payment_uri('bch', '13i2BNi49URkZXgVwkoA7nKT1TSE97uWyY', 10000) == 'bitcoincash:13i2BNi49URkZXgVwkoA7nKT1TSE97uWyY?amount=0.00010000'
assert cli.payment_uri('bch', 'bitcoincash:qqwmyjjplsqwltkcgyeagqpjspaaksz3qggnfug7gy', 10000) == 'bitcoincash:qqwmyjjplsqwltkcgyeagqpjspaaksz3qggnfug7gy?amount=0.00010000'

Loading…
Cancel
Save