Skip to content

Commit eaadc38

Browse files
authored
Change the default returning type of 'to_cbor' to bytes (#232)
Change the default returning type of 'to_cbor' to bytes and add 'to_cbor_hex' that returns cbor hex.
1 parent 40f00fb commit eaadc38

28 files changed

+123
-136
lines changed

docs/requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ ecpy==1.2.5 ; python_version >= "3.7" and python_version < "4.0"
2121
exceptiongroup==1.1.1 ; python_version >= "3.7" and python_version < "3.11"
2222
execnet==1.9.0 ; python_version >= "3.7" and python_version < "4.0"
2323
flake8==5.0.4 ; python_version >= "3.7" and python_version < "4.0"
24-
flask==2.2.3 ; python_version >= "3.7" and python_version < "4.0"
24+
flask==2.2.4 ; python_version >= "3.7" and python_version < "4.0"
25+
frozendict==2.3.8 ; python_version >= "3.7" and python_version < "4.0"
26+
frozenlist==1.3.3 ; python_version >= "3.7" and python_version < "4.0"
2527
idna==3.4 ; python_version >= "3.7" and python_version < "4"
2628
imagesize==1.4.1 ; python_version >= "3.7" and python_version < "4.0"
2729
importlib-metadata==4.2.0 ; python_version >= "3.7" and python_version < "3.10"
@@ -37,7 +39,7 @@ mypy==1.2.0 ; python_version >= "3.7" and python_version < "4.0"
3739
oscrypto==1.3.0 ; python_version >= "3.7" and python_version < "4.0"
3840
packaging==23.1 ; python_version >= "3.7" and python_version < "4.0"
3941
pathspec==0.11.1 ; python_version >= "3.7" and python_version < "4.0"
40-
platformdirs==3.2.0 ; python_version >= "3.7" and python_version < "4.0"
42+
platformdirs==3.3.0 ; python_version >= "3.7" and python_version < "4.0"
4143
pluggy==1.0.0 ; python_version >= "3.7" and python_version < "4.0"
4244
pprintpp==0.4.0 ; python_version >= "3.7" and python_version < "4.0"
4345
py==1.11.0 ; python_version >= "3.7" and python_version < "4.0"
@@ -52,7 +54,7 @@ pytest==7.3.1 ; python_version >= "3.7" and python_version < "4.0"
5254
pytz==2023.3 ; python_version >= "3.7" and python_version < "3.9"
5355
requests==2.28.2 ; python_version >= "3.7" and python_version < "4"
5456
retry==0.9.2 ; python_version >= "3.7" and python_version < "4.0"
55-
setuptools==67.7.1 ; python_version >= "3.7" and python_version < "4.0"
57+
setuptools==67.7.2 ; python_version >= "3.7" and python_version < "4.0"
5658
six==1.16.0 ; python_version >= "3.7" and python_version < "4.0"
5759
snowballstemmer==2.2.0 ; python_version >= "3.7" and python_version < "4.0"
5860
sphinx-copybutton==0.5.2 ; python_version >= "3.7" and python_version < "4.0"

docs/source/guides/plutus.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To calculate the hash of a datum, we can leverage the helper class `PlutusData`.
2424
Empty datum::
2525

2626
>>> empty_datum = PlutusData()
27-
>>> empty_datum.to_cbor()
27+
>>> empty_datum.to_cbor_hex()
2828
'd87980'
2929

3030
Sample datum with int, bytes, List and hashmap inputs::
@@ -39,7 +39,7 @@ Sample datum with int, bytes, List and hashmap inputs::
3939
... d: dict
4040

4141
>>> datum = MyDatum(123, b"1234", IndefiniteList([4, 5, 6]), {1: b"1", 2: b"2"})
42-
>>> datum.to_cbor()
42+
>>> datum.to_cbor_hex()
4343
'd87a9f187b43333231ff'
4444

4545
You can also wrap `PlutusData` within `PlutusData`::
@@ -55,7 +55,7 @@ You can also wrap `PlutusData` within `PlutusData`::
5555
>>> deadline = 1643235300000
5656
>>> other_datum = MyDatum(123, b"1234", IndefiniteList([4, 5, 6]), {1: b"1", 2: b"2"})
5757
>>> include_datum = InclusionDatum(key_hash, deadline, other_datum)
58-
>>> include_datum.to_cbor()
58+
>>> include_datum.to_cbor_hex()
5959
'd87a9f581cc2ff616e11299d9094ce0a7eb5b7284b705147a822f4ffbd471f971a1b0000017e9874d2a0d8668218829f187b44313233349f040506ffa2014131024132ffff'
6060

6161
`PlutusData` supports conversion from/to JSON format, which
@@ -67,7 +67,7 @@ Similarly, redeemer can be serialized like following::
6767

6868
>>> data = MyDatum(123, b"234", IndefiniteList([]), {1: b"1", 2: b"2"})
6969
>>> redeemer = Redeemer(data, ExecutionUnits(1000000, 1000000))
70-
>>> redeemer.to_cbor()
70+
>>> redeemer.to_cbor_hex()
7171
'840000d8668218829f187b433233349fffa2014131024132ff821a000f42401a000f4240'
7272

7373
-----------------------
@@ -178,7 +178,7 @@ Note that we will just use the datatype defined in the contract, as it also uses
178178
Build, sign and submit the transaction:
179179

180180
>>> signed_tx = builder.build_and_sign([payment_skey], giver_address)
181-
>>> context.submit_tx(signed_tx.to_cbor())
181+
>>> context.submit_tx(signed_tx.to_cbor_hex())
182182

183183
Step 6
184184

@@ -219,7 +219,7 @@ Now lets try to resubmit this::
219219

220220
>>> signed_tx = builder.build_and_sign([payment_skey_2], taker_address)
221221

222-
>>> context.submit_tx(signed_tx.to_cbor())
222+
>>> context.submit_tx(signed_tx.to_cbor_hex())
223223

224224
The funds locked in script address is successfully retrieved to the taker address.
225225

docs/source/guides/serialization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Examples::
3434
... outputs=[output1, output2],
3535
... fee=fee
3636
... )
37-
>>> cbor_hex = tx_body.to_cbor()
37+
>>> cbor_hex = tx_body.to_cbor_hex()
3838
a50081825820732bfd67e66be8e8288349fcaaa2294973ef6271cc189a239bb431275401b8e500018282581d60f6532850e1bccee9c72a9113ad98bcc5dbb30d2ac960262444f6e5f41b000000174876e80082581d60f6532850e1bccee9c72a9113ad98bcc5dbb30d2ac960262444f6e5f41b000000ba43b4b7f7021a000288090d800e80
3939

