lunalib 1.6.6__py3-none-any.whl → 1.7.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.
- lunalib/core/blockchain.py +182 -2
- lunalib/core/daemon.py +108 -5
- lunalib/core/p2p.py +19 -4
- lunalib/core/wallet.py +747 -478
- lunalib/core/wallet_db.py +67 -0
- lunalib/mining/miner.py +33 -14
- {lunalib-1.6.6.dist-info → lunalib-1.7.3.dist-info}/METADATA +2 -1
- {lunalib-1.6.6.dist-info → lunalib-1.7.3.dist-info}/RECORD +10 -9
- {lunalib-1.6.6.dist-info → lunalib-1.7.3.dist-info}/WHEEL +0 -0
- {lunalib-1.6.6.dist-info → lunalib-1.7.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import sqlite3
|
|
2
|
+
import os
|
|
3
|
+
from cryptography.fernet import Fernet
|
|
4
|
+
import hashlib
|
|
5
|
+
import base64
|
|
6
|
+
import json
|
|
7
|
+
import time
|
|
8
|
+
|
|
9
|
+
class WalletDB:
|
|
10
|
+
def __init__(self, data_dir=None):
|
|
11
|
+
self.data_dir = data_dir or os.path.expanduser("~/.lunawallet")
|
|
12
|
+
os.makedirs(self.data_dir, exist_ok=True)
|
|
13
|
+
self.db_path = os.path.join(self.data_dir, "wallets.db")
|
|
14
|
+
self.conn = sqlite3.connect(self.db_path)
|
|
15
|
+
self._init_db()
|
|
16
|
+
|
|
17
|
+
def _init_db(self):
|
|
18
|
+
c = self.conn.cursor()
|
|
19
|
+
c.execute('''CREATE TABLE IF NOT EXISTS wallets (
|
|
20
|
+
address TEXT PRIMARY KEY,
|
|
21
|
+
label TEXT,
|
|
22
|
+
public_key TEXT,
|
|
23
|
+
encrypted_private_key BLOB,
|
|
24
|
+
is_locked INTEGER,
|
|
25
|
+
created REAL,
|
|
26
|
+
balance REAL,
|
|
27
|
+
available_balance REAL
|
|
28
|
+
)''')
|
|
29
|
+
self.conn.commit()
|
|
30
|
+
|
|
31
|
+
def save_wallet(self, address, label, public_key, encrypted_private_key, is_locked, created, balance, available_balance):
|
|
32
|
+
c = self.conn.cursor()
|
|
33
|
+
c.execute('''REPLACE INTO wallets (address, label, public_key, encrypted_private_key, is_locked, created, balance, available_balance)
|
|
34
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)''',
|
|
35
|
+
(address, label, public_key, encrypted_private_key, int(is_locked), created, balance, available_balance))
|
|
36
|
+
self.conn.commit()
|
|
37
|
+
|
|
38
|
+
def load_wallet(self, address):
|
|
39
|
+
c = self.conn.cursor()
|
|
40
|
+
c.execute('SELECT * FROM wallets WHERE address=?', (address,))
|
|
41
|
+
row = c.fetchone()
|
|
42
|
+
if row:
|
|
43
|
+
return {
|
|
44
|
+
'address': row[0],
|
|
45
|
+
'label': row[1],
|
|
46
|
+
'public_key': row[2],
|
|
47
|
+
'encrypted_private_key': row[3],
|
|
48
|
+
'is_locked': bool(row[4]),
|
|
49
|
+
'created': row[5],
|
|
50
|
+
'balance': row[6],
|
|
51
|
+
'available_balance': row[7],
|
|
52
|
+
}
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
def list_wallets(self):
|
|
56
|
+
c = self.conn.cursor()
|
|
57
|
+
c.execute('SELECT address, label, is_locked, balance, available_balance FROM wallets')
|
|
58
|
+
return c.fetchall()
|
|
59
|
+
|
|
60
|
+
def close(self):
|
|
61
|
+
self.conn.close()
|
|
62
|
+
|
|
63
|
+
# Example usage:
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
db = WalletDB()
|
|
66
|
+
print("Wallets:", db.list_wallets())
|
|
67
|
+
db.close()
|
lunalib/mining/miner.py
CHANGED
|
@@ -687,16 +687,20 @@ class Miner:
|
|
|
687
687
|
# Validate all transactions
|
|
688
688
|
valid_transactions = self._validate_transactions(mempool)
|
|
689
689
|
|
|
690
|
-
# If no valid transactions, create a reward transaction
|
|
691
|
-
if not valid_transactions:
|
|
692
|
-
reward_tx = self._create_empty_block_reward(new_index)
|
|
693
|
-
valid_transactions = [reward_tx]
|
|
694
|
-
|
|
695
690
|
# Calculate block difficulty based on transactions
|
|
696
691
|
block_difficulty = self._calculate_block_difficulty(valid_transactions)
|
|
697
692
|
|
|
698
|
-
# Calculate block reward
|
|
699
|
-
|
|
693
|
+
# Calculate block reward:
|
|
694
|
+
# - Empty blocks use LINEAR system: difficulty 1 = 1 LKC, difficulty 2 = 2 LKC, etc.
|
|
695
|
+
# - Blocks with transactions use EXPONENTIAL system: 10^(difficulty-1)
|
|
696
|
+
if not valid_transactions:
|
|
697
|
+
# Empty block: linear reward
|
|
698
|
+
total_reward = float(block_difficulty)
|
|
699
|
+
reward_tx = self._create_empty_block_reward(new_index, block_difficulty, total_reward)
|
|
700
|
+
valid_transactions = [reward_tx]
|
|
701
|
+
else:
|
|
702
|
+
# Regular block: exponential reward
|
|
703
|
+
total_reward = self._calculate_exponential_block_reward(block_difficulty)
|
|
700
704
|
|
|
701
705
|
# Create block data
|
|
702
706
|
block_data = {
|
|
@@ -843,17 +847,19 @@ class Miner:
|
|
|
843
847
|
"""
|
|
844
848
|
return self.difficulty_system.calculate_block_reward(difficulty)
|
|
845
849
|
|
|
846
|
-
def _create_empty_block_reward(self, block_index: int) -> Dict:
|
|
847
|
-
"""Create reward transaction for empty blocks"""
|
|
850
|
+
def _create_empty_block_reward(self, block_index: int, difficulty: int, reward_amount: float) -> Dict:
|
|
851
|
+
"""Create reward transaction for empty blocks using LINEAR reward system (difficulty = reward)"""
|
|
848
852
|
return {
|
|
849
853
|
'type': 'reward',
|
|
850
854
|
'from': 'network',
|
|
851
855
|
'to': self.config.miner_address,
|
|
852
|
-
'amount':
|
|
856
|
+
'amount': reward_amount,
|
|
853
857
|
'timestamp': time.time(),
|
|
854
858
|
'block_height': block_index,
|
|
859
|
+
'difficulty': difficulty,
|
|
855
860
|
'hash': f"reward_{block_index}_{int(time.time())}",
|
|
856
|
-
'description': 'Empty block mining reward'
|
|
861
|
+
'description': f'Empty block mining reward (Linear: Difficulty {difficulty} = {reward_amount} LKC)',
|
|
862
|
+
'is_empty_block': True
|
|
857
863
|
}
|
|
858
864
|
|
|
859
865
|
def _cuda_mine(self, block_data: Dict, difficulty: int) -> Optional[Dict]:
|
|
@@ -1021,14 +1027,27 @@ class Miner:
|
|
|
1021
1027
|
safe_print(f"⚠️ Could not validate previous hash: {e}")
|
|
1022
1028
|
|
|
1023
1029
|
# Validate reward matches difficulty
|
|
1024
|
-
|
|
1030
|
+
# Empty blocks use LINEAR system (difficulty = reward)
|
|
1031
|
+
# Regular blocks use EXPONENTIAL system (10^(difficulty-1))
|
|
1032
|
+
transactions = block.get('transactions', [])
|
|
1033
|
+
is_empty_block = len(transactions) == 1 and transactions[0].get('is_empty_block', False)
|
|
1034
|
+
|
|
1035
|
+
if is_empty_block:
|
|
1036
|
+
# Empty block: linear reward
|
|
1037
|
+
expected_reward = float(difficulty)
|
|
1038
|
+
else:
|
|
1039
|
+
# Regular block: exponential reward
|
|
1040
|
+
expected_reward = self.difficulty_system.calculate_block_reward(difficulty)
|
|
1041
|
+
|
|
1025
1042
|
actual_reward = block.get('reward', 0)
|
|
1026
1043
|
|
|
1027
1044
|
# Allow some tolerance for floating point comparison
|
|
1028
1045
|
if abs(actual_reward - expected_reward) > 0.01:
|
|
1029
|
-
|
|
1046
|
+
reward_type = "Linear" if is_empty_block else "Exponential"
|
|
1047
|
+
return False, f"Reward mismatch ({reward_type}): expected {expected_reward} LKC for difficulty {difficulty}, got {actual_reward} LKC"
|
|
1030
1048
|
|
|
1031
|
-
|
|
1049
|
+
reward_type = "Linear" if is_empty_block else "Exponential"
|
|
1050
|
+
safe_print(f"✅ Block validation passed ({reward_type}): Hash meets difficulty {difficulty}, Reward: {actual_reward} LKC")
|
|
1032
1051
|
return True, ""
|
|
1033
1052
|
|
|
1034
1053
|
def _clear_transactions_from_mempool(self, transactions: List[Dict]):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lunalib
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.3
|
|
4
4
|
Summary: Cryptocurrency Ecosystem library (LunaLib)
|
|
5
5
|
Home-page:
|
|
6
6
|
Author: Ling Lin
|
|
@@ -15,6 +15,7 @@ Requires-Dist: requests
|
|
|
15
15
|
Requires-Dist: numpy
|
|
16
16
|
Requires-Dist: pytest
|
|
17
17
|
Requires-Dist: pandas
|
|
18
|
+
Requires-Dist: base58
|
|
18
19
|
Dynamic: author
|
|
19
20
|
Dynamic: classifier
|
|
20
21
|
Dynamic: description
|
|
@@ -2,13 +2,14 @@ lunalib/__init__.py,sha256=fEvoHvfcC6ilDGQrhXaVmcdB4yDmuijxz6YZHkjbuBg,527
|
|
|
2
2
|
lunalib/cli.py,sha256=SyuJIhvqld-XL9ks9XFOuyqVb44qyBUbahlqE_RDVkM,524
|
|
3
3
|
lunalib/luna_lib.py,sha256=ue9Bs93xjpg7_GHSUJPKBhf8nF5YcbCIdoMIu-jDgG4,2748
|
|
4
4
|
lunalib/core/__init__.py,sha256=V86B0jI8snFIg8yCyd_Qoi2Tl6elQn_1cT-oeR6Ig3s,361
|
|
5
|
-
lunalib/core/blockchain.py,sha256=
|
|
5
|
+
lunalib/core/blockchain.py,sha256=yhK_PcyYuH5rAAbRZar-8DbF2kMWde7Ku2TOa1FIbrE,44530
|
|
6
6
|
lunalib/core/crypto.py,sha256=R_f2sj7ASNnMW8Dtf2LIWTw-vCUjXD33zJPqPcPQVB8,10684
|
|
7
|
-
lunalib/core/daemon.py,sha256=
|
|
7
|
+
lunalib/core/daemon.py,sha256=VhEky7-h-mwCBVFJp7DtoMkpvmGbdcbuoG9qNkbEvbg,21048
|
|
8
8
|
lunalib/core/mempool.py,sha256=itYFGQEuUde0Xh6WXcEz_n8hDsNhxkEAlRQ5g_Qiygg,14845
|
|
9
|
-
lunalib/core/p2p.py,sha256=
|
|
9
|
+
lunalib/core/p2p.py,sha256=cj3dda05oL6W5oMsvJ_HT3U0qr1FL6DR-YI78k3InKg,13784
|
|
10
10
|
lunalib/core/sm2.py,sha256=Eq8Er3XQW5rYJXwaPT5vw5NoVXbSWhyuvjoG1LMo-NQ,23454
|
|
11
|
-
lunalib/core/wallet.py,sha256=
|
|
11
|
+
lunalib/core/wallet.py,sha256=jgiFW_jBEgz5FwD-Q3ouPboU7nxcZ5nTHBa55izWXW8,64060
|
|
12
|
+
lunalib/core/wallet_db.py,sha256=6iefUlIilnsdh94G3PXIta579QDY_SMdagjdZG4SvJY,2300
|
|
12
13
|
lunalib/core/wallet_manager.py,sha256=KK58hrr_xF1vZ4qI6x_BJqrs9XXh5m0XbZYnZmi9yoU,26031
|
|
13
14
|
lunalib/core/wallet_sync_helper.py,sha256=CGfSBXvf8vg4SGsLaxsjGwHVbD9dmfcuMrZ_CO0J5lE,6282
|
|
14
15
|
lunalib/gtx/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -18,7 +19,7 @@ lunalib/gtx/genesis.py,sha256=dDiLz-jW0zr5WUifYo9lzsrafQGOuZ9oakv_TX6QdPg,16028
|
|
|
18
19
|
lunalib/mining/__init__.py,sha256=kOwXt_fwjHLUvV3XxieG2LZyKMW316brXLF8V8lHBUo,193
|
|
19
20
|
lunalib/mining/cuda_manager.py,sha256=VjVx9KLhT2F1jOOhva8ioGP32oQIAciZjf1irWl1jJY,5136
|
|
20
21
|
lunalib/mining/difficulty.py,sha256=hKCtvEovb4le5Fnhz6Mm8-Cugjm_CduJnZA2aNC2eyU,5326
|
|
21
|
-
lunalib/mining/miner.py,sha256=
|
|
22
|
+
lunalib/mining/miner.py,sha256=WP5UBOajLYT9JzAjLAshwq-f8CsLKYdLJpUX9kY2PdI,48898
|
|
22
23
|
lunalib/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
24
|
lunalib/storage/cache.py,sha256=U-riY8OTzxCOpl8yvhpbU3YUysEKgrPlmhO4F4cI9FM,5352
|
|
24
25
|
lunalib/storage/database.py,sha256=2f3Ie6JnuK7L0YGtAdZt5mgj90pokneXhSQKUyvx8Pc,8219
|
|
@@ -27,7 +28,7 @@ lunalib/transactions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
27
28
|
lunalib/transactions/security.py,sha256=cQJRasJ37Z8mJo8gt0JJOb0_M9CQ0QScr67y3M_NP4Q,10309
|
|
28
29
|
lunalib/transactions/transactions.py,sha256=3PgyW8gDQwY-gAPGY_T3m7RE_9HzEIOjTf6CWCsOKFY,18151
|
|
29
30
|
lunalib/transactions/validator.py,sha256=FQ-jVjj8VoVTlq65blB_hprAwJOtpc2peYdQk_L2xmg,2730
|
|
30
|
-
lunalib-1.
|
|
31
|
-
lunalib-1.
|
|
32
|
-
lunalib-1.
|
|
33
|
-
lunalib-1.
|
|
31
|
+
lunalib-1.7.3.dist-info/METADATA,sha256=fIuJMB5peqbLQwWN3JOWQBC5ppz8vjC2lP5P79Dx1O0,797
|
|
32
|
+
lunalib-1.7.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
33
|
+
lunalib-1.7.3.dist-info/top_level.txt,sha256=eLcoOCtOwfvoqUu5g5CNBZB9bdhGXbTwmjuOM7i8ylw,8
|
|
34
|
+
lunalib-1.7.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|