Skip to content

Commit 1613ebe

Browse files
author
Yuanheng Wang
committed
Fix ExtendedSigning key generation from HDWallet
2 parents a77430d + 79848b4 commit 1613ebe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2116
-870
lines changed

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[run]
22
branch = True
33
omit =
4-
pycardano/crypto/*
4+
pycardano/crypto/bech32.py
55

66
[report]
77
# Regexes for lines to exclude from consideration

.github/donate_addr.png

2.77 KB
Loading
File renamed without changes.

.github/workflows/main.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Build
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: "**"
66
pull_request:
77
branches: ["main"]
88
types: [opened, reopened, edited, synchronize]
@@ -14,7 +14,11 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest, macos-latest]
17-
python-version: [3.7, 3.8, 3.9, '3.10']
17+
python-version: [3.7, 3.8, 3.9, '3.10', '3.11']
18+
exclude:
19+
# excludes python 3.11 on macOS
20+
- os: macos-latest
21+
python-version: '3.11'
1822

1923
steps:
2024
- uses: actions/checkout@v3
@@ -28,16 +32,16 @@ jobs:
2832
- name: Install dependencies
2933
run: |
3034
poetry install
31-
- name: Lint with flake8
32-
run: |
33-
poetry run flake8 pycardano
3435
- name: Run unit tests
3536
run: |
3637
poetry run pytest --doctest-modules --ignore=examples --cov=pycardano --cov-config=.coveragerc --cov-report=xml
3738
- name: "Upload coverage to Codecov"
38-
uses: codecov/codecov-action@v2
39+
uses: codecov/codecov-action@v3
3940
with:
4041
fail_ci_if_error: true
42+
- name: Run static analyses
43+
run: |
44+
make qa
4145
4246
continuous-integration:
4347
runs-on: ${{ matrix.os }}
@@ -59,3 +63,15 @@ jobs:
5963
- name: Run integration tests
6064
run: |
6165
cd integration-test && ./run_tests.sh
66+
67+
- name: Dump docker logs
68+
if: failure()
69+
run: |
70+
cd integration-test && docker-compose logs --no-color > integration-test.log
71+
72+
- name: Upload integration-test.log
73+
if: failure()
74+
uses: actions/upload-artifact@v2
75+
with:
76+
name: integration-test.log
77+
path: integration-test/integration-test.log

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
.coverage
33
cov_html
44
docs/build
5-
dist
5+
dist
6+
7+
# IDE
8+
.idea
9+
.code

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.7.0] - 2022-10-16
8+
9+
### Added
10+
11+
- Support HDWallets and mnemonic phrases. (#85)
12+
13+
### Fixed
14+
15+
- Fix key error when there are duplicates in reference scripts.
16+
- If merging change into existing outputs is enabled, do not enforce min_utxo on changes.
17+
- Make script estimation more accurate.
18+
719
## [0.6.3] - 2022-10-02
820

921
### Added

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean clean-test clean-pyc clean-build format test help docs
1+
.PHONY: cov cov-html clean clean-test clean-pyc clean-build qa format test test-single help docs
22
.DEFAULT_GOAL := help
33

44
define BROWSER_PYSCRIPT
@@ -57,8 +57,13 @@ clean-test: ## remove test and coverage artifacts
5757
test: ## runs tests
5858
poetry run pytest -s -vv -n 4
5959

60-
qa: ## runs static analysis with flake8
60+
test-single: ## runs tests with "single" markers
61+
poetry run pytest -s -vv -m single
62+
63+
qa: ## runs static analyses
6164
poetry run flake8 pycardano
65+
poetry run mypy --install-types --non-interactive pycardano
66+
poetry run black --check .
6267

6368
format: ## runs code style and formatter
6469
poetry run isort .

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img src="./logo.png" height=200 width=200 />
2+
<img src="./.github/logo.png" height=200 width=200 />
33
</p>
44

55
---
@@ -9,12 +9,14 @@
99
[![PyPi version](https://badgen.net/pypi/v/pycardano)](https://pypi.python.org/pypi/pycardano/)
1010
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/pycardano)](https://pypi.python.org/pypi/pycardano/)
1111
[![PyPI download month](https://img.shields.io/pypi/dm/pycardano)](https://pypi.python.org/pypi/pycardano/)
12-
[![Discord](https://img.shields.io/discord/949404918903631923.svg?label=chat&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/qT9Mn9xjgz)
1312

14-
[![PyCardano](https://github.com/cffls/pycardano/actions/workflows/main.yml/badge.svg)](https://github.com/cffls/pycardano/actions/workflows/main.yml)
15-
[![codecov](https://codecov.io/gh/cffls/pycardano/branch/main/graph/badge.svg?token=62N0IL9IMQ)](https://codecov.io/gh/cffls/pycardano)
13+
[![PyCardano](https://github.com/Python-Cardano/pycardano/actions/workflows/main.yml/badge.svg)](https://github.com/Python-Cardano/pycardano/actions/workflows/main.yml)
14+
[![codecov](https://codecov.io/gh/Python-Cardano/pycardano/branch/main/graph/badge.svg?token=62N0IL9IMQ)](https://codecov.io/gh/Python-Cardano/pycardano)
1615
[![Documentation Status](https://readthedocs.org/projects/pycardano/badge/?version=latest)](https://pycardano.readthedocs.io/en/latest/?badge=latest)
1716

17+
[![Discord](https://img.shields.io/discord/949404918903631923.svg?label=chat&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/qT9Mn9xjgz)
18+
[![Twitter](https://img.shields.io/twitter/follow/PyCardano?style=social&label=Follow%20%40PyCardano)](https://twitter.com/PyCardano)
19+
1820

1921
PyCardano is a Cardano library written in Python. It allows users to create and sign transactions without
2022
depending on third-party Cardano serialization tools, such as
@@ -41,9 +43,9 @@ could be beneficial for faster R&D iterations.
4143
- [X] Plutus script
4244
- [X] Staking certificates
4345
- [X] Reward withdraw
44-
- [ ] Mnemonic
46+
- [X] Mnemonic
47+
- [X] HD Wallet
4548
- [ ] Byron Address
46-
- [ ] HD Wallet
4749
- [ ] Pool certificate
4850
- [ ] Protocol proposal update
4951

@@ -158,7 +160,7 @@ context.submit_tx(signed_tx.to_cbor())
158160
```
159161
</details>
160162

161-
See more usages under [examples](https://github.com/cffls/pycardano/tree/main/examples).
163+
See more usages under [examples](https://github.com/Python-Cardano/pycardano/tree/main/examples).
162164

163165

164166
### Development
@@ -170,7 +172,7 @@ See more usages under [examples](https://github.com/cffls/pycardano/tree/main/ex
170172

171173
Clone the repository:
172174

173-
`git clone https://github.com/cffls/pycardano.git`
175+
`git clone https://github.com/Python-Cardano/pycardano.git`
174176

175177
PyCardano uses [poetry](https://python-poetry.org/) to manage its dependencies.
176178
Install poetry for osx / linux / bashonwindows:
@@ -235,10 +237,25 @@ Build docs and open the docs in browser:
235237

236238
</details>
237239

240+
## Donation and Sponsor
241+
If you find this project helpful, please consider donate or sponsor us. Your donation and sponsor will allow us to
242+
spend more time on improving PyCardano and adding more features in the future.
243+
244+
You can support us by 1) sponsoring through Github, or 2) donating ADA to our ADA Handle `pycardano` or to the address below:
245+
246+
[`addr1vxa4qadv7hk2dd3jtz9rep7sp92lkgwzefwkmsy3qkglq5qzv8c0d`](https://cardanoscan.io/address/61bb5075acf5eca6b632588a3c87d00955fb21c2ca5d6dc0910591f050)
247+
248+
<p>
249+
<img src="./.github/donate_addr.png" height=150 width=150/>
250+
</p>
251+
252+
238253
## Sponsors :heart:
239254

240255
<p align="left">
241256
<a href="https://www.blockery.io/"><img src="https://avatars.githubusercontent.com/u/97766045?s=50&v=4"/></a>
242257
<a href="https://github.com/KtorZ"><img src="https://avatars.githubusercontent.com/u/5680256?s=50&v=4"/></a>
243258
<a href="https://github.com/lacepool"><img src="https://avatars.githubusercontent.com/u/79309785?s=50&v=4"/></a>
259+
<a href="https://github.com/muppetADA"><img width="50" src="https://avatars.githubusercontent.com/u/115075316?s=50&v=4"/></a>
260+
<a href="https://github.com/CardanoDur"><img width="50" src="https://avatars.githubusercontent.com/u/1000466?s=50&v=4"/></a>
244261
</p>

docs/requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ babel==2.10.3 ; python_version >= "3.7" and python_version < "4.0"
55
black==22.8.0 ; python_version >= "3.7" and python_version < "4.0"
66
blockfrost-python==0.5.1 ; python_version >= "3.7" and python_version < "4"
77
cbor2==5.4.3 ; python_version >= "3.7" and python_version < "4.0"
8-
certifi==2022.6.15.2 ; python_version >= "3.7" and python_version < "4"
8+
certifi==2022.9.14 ; python_version >= "3.7" and python_version < "4"
99
certvalidator==0.11.1 ; python_version >= "3.7" and python_version < "4.0"
1010
cffi==1.15.1 ; python_version >= "3.7" and python_version < "4.0"
1111
charset-normalizer==2.1.1 ; python_version >= "3.7" and python_version < "4"
@@ -17,6 +17,7 @@ cryptography==38.0.1 ; python_version >= "3.7" and python_version < "4.0"
1717
decorator==5.1.1 ; python_version >= "3.7" and python_version < "4.0"
1818
docutils==0.17.1 ; python_version >= "3.7" and python_version < "4.0"
1919
ecdsa==0.18.0 ; python_version >= "3.7" and python_version < "4.0"
20+
ecpy==1.2.5 ; python_version >= "3.7" and python_version < "4.0"
2021
execnet==1.9.0 ; python_version >= "3.7" and python_version < "4.0"
2122
flake8==4.0.1 ; python_version >= "3.7" and python_version < "4.0"
2223
flask==2.2.2 ; python_version >= "3.7" and python_version < "4.0"
@@ -29,6 +30,7 @@ itsdangerous==2.1.2 ; python_version >= "3.7" and python_version < "4.0"
2930
jinja2==3.1.2 ; python_version >= "3.7" and python_version < "4.0"
3031
markupsafe==2.1.1 ; python_version >= "3.7" and python_version < "4.0"
3132
mccabe==0.6.1 ; python_version >= "3.7" and python_version < "4.0"
33+
mnemonic==0.20 ; python_version >= "3.7" and python_version < "4.0"
3234
mypy-extensions==0.4.3 ; python_version >= "3.7" and python_version < "4.0"
3335
oscrypto==1.3.0 ; python_version >= "3.7" and python_version < "4.0"
3436
packaging==21.3 ; python_version >= "3.7" and python_version < "4.0"
@@ -50,7 +52,6 @@ pytest==7.1.3 ; python_version >= "3.7" and python_version < "4.0"
5052
pytz==2022.2.1 ; python_version >= "3.7" and python_version < "4.0"
5153
requests==2.28.1 ; python_version >= "3.7" and python_version < "4"
5254
retry==0.9.2 ; python_version >= "3.7" and python_version < "4.0"
53-
setuptools==65.3.0 ; python_version >= "3.7" and python_version < "4.0"
5455
six==1.16.0 ; python_version >= "3.7" and python_version < "4.0"
5556
snowballstemmer==2.2.0 ; python_version >= "3.7" and python_version < "4.0"
5657
sphinx-copybutton==0.5.0 ; python_version >= "3.7" and python_version < "4.0"

docs/source/api/pycardano.cip.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
CIP
22
=====================
33

4+
Implementation of Cardano Improvement Proposals (CIPs)
5+
46
.. automodule:: pycardano.cip.cip8
57
:members:
68
:undoc-members:

docs/source/api/pycardano.crypto.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Crypto
2+
=============================
3+
A module that contains cryptographic functions.
4+
5+
.. automodule:: pycardano.crypto.bip32
6+
:members:
7+
:undoc-members:
8+
:show-inheritance:

docs/source/guides/plutus.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,71 @@ Taker/Unlocker provides collateral. Collateral has been introduced in Alonzo tra
161161

162162
The funds locked in script address is successfully retrieved to the taker address.
163163

164+
-------------
165+
Vasil Upgrade
166+
-------------
167+
As part of the Basho phase of Cardano roadmap, the Vasil upgrade brings new capabilities on Plutus, namely reference inputs, inline datums, reference scripts, collateral output and Plutus V2 primitives.
168+
169+
- **Reference inputs** (`CIP-31 <https://cips.cardano.org/cips/cip31/>`_): This upgrade enables data sharing on-chain. Previously, datums were carried in transaction outputs; they stored and provided access to information on the blockchain. However, to access information in this datum, one had to spend the output that the datum was attached to. This required the re-creation of a spent output. The addition of reference inputs now allows developers to look at the datum without extra steps. This facilitates access to information stored on the blockchain without the need for spending and re-creating UTXOs. This can be useful for oracles and other use cases where state need to be inspected.
170+
171+
- **Inline datums** (`CIP-32 <https://cips.cardano.org/cips/cip32/>`_): Transaction datums were previously attached to outputs as hashes. With the implementation of inline datums, developers can now create scripts and attach datums directly to outputs instead of using their hashes. This simplifies how datums are used – a user can see the actual datum rather than supply it to match the given hash.
172+
173+
- **Reference scripts** (`CIP-33 <https://cips.cardano.org/cips/cip33/>`_): In Alonzo, when spending an output locked within a Plutus script, one had to include the script in the spending transaction. This increased the size of the script and caused certain delays in its processing. The reference scripts upgrade allows developers to reference a script without including it in each transaction. This significantly reduces transaction size, improves throughput, and reduces script execution costs (since the script only needs to be paid for once).
174+
175+
- **Explicit collateral output** (`CIP-40 <https://cips.cardano.org/cips/cip40/>`_): Transactions that call Plutus smart contracts are required to put up collateral to cover the potential cost of smart contract execution failure. If contract execution fails during phase 2 validation, all the funds stored in the chose UTXO for the collateral will be lost. After Vasil, user can specify a change address for the script collateral. If the script fails phase-2 validation, only the collateral amount will be taken, and the remaining funds will be sent to the change address.
176+
177+
- **Plutus V2 scripts**: The Vasil upgrade includes a new cost model that's lower than before, and developers will be able to see redeemers for all inputs rather than just the one being passed to the currently executing script.
178+
179+
Using the same FortyTwo example, now in Vasil, we show how reference scripts can be used. Reference script exists at a particular transaction output, and it can be used to witness UTxO at the corresponding script address::
180+
181+
>>> builder = TransactionBuilder(context)
182+
>>> builder.add_input_address(giver_address)
183+
>>> datum = 42
184+
>>> # Include scripts in the script address
185+
>>> builder.add_output(
186+
>>> TransactionOutput(script_address, 50000000, script=forty_two_script)
187+
>>> )
188+
189+
With reference script, actual script doesn't need to be included in the transaction anymore in order to spend UTxO sitting at script address::
190+
191+
>>> utxo_to_spend = None
192+
>>> # Spend the utxo that has datum/datum hash but no script
193+
>>> for utxo in chain_context.utxos(str(script_address)):
194+
>>> if not utxo.output.script and (
195+
>>> utxo.output.datum_hash == datum_hash(datum)
196+
>>> or utxo.output.datum == datum
197+
>>> ):
198+
>>> utxo_to_spend = utxo
199+
>>> break
200+
201+
>>> builder = TransactionBuilder(context)
202+
>>> builder.add_script_input(utxo_to_spend, datum=datum, redeemer=redeemer)
203+
>>> take_output = TransactionOutput(taker_address, 25123456)
204+
>>> builder.add_output(take_output)
205+
>>> signed_tx = builder.build_and_sign([extended_payment_skey], taker_address)
206+
207+
Again, with the same example, we show that you can send funds to script address with inline datums directly::
208+
209+
>>> builder = TransactionBuilder(context)
210+
>>> builder.add_input_address(giver_address)
211+
>>> datum = 42
212+
>>> builder.add_output(
213+
>>> TransactionOutput(script_address, 50000000, datum=datum, script=forty_two_script)
214+
>>> )
215+
216+
With inline datum, we no longer have to include a datum within our transaction for our plutus spending scripts. Instead we can specify the transaction output where our datum exists to be used in conjunction with our Plutus spending script. This reduces the overall size of our transaction::
217+
218+
>>> utxo_to_spend = None
219+
>>> # Speed the utxo that has both inline script and inline datum
220+
>>> for utxo in chain_context.utxos(str(script_address)):
221+
>>> if utxo.output.datum and utxo.output.script:
222+
>>> utxo_to_spend = utxo
223+
>>> break
224+
225+
>>> builder = TransactionBuilder(context)
226+
>>> builder.add_script_input(utxo_to_spend, redeemer=redeemer)
227+
>>> take_output = TransactionOutput(taker_address, 25123456)
228+
>>> builder.add_output(take_output)
229+
>>> signed_tx = builder.build_and_sign([extended_payment_skey], taker_address)
230+
231+

docs/source/guides/transaction.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,22 @@ Specify output amount::
142142

143143
Step 6
144144

145+
Add additional transaction information as needed:
146+
147+
>>> builder.ttl = 3600
148+
>>> builder.reference_inputs.add(tx_in)
149+
150+
Step 7
151+
145152
Create a signed transaction using transaction builder. Unlike building a raw transaction, where we need to manually
146153
sign a transaction and build a transaction witness set, transaction builder can build and sign a transaction directly
147154
with its `build_and_sign` method. The code below tells the builder to build a transaction and sign the transaction
148155
with a list of signing keys (in this case, we only need the signature from one signing key, `sk`) and send the change
149156
back to sender's address::
150157

151-
>>> tx = builder.build_and_sign([sk], change_address=address)
158+
>>> signed_tx = builder.build_and_sign([sk], change_address=address)
152159

153-
Transaction ID could be obtained from the transaction obejct::
160+
Transaction ID could be obtained from the transaction object::
154161

155162
>>> tx.id
156163
TransactionId(hex='1d40b950ded3a144fb4c100d1cf8b85719da91b06845530e34a0304427692ce4')

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ making it a light-weight library that is easy and fast to set up in all kinds of
3535
api/pycardano.backend.base
3636
api/pycardano.certificate
3737
api/pycardano.cip
38+
api/pycardano.crypto
3839
api/pycardano.coinselection
3940
api/pycardano.exception
4041
api/pycardano.hash

integration-test/configs/local-vasil/shelley-genesis.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646
"pools": {},
4747
"stake": {}
4848
},
49-
"epochLength": 2
49+
"epochLength": 4
5050
}

integration-test/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ services:
7373
max-file: "10"
7474

7575
kupo:
76-
image: cardanosolutions/kupo
76+
image: cardanosolutions/kupo:v2.1.0
7777
environment:
7878
NETWORK: "${NETWORK:-local}"
7979

0 commit comments

Comments
 (0)