Skip to content

Commit 79848b4

Browse files
Merge branch 'Python-Cardano:main' into main
2 parents c763b47 + 6d25033 commit 79848b4

26 files changed

+529
-262
lines changed

.github/donate_addr.png

2.77 KB
Loading
File renamed without changes.

README.md

Lines changed: 21 additions & 6 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
@@ -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,6 +237,19 @@ 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">

integration-test/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export POOL_ID=$(cat "$ROOT"/keys/pool/pool.id)
5050
# Wait for stake pool to start producing blocks
5151
sleep 30
5252

53-
poetry run pytest -s -vv -n 2 "$ROOT"/test
53+
poetry run pytest -s -vv "$ROOT"/test
5454

5555
# Cleanup
5656
docker-compose down --volumes --remove-orphans

integration-test/test/test_ogmios.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from retry import retry
2+
3+
from .base import TEST_RETRIES, TestBase
4+
5+
6+
class TestProtocolParam(TestBase):
7+
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4))
8+
def test_protocol_param_cost_models(self):
9+
protocol_param = self.chain_context.protocol_param
10+
11+
cost_models = protocol_param.cost_models
12+
for _, cost_model in cost_models.items():
13+
assert "addInteger-cpu-arguments-intercept" in cost_model
14+
assert "addInteger-cpu-arguments-slope" in cost_model

poetry.lock

Lines changed: 88 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pycardano/address.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020
from pycardano.hash import VERIFICATION_KEY_HASH_SIZE, ScriptHash, VerificationKeyHash
2121
from pycardano.network import Network
22-
from pycardano.serialization import CBORSerializable
22+
from pycardano.serialization import CBORSerializable, limit_primitive_type
2323

2424
__all__ = ["AddressType", "PointerAddress", "Address"]
2525

@@ -160,6 +160,7 @@ def to_primitive(self) -> bytes:
160160
return self.encode()
161161

162162
@classmethod
163+
@limit_primitive_type(bytes)
163164
def from_primitive(cls: Type[PointerAddress], value: bytes) -> PointerAddress:
164165
return cls.decode(value)
165166

@@ -339,6 +340,7 @@ def to_primitive(self) -> bytes:
339340
return bytes(self)
340341

341342
@classmethod
343+
@limit_primitive_type(bytes, str)
342344
def from_primitive(cls: Type[Address], value: Union[bytes, str]) -> Address:
343345
if isinstance(value, str):
344346
value = bytes(decode(value))

pycardano/backend/base.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,90 +19,90 @@
1919
ALONZO_COINS_PER_UTXO_WORD = 34482
2020

2121

22-
@dataclass
22+
@dataclass(frozen=True)
2323
class GenesisParameters:
2424
"""Cardano genesis parameters"""
2525

26-
active_slots_coefficient: float = None
26+
active_slots_coefficient: float
2727

28-
update_quorum: int = None
28+
update_quorum: int
2929

30-
max_lovelace_supply: int = None
30+
max_lovelace_supply: int
3131

32-
network_magic: int = None
32+
network_magic: int
3333

34-
epoch_length: int = None
34+
epoch_length: int
3535

36-
system_start: int = None
36+
system_start: int
3737

38-
slots_per_kes_period: int = None
38+
slots_per_kes_period: int
3939

40-
slot_length: int = None
40+
slot_length: int
4141

42-
max_kes_evolutions: int = None
42+
max_kes_evolutions: int
4343

44-
security_param: int = None
44+
security_param: int
4545

4646

47-
@dataclass
47+
@dataclass(frozen=True)
4848
class ProtocolParameters:
4949
"""Cardano protocol parameters"""
5050

51-
min_fee_constant: int = None
51+
min_fee_constant: int
5252

53-
min_fee_coefficient: int = None
53+
min_fee_coefficient: int
5454

55-
max_block_size: int = None
55+
max_block_size: int
5656

57-
max_tx_size: int = None
57+
max_tx_size: int
5858

59-
max_block_header_size: int = None
59+
max_block_header_size: int
6060

61-
key_deposit: int = None
61+
key_deposit: int
6262

63-
pool_deposit: int = None
63+
pool_deposit: int
6464

65-
pool_influence: float = None
65+
pool_influence: float
6666

67-
monetary_expansion: float = None
67+
monetary_expansion: float
6868

69-
treasury_expansion: float = None
69+
treasury_expansion: float
7070

71-
decentralization_param: float = None
71+
decentralization_param: float
7272

73-
extra_entropy: str = None
73+
extra_entropy: str
7474

75-
protocol_major_version: int = None
75+
protocol_major_version: int
7676

