Skip to content

Commit

Permalink
Merge branch 'develop' into stateproof
Browse files Browse the repository at this point in the history
  • Loading branch information
algoidan committed Feb 10, 2022
2 parents 72e0950 + 0bdd947 commit 45b01c7
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 598 deletions.
47 changes: 39 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
version: 2.1

workflows:
version: 2
test:
jobs:
- unit-test
- integration-test
- docset

jobs:
build:
machine:
image: "ubuntu-2004:202104-01"
unit-test:
docker:
- image: python:3.7.9
steps:
- checkout
- run: pip install -r requirements.txt
- run: black --check .
- run: python3 test_unit.py
integration-test:
machine:
image: "ubuntu-2004:202104-01"
steps:
- checkout
- run: make docker-test
docset:
docker:
# NOTE: We might eventually need Docker authentication here.
- image: cimg/python:3.9
steps:
- checkout
- run:
# NOTE: We might add caching at `pip` level here.
command: |
pip3 install -r requirements.txt
black --check .
set -e
python3 test_unit.py
make docker-test
pip install -r requirements.txt
cd docs
pip install -r requirements.txt
pip install sphinx sphinx_rtd_theme doc2dash
make html
doc2dash --name py-algo-sdk --index-page index.html --online-redirect-url https://py-algorand-sdk.readthedocs.io/en/latest/ _build/html
tar -czvf py-algo-sdk.docset.tar.gz py-algo-sdk.docset
mv py-algo-sdk.docset.tar.gz /tmp
- store_artifacts:
path: /tmp/py-algo-sdk.docset.tar.gz
destination: py-algo-sdk.docset.tar.gz
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ venv.bak/
*.feature
test/features
test-harness

# Build files
py-algorand-sdk-*

# Pycharm
.idea
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
UNITS = "@unit.abijson or @unit.algod or @unit.applications or @unit.atomic_transaction_composer or @unit.dryrun or @unit.feetest or @unit.indexer or @unit.indexer.logs or @unit.offline or @unit.rekey or @unit.transactions.keyreg or @unit.responses or @unit.responses.231 or @unit.tealsign or @unit.transactions or @unit.transactions.payment"
unit:
behave --tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.tealsign or @unit.dryrun or @unit.applications or @unit.responses or @unit.transactions or @unit.transactions.keyreg or @unit.transactions.payment or @unit.responses.231 or @unit.feetest or @unit.indexer.logs or @unit.abijson or @unit.atomic_transaction_composer" test -f progress2
behave --tags=$(UNITS) test -f progress2

INTEGRATIONS = "@abi or @algod or @applications or @applications.verified or @assets or @auction or @c2c or @compile or @dryrun or @dryrun.testing or @indexer or @indexer.231 or @indexer.applications or @kmd or @rekey or @send.keyregtxn or @send"
integration:
behave --tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @indexer.applications or @send.keyregtxn or @rekey or @compile or @dryrun or @dryrun.testing or @applications or @applications.verified or @indexer.231 or @abi" test -f progress2
behave --tags=$(INTEGRATIONS) test -f progress2

