28
28
from hathor .indexes .height_index import HeightInfo
29
29
from hathor .profiler import get_cpu_profiler
30
30
from hathor .pubsub import PubSubManager
31
- from hathor .transaction .base_transaction import BaseTransaction
31
+ from hathor .transaction .base_transaction import BaseTransaction , TxOutput
32
32
from hathor .transaction .block import Block
33
33
from hathor .transaction .storage .exceptions import (
34
34
TransactionDoesNotExist ,
@@ -305,7 +305,13 @@ def get_best_block(self) -> Block:
305
305
def _save_or_verify_genesis (self ) -> None :
306
306
"""Save all genesis in the storage."""
307
307
self ._saving_genesis = True
308
- for tx in self ._get_genesis_from_settings ():
308
+ genesis_txs = [
309
+ self ._construct_genesis_block (),
310
+ self ._construct_genesis_tx1 (),
311
+ self ._construct_genesis_tx2 (),
312
+ ]
313
+
314
+ for tx in genesis_txs :
309
315
try :
310
316
assert tx .hash is not None
311
317
tx2 = self .get_transaction (tx .hash )
@@ -318,14 +324,6 @@ def _save_or_verify_genesis(self) -> None:
318
324
self ._genesis_cache [tx2 .hash ] = tx2
319
325
self ._saving_genesis = False
320
326
321
- def _get_genesis_from_settings (self ) -> list [BaseTransaction ]:
322
- """Return all genesis from settings."""
323
- from hathor .transaction .genesis import get_all_genesis
324
- all_genesis = get_all_genesis (self ._settings )
325
- for tx in all_genesis :
326
- tx .storage = self
327
- return all_genesis
328
-
329
327
def _save_to_weakref (self , tx : BaseTransaction ) -> None :
330
328
""" Save transaction to weakref.
331
329
"""
@@ -1089,6 +1087,48 @@ def compute_transactions_that_became_invalid(self, new_best_height: int) -> list
1089
1087
to_remove .append (tx )
1090
1088
return to_remove
1091
1089
1090
+ def _construct_genesis_block (self ) -> Block :
1091
+ """Return the genesis block."""
1092
+ block = Block (
1093
+ storage = self ,
1094
+ nonce = self ._settings .GENESIS_BLOCK_NONCE ,
1095
+ timestamp = self ._settings .GENESIS_BLOCK_TIMESTAMP ,
1096
+ weight = self ._settings .MIN_BLOCK_WEIGHT ,
1097
+ outputs = [
1098
+ TxOutput (self ._settings .GENESIS_TOKENS , self ._settings .GENESIS_OUTPUT_SCRIPT ),
1099
+ ],
1100
+ )
1101
+ block .update_hash ()
1102
+
1103
+ assert block .hash == self ._settings .GENESIS_BLOCK_HASH
1104
+ return block
1105
+
1106
+ def _construct_genesis_tx1 (self ) -> Transaction :
1107
+ """Return the genesis tx1."""
1108
+ tx1 = Transaction (
1109
+ storage = self ,
1110
+ nonce = self ._settings .GENESIS_TX1_NONCE ,
1111
+ timestamp = self ._settings .GENESIS_TX1_TIMESTAMP ,
1112
+ weight = self ._settings .MIN_TX_WEIGHT ,
1113
+ )
1114
+ tx1 .update_hash ()
1115
+
1116
+ assert tx1 .hash == self ._settings .GENESIS_TX1_HASH
1117
+ return tx1
1118
+
1119
+ def _construct_genesis_tx2 (self ) -> Transaction :
1120
+ """Return the genesis tx2."""
1121
+ tx2 = Transaction (
1122
+ storage = self ,
1123
+ nonce = self ._settings .GENESIS_TX2_NONCE ,
1124
+ timestamp = self ._settings .GENESIS_TX2_TIMESTAMP ,
1125
+ weight = self ._settings .MIN_TX_WEIGHT ,
1126
+ )
1127
+ tx2 .update_hash ()
1128
+
1129
+ assert tx2 .hash == self ._settings .GENESIS_TX2_HASH
1130
+ return tx2
1131
+
1092
1132
1093
1133
class BaseTransactionStorage (TransactionStorage ):
1094
1134
indexes : Optional [IndexesManager ]
0 commit comments