Skip to content

Commit 95881a0

Browse files
authored
Simplifies the backend interface (use available classes!) (#206)
This is a minimal effort change to the backends to leverage the available classes in PyCardano for user-friendliness In particular, if a class for something is available then the backend should support it
1 parent 090879e commit 95881a0

File tree

16 files changed

+91
-56
lines changed

16 files changed

+91
-56
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ builder = TransactionBuilder(context)
105105
builder.add_input_address(address)
106106

107107
# Get all UTxOs currently sitting at this address
108-
utxos = context.utxos(str(address))
108+
utxos = context.utxos(address)
109109

110110
# We can also tell the builder to include a specific UTxO in the transaction.
111111
# Similarly, "add_input" could be called multiple times.
@@ -156,7 +156,7 @@ builder.add_output(
156156
signed_tx = builder.build_and_sign([psk], change_address=address)
157157

158158
# Submit signed transaction to the network
159-
context.submit_tx(signed_tx.to_cbor())
159+
context.submit_tx(signed_tx)
160160

161161
```
162162
</details>

examples/delegator_loyalty_rewards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,5 @@
101101

102102
print("#### Transaction id ####")
103103
print(signed_tx.id)
104-
context.submit_tx(signed_tx.to_cbor())
104+
context.submit_tx(signed_tx)
105105
print("Transaction successfully submitted!")

examples/full_stack/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ def submit_tx():
7777
print(f"Transaction: \n {tx}")
7878
print(f"Transaction cbor: {tx.to_cbor()}")
7979
print(f"Transaction ID: {tx_id}")
80-
chain_context.submit_tx(tx.to_cbor())
80+
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
@@ -172,4 +172,4 @@ def load_or_create_key_pair(base_dir, base_name):
172172

173173
# Submit signed transaction to the network
174174
print("############### Submitting transaction ###############")
175-
chain_context.submit_tx(signed_tx.to_cbor())
175+
chain_context.submit_tx(signed_tx)

examples/plutus/forty_two/forty_two.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def submit_tx(tx):
4343
print(tx)
4444
print(tx.to_cbor())
4545
print("############### Submitting transaction ###############")
46-
chain_context.submit_tx(tx.to_cbor())
46+
chain_context.submit_tx(tx)
4747
wait_for_tx(str(tx.id))
4848

4949

@@ -91,15 +91,15 @@ def submit_tx(tx):
9191
utxo_to_spend = None
9292

9393
# Spend the utxo with datum 42 sitting at the script address
94-
for utxo in chain_context.utxos(str(script_address)):
94+
for utxo in chain_context.utxos(script_address):
9595
print(utxo)
9696
if utxo.output.datum:
9797
utxo_to_spend = utxo
9898
break
9999

100100
# Find the reference script utxo
101101
reference_script_utxo = None
102-
for utxo in chain_context.utxos(str(giver_address)):
102+
for utxo in chain_context.utxos(giver_address):
103103
if utxo.output.script and utxo.output.script == forty_two_script:
104104
reference_script_utxo = utxo
105105
break

examples/tx_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
builder.add_input_address(address)
3232

3333
# Get all UTxOs currently sitting at this address
34-
utxos = context.utxos(str(address))
34+
utxos = context.utxos(address)
3535

3636
# We can also tell the builder to include a specific UTxO in the transaction.
3737
# Similarly, "add_input" could be called multiple times.
@@ -82,4 +82,4 @@
8282
signed_tx = builder.build_and_sign([psk], change_address=address)
8383

8484
# Submit signed transaction to the network
85-
context.submit_tx(signed_tx.to_cbor())
85+
context.submit_tx(signed_tx)

integration-test/test/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class TestBase:
4545

4646
@retry(tries=TEST_RETRIES, delay=3)
4747
def assert_output(self, target_address, target_output):
48-
utxos = self.chain_context.utxos(str(target_address))
48+
utxos = self.chain_context.utxos(target_address)
4949
found = False
5050

5151
for utxo in utxos:
@@ -69,5 +69,5 @@ def fund(self, source_address, source_key, target_address, amount=5000000):
6969
print(signed_tx)
7070
print(signed_tx.to_cbor())
7171
print("############### Submitting transaction ###############")
72-
self.chain_context.submit_tx(signed_tx.to_cbor())
72+
self.chain_context.submit_tx(signed_tx)
7373
self.assert_output(target_address, target_output=output)

integration-test/test/test_certificate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_stake_delegation(self):
1717
self.NETWORK,
1818
)
1919

20-
utxos = self.chain_context.utxos(str(address))
20+
utxos = self.chain_context.utxos(address)
2121

2222
if not utxos:
2323
giver_address = Address(self.payment_vkey.hash(), network=self.NETWORK)
@@ -33,7 +33,7 @@ def test_stake_delegation(self):
3333
print(signed_tx)
3434
print(signed_tx.to_cbor())
3535
print("############### Submitting transaction ###############")
36-
self.chain_context.submit_tx(signed_tx.to_cbor())
36+
self.chain_context.submit_tx(signed_tx)
3737

3838
time.sleep(3)
3939

@@ -60,7 +60,7 @@ def test_stake_delegation(self):
6060
print(signed_tx)
6161
print(signed_tx.to_cbor())
6262
print("############### Submitting transaction ###############")
63-
self.chain_context.submit_tx(signed_tx.to_cbor())
63+
self.chain_context.submit_tx(signed_tx)
6464

6565
time.sleep(8)
6666

@@ -86,4 +86,4 @@ def test_stake_delegation(self):
8686
print(signed_tx)
8787
print(signed_tx.to_cbor())
8888
print("############### Submitting transaction ###############")
89-
self.chain_context.submit_tx(signed_tx.to_cbor())
89+
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
@@ -102,6 +102,6 @@ class MyPlutusData(PlutusData):
102102

103103
# Submit signed transaction to the network
104104
print("############### Submitting transaction ###############")
105-
self.chain_context.submit_tx(signed_tx.to_cbor())
105+
self.chain_context.submit_tx(signed_tx)
106106

107107
self.assert_output(address, nft_output)

integration-test/test/test_mint.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def load_or_create_key_pair(base_dir, base_name):
136136

137137
# Submit signed transaction to the network
138138
print("############### Submitting transaction ###############")
139-
self.chain_context.submit_tx(signed_tx.to_cbor())
139+
self.chain_context.submit_tx(signed_tx)
140140

141141
self.assert_output(address, nft_output)
142142

@@ -162,7 +162,7 @@ def load_or_create_key_pair(base_dir, base_name):
162162

163163
# Submit signed transaction to the network
164164
print("############### Submitting transaction ###############")
165-
self.chain_context.submit_tx(signed_tx.to_cbor())
165+
self.chain_context.submit_tx(signed_tx)
166166

167167
self.assert_output(address, nft_to_send)
168168

@@ -233,7 +233,7 @@ def test_mint_nft_with_script(self):
233233
self.fund(address, self.payment_skey, address)
234234

235235
non_nft_utxo = None
236-
for utxo in self.chain_context.utxos(str(address)):
236+
for utxo in self.chain_context.utxos(address):
237237
# multi_asset should be empty for collateral utxo
238238
if not utxo.output.amount.multi_asset:
239239
non_nft_utxo = utxo
@@ -251,7 +251,7 @@ def test_mint_nft_with_script(self):
251251

252252
# Submit signed transaction to the network
253253
print("############### Submitting transaction ###############")
254-
self.chain_context.submit_tx(signed_tx.to_cbor())
254+
self.chain_context.submit_tx(signed_tx)
255255

256256
self.assert_output(address, nft_output)
257257

@@ -338,6 +338,6 @@ class MyPlutusData(PlutusData):
338338

339339
# Submit signed transaction to the network
340340
print("############### Submitting transaction ###############")
341-
self.chain_context.submit_tx(signed_tx.to_cbor())
341+
self.chain_context.submit_tx(signed_tx)
342342

343343
self.assert_output(address, nft_output)

0 commit comments

Comments
 (0)