-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wen not ValueError: Circular reference detected
- Loading branch information
Showing
6 changed files
with
168 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright 2023 IOTA Stiftung | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from enum import Enum | ||
from typing import Any, Optional | ||
|
||
|
||
class PayloadType(Enum): | ||
TreasuryTransaction = 4 | ||
TaggedData = 5 | ||
Transaction = 6 | ||
Milestone = 7 | ||
|
||
|
||
class Payload(): | ||
def __init__(self, type, milestone: Optional[Any] = None, tagged_data=None, transaction=None, treasury_transaction: Optional[Any] = None): | ||
"""Initialize a payload | ||
""" | ||
self.type = type | ||
self.milestone = milestone | ||
self.tagged_data = tagged_data | ||
self.transaction = transaction | ||
self.treasury_transaction = treasury_transaction | ||
|
||
def as_dict(self): | ||
config = {k: v for k, v in self.__dict__.items() if v != None} | ||
|
||
config['type'] = config['type'].value | ||
|
||
if 'sender' in config: | ||
config['address'] = config.pop('sender').as_dict() | ||
|
||
if 'issuer' in config: | ||
config['address'] = config.pop('issuer').as_dict() | ||
|
||
return config | ||
|
||
|
||
class MilestonePayload(Payload): | ||
def __init__(self, essence, signatures): | ||
"""Initialize a MilestonePayload | ||
""" | ||
self.essence = essence | ||
self.signatures = signatures | ||
super().__init__(PayloadType.Milestone, milestone=self) | ||
|
||
|
||
class TaggedDataPayload(Payload): | ||
def __init__(self, tag, data): | ||
"""Initialize a TaggedDataPayload | ||
""" | ||
self.tag = tag | ||
self.data = data | ||
super().__init__(PayloadType.TaggedData, tagged_data=self) | ||
|
||
|
||
class TransactionPayload(Payload): | ||
def __init__(self, essence, unlocks): | ||
"""Initialize a TransactionPayload | ||
""" | ||
self.essence = essence | ||
self.unlocks = unlocks | ||
super().__init__(PayloadType.Transaction, transaction=self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2023 IOTA Stiftung | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from iota_sdk.types.burn import Burn | ||
from iota_sdk.types.output_id import OutputId | ||
from iota_sdk.types.payload import TaggedDataPayload | ||
from enum import Enum | ||
from typing import Optional, List | ||
|
||
class AccountAddress: | ||
def __int__(self, | ||
address: str, | ||
key_index: int, | ||
internal: bool, | ||
used: bool): | ||
self.address = address | ||
self.keyIndex = key_index | ||
self.internal = internal | ||
self.used = used | ||
|
||
|
||
class CustomAddress(Enum): | ||
AccountAddress=AccountAddress | ||
|
||
class RemainderValueStrategy(Enum): | ||
ChangeAddress = "ChangeAddress", | ||
ReuseAddress = "ReuseAddress", | ||
CustomAddress = CustomAddress | ||
|
||
def __int__(self): | ||
return self.value | ||
|
||
|
||
class TransactionOptions(): | ||
def __init__(self, remainder_value_strategy: RemainderValueStrategy = RemainderValueStrategy.ReuseAddress, | ||
tagged_data_payload: Optional[TaggedDataPayload] = None, | ||
custom_inputs: Optional[List[OutputId]] = None, | ||
mandatory_inputs: Optional[List[OutputId]] = None, | ||
burn: Optional[Burn] = None, | ||
note: Optional[str] = None, | ||
allow_micro_amount: Optional[bool] = None): | ||
"""Initialize TransactionOptions | ||
""" | ||
self.remainder_value_strategy = remainder_value_strategy | ||
self.tagged_data_payload = tagged_data_payload | ||
self.custom_inputs = custom_inputs | ||
self.mandatory_inputs = mandatory_inputs | ||
self.burn = burn | ||
self.note = note | ||
self.allow_micro_amount = allow_micro_amount | ||
|
||
def as_dict(self): | ||
config = dict(self.__dict__) | ||
|
||
# config['type'] = config['type'].value | ||
|
||
# if self.type == AddressType.ED25519: | ||
# config['pubKeyHash'] = config.pop('address_or_id') | ||
# elif self.type == AddressType.ALIAS: | ||
# config['aliasId'] = config.pop('address_or_id') | ||
# elif self.type == AddressType.NFT: | ||
# config['nftId'] = config.pop('address_or_id') | ||
|
||
return {k: v for k, v in config.items() if v} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters