lunalib 1.5.0__py3-none-any.whl → 1.5.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lunalib/core/sm2.py +723 -723
- lunalib/core/wallet.py +176 -0
- lunalib/core/wallet_manager.py +638 -0
- lunalib/core/wallet_sync_helper.py +163 -0
- lunalib/mining/miner.py +24 -15
- lunalib/storage/cache.py +13 -4
- lunalib/storage/database.py +14 -5
- lunalib/storage/encryption.py +11 -2
- lunalib/transactions/security.py +11 -2
- lunalib/transactions/transactions.py +23 -14
- lunalib-1.5.2.dist-info/METADATA +20 -0
- lunalib-1.5.2.dist-info/RECORD +31 -0
- lunalib-1.5.2.dist-info/top_level.txt +1 -0
- core/__init__.py +0 -0
- core/blockchain.py +0 -172
- core/crypto.py +0 -32
- core/wallet.py +0 -408
- gtx/__init__.py +0 -0
- gtx/bill_registry.py +0 -122
- gtx/digital_bill.py +0 -273
- gtx/genesis.py +0 -338
- lunalib/requirements.txt +0 -44
- lunalib-1.5.0.dist-info/METADATA +0 -283
- lunalib-1.5.0.dist-info/RECORD +0 -51
- lunalib-1.5.0.dist-info/entry_points.txt +0 -2
- lunalib-1.5.0.dist-info/top_level.txt +0 -6
- mining/__init__.py +0 -0
- mining/cuda_manager.py +0 -137
- mining/difficulty.py +0 -106
- mining/miner.py +0 -107
- storage/__init__.py +0 -0
- storage/cache.py +0 -148
- storage/database.py +0 -222
- storage/encryption.py +0 -105
- transactions/__init__.py +0 -0
- transactions/security.py +0 -172
- transactions/transactions.py +0 -424
- transactions/validator.py +0 -71
- {lunalib-1.5.0.dist-info → lunalib-1.5.2.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# lunalib/wallet_sync_helper.py
|
|
2
|
+
"""
|
|
3
|
+
Wallet Sync Helper
|
|
4
|
+
|
|
5
|
+
Provides integration between LunaWallet, BlockchainManager, MempoolManager,
|
|
6
|
+
and the WalletStateManager for seamless real-time balance and transaction updates.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import List, Dict, Optional, Callable
|
|
10
|
+
from .wallet_manager import get_wallet_manager
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class WalletSyncHelper:
|
|
14
|
+
"""
|
|
15
|
+
Helper class to sync LunaWallet with WalletStateManager using data from
|
|
16
|
+
BlockchainManager and MempoolManager.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, wallet=None, blockchain=None, mempool=None):
|
|
20
|
+
"""
|
|
21
|
+
Initialize sync helper.
|
|
22
|
+
|
|
23
|
+
Parameters:
|
|
24
|
+
wallet: LunaWallet instance
|
|
25
|
+
blockchain: BlockchainManager instance
|
|
26
|
+
mempool: MempoolManager instance
|
|
27
|
+
"""
|
|
28
|
+
self.wallet = wallet
|
|
29
|
+
self.blockchain = blockchain
|
|
30
|
+
self.mempool = mempool
|
|
31
|
+
self.state_manager = get_wallet_manager()
|
|
32
|
+
|
|
33
|
+
def register_wallets_from_lunawallet(self) -> Dict:
|
|
34
|
+
"""Register all wallets from LunaWallet into the state manager"""
|
|
35
|
+
if not self.wallet:
|
|
36
|
+
print("⚠️ No wallet instance provided")
|
|
37
|
+
return {}
|
|
38
|
+
|
|
39
|
+
addresses = list(self.wallet.wallets.keys())
|
|
40
|
+
if not addresses:
|
|
41
|
+
print("⚠️ No wallets registered in LunaWallet")
|
|
42
|
+
return {}
|
|
43
|
+
|
|
44
|
+
print(f"📱 Registering {len(addresses)} wallets with state manager...")
|
|
45
|
+
states = self.state_manager.register_wallets(addresses)
|
|
46
|
+
print(f"✅ Registered {len(states)} wallets")
|
|
47
|
+
|
|
48
|
+
return states
|
|
49
|
+
|
|
50
|
+
def sync_wallets_now(self) -> Dict:
|
|
51
|
+
"""
|
|
52
|
+
Perform a single synchronization of all registered wallets.
|
|
53
|
+
|
|
54
|
+
Returns: Dictionary of wallet addresses and their updated summaries
|
|
55
|
+
"""
|
|
56
|
+
if not self.blockchain or not self.mempool:
|
|
57
|
+
print("⚠️ Blockchain or mempool not provided")
|
|
58
|
+
return {}
|
|
59
|
+
|
|
60
|
+
addresses = list(self.state_manager.wallet_states.keys())
|
|
61
|
+
if not addresses:
|
|
62
|
+
print("⚠️ No wallets registered")
|
|
63
|
+
return {}
|
|
64
|
+
|
|
65
|
+
print(f"🔄 Syncing {len(addresses)} wallets...")
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
# Get data from blockchain and mempool
|
|
69
|
+
blockchain_txs = self.blockchain.scan_transactions_for_addresses(addresses)
|
|
70
|
+
mempool_txs = self.mempool.get_pending_transactions_for_addresses(addresses)
|
|
71
|
+
|
|
72
|
+
# Sync the state manager
|
|
73
|
+
self.state_manager.sync_wallets_from_sources(blockchain_txs, mempool_txs)
|
|
74
|
+
|
|
75
|
+
# Update LunaWallet balances if available
|
|
76
|
+
if self.wallet:
|
|
77
|
+
self._update_lunawallet_balances()
|
|
78
|
+
|
|
79
|
+
# Return summaries
|
|
80
|
+
return self.state_manager.get_all_summaries()
|
|
81
|
+
|
|
82
|
+
except Exception as e:
|
|
83
|
+
print(f"❌ Sync error: {e}")
|
|
84
|
+
return {}
|
|
85
|
+
|
|
86
|
+
def _update_lunawallet_balances(self):
|
|
87
|
+
"""Update LunaWallet instance balances from state manager"""
|
|
88
|
+
if not self.wallet:
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
balances = self.state_manager.get_all_balances()
|
|
92
|
+
|
|
93
|
+
for address, balance_data in balances.items():
|
|
94
|
+
if address in self.wallet.wallets:
|
|
95
|
+
wallet_data = self.wallet.wallets[address]
|
|
96
|
+
wallet_data['balance'] = balance_data['confirmed_balance']
|
|
97
|
+
wallet_data['available_balance'] = balance_data['available_balance']
|
|
98
|
+
|
|
99
|
+
# Update current wallet if one is selected
|
|
100
|
+
if self.wallet.current_wallet_address in balances:
|
|
101
|
+
balance_data = balances[self.wallet.current_wallet_address]
|
|
102
|
+
self.wallet.balance = balance_data['confirmed_balance']
|
|
103
|
+
self.wallet.available_balance = balance_data['available_balance']
|
|
104
|
+
|
|
105
|
+
def start_continuous_sync(self, poll_interval: int = 30,
|
|
106
|
+
on_balance_update: Optional[Callable] = None,
|
|
107
|
+
on_transaction_update: Optional[Callable] = None) -> None:
|
|
108
|
+
"""
|
|
109
|
+
Start continuous synchronization in the background.
|
|
110
|
+
|
|
111
|
+
Parameters:
|
|
112
|
+
poll_interval: Seconds between syncs
|
|
113
|
+
on_balance_update: Callback function(balance_data) for balance updates
|
|
114
|
+
on_transaction_update: Callback function(transaction_data) for transaction updates
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
if on_balance_update:
|
|
118
|
+
self.state_manager.on_balance_update(on_balance_update)
|
|
119
|
+
|
|
120
|
+
if on_transaction_update:
|
|
121
|
+
self.state_manager.on_transaction_update(on_transaction_update)
|
|
122
|
+
|
|
123
|
+
def get_blockchain_data(addresses):
|
|
124
|
+
try:
|
|
125
|
+
return self.blockchain.scan_transactions_for_addresses(addresses)
|
|
126
|
+
except Exception as e:
|
|
127
|
+
print(f"⚠️ Blockchain scan error: {e}")
|
|
128
|
+
return {}
|
|
129
|
+
|
|
130
|
+
def get_mempool_data(addresses):
|
|
131
|
+
try:
|
|
132
|
+
return self.mempool.get_pending_transactions_for_addresses(addresses)
|
|
133
|
+
except Exception as e:
|
|
134
|
+
print(f"⚠️ Mempool fetch error: {e}")
|
|
135
|
+
return {}
|
|
136
|
+
|
|
137
|
+
self.state_manager.sync_wallets_background(
|
|
138
|
+
get_blockchain_data,
|
|
139
|
+
get_mempool_data,
|
|
140
|
+
poll_interval
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def get_wallet_balance(self, address: str) -> Optional[Dict]:
|
|
144
|
+
"""Get current balance for a wallet"""
|
|
145
|
+
return self.state_manager.get_balance(address)
|
|
146
|
+
|
|
147
|
+
def get_wallet_transactions(self, address: str, tx_type: str = 'all') -> List[Dict]:
|
|
148
|
+
"""Get transactions for a wallet"""
|
|
149
|
+
return self.state_manager.get_transactions(address, tx_type)
|
|
150
|
+
|
|
151
|
+
def get_wallet_summary(self, address: str) -> Optional[Dict]:
|
|
152
|
+
"""Get complete summary for a wallet"""
|
|
153
|
+
return self.state_manager.get_wallet_summary(address)
|
|
154
|
+
|
|
155
|
+
def get_all_wallets_summary(self) -> Dict:
|
|
156
|
+
"""Get summaries for all wallets"""
|
|
157
|
+
return self.state_manager.get_all_summaries()
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# Convenience function to create sync helper
|
|
161
|
+
def create_wallet_sync_helper(wallet=None, blockchain=None, mempool=None) -> WalletSyncHelper:
|
|
162
|
+
"""Create a new WalletSyncHelper instance"""
|
|
163
|
+
return WalletSyncHelper(wallet, blockchain, mempool)
|
lunalib/mining/miner.py
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# lunalib/mining/miner.py
|
|
2
2
|
import time
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
# --- Unicode-safe print for Windows console ---
|
|
6
|
+
def safe_print(*args, **kwargs):
|
|
7
|
+
try:
|
|
8
|
+
print(*args, **kwargs)
|
|
9
|
+
except UnicodeEncodeError:
|
|
10
|
+
encoding = getattr(sys.stdout, 'encoding', 'utf-8')
|
|
11
|
+
print(*(str(a).encode(encoding, errors='replace').decode(encoding) for a in args), **kwargs)
|
|
3
12
|
import hashlib
|
|
4
13
|
import json
|
|
5
14
|
import threading
|
|
@@ -28,7 +37,7 @@ class GenesisMiner:
|
|
|
28
37
|
"total_hash_attempts": 0
|
|
29
38
|
}
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
safe_print("🔧 GenesisMiner initialized with integrated lunalib components")
|
|
32
41
|
|
|
33
42
|
def mine_bill(self, denomination: float, user_address: str, bill_data: Dict = None) -> Dict:
|
|
34
43
|
"""Mine a GTX Genesis bill using DigitalBill system"""
|
|
@@ -43,7 +52,7 @@ class GenesisMiner:
|
|
|
43
52
|
bill_data=bill_data or {}
|
|
44
53
|
)
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
safe_print(f"⛏️ Mining GTX ${denomination:,} Bill - Difficulty: {difficulty} zeros")
|
|
47
56
|
|
|
48
57
|
start_time = time.time()
|
|
49
58
|
mining_result = self._perform_bill_mining(digital_bill, difficulty)
|
|
@@ -63,10 +72,10 @@ class GenesisMiner:
|
|
|
63
72
|
self.mining_stats["total_mining_time"] += mining_time
|
|
64
73
|
self.mining_stats["total_hash_attempts"] += mining_result["nonce"]
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
safe_print(f"✅ Successfully mined GTX ${denomination:,} bill!")
|
|
76
|
+
safe_print(f"⏱️ Mining time: {mining_time:.2f}s")
|
|
77
|
+
safe_print(f"📊 Hash attempts: {mining_result['nonce']:,}")
|
|
78
|
+
safe_print(f"🔗 Bill hash: {mining_result['hash'][:32]}...")
|
|
70
79
|
|
|
71
80
|
# Convert to GTX Genesis transaction
|
|
72
81
|
gtx_transaction = self._create_gtx_genesis_transaction(bill)
|
|
@@ -105,8 +114,8 @@ class GenesisMiner:
|
|
|
105
114
|
# Calculate block difficulty
|
|
106
115
|
difficulty = self.difficulty_system.get_transaction_block_difficulty(transactions)
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
safe_print(f"⛏️ Mining Transaction Block #{block_height} - Difficulty: {difficulty} zeros")
|
|
118
|
+
safe_print(f"📦 Transactions: {len(transactions)} | Previous Hash: {previous_hash[:16]}...")
|
|
110
119
|
|
|
111
120
|
# Create block structure for mining
|
|
112
121
|
block_data = {
|
|
@@ -162,20 +171,20 @@ class GenesisMiner:
|
|
|
162
171
|
self.mining_stats["total_mining_time"] += mining_time
|
|
163
172
|
self.mining_stats["total_hash_attempts"] += mining_result["nonce"]
|
|
164
173
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
174
|
+
safe_print(f"✅ Successfully mined and validated Transaction Block #{block_height}!")
|
|
175
|
+
safe_print(f"⏱️ Mining time: {mining_time:.2f}s")
|
|
176
|
+
safe_print(f"💰 Block reward: {block['reward']:.6f} LUN")
|
|
177
|
+
safe_print(f"📊 Transactions: {block['transaction_count']}")
|
|
178
|
+
safe_print(f"🔗 Block hash: {mining_result['hash'][:32]}...")
|
|
170
179
|
|
|
171
180
|
# Submit block to blockchain
|
|
172
181
|
submission_success = self.blockchain_manager.submit_mined_block(block)
|
|
173
182
|
if submission_success:
|
|
174
|
-
|
|
183
|
+
safe_print("✅ Block successfully submitted to blockchain!")
|
|
175
184
|
# Clear mined transactions from local mempool
|
|
176
185
|
self._clear_mined_transactions(transactions)
|
|
177
186
|
else:
|
|
178
|
-
|
|
187
|
+
safe_print("⚠️ Block mined but submission failed")
|
|
179
188
|
|
|
180
189
|
return {
|
|
181
190
|
"success": True,
|
lunalib/storage/cache.py
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
# --- Unicode-safe print for Windows console ---
|
|
5
|
+
def safe_print(*args, **kwargs):
|
|
6
|
+
try:
|
|
7
|
+
print(*args, **kwargs)
|
|
8
|
+
except UnicodeEncodeError:
|
|
9
|
+
encoding = getattr(sys.stdout, 'encoding', 'utf-8')
|
|
10
|
+
print(*(str(a).encode(encoding, errors='replace').decode(encoding) for a in args), **kwargs)
|
|
2
11
|
import sqlite3
|
|
3
12
|
import pickle
|
|
4
13
|
import gzip
|
|
@@ -66,7 +75,7 @@ class BlockchainCache:
|
|
|
66
75
|
conn.commit()
|
|
67
76
|
conn.close()
|
|
68
77
|
except Exception as e:
|
|
69
|
-
|
|
78
|
+
safe_print(f"Cache save error: {e}")
|
|
70
79
|
|
|
71
80
|
def get_block(self, height: int) -> Optional[Dict]:
|
|
72
81
|
"""Get block from cache"""
|
|
@@ -88,7 +97,7 @@ class BlockchainCache:
|
|
|
88
97
|
|
|
89
98
|
conn.close()
|
|
90
99
|
except Exception as e:
|
|
91
|
-
|
|
100
|
+
safe_print(f"Cache read error: {e}")
|
|
92
101
|
|
|
93
102
|
return None
|
|
94
103
|
|
|
@@ -116,7 +125,7 @@ class BlockchainCache:
|
|
|
116
125
|
continue
|
|
117
126
|
|
|
118
127
|
except Exception as e:
|
|
119
|
-
|
|
128
|
+
safe_print(f"Block range cache error: {e}")
|
|
120
129
|
|
|
121
130
|
return blocks
|
|
122
131
|
|
|
@@ -145,4 +154,4 @@ class BlockchainCache:
|
|
|
145
154
|
conn.commit()
|
|
146
155
|
conn.close()
|
|
147
156
|
except Exception as e:
|
|
148
|
-
|
|
157
|
+
safe_print(f"Cache cleanup error: {e}")
|
lunalib/storage/database.py
CHANGED
|
@@ -3,6 +3,15 @@ import sqlite3
|
|
|
3
3
|
import json
|
|
4
4
|
import time
|
|
5
5
|
from typing import Dict, List, Optional, Any
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
# --- Unicode-safe print for Windows console ---
|
|
9
|
+
def safe_print(*args, **kwargs):
|
|
10
|
+
try:
|
|
11
|
+
print(*args, **kwargs)
|
|
12
|
+
except UnicodeEncodeError:
|
|
13
|
+
encoding = getattr(sys.stdout, 'encoding', 'utf-8')
|
|
14
|
+
print(*(str(a).encode(encoding, errors='replace').decode(encoding) for a in args), **kwargs)
|
|
6
15
|
|
|
7
16
|
class WalletDatabase:
|
|
8
17
|
"""Manages wallet data storage"""
|
|
@@ -96,7 +105,7 @@ class WalletDatabase:
|
|
|
96
105
|
return True
|
|
97
106
|
|
|
98
107
|
except Exception as e:
|
|
99
|
-
|
|
108
|
+
safe_print(f"Save wallet error: {e}")
|
|
100
109
|
return False
|
|
101
110
|
|
|
102
111
|
def load_wallet(self, address: str) -> Optional[Dict]:
|
|
@@ -122,7 +131,7 @@ class WalletDatabase:
|
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
except Exception as e:
|
|
125
|
-
|
|
134
|
+
safe_print(f"Load wallet error: {e}")
|
|
126
135
|
|
|
127
136
|
return None
|
|
128
137
|
|
|
@@ -157,7 +166,7 @@ class WalletDatabase:
|
|
|
157
166
|
return True
|
|
158
167
|
|
|
159
168
|
except Exception as e:
|
|
160
|
-
|
|
169
|
+
safe_print(f"Save transaction error: {e}")
|
|
161
170
|
return False
|
|
162
171
|
|
|
163
172
|
def get_wallet_transactions(self, wallet_address: str, limit: int = 100) -> List[Dict]:
|
|
@@ -187,7 +196,7 @@ class WalletDatabase:
|
|
|
187
196
|
return transactions
|
|
188
197
|
|
|
189
198
|
except Exception as e:
|
|
190
|
-
|
|
199
|
+
safe_print(f"Get transactions error: {e}")
|
|
191
200
|
return []
|
|
192
201
|
|
|
193
202
|
def save_pending_transaction(self, transaction: Dict, wallet_address: str) -> bool:
|
|
@@ -218,5 +227,5 @@ class WalletDatabase:
|
|
|
218
227
|
return True
|
|
219
228
|
|
|
220
229
|
except Exception as e:
|
|
221
|
-
|
|
230
|
+
safe_print(f"Save pending transaction error: {e}")
|
|
222
231
|
return False
|
lunalib/storage/encryption.py
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import json
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
# --- Unicode-safe print for Windows console ---
|
|
6
|
+
def safe_print(*args, **kwargs):
|
|
7
|
+
try:
|
|
8
|
+
print(*args, **kwargs)
|
|
9
|
+
except UnicodeEncodeError:
|
|
10
|
+
encoding = getattr(sys.stdout, 'encoding', 'utf-8')
|
|
11
|
+
print(*(str(a).encode(encoding, errors='replace').decode(encoding) for a in args), **kwargs)
|
|
3
12
|
import base64
|
|
4
13
|
import hashlib
|
|
5
14
|
from cryptography.fernet import Fernet
|
|
@@ -37,7 +46,7 @@ class EncryptionManager:
|
|
|
37
46
|
}
|
|
38
47
|
|
|
39
48
|
except Exception as e:
|
|
40
|
-
|
|
49
|
+
safe_print(f"Encryption error: {e}")
|
|
41
50
|
return {}
|
|
42
51
|
|
|
43
52
|
def decrypt_wallet(self, encrypted_data: Dict, password: str) -> Optional[Dict]:
|
|
@@ -65,7 +74,7 @@ class EncryptionManager:
|
|
|
65
74
|
return wallet_data
|
|
66
75
|
|
|
67
76
|
except Exception as e:
|
|
68
|
-
|
|
77
|
+
safe_print(f"Decryption error: {e}")
|
|
69
78
|
return None
|
|
70
79
|
|
|
71
80
|
def _derive_key(self, password: str) -> bytes:
|
lunalib/transactions/security.py
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import time
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
# --- Unicode-safe print for Windows console ---
|
|
5
|
+
def safe_print(*args, **kwargs):
|
|
6
|
+
try:
|
|
7
|
+
print(*args, **kwargs)
|
|
8
|
+
except UnicodeEncodeError:
|
|
9
|
+
encoding = getattr(sys.stdout, 'encoding', 'utf-8')
|
|
10
|
+
print(*(str(a).encode(encoding, errors='replace').decode(encoding) for a in args), **kwargs)
|
|
2
11
|
import hashlib
|
|
3
12
|
from typing import Dict, Tuple
|
|
4
13
|
|
|
@@ -17,11 +26,11 @@ class TransactionSecurity:
|
|
|
17
26
|
from ..core.crypto import KeyManager as SM2KeyManager
|
|
18
27
|
self.key_manager = SM2KeyManager()
|
|
19
28
|
self.sm2_available = True
|
|
20
|
-
|
|
29
|
+
safe_print("[SECURITY] SM2 KeyManager loaded successfully")
|
|
21
30
|
except ImportError as e:
|
|
22
31
|
self.key_manager = None
|
|
23
32
|
self.sm2_available = False
|
|
24
|
-
|
|
33
|
+
safe_print(f"[SECURITY] SM2 KeyManager not available: {e}")
|
|
25
34
|
|
|
26
35
|
def validate_transaction_security(self, transaction: Dict) -> Tuple[bool, str]:
|
|
27
36
|
"""Comprehensive transaction security validation with SM2"""
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# lunalib/transactions/transactions.py
|
|
2
2
|
import time
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
# --- Unicode-safe print for Windows console ---
|
|
6
|
+
def safe_print(*args, **kwargs):
|
|
7
|
+
try:
|
|
8
|
+
print(*args, **kwargs)
|
|
9
|
+
except UnicodeEncodeError:
|
|
10
|
+
encoding = getattr(sys.stdout, 'encoding', 'utf-8')
|
|
11
|
+
print(*(str(a).encode(encoding, errors='replace').decode(encoding) for a in args), **kwargs)
|
|
3
12
|
import hashlib
|
|
4
13
|
import json
|
|
5
14
|
from typing import Dict, Optional, Tuple, List
|
|
@@ -9,10 +18,10 @@ from ..core.mempool import MempoolManager
|
|
|
9
18
|
try:
|
|
10
19
|
from ..core.crypto import KeyManager as SM2KeyManager
|
|
11
20
|
SM2_AVAILABLE = True
|
|
12
|
-
|
|
21
|
+
safe_print("DEBUG: Using SM2 KeyManager from crypto module")
|
|
13
22
|
except ImportError as e:
|
|
14
23
|
SM2_AVAILABLE = False
|
|
15
|
-
|
|
24
|
+
safe_print(f"WARNING: SM2 KeyManager not available: {e}")
|
|
16
25
|
|
|
17
26
|
class TransactionSecurity:
|
|
18
27
|
"""Transaction security validation and risk assessment"""
|
|
@@ -71,7 +80,7 @@ class TransactionManager:
|
|
|
71
80
|
if SM2_AVAILABLE:
|
|
72
81
|
self.key_manager = SM2KeyManager()
|
|
73
82
|
else:
|
|
74
|
-
|
|
83
|
+
safe_print("ERROR: SM2 KeyManager not available - cannot sign transactions")
|
|
75
84
|
self.key_manager = None
|
|
76
85
|
|
|
77
86
|
def create_transaction(self, from_address: str, to_address: str, amount: float,
|
|
@@ -99,33 +108,33 @@ class TransactionManager:
|
|
|
99
108
|
# Sign the transaction data
|
|
100
109
|
tx_string = self._get_signing_data(transaction)
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Signing data: {tx_string}")
|
|
112
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Private key available: {bool(private_key)}")
|
|
113
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Private key length: {len(private_key)}")
|
|
105
114
|
|
|
106
115
|
signature = self.key_manager.sign_data(tx_string, private_key)
|
|
107
116
|
|
|
108
117
|
# Get public key from private key
|
|
109
118
|
public_key = self.key_manager.derive_public_key(private_key)
|
|
110
119
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
120
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Generated signature: {signature}")
|
|
121
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Generated public key: {public_key}")
|
|
122
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Signature length: {len(signature)}")
|
|
123
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Public key length: {len(public_key)}")
|
|
115
124
|
|
|
116
125
|
transaction["signature"] = signature
|
|
117
126
|
transaction["public_key"] = public_key
|
|
118
127
|
|
|
119
128
|
# Immediately test verification
|
|
120
129
|
test_verify = self.key_manager.verify_signature(tx_string, signature, public_key)
|
|
121
|
-
|
|
130
|
+
safe_print(f"[TRANSACTIONS CREATE DEBUG] Immediate self-verification: {test_verify}")
|
|
122
131
|
|
|
123
132
|
if not test_verify:
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
safe_print(f"[TRANSACTIONS CREATE ERROR] Signature doesn't verify immediately!")
|
|
134
|
+
safe_print(f"[TRANSACTIONS CREATE ERROR] This suggests an SM2 implementation issue")
|
|
126
135
|
|
|
127
136
|
except Exception as e:
|
|
128
|
-
|
|
137
|
+
safe_print(f"[TRANSACTIONS CREATE ERROR] Signing failed: {e}")
|
|
129
138
|
import traceback
|
|
130
139
|
traceback.print_exc()
|
|
131
140
|
transaction["signature"] = "unsigned"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lunalib
|
|
3
|
+
Version: 1.5.2
|
|
4
|
+
Summary: Cryptocurrency Ecosystem library (LunaLib)
|
|
5
|
+
Home-page:
|
|
6
|
+
Author: Ling Lin
|
|
7
|
+
Author-email:
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: requires-python
|
|
18
|
+
Dynamic: summary
|
|
19
|
+
|
|
20
|
+
A modular cryptocurrency ecosystem library including blockchain, wallet, mining, storage, and transaction management.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
lunalib/__init__.py,sha256=fEvoHvfcC6ilDGQrhXaVmcdB4yDmuijxz6YZHkjbuBg,527
|
|
2
|
+
lunalib/cli.py,sha256=SyuJIhvqld-XL9ks9XFOuyqVb44qyBUbahlqE_RDVkM,524
|
|
3
|
+
lunalib/luna_lib.py,sha256=ue9Bs93xjpg7_GHSUJPKBhf8nF5YcbCIdoMIu-jDgG4,2748
|
|
4
|
+
lunalib/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
lunalib/core/blockchain.py,sha256=gnlYSU1CIaa38bxByfKHlMpt8GMYpvib0EboVfNESek,36568
|
|
6
|
+
lunalib/core/crypto.py,sha256=R_f2sj7ASNnMW8Dtf2LIWTw-vCUjXD33zJPqPcPQVB8,10684
|
|
7
|
+
lunalib/core/mempool.py,sha256=itYFGQEuUde0Xh6WXcEz_n8hDsNhxkEAlRQ5g_Qiygg,14845
|
|
8
|
+
lunalib/core/sm2.py,sha256=Eq8Er3XQW5rYJXwaPT5vw5NoVXbSWhyuvjoG1LMo-NQ,23454
|
|
9
|
+
lunalib/core/wallet.py,sha256=RNrEI7_tsaJOLcCJoTy_lLj22bc_bJtoO7iR3C3u7Ls,57435
|
|
10
|
+
lunalib/core/wallet_manager.py,sha256=KK58hrr_xF1vZ4qI6x_BJqrs9XXh5m0XbZYnZmi9yoU,26031
|
|
11
|
+
lunalib/core/wallet_sync_helper.py,sha256=CGfSBXvf8vg4SGsLaxsjGwHVbD9dmfcuMrZ_CO0J5lE,6282
|
|
12
|
+
lunalib/gtx/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
lunalib/gtx/bill_registry.py,sha256=J1TivYIzmJEVQHNJrZxqOOEbUSlJs7rQIXfSA90ztL4,4333
|
|
14
|
+
lunalib/gtx/digital_bill.py,sha256=EnQvAztMNE9uHuxXWmShEpNl084y-clHagK5s1Amvpc,10614
|
|
15
|
+
lunalib/gtx/genesis.py,sha256=Mic48kI93fzMoz3Zm8xXGk8MXqUhfpLsNFLs8-ZJdCE,15939
|
|
16
|
+
lunalib/mining/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
lunalib/mining/cuda_manager.py,sha256=PUnmVvpu98OTZNdKIIYpVXnY__Ng4pHyZoh8wU-tDCM,5174
|
|
18
|
+
lunalib/mining/difficulty.py,sha256=tzIYmdcm1Xr9-8wyTwwkXJvJoGDyE77o_nu9d81VGvI,3927
|
|
19
|
+
lunalib/mining/miner.py,sha256=8MYsp3-ua5K-8FneHWfEkdOezWhluDRe3ACJeIGAA-0,27930
|
|
20
|
+
lunalib/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
+
lunalib/storage/cache.py,sha256=U-riY8OTzxCOpl8yvhpbU3YUysEKgrPlmhO4F4cI9FM,5352
|
|
22
|
+
lunalib/storage/database.py,sha256=2f3Ie6JnuK7L0YGtAdZt5mgj90pokneXhSQKUyvx8Pc,8219
|
|
23
|
+
lunalib/storage/encryption.py,sha256=59g8vFFPAkc_L7t2TXas9Rs4oB3JB1t5ikmDbs4aaqM,4399
|
|
24
|
+
lunalib/transactions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
+
lunalib/transactions/security.py,sha256=3q0ENtUD9C3C6FbocwzbDtMXcedKEpeUQdEBNUVSHXA,10269
|
|
26
|
+
lunalib/transactions/transactions.py,sha256=3Y0Gu-vIdtIdIwj1z2oymIJ3LPPWsYTQULny-eVtvPA,18016
|
|
27
|
+
lunalib/transactions/validator.py,sha256=FQ-jVjj8VoVTlq65blB_hprAwJOtpc2peYdQk_L2xmg,2730
|
|
28
|
+
lunalib-1.5.2.dist-info/METADATA,sha256=D88XMMu1LCG1mmFt7NaavHGWndGw6nIPGUoKB1LZAvI,628
|
|
29
|
+
lunalib-1.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
30
|
+
lunalib-1.5.2.dist-info/top_level.txt,sha256=eLcoOCtOwfvoqUu5g5CNBZB9bdhGXbTwmjuOM7i8ylw,8
|
|
31
|
+
lunalib-1.5.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lunalib
|
core/__init__.py
DELETED
|
File without changes
|