diff --git a/pycardano/transaction.py b/pycardano/transaction.py index fa324059..833df586 100644 --- a/pycardano/transaction.py +++ b/pycardano/transaction.py @@ -14,7 +14,7 @@ from pycardano.address import Address from pycardano.certificate import Certificate -from pycardano.exception import InvalidDataException, InvalidOperationException +from pycardano.exception import InvalidDataException from pycardano.hash import ( TRANSACTION_HASH_SIZE, AuxiliaryDataHash, @@ -95,14 +95,7 @@ def __iadd__(self, other: Asset) -> Asset: def __sub__(self, other: Asset) -> Asset: new_asset = deepcopy(self) for n in other: - if n not in new_asset: - raise InvalidOperationException( - f"Asset: {new_asset} does not have asset with name: {n}" - ) - # According to ledger rule, the value of an asset could be negative, so we don't check the value here and - # will leave the check to users when necessary. - # https://github.com/input-output-hk/cardano-ledger/blob/master/eras/alonzo/test-suite/cddl-files/alonzo.cddl#L378 - new_asset[n] -= other[n] + new_asset[n] = new_asset.get(n, 0) - other[n] return new_asset def __eq__(self, other): @@ -135,9 +128,7 @@ def union(self, other: MultiAsset) -> MultiAsset: def __add__(self, other): new_multi_asset = deepcopy(self) for p in other: - if p not in new_multi_asset: - new_multi_asset[p] = Asset() - new_multi_asset[p] += other[p] + new_multi_asset[p] = new_multi_asset.get(p, Asset()) + other[p] return new_multi_asset def __iadd__(self, other): @@ -148,11 +139,7 @@ def __iadd__(self, other): def __sub__(self, other: MultiAsset) -> MultiAsset: new_multi_asset = deepcopy(self) for p in other: - if p not in new_multi_asset: - raise InvalidOperationException( - f"MultiAsset: {new_multi_asset} doesn't have policy: {p}" - ) - new_multi_asset[p] -= other[p] + new_multi_asset[p] = new_multi_asset.get(p, Asset()) - other[p] return new_multi_asset def __eq__(self, other):