77-
protocol_minor_version: int = None
77+
protocol_minor_version: int
7878

79-
min_utxo: int = None
79+
min_utxo: int
8080

81-
min_pool_cost: int = None
81+
min_pool_cost: int
8282

83-
price_mem: float = None
83+
price_mem: float
8484

85-
price_step: float = None
85+
price_step: float
8686

87-
max_tx_ex_mem: int = None
87+
max_tx_ex_mem: int
8888

89-
max_tx_ex_steps: int = None
89+
max_tx_ex_steps: int
9090

91-
max_block_ex_mem: int = None
91+
max_block_ex_mem: int
9292

93-
max_block_ex_steps: int = None
93+
max_block_ex_steps: int
9494

95-
max_val_size: int = None
95+
max_val_size: int
9696

97-
collateral_percent: int = None
97+
collateral_percent: int
9898

99-
max_collateral_inputs: int = None
99+
max_collateral_inputs: int
100100

101-
coins_per_utxo_word: int = None
101+
coins_per_utxo_word: int
102102

103-
coins_per_utxo_byte: int = None
103+
coins_per_utxo_byte: int
104104

105-
cost_models: Dict[str, Dict[str, int]] = None
105+
cost_models: Dict[str, Dict[str, int]]
106106
"""A dict contains cost models for Plutus. The key will be "PlutusV1", "PlutusV2", etc.
107107
The value will be a dict of cost model parameters."""
108108

pycardano/backend/blockfrost.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
22
import tempfile
33
import time
4-
from typing import Dict, List, Union
4+
from typing import Dict, List, Optional, Union
55

66
import cbor2
77
from blockfrost import ApiUrls, BlockFrostApi
8+
from blockfrost.utils import Namespace
89

910
from pycardano.address import Address
1011
from pycardano.backend.base import (
@@ -28,6 +29,7 @@
2829
UTxO,
2930
Value,
3031
)
32+
from pycardano.types import JsonDict
3133

3234
__all__ = ["BlockFrostChainContext"]
3335

@@ -40,8 +42,14 @@ class BlockFrostChainContext(ChainContext):
4042
network (Network): Network to use.
4143
"""
4244

45+
api: BlockFrostApi
46+
_epoch_info: Namespace
47+
_epoch: Optional[int] = None
48+
_genesis_param: Optional[GenesisParameters] = None
49+
_protocol_param: Optional[ProtocolParameters] = None
50+
4351
def __init__(
44-
self, project_id: str, network: Network = Network.TESTNET, base_url: str = None
52+
self, project_id: str, network: Network = Network.TESTNET, base_url: str = ""
4553
):
4654
self._network = network
4755
self._project_id = project_id
@@ -72,7 +80,8 @@ def network(self) -> Network:
7280
@property
7381
def epoch(self) -> int:
7482
if not self._epoch or self._check_epoch_and_update():
75-
self._epoch = self.api.epoch_latest().epoch
83+
new_epoch: int = self.api.epoch_latest().epoch
84+
self._epoch = new_epoch
7685
return self._epoch
7786

7887
@property
@@ -107,6 +116,7 @@ def protocol_param(self) -> ProtocolParameters:
107116
protocol_major_version=int(params.protocol_major_ver),
108117
protocol_minor_version=int(params.protocol_minor_ver),
109118
min_utxo=int(params.min_utxo),
119+
min_pool_cost=int(params.min_pool_cost),
110120
price_mem=float(params.price_mem),
111121
price_step=float(params.price_step),
112122
max_tx_ex_mem=int(params.max_tx_ex_mem),
@@ -138,9 +148,10 @@ def _get_script(
138148
cbor2.loads(bytes.fromhex(self.api.script_cbor(script_hash).cbor))
139149
)
140150
else:
141-
return NativeScript.from_dict(
142-
self.api.script_json(script_hash, return_type="json")["json"]
143-
)
151+
script_json: JsonDict = self.api.script_json(
152+
script_hash, return_type="json"
153+
)["json"]
154+
return NativeScript.from_dict(script_json)
144155

145156
def utxos(self, address: str) -> List[UTxO]:
146157
results = self.api.address_utxos(address, gather_pages=True)
@@ -152,7 +163,7 @@ def utxos(self, address: str) -> List[UTxO]:
152163
[result.tx_hash, result.output_index]
153164
)
154165
amount = result.amount
155-
lovelace_amount = None
166+
lovelace_amount = 0
156167
multi_assets = MultiAsset()
157168
for item in amount:
158169
if item.unit == "lovelace":

0 commit comments

Comments
 (0)