lunalib 1.1.0__py3-none-any.whl → 1.2.3__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.
- core/__init__.py +0 -0
- core/blockchain.py +172 -0
- core/crypto.py +32 -0
- core/wallet.py +347 -0
- gtx/__init__.py +0 -0
- gtx/bill_registry.py +122 -0
- gtx/digital_bill.py +273 -0
- gtx/genesis.py +338 -0
- lunalib/__init__.py +4 -2
- lunalib/core/blockchain.py +210 -23
- lunalib/core/wallet.py +1 -1
- lunalib/gtx/genesis.py +8 -8
- lunalib/luna_lib.py +12 -2
- lunalib/mining/miner.py +552 -42
- {lunalib-1.1.0.dist-info → lunalib-1.2.3.dist-info}/METADATA +1 -1
- lunalib-1.2.3.dist-info/RECORD +50 -0
- lunalib-1.2.3.dist-info/top_level.txt +6 -0
- mining/__init__.py +0 -0
- mining/cuda_manager.py +137 -0
- mining/difficulty.py +106 -0
- mining/miner.py +107 -0
- storage/__init__.py +0 -0
- storage/cache.py +148 -0
- storage/database.py +222 -0
- storage/encryption.py +105 -0
- transactions/__init__.py +0 -0
- transactions/security.py +172 -0
- transactions/transactions.py +379 -0
- transactions/validator.py +71 -0
- lunalib-1.1.0.dist-info/RECORD +0 -30
- lunalib-1.1.0.dist-info/top_level.txt +0 -1
- {lunalib-1.1.0.dist-info → lunalib-1.2.3.dist-info}/WHEEL +0 -0
- {lunalib-1.1.0.dist-info → lunalib-1.2.3.dist-info}/entry_points.txt +0 -0
lunalib/core/blockchain.py
CHANGED
|
@@ -405,10 +405,12 @@ class BlockchainManager:
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
def _find_address_transactions(self, block: Dict, address: str) -> List[Dict]:
|
|
408
|
-
"""Find transactions in block that involve the address -
|
|
408
|
+
"""Find transactions in block that involve the address - FIXED VERSION"""
|
|
409
409
|
transactions = []
|
|
410
410
|
address_lower = address.lower()
|
|
411
411
|
|
|
412
|
+
print(f"🔍 Scanning block #{block.get('index')} for address: {address}")
|
|
413
|
+
|
|
412
414
|
# Check block reward (miner rewards)
|
|
413
415
|
miner = block.get('miner', '').lower()
|
|
414
416
|
if miner == address_lower:
|
|
@@ -416,36 +418,221 @@ class BlockchainManager:
|
|
|
416
418
|
'type': 'reward',
|
|
417
419
|
'from': 'network',
|
|
418
420
|
'to': address,
|
|
419
|
-
'amount': block.get('reward', 0),
|
|
421
|
+
'amount': float(block.get('reward', 0)),
|
|
420
422
|
'block_height': block.get('index'),
|
|
421
423
|
'timestamp': block.get('timestamp'),
|
|
422
424
|
'hash': f"reward_{block.get('index')}_{address}",
|
|
423
425
|
'status': 'confirmed',
|
|
424
|
-
'description': f'Mining reward for block #{block.get("index")}'
|
|
426
|
+
'description': f'Mining reward for block #{block.get("index")}',
|
|
427
|
+
'direction': 'incoming',
|
|
428
|
+
'effective_amount': float(block.get('reward', 0))
|
|
425
429
|
}
|
|
426
430
|
transactions.append(reward_tx)
|
|
427
431
|
print(f"🎁 Found mining reward: {block.get('reward', 0)} LUN for block #{block.get('index')}")
|
|
428
432
|
|
|
429
|
-
# Check
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
433
|
+
# Check all transactions in the block
|
|
434
|
+
block_transactions = block.get('transactions', [])
|
|
435
|
+
print(f" Block has {len(block_transactions)} transactions")
|
|
436
|
+
|
|
437
|
+
for tx_index, tx in enumerate(block_transactions):
|
|
438
|
+
print(f"\n TX #{tx_index}:")
|
|
439
|
+
|
|
440
|
+
# Convert all values to strings for easier matching
|
|
441
|
+
tx_str = str(tx).lower()
|
|
442
|
+
|
|
443
|
+
# Method 0: Check if address appears in transaction
|
|
444
|
+
if address_lower in tx_str:
|
|
445
|
+
print(f" 🔄 Address found in transaction #{tx_index}")
|
|
446
|
+
print(f" TX data: {tx}")
|
|
447
|
+
|
|
448
|
+
# Use the helper method to extract information
|
|
449
|
+
enhanced_tx = self._handle_regular_transfers(tx, address_lower)
|
|
450
|
+
|
|
451
|
+
if enhanced_tx.get('direction') in ['incoming', 'outgoing']:
|
|
452
|
+
enhanced_tx['block_height'] = block.get('index')
|
|
453
|
+
enhanced_tx['status'] = 'confirmed'
|
|
454
|
+
enhanced_tx['tx_index'] = tx_index
|
|
455
|
+
enhanced_tx['hash'] = tx.get('hash') or f"tx_{block.get('index')}_{tx_index}"
|
|
456
|
+
|
|
457
|
+
# Ensure amount and fee are floats
|
|
458
|
+
enhanced_tx['amount'] = float(enhanced_tx.get('amount', 0))
|
|
459
|
+
enhanced_tx['fee'] = float(enhanced_tx.get('fee', 0))
|
|
460
|
+
|
|
461
|
+
# Calculate effective amount based on direction
|
|
462
|
+
if enhanced_tx['direction'] == 'outgoing':
|
|
463
|
+
# For outgoing: negative (amount + fee)
|
|
464
|
+
enhanced_tx['effective_amount'] = -(enhanced_tx['amount'] + enhanced_tx['fee'])
|
|
465
|
+
print(f" ⬇️ OUTGOING: {enhanced_tx['amount']} + {enhanced_tx['fee']} fee = {enhanced_tx['effective_amount']}")
|
|
466
|
+
print(f" From: {enhanced_tx.get('from', 'unknown')}")
|
|
467
|
+
print(f" To: {enhanced_tx.get('to', 'unknown')}")
|
|
468
|
+
else:
|
|
469
|
+
# For incoming: positive amount only
|
|
470
|
+
enhanced_tx['effective_amount'] = enhanced_tx['amount']
|
|
471
|
+
print(f" ⬆️ INCOMING: +{enhanced_tx['amount']}")
|
|
472
|
+
print(f" From: {enhanced_tx.get('from', 'unknown')}")
|
|
473
|
+
print(f" To: {enhanced_tx.get('to', 'unknown')}")
|
|
474
|
+
|
|
475
|
+
transactions.append(enhanced_tx)
|
|
476
|
+
continue # Skip other parsing methods
|
|
434
477
|
|
|
435
|
-
#
|
|
436
|
-
if
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
478
|
+
# Method 1: Check for standard transfer format
|
|
479
|
+
if 'type' in tx or 'from' in tx or 'to' in tx:
|
|
480
|
+
from_addr = (tx.get('from') or '').lower()
|
|
481
|
+
to_addr = (tx.get('to') or '').lower()
|
|
482
|
+
amount = float(tx.get('amount', 0))
|
|
483
|
+
fee = float(tx.get('fee', 0))
|
|
441
484
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
485
|
+
# Check if this transaction involves our address
|
|
486
|
+
if from_addr == address_lower or to_addr == address_lower:
|
|
487
|
+
enhanced_tx = tx.copy()
|
|
488
|
+
enhanced_tx['block_height'] = block.get('index')
|
|
489
|
+
enhanced_tx['status'] = 'confirmed'
|
|
490
|
+
enhanced_tx['tx_index'] = tx_index
|
|
491
|
+
|
|
492
|
+
# Ensure type is set
|
|
493
|
+
if not enhanced_tx.get('type'):
|
|
494
|
+
enhanced_tx['type'] = tx.get('bill_type', 'transfer')
|
|
495
|
+
|
|
496
|
+
# Ensure amounts are floats
|
|
497
|
+
enhanced_tx['amount'] = amount
|
|
498
|
+
enhanced_tx['fee'] = fee
|
|
450
499
|
|
|
451
|
-
|
|
500
|
+
# Add direction information
|
|
501
|
+
if from_addr == address_lower:
|
|
502
|
+
enhanced_tx['direction'] = 'outgoing'
|
|
503
|
+
# For outgoing: negative (amount + fee)
|
|
504
|
+
enhanced_tx['effective_amount'] = -(amount + fee)
|
|
505
|
+
print(f" ⬇️ STANDARD OUTGOING from our address")
|
|
506
|
+
print(f" From: {from_addr} (OURS)")
|
|
507
|
+
print(f" To: {to_addr}")
|
|
508
|
+
print(f" Amount: {amount}, Fee: {fee}, Total: {enhanced_tx['effective_amount']}")
|
|
509
|
+
else:
|
|
510
|
+
enhanced_tx['direction'] = 'incoming'
|
|
511
|
+
enhanced_tx['effective_amount'] = amount
|
|
512
|
+
print(f" ⬆️ STANDARD INCOMING to our address")
|
|
513
|
+
print(f" From: {from_addr}")
|
|
514
|
+
print(f" To: {to_addr} (OURS)")
|
|
515
|
+
print(f" Amount: {amount}")
|
|
516
|
+
|
|
517
|
+
transactions.append(enhanced_tx)
|
|
518
|
+
continue
|
|
519
|
+
|
|
520
|
+
# Method 2: Check for GTX/bill_type format
|
|
521
|
+
if 'bill_type' in tx:
|
|
522
|
+
bill_type = tx.get('bill_type', '')
|
|
523
|
+
amount = float(tx.get('amount', 0))
|
|
524
|
+
fee = float(tx.get('fee', 0))
|
|
525
|
+
|
|
526
|
+
# Try to find address fields
|
|
527
|
+
address_fields = ['from_address', 'from', 'sender', 'to_address', 'to', 'receiver', 'owner']
|
|
528
|
+
|
|
529
|
+
for field in address_fields:
|
|
530
|
+
if field in tx:
|
|
531
|
+
tx_addr = (tx.get(field) or '').lower()
|
|
532
|
+
if tx_addr == address_lower:
|
|
533
|
+
enhanced_tx = tx.copy()
|
|
534
|
+
enhanced_tx['block_height'] = block.get('index')
|
|
535
|
+
enhanced_tx['status'] = 'confirmed'
|
|
536
|
+
enhanced_tx['tx_index'] = tx_index
|
|
537
|
+
enhanced_tx['type'] = bill_type.lower()
|
|
538
|
+
|
|
539
|
+
# Map bill_type to standard type
|
|
540
|
+
if 'gtx_genesis' in bill_type.lower():
|
|
541
|
+
enhanced_tx['type'] = 'gtx_genesis'
|
|
542
|
+
enhanced_tx['description'] = 'GTX Genesis Transaction'
|
|
543
|
+
|
|
544
|
+
enhanced_tx['amount'] = amount
|
|
545
|
+
enhanced_tx['fee'] = fee
|
|
546
|
+
|
|
547
|
+
# Determine direction
|
|
548
|
+
if field in ['from_address', 'from', 'sender']:
|
|
549
|
+
enhanced_tx['direction'] = 'outgoing'
|
|
550
|
+
enhanced_tx['effective_amount'] = -(amount + fee)
|
|
551
|
+
enhanced_tx['from'] = tx_addr
|
|
552
|
+
enhanced_tx['to'] = tx.get('to_address') or tx.get('receiver') or tx.get('to') or 'unknown'
|
|
553
|
+
print(f" ⬇️ GTX OUTGOING ({bill_type})")
|
|
554
|
+
print(f" From: {tx_addr} (OURS)")
|
|
555
|
+
print(f" Amount: {amount}, Fee: {fee}, Total: {enhanced_tx['effective_amount']}")
|
|
556
|
+
else:
|
|
557
|
+
enhanced_tx['direction'] = 'incoming'
|
|
558
|
+
enhanced_tx['effective_amount'] = amount
|
|
559
|
+
enhanced_tx['from'] = tx.get('from_address') or tx.get('sender') or tx.get('from') or 'network'
|
|
560
|
+
enhanced_tx['to'] = tx_addr
|
|
561
|
+
print(f" ⬆️ GTX INCOMING ({bill_type})")
|
|
562
|
+
print(f" To: {tx_addr} (OURS)")
|
|
563
|
+
print(f" Amount: {amount}")
|
|
564
|
+
|
|
565
|
+
transactions.append(enhanced_tx)
|
|
566
|
+
break
|
|
567
|
+
|
|
568
|
+
print(f"\n ✅ Total transactions found for address: {len(transactions)}")
|
|
569
|
+
|
|
570
|
+
# Debug: Show transaction types found
|
|
571
|
+
incoming = [t for t in transactions if t.get('direction') == 'incoming']
|
|
572
|
+
outgoing = [t for t in transactions if t.get('direction') == 'outgoing']
|
|
573
|
+
print(f" Incoming: {len(incoming)}, Outgoing: {len(outgoing)}")
|
|
574
|
+
|
|
575
|
+
return transactions
|
|
576
|
+
def _handle_regular_transfers(self, tx: Dict, address_lower: str) -> Dict:
|
|
577
|
+
"""Handle regular transfer transactions that might be in different formats"""
|
|
578
|
+
enhanced_tx = tx.copy()
|
|
579
|
+
|
|
580
|
+
# Try to extract addresses from various possible field names
|
|
581
|
+
possible_from_fields = ['from', 'sender', 'from_address', 'source', 'payer']
|
|
582
|
+
possible_to_fields = ['to', 'receiver', 'to_address', 'destination', 'payee']
|
|
583
|
+
possible_amount_fields = ['amount', 'value', 'quantity', 'transfer_amount']
|
|
584
|
+
possible_fee_fields = ['fee', 'gas', 'transaction_fee', 'gas_fee']
|
|
585
|
+
|
|
586
|
+
# Find from address
|
|
587
|
+
from_addr = ''
|
|
588
|
+
for field in possible_from_fields:
|
|
589
|
+
if field in tx:
|
|
590
|
+
from_addr = (tx.get(field) or '').lower()
|
|
591
|
+
break
|
|
592
|
+
|
|
593
|
+
# Find to address
|
|
594
|
+
to_addr = ''
|
|
595
|
+
for field in possible_to_fields:
|
|
596
|
+
if field in tx:
|
|
597
|
+
to_addr = (tx.get(field) or '').lower()
|
|
598
|
+
break
|
|
599
|
+
|
|
600
|
+
# Find amount
|
|
601
|
+
amount = 0
|
|
602
|
+
for field in possible_amount_fields:
|
|
603
|
+
if field in tx:
|
|
604
|
+
amount = float(tx.get(field, 0))
|
|
605
|
+
break
|
|
606
|
+
|
|
607
|
+
# Find fee
|
|
608
|
+
fee = 0
|
|
609
|
+
for field in possible_fee_fields:
|
|
610
|
+
if field in tx:
|
|
611
|
+
fee = float(tx.get(field, 0))
|
|
612
|
+
break
|
|
613
|
+
|
|
614
|
+
# Set direction
|
|
615
|
+
if from_addr == address_lower:
|
|
616
|
+
enhanced_tx['direction'] = 'outgoing'
|
|
617
|
+
enhanced_tx['effective_amount'] = -(amount + fee)
|
|
618
|
+
enhanced_tx['from'] = from_addr
|
|
619
|
+
enhanced_tx['to'] = to_addr
|
|
620
|
+
enhanced_tx['amount'] = amount
|
|
621
|
+
enhanced_tx['fee'] = fee
|
|
622
|
+
elif to_addr == address_lower:
|
|
623
|
+
enhanced_tx['direction'] = 'incoming'
|
|
624
|
+
enhanced_tx['effective_amount'] = amount
|
|
625
|
+
enhanced_tx['from'] = from_addr
|
|
626
|
+
enhanced_tx['to'] = to_addr
|
|
627
|
+
enhanced_tx['amount'] = amount
|
|
628
|
+
enhanced_tx['fee'] = fee
|
|
629
|
+
else:
|
|
630
|
+
# If we can't determine direction from addresses, check other fields
|
|
631
|
+
enhanced_tx['direction'] = 'unknown'
|
|
632
|
+
enhanced_tx['effective_amount'] = amount
|
|
633
|
+
|
|
634
|
+
# Set type if not present
|
|
635
|
+
if not enhanced_tx.get('type'):
|
|
636
|
+
enhanced_tx['type'] = 'transfer'
|
|
637
|
+
|
|
638
|
+
return enhanced_tx
|
lunalib/core/wallet.py
CHANGED
|
@@ -277,7 +277,7 @@ class LunaWallet:
|
|
|
277
277
|
def get_transaction_history(self) -> dict:
|
|
278
278
|
"""Get complete transaction history (both pending and confirmed)"""
|
|
279
279
|
try:
|
|
280
|
-
from lunalib.blockchain import BlockchainManager
|
|
280
|
+
from lunalib.core.blockchain import BlockchainManager
|
|
281
281
|
from lunalib.core.mempool import MempoolManager
|
|
282
282
|
|
|
283
283
|
blockchain = BlockchainManager()
|
lunalib/gtx/genesis.py
CHANGED
|
@@ -90,7 +90,7 @@ class GTXGenesis:
|
|
|
90
90
|
if signature == expected_signature:
|
|
91
91
|
signature_valid = True
|
|
92
92
|
verification_method = "metadata_hash_signature"
|
|
93
|
-
print(f"
|
|
93
|
+
print(f"Verified: hash(public_key + metadata_hash)")
|
|
94
94
|
|
|
95
95
|
# METHOD 3: Check DigitalBill calculated hash
|
|
96
96
|
elif signature_valid is None:
|
|
@@ -122,23 +122,23 @@ class GTXGenesis:
|
|
|
122
122
|
if signature == calculated_hash:
|
|
123
123
|
signature_valid = True
|
|
124
124
|
verification_method = "digital_bill_calculate_hash"
|
|
125
|
-
print(f"
|
|
125
|
+
print(f"Verified: DigitalBill.calculate_hash()")
|
|
126
126
|
print(f" Calculated hash: {calculated_hash}")
|
|
127
127
|
|
|
128
128
|
# Approach 2: Use the verify() method (checks all signature types)
|
|
129
129
|
elif digital_bill.verify():
|
|
130
130
|
signature_valid = True
|
|
131
131
|
verification_method = "digital_bill_verify_method"
|
|
132
|
-
print(f"
|
|
132
|
+
print(f"Verified: DigitalBill.verify()")
|
|
133
133
|
|
|
134
134
|
# Approach 3: Check if signature matches metadata_hash generation
|
|
135
135
|
elif signature == digital_bill._generate_metadata_hash():
|
|
136
136
|
signature_valid = True
|
|
137
137
|
verification_method = "digital_bill_metadata_hash"
|
|
138
|
-
print(f"
|
|
138
|
+
print(f"Verified: matches generated metadata_hash")
|
|
139
139
|
|
|
140
140
|
else:
|
|
141
|
-
print(f"
|
|
141
|
+
print(f"DigitalBill verification failed:")
|
|
142
142
|
print(f" Calculated hash: {calculated_hash}")
|
|
143
143
|
print(f" Signature: {signature}")
|
|
144
144
|
print(f" Metadata hash: {metadata_hash}")
|
|
@@ -173,19 +173,19 @@ class GTXGenesis:
|
|
|
173
173
|
if signature == bill_json_hash:
|
|
174
174
|
signature_valid = True
|
|
175
175
|
verification_method = "bill_json_hash"
|
|
176
|
-
print(f"
|
|
176
|
+
print(f"Verified: hash(bill_data_json)")
|
|
177
177
|
|
|
178
178
|
# Final fallback: accept any non-empty signature temporarily
|
|
179
179
|
if signature_valid is None and signature and len(signature) > 10:
|
|
180
180
|
signature_valid = True
|
|
181
181
|
verification_method = "fallback_accept"
|
|
182
|
-
print(f"
|
|
182
|
+
print(f"Using fallback acceptance for signature")
|
|
183
183
|
|
|
184
184
|
# If all methods failed
|
|
185
185
|
if signature_valid is None:
|
|
186
186
|
signature_valid = False
|
|
187
187
|
verification_method = "all_failed"
|
|
188
|
-
print(f"
|
|
188
|
+
print(f"All verification methods failed")
|
|
189
189
|
|
|
190
190
|
# Return result in same format as endpoint
|
|
191
191
|
if signature_valid:
|
lunalib/luna_lib.py
CHANGED
|
@@ -8,6 +8,7 @@ from mining.miner import GenesisMiner
|
|
|
8
8
|
from gtx.genesis import GTXGenesis
|
|
9
9
|
from transactions.transactions import TransactionManager
|
|
10
10
|
from core.blockchain import BlockchainManager
|
|
11
|
+
from core.mempool import MempoolManager
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class LunaLib:
|
|
@@ -19,6 +20,7 @@ class LunaLib:
|
|
|
19
20
|
GTX = GTXGenesis
|
|
20
21
|
Transaction = TransactionManager
|
|
21
22
|
Blockchain = BlockchainManager
|
|
23
|
+
Mempool = MempoolManager
|
|
22
24
|
|
|
23
25
|
@staticmethod
|
|
24
26
|
def get_version():
|
|
@@ -33,7 +35,8 @@ class LunaLib:
|
|
|
33
35
|
'Miner': 'GenesisMiner - Mining operations',
|
|
34
36
|
'GTX': 'GTXGenesis - GTX token operations',
|
|
35
37
|
'Transaction': 'TransactionManager - Transaction handling',
|
|
36
|
-
'Blockchain': 'BlockchainManager - Blockchain operations with endpoint support'
|
|
38
|
+
'Blockchain': 'BlockchainManager - Blockchain operations with endpoint support',
|
|
39
|
+
'Mempool': 'MempoolManager - Memory Pool management and endpoint'
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
|
|
@@ -50,6 +53,10 @@ def create_blockchain_manager(endpoint_url="https://bank.linglin.art"):
|
|
|
50
53
|
"""Create a blockchain manager with optional endpoint URL"""
|
|
51
54
|
return BlockchainManager(endpoint_url)
|
|
52
55
|
|
|
56
|
+
def create_mempool_manager(endpoint_url="https://bank.linglin.art"):
|
|
57
|
+
"""Create a blockchain manager with optional endpoint URL"""
|
|
58
|
+
return MempoolManager(network_endpoints=[endpoint_url])
|
|
59
|
+
|
|
53
60
|
def get_transaction_manager():
|
|
54
61
|
"""Get transaction manager instance"""
|
|
55
62
|
return TransactionManager()
|
|
@@ -63,9 +70,11 @@ __all__ = [
|
|
|
63
70
|
'GTXGenesis',
|
|
64
71
|
'TransactionManager',
|
|
65
72
|
'BlockchainManager',
|
|
73
|
+
'MempoolManager',
|
|
66
74
|
'create_wallet',
|
|
67
75
|
'create_miner',
|
|
68
76
|
'create_blockchain_manager',
|
|
77
|
+
'create_mempool_manager',
|
|
69
78
|
'get_transaction_manager'
|
|
70
79
|
]
|
|
71
80
|
|
|
@@ -74,4 +83,5 @@ LunaWallet = LunaWallet
|
|
|
74
83
|
GenesisMiner = GenesisMiner
|
|
75
84
|
GTXGenesis = GTXGenesis
|
|
76
85
|
TransactionManager = TransactionManager
|
|
77
|
-
BlockchainManager = BlockchainManager
|
|
86
|
+
BlockchainManager = BlockchainManager
|
|
87
|
+
MempoolManager = MempoolManager
|