Skip to content

Commit

Permalink
Make TaggedDataPayload work
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Feb 14, 2024
1 parent 68ed93e commit f1a623a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
4 changes: 4 additions & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `NodeInfoProtocol.belowMaxDepth`;
- `{NodeInfoProtocol, RentStructure}::as_dict()`;

### Changed

- Made the type of `TaggedDataPayload` required as first field in `__init__()`;

### Fixed

- Made `TaggedDataPayload::{tag, data}` optional;
Expand Down
34 changes: 18 additions & 16 deletions bindings/python/examples/wallet/transaction_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@

from dotenv import load_dotenv

from iota_sdk import (RemainderValueStrategy, TaggedDataPayload,
from iota_sdk import (RemainderValueStrategy, TaggedDataPayload, PayloadType,
TransactionOptions, Wallet, utf8_to_hex)

load_dotenv()

# This example sends a transaction with a tagged data payload.

wallet = Wallet(os.environ['WALLET_DB_PATH'])
TaggedDataPayload(PayloadType.TaggedData,
utf8_to_hex("tag"), utf8_to_hex("data"))
# wallet = Wallet(os.environ['WALLET_DB_PATH'])

account = wallet.get_account('Alice')
# account = wallet.get_account('Alice')

# Sync account with the node
response = account.sync()
# # Sync account with the node
# response = account.sync()

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
# if 'STRONGHOLD_PASSWORD' not in os.environ:
# raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")

wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])
# wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

params = [{
"address": "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
"amount": "1000000",
}]
# params = [{
# "address": "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
# "amount": "1000000",
# }]

transaction = account.send_with_params(params, TransactionOptions(remainder_value_strategy=RemainderValueStrategy.ReuseAddress,
note="my first tx", tagged_data_payload=TaggedDataPayload(utf8_to_hex("tag"), utf8_to_hex("data"))))
print(transaction)
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}')
# transaction = account.send_with_params(params, TransactionOptions(remainder_value_strategy=RemainderValueStrategy.ReuseAddress,
# note="my first tx", tagged_data_payload=TaggedDataPayload(PayloadType.TaggedData, utf8_to_hex("tag"), utf8_to_hex("data"))))
# print(transaction)
# print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}')
11 changes: 10 additions & 1 deletion bindings/python/iota_sdk/types/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
import dacite
from dataclasses import dataclass, field
from enum import IntEnum
from typing import Any, Dict, Optional, List, Union
Expand Down Expand Up @@ -140,6 +141,7 @@ class TaggedDataPayload(Payload):
"""A tagged data payload.
Attributes:
type: The type of the tagged data payload, must be 5.
tag: The tag part of the tagged data payload.
data: The data part of the tagged data payload.
"""
Expand All @@ -148,7 +150,14 @@ class TaggedDataPayload(Payload):
type: int = field(
default_factory=lambda: int(
PayloadType.TaggedData),
init=False)
init=True)

def __post_init__(self):
if self.type != int(
PayloadType.TaggedData):
return dacite.UnionMatchError("invalid TaggedDataPayload type")
self.type = int(
PayloadType.TaggedData)


@dataclass
Expand Down

0 comments on commit f1a623a

Please sign in to comment.