Skip to content

Commit c4f801a

Browse files
committed
Merge branch 'main' into feat/list_plutusdata
2 parents e375088 + 985a2b6 commit c4f801a

23 files changed

+910
-767
lines changed

docs/source/guides/transaction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Step 6
147147
Add additional transaction information as needed:
148148

149149
>>> builder.ttl = 3600
150-
>>> builder.reference_inputs.add(tx_in)
150+
>>> builder.reference_inputs.add(utxo)
151151

152152
Step 7
153153

integration-test/test/test_certificate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
class TestDelegation(TestBase):
1212
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4))
1313
def test_stake_delegation(self):
14-
1514
address = Address(
1615
self.payment_key_pair.verification_key.hash(),
1716
self.stake_key_pair.verification_key.hash(),

integration-test/test/test_plutus.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
class TestPlutus(TestBase):
1313
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4))
1414
def test_plutus_v1(self):
15-
1615
# ----------- Giver give ---------------
1716

1817
with open("./plutus_scripts/fortytwo.plutus", "r") as f:
@@ -97,7 +96,6 @@ def test_plutus_v1(self):
9796
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4))
9897
@pytest.mark.post_alonzo
9998
def test_plutus_v2_datum_hash(self):
100-
10199
# ----------- Giver give ---------------
102100

103101
with open("./plutus_scripts/fortytwoV2.plutus", "r") as f:
@@ -173,7 +171,6 @@ def test_plutus_v2_datum_hash(self):
173171
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4))
174172
@pytest.mark.post_alonzo
175173
def test_plutus_v2_inline_script_inline_datum(self):
176-
177174
# ----------- Giver give ---------------
178175

179176
with open("./plutus_scripts/fortytwoV2.plutus", "r") as f:
@@ -237,7 +234,6 @@ def test_plutus_v2_inline_script_inline_datum(self):
237234
@retry(tries=TEST_RETRIES, backoff=1.5, delay=6, jitter=(0, 4))
238235
@pytest.mark.post_alonzo
239236
def test_plutus_v2_ref_script(self):
240-
241237
# ----------- Create a reference script ---------------
242238

243239
with open("./plutus_scripts/fortytwoV2.plutus", "r") as f:

poetry.lock

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

pycardano/certificate.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
@dataclass(repr=False)
1717
class StakeCredential(ArrayCBORSerializable):
18-
1918
_CODE: Optional[int] = field(init=False, default=None)
2019

2120
credential: Union[VerificationKeyHash, ScriptHash]
@@ -29,23 +28,20 @@ def __post_init__(self):
2928

3029
@dataclass(repr=False)
3130
class StakeRegistration(ArrayCBORSerializable):
32-
3331
_CODE: int = field(init=False, default=0)
3432

3533
stake_credential: StakeCredential
3634

3735

3836
@dataclass(repr=False)
3937
class StakeDeregistration(ArrayCBORSerializable):
40-
4138
_CODE: int = field(init=False, default=1)
4239

4340
stake_credential: StakeCredential
4441

4542

4643
@dataclass(repr=False)
4744
class StakeDelegation(ArrayCBORSerializable):
48-
4945
_CODE: int = field(init=False, default=2)
5046

5147
stake_credential: StakeCredential

