Skip to content

Commit 4bf6a62

Browse files
committed
Convert a string address to Address object in TransactionOutput
Sometimes user will pass a string address to TransactionOutput, which results in an incorrect cbor. This commit will automatically convert the string address to an Address object.
1 parent 4f3244b commit 4bf6a62

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pycardano/transaction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ class TransactionOutput(CBORSerializable):
388388
post_alonzo: Optional[bool] = False
389389

390390
def __post_init__(self):
391+
if isinstance(self.address, str):
392+
self.address = Address.from_primitive(self.address)
391393
if isinstance(self.amount, int):
392394
self.amount = Value(self.amount)
393395

test/pycardano/test_transaction.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def test_transaction_output():
4444
check_two_way_cbor(output)
4545

4646

47+
def test_transaction_output_str_address():
48+
addr = "addr_test1vrm9x2zsux7va6w892g38tvchnzahvcd9tykqf3ygnmwtaqyfg52x"
49+
output = TransactionOutput(addr, 100000000000)
50+
assert (
51+
output.to_cbor()
52+
== "82581d60f6532850e1bccee9c72a9113ad98bcc5dbb30d2ac960262444f6e5f41b000000174876e800"
53+
)
54+
check_two_way_cbor(output)
55+
56+
4757
def test_transaction_output_inline_datum():
4858
addr = Address.decode(
4959
"addr_test1vrm9x2zsux7va6w892g38tvchnzahvcd9tykqf3ygnmwtaqyfg52x"

0 commit comments

Comments
 (0)