Skip to content

Commit a322a2d

Browse files
committed
works well for token burn
Signed-off-by: exploreriii <133720349+exploreriii@users.noreply.github.com>
1 parent b76580f commit a322a2d

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

scripts/src_vs_proto/steps_6_token_burn.py

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
"""
33
Step 6: Extract TokenBurnTransaction info from Step 3 output
44
+ corresponding proto attributes and setters from Step 4 output
5+
+ regex + mapping to check if proto really missing
56
"""
67

78
from pathlib import Path
89
import importlib.util
910
import sys
11+
import re
1012

1113
# Step 3 and Step 4 generated files
1214
STEP3_FILE = Path(__file__).resolve().parent / "steps_3_token_classes_info_readable.py"
@@ -22,25 +24,62 @@ def load_module(file_path: Path, module_name: str):
2224
spec.loader.exec_module(module)
2325
return module
2426

27+
def camel_to_snake(name: str) -> str:
28+
"""Convert camelCase or PascalCase to snake_case."""
29+
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
30+
s2 = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1)
31+
return s2.lower()
32+
33+
# Special proto -> SDK mappings
34+
PROTO_TO_SDK_MAP = {
35+
"token": "token_id",
36+
"serialNumbers": "serials",
37+
}
38+
39+
def map_proto_to_sdk(proto_attr: str) -> str:
40+
"""Apply special mapping rules + snake_case conversion."""
41+
if proto_attr in PROTO_TO_SDK_MAP:
42+
return PROTO_TO_SDK_MAP[proto_attr]
43+
return camel_to_snake(proto_attr)
44+
45+
def map_proto_setter_to_sdk(proto_setter: str) -> str:
46+
"""Convert proto setter to SDK setter."""
47+
if proto_setter.startswith("set_"):
48+
core = proto_setter[4:] # remove 'set_'
49+
return f"set_{map_proto_to_sdk(core)}"
50+
return proto_setter
51+
2552
if __name__ == "__main__":
2653
# Load Step 3 (SDK classes)
2754
step3_module = load_module(STEP3_FILE, "step3_token_classes")
2855
tb_info = getattr(step3_module.token_burn_transaction, "TokenBurnTransaction", None)
29-
30-
if tb_info:
31-
print("✅ TokenBurnTransaction info extracted from Step 3 output")
32-
print("Attributes:", tb_info['attributes'])
33-
print("Setters:", tb_info['setters'])
34-
else:
35-
print("⚠️ TokenBurnTransaction not found in Step 3 output")
56+
if not tb_info:
57+
tb_info = {'attributes': [], 'setters': []}
3658

3759
# Load Step 4 (proto mappings)
3860
step4_module = load_module(STEP4_FILE, "step4_proto_attributes")
3961
proto_info = getattr(step4_module, "proto_mappings", {}).get("TokenBurnTransactionBody", None)
62+
if not proto_info:
63+
proto_info = {'attributes': [], 'setters': []}
64+
65+
# Map proto attributes and setters to SDK equivalents
66+
mapped_proto_attrs = [map_proto_to_sdk(a) for a in proto_info['attributes']]
67+
mapped_proto_setters = [map_proto_setter_to_sdk(s) for s in proto_info['setters']]
68+
69+
# Compute missing attributes and setters
70+
missing_attributes = [a for a in mapped_proto_attrs if a not in tb_info['attributes']]
71+
missing_setters = [s for s in mapped_proto_setters if s not in tb_info['setters']]
72+
73+
print("✅ SDK Attributes:", tb_info['attributes'])
74+
print("✅ SDK Setters:", tb_info['setters'])
75+
print("\n✅ Proto Attributes (mapped):", mapped_proto_attrs)
76+
print("✅ Proto Setters (mapped):", mapped_proto_setters)
4077

41-
if proto_info:
42-
print("\n📦 Corresponding Proto: TokenBurnTransactionBody")
43-
print("Attributes:", proto_info['attributes'])
44-
print("Setters:", proto_info['setters'])
78+
if missing_attributes or missing_setters:
79+
print("\n⚠️ Proto attributes/setters really missing in SDK TokenBurnTransaction:")
80+
if missing_attributes:
81+
print("⚠️Missing attributes:", missing_attributes)
82+
if missing_setters:
83+
print("⚠️Missing setters:", missing_setters)
4584
else:
46-
print("⚠️ Proto TokenBurnTransactionBody not found in Step 4 output")
85+
print("\n✅ No proto attributes or setters are actually missing in the SDK TokenBurnTransaction")

0 commit comments

Comments
 (0)