docker-test:
./run_integration.sh
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# py-algorand-sdk
[![Build Status](https://travis-ci.com/algorand/py-algorand-sdk.svg?branch=master)](https://travis-ci.com/algorand/py-algorand-sdk)
[![PyPI version](https://badge.fury.io/py/py-algorand-sdk.svg)](https://badge.fury.io/py/py-algorand-sdk)
[![Documentation Status](https://readthedocs.org/projects/py-algorand-sdk/badge/?version=latest&style=flat)](https://py-algorand-sdk.readthedocs.io/en/latest)

[![Build Status](https://travis-ci.com/algorand/py-algorand-sdk.svg?branch=master)](https://travis-ci.com/algorand/py-algorand-sdk)
[![PyPI version](https://badge.fury.io/py/py-algorand-sdk.svg)](https://badge.fury.io/py/py-algorand-sdk)
[![Documentation Status](https://readthedocs.org/projects/py-algorand-sdk/badge/?version=latest&style=flat)](https://py-algorand-sdk.readthedocs.io/en/latest)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

A python library for interacting with the Algorand network.

## Installation

Run ```$ pip3 install py-algorand-sdk``` to install the package.
Run `$ pip3 install py-algorand-sdk` to install the package.

Alternatively, choose a [distribution file](https://pypi.org/project/py-algorand-sdk/#files), and run ```$ pip3 install [file name]```.
Alternatively, choose a [distribution file](https://pypi.org/project/py-algorand-sdk/#files), and run `$ pip3 install [file name]`.

## SDK Development

Install dependencies
* `pip install -r requirements.txt`

- `pip install -r requirements.txt`

Run tests
* `make docker-test`

- `make docker-test`

Format code:
* `black .`

- `black .`

## Quick start

Expand Down Expand Up @@ -50,18 +54,18 @@ Follow the instructions in Algorand's [developer resources](https://developer.al

Before running [example.py](https://github.com/algorand/py-algorand-sdk/blob/master/examples/example.py), start kmd on a private network or testnet node:

```
$ ./goal kmd start -d [data directory]
```bash
./goal kmd start -d [data directory]
```

Next, create a wallet and an account:

```
$ ./goal wallet new [wallet name] -d [data directory]
```bash
./goal wallet new [wallet name] -d [data directory]
```

```
$ ./goal account new -d [data directory] -w [wallet name]
```bash
./goal account new -d [data directory] -w [wallet name]
```

Visit the [Algorand dispenser](https://bank.testnet.algorand.network/) and enter the account address to fund your account.
Expand All @@ -71,7 +75,9 @@ Next, in [tokens.py](https://github.com/algorand/py-algorand-sdk/blob/master/exa
You're now ready to run example.py!

## Documentation

Documentation for the Python SDK is available at [py-algorand-sdk.readthedocs.io](https://py-algorand-sdk.readthedocs.io/en/latest/).

## License
py-algorand-sdk is licensed under a MIT license. See the [LICENSE](https://github.com/algorand/py-algorand-sdk/blob/master/LICENSE) file for details.

py-algorand-sdk is licensed under an MIT license. See the [LICENSE](https://github.com/algorand/py-algorand-sdk/blob/master/LICENSE) file for details.
1 change: 1 addition & 0 deletions algosdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from . import template
from . import transaction
from . import util
from . import v2client
from . import wallet
from . import wordlist

Expand Down
34 changes: 19 additions & 15 deletions algosdk/atomic_transaction_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,26 +495,27 @@ def execute(
raw_value = None
return_value = None
decode_error = None
tx_info = None

if i not in self.method_dict:
continue
# Return is void
if self.method_dict[i].returns.type == abi.Returns.VOID:
method_results.append(
ABIResult(
tx_id=tx_id,
raw_value=raw_value,
return_value=return_value,
decode_error=decode_error,
)
)
continue

# Parse log for ABI method return value
try:
resp = client.pending_transaction_info(tx_id)
confirmed_round = resp["confirmed-round"]
logs = resp["logs"] if "logs" in resp else []
tx_info = client.pending_transaction_info(tx_id)
if self.method_dict[i].returns.type == abi.Returns.VOID:
method_results.append(
ABIResult(
tx_id=tx_id,
raw_value=raw_value,
return_value=return_value,
decode_error=decode_error,
tx_info=tx_info,
)
)
continue

logs = tx_info["logs"] if "logs" in tx_info else []

# Look for the last returned value in the log
if not logs:
Expand Down Expand Up @@ -543,6 +544,7 @@ def execute(
raw_value=raw_value,
return_value=return_value,
decode_error=decode_error,
tx_info=tx_info,
)
method_results.append(abi_result)

Expand Down Expand Up @@ -689,16 +691,18 @@ def __init__(
raw_value: bytes,
return_value: Any,
decode_error: error,
tx_info: dict,
) -> None:
self.tx_id = tx_id
self.raw_value = raw_value
self.return_value = return_value
self.decode_error = decode_error
self.tx_info = tx_info


class AtomicTransactionResponse:
def __init__(
self, confirmed_round: int, tx_ids: List[str], results: ABIResult
self, confirmed_round: int, tx_ids: List[str], results: List[ABIResult]
) -> None:
self.confirmed_round = confirmed_round
self.tx_ids = tx_ids
Expand Down
14 changes: 14 additions & 0 deletions algosdk/future/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@


class Template:
"""
NOTE: This class is deprecated
"""

def get_address(self):
"""
Return the address of the contract.
Expand All @@ -19,6 +23,8 @@ def get_program(self):

class Split(Template):
"""
NOTE: This class is deprecated.
Split allows locking algos in an account which allows transfering to two
predefined addresses in a specified ratio such that for the given ratn and
ratd parameters we have:
Expand Down Expand Up @@ -156,6 +162,8 @@ def get_split_funds_transaction(contract, amount: int, sp):

class HTLC(Template):
"""
NOTE: This class is deprecated.
Hash Time Locked Contract allows a user to recieve the Algo prior to a
deadline (in terms of a round) by proving knowledge of a special value
or to forfeit the ability to claim, returning it to the payer.
Expand Down Expand Up @@ -291,6 +299,8 @@ def get_transaction(contract, preimage, sp):

class DynamicFee(Template):
"""
NOTE: This class is deprecated.
DynamicFee contract allows you to create a transaction without
specifying the fee. The fee will be determined at the moment of
transfer.
Expand Down Expand Up @@ -416,6 +426,8 @@ def sign_dynamic_fee(self, private_key):

class PeriodicPayment(Template):
"""
NOTE: This class is deprecated.
PeriodicPayment contract enables creating an account which allows the
withdrawal of a fixed amount of assets every fixed number of rounds to a
specific Algrorand Address. In addition, the contract allows to add
Expand Down Expand Up @@ -528,6 +540,8 @@ def get_withdrawal_transaction(contract, sp):

class LimitOrder(Template):
"""
NOTE: This class is deprecated.
Limit Order allows to trade Algos for other assets given a specific ratio;
for N Algos, swap for Rate * N Assets.
...
Expand Down
5 changes: 4 additions & 1 deletion algosdk/future/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ def verify(self, public_key):
try:
verify_key.verify(to_sign, base64.b64decode(self.sig))
return True
except BadSignatureError:
except (BadSignatureError, ValueError):
return False

return self.msig.verify(to_sign)
Expand Down Expand Up @@ -3178,6 +3178,9 @@ def create_dryrun(
# Make sure the application account is in the accounts array
accts.append(logic.get_application_address(app))

# Make sure the creator is added to accounts array
accts.append(app_info["params"]["creator"])

# Dedupe and filter None, add asset creator to accounts to include in dryrun
assets = [i for i in set(assets) if i]
for asset in assets:
Expand Down
6 changes: 6 additions & 0 deletions algosdk/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ def get_application_address(appID: int) -> str:
Returns:
str: The address corresponding to that application's escrow account.
"""
assert isinstance(
appID, int
), "(Expected an int for appID but got [{}] which has type [{}])".format(
appID, type(appID)
)

to_sign = constants.APPID_PREFIX + appID.to_bytes(8, "big")
checksum = encoding.checksum(to_sign)
return encoding.encode_address(checksum)
14 changes: 5 additions & 9 deletions algosdk/v2client/algod.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from urllib.request import Request, urlopen
import base64
import json
from urllib import parse
import urllib.error
import json
import base64
from .. import error
from .. import encoding
from .. import constants
from .. import future
import msgpack
from .. import util
from urllib.request import Request, urlopen

from .. import constants, encoding, error, future, logic, util

api_version_path_prefix = "/v2"

Expand Down
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
py-algo-sdk.docset
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.
black==21.9b0
glom==20.11.0
pytest==6.2.5
git+https://github.com/behave/behave
2 changes: 1 addition & 1 deletion test/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def encode_bytes(d):
encode_bytes(d[i])
else:
if isinstance(d[i], bytes):
d[i] = base64.b64encode(v).decode()
d[i] = base64.b64encode(d[i]).decode()
return d


Expand Down
Empty file added test/steps/__init__.py
Empty file.
Loading

0 comments on commit 45b01c7

Please sign in to comment.