4040
>>> restored_tx_body = TransactionBody.from_cbor(cbor_hex)

docs/source/guides/transaction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,5 @@ Transaction submission
178178
Once we have a signed transaction, it could be submitted to the network. The easiest way to do so is through a chain
179179
context::
180180

181-
>>> context.submit_tx(signed_tx.to_cbor())
181+
>>> context.submit_tx(signed_tx.to_cbor_hex())
182182

examples/full_stack/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def home_page():
6565
@app.route("/build_tx", methods=["POST"])
6666
def build_tx():
6767
tx = build_transaction(request.json)
68-
cbor_hex = tx.to_cbor()
68+
cbor_hex = tx.to_cbor_hex()
6969
print(cbor_hex)
7070
return {"tx": cbor_hex}
7171

@@ -75,7 +75,7 @@ def submit_tx():
7575
tx = compose_tx_and_witness(request.json)
7676
tx_id = tx.transaction_body.hash().hex()
7777
print(f"Transaction: \n {tx}")
78-
print(f"Transaction cbor: {tx.to_cbor()}")
78+
print(f"Transaction cbor: {tx.to_cbor_hex()}")
7979
print(f"Transaction ID: {tx_id}")
8080
chain_context.submit_tx(tx)
8181
return {"tx_id": tx_id}

examples/native_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def load_or_create_key_pair(base_dir, base_name):
168168

169169
print("############### Transaction created ###############")
170170
print(signed_tx)
171-
print(signed_tx.to_cbor())
171+
print(signed_tx.to_cbor_hex())
172172

173173
# Submit signed transaction to the network
174174
print("############### Submitting transaction ###############")

examples/plutus/forty_two/forty_two.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def wait_for_tx(tx_id):
4141
def submit_tx(tx):
4242
print("############### Transaction created ###############")
4343
print(tx)
44-
print(tx.to_cbor())
44+
print(tx.to_cbor_hex())
4545
print("############### Submitting transaction ###############")
4646
chain_context.submit_tx(tx)
4747
wait_for_tx(str(tx.id))

integration-test/test/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def fund(self, source_address, source_key, target_address, amount=5000000):
6767

6868
print("############### Transaction created ###############")
6969
print(signed_tx)
70-
print(signed_tx.to_cbor())
70+
print(signed_tx.to_cbor_hex())
7171
print("############### Submitting transaction ###############")
7272
self.chain_context.submit_tx(signed_tx)
7373
self.assert_output(target_address, target_output=output)

integration-test/test/test_certificate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_stake_delegation(self):
3131

3232
print("############### Transaction created ###############")
3333
print(signed_tx)
34-
print(signed_tx.to_cbor())
34+
print(signed_tx.to_cbor_hex())
3535
print("############### Submitting transaction ###############")
3636
self.chain_context.submit_tx(signed_tx)
3737

@@ -58,7 +58,7 @@ def test_stake_delegation(self):
5858

5959
print("############### Transaction created ###############")
6060
print(signed_tx)
61-
print(signed_tx.to_cbor())
61+
print(signed_tx.to_cbor_hex())
6262
print("############### Submitting transaction ###############")
6363
self.chain_context.submit_tx(signed_tx)
6464

@@ -84,6 +84,6 @@ def test_stake_delegation(self):
8484

8585
print("############### Transaction created ###############")
8686
print(signed_tx)
87-
print(signed_tx.to_cbor())
87+
print(signed_tx.to_cbor_hex())
8888
print("############### Submitting transaction ###############")
8989
self.chain_context.submit_tx(signed_tx)

integration-test/test/test_min_utxo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class MyPlutusData(PlutusData):
9898

9999
print("############### Transaction created ###############")
100100
print(signed_tx)
101-
print(signed_tx.to_cbor())
101+
print(signed_tx.to_cbor_hex())
102102

103103
# Submit signed transaction to the network
104104
print("############### Submitting transaction ###############")

0 commit comments

Comments
 (0)