pycardano/cip/cip8.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def verify(
151151

152152
# generate/extract the cose key
153153
if not attach_cose_key:
154-
155154
# get the verification key from the headers
156155
verification_key = decoded_message.phdr[KID]
157156

pycardano/coinselection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ def select(
8484
include_max_fee: Optional[bool] = True,
8585
respect_min_utxo: Optional[bool] = True,
8686
) -> Tuple[List[UTxO], Value]:
87-
8887
available: List[UTxO] = sorted(utxos, key=lambda utxo: utxo.output.lovelace)
8988
max_fee = max_tx_fee(context) if include_max_fee else 0
9089
total_requested = Value(max_fee)

pycardano/key.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def __eq__(self, other):
148148
def __repr__(self) -> str:
149149
return self.to_json()
150150

151+
def __hash__(self):
152+
return hash(self.payload)
153+
151154

152155
class SigningKey(Key):
153156
def sign(self, data: bytes) -> bytes:

pycardano/plutus.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,36 @@ def _dfs(obj):
605605
converted_fields.append(t.from_dict(f))
606606
else:
607607
converted_fields.append(_dfs(f))
608+
609+
elif (
610+
hasattr(f_info.type, "__origin__")
611+
and f_info.type.__origin__ is dict
612+
):
613+
t_args = f_info.type.__args__
614+
if len(t_args) != 2:
615+
raise DeserializeException(
616+
"Dict type with wrong number of arguments"
617+
)
618+
if "map" not in f:
619+
raise DeserializeException(
620+
f'Expected type "map" in object but got "{f}"'
621+
)
622+
key_t = t_args[0]
623+
val_t = t_args[1]
624+
if inspect.isclass(key_t) and issubclass(key_t, PlutusData):
625+
key_convert = key_t.from_dict
626+
else:
627+
key_convert = _dfs
628+
if inspect.isclass(val_t) and issubclass(val_t, PlutusData):
629+
val_convert = val_t.from_dict
630+
else:
631+
val_convert = _dfs
632+
converted_fields.append(
633+
{
634+
key_convert(pair["k"]): val_convert(pair["v"])
635+
for pair in f["map"]
636+
}
637+
)
608638
else:
609639
converted_fields.append(_dfs(f))
610640
return cls(*converted_fields)
@@ -639,7 +669,6 @@ def from_json(cls: Type[PlutusData], data: str) -> PlutusData:
639669

640670
@dataclass
641671
class RawPlutusData(CBORSerializable):
642-
643672
data: CBORTag
644673

645674
def to_primitive(self) -> CBORTag:

pycardano/serialization.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
]
3838

3939

40+
def _identity(x):
41+
return x
42+
43+
4044
class IndefiniteList(UserList):
4145
def __init__(self, li: Primitive): # type: ignore
4246
super().__init__(li) # type: ignore
@@ -428,6 +432,25 @@ def _restore_dataclass_field(
428432
return IndefiniteList(v)
429433
elif isclass(f.type) and issubclass(f.type, IndefiniteList):
430434
return IndefiniteList(v)
435+
elif hasattr(f.type, "__origin__") and (f.type.__origin__ is dict):
436+
t_args = f.type.__args__
437+
if len(t_args) != 2:
438+
raise DeserializeException(
439+
f"Dict types need exactly two type arguments, but got {t_args}"
440+
)
441+
key_t = t_args[0]
442+
val_t = t_args[1]
443+
if isclass(key_t) and issubclass(key_t, CBORSerializable):
444+
key_converter = key_t.from_primitive
445+
else:
446+
key_converter = _identity
447+
if isclass(val_t) and issubclass(val_t, CBORSerializable):
448+
val_converter = val_t.from_primitive
449+
else:
450+
val_converter = _identity
451+
if not isinstance(v, dict):
452+
raise DeserializeException(f"Expected dict type but got {type(v)}")
453+
return {key_converter(key): val_converter(val) for key, val in v.items()}
431454
elif hasattr(f.type, "__origin__") and (
432455
f.type.__origin__ is Union or f.type.__origin__ is Optional
433456
):

pycardano/transaction.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ def to_shallow_primitive(self):
267267

268268
@dataclass(repr=False)
269269
class _Script(ArrayCBORSerializable):
270-
271270
_TYPE: int = field(init=False, default=0)
272271

273272
script: Union[NativeScript, PlutusV1Script, PlutusV2Script]
@@ -293,7 +292,6 @@ def from_primitive(cls: Type[_Script], values: List[Primitive]) -> _Script:
293292

294293
@dataclass(repr=False)
295294
class _DatumOption(ArrayCBORSerializable):
296-
297295
_TYPE: int = field(init=False, default=0)
298296

299297
datum: Union[DatumHash, Any]
@@ -329,7 +327,6 @@ def from_primitive(
329327

330328
@dataclass(repr=False)
331329
class _ScriptRef(CBORSerializable):
332-
333330
script: _Script
334331

335332
def to_primitive(self) -> Primitive:
@@ -374,7 +371,6 @@ class _TransactionOutputLegacy(ArrayCBORSerializable):
374371

375372
@dataclass(repr=False)
376373
class TransactionOutput(CBORSerializable):
377-
378374
address: Address
379375

380376
amount: Union[Value]

0 commit comments

Comments
 (0)