|
16 | 16 | from backend.database_handler.contract_snapshot import ContractSnapshot
|
17 | 17 | import os
|
18 | 18 |
|
| 19 | +from backend.rollup.consensus_service import ConsensusService |
| 20 | + |
19 | 21 |
|
20 | 22 | class TransactionAddressFilter(Enum):
|
21 | 23 | ALL = "all"
|
@@ -145,64 +147,6 @@ def insert_transaction(
|
145 | 147 | )
|
146 | 148 | ghost_contract_address = None
|
147 | 149 |
|
148 |
| - if type == TransactionType.DEPLOY_CONTRACT.value: |
149 |
| - # Hardhat account |
150 |
| - account = self.web3.eth.accounts[0] |
151 |
| - private_key = os.environ.get("HARDHAT_PRIVATE_KEY") |
152 |
| - |
153 |
| - # Ghost contract |
154 |
| - # Read contract ABI and bytecode from compiled contract |
155 |
| - # contract_file = os.path.join( |
156 |
| - # os.getcwd(), |
157 |
| - # "app/hardhat/artifacts/contracts/GhostContract.sol/GhostContract.json", |
158 |
| - # ) |
159 |
| - |
160 |
| - # with open(contract_file, "r") as f: |
161 |
| - # contract_json = json.loads(f.read()) |
162 |
| - # abi = contract_json["abi"] |
163 |
| - # bytecode = contract_json["bytecode"] |
164 |
| - |
165 |
| - # # Create the contract instance |
166 |
| - # contract = self.web3.eth.contract(abi=abi, bytecode=bytecode) |
167 |
| - |
168 |
| - # # Build the transaction |
169 |
| - # gas_estimate = self.web3.eth.estimate_gas( |
170 |
| - # contract.constructor().build_transaction( |
171 |
| - # { |
172 |
| - # "from": account, |
173 |
| - # "nonce": self.web3.eth.get_transaction_count(account), |
174 |
| - # "gasPrice": 0, |
175 |
| - # } |
176 |
| - # ) |
177 |
| - # ) |
178 |
| - # transaction = contract.constructor().build_transaction( |
179 |
| - # { |
180 |
| - # "from": account, |
181 |
| - # "nonce": self.web3.eth.get_transaction_count(account), |
182 |
| - # "gas": gas_estimate, |
183 |
| - # "gasPrice": 0, |
184 |
| - # } |
185 |
| - # ) |
186 |
| - |
187 |
| - # # Sign the transaction |
188 |
| - # signed_tx = self.web3.eth.account.sign_transaction( |
189 |
| - # transaction, private_key=private_key |
190 |
| - # ) |
191 |
| - |
192 |
| - # # Send the transaction |
193 |
| - # tx_hash = self.web3.eth.send_raw_transaction(signed_tx.raw_transaction) |
194 |
| - |
195 |
| - # # Wait for the transaction receipt |
196 |
| - # receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash) |
197 |
| - # ghost_contract_address = receipt.contractAddress |
198 |
| - |
199 |
| - elif type == TransactionType.RUN_CONTRACT.value: |
200 |
| - genlayer_contract_address = to_address |
201 |
| - # contract_snapshot = ContractSnapshot( |
202 |
| - # genlayer_contract_address, self.session |
203 |
| - # ) |
204 |
| - # ghost_contract_address = contract_snapshot.ghost_contract_address |
205 |
| - |
206 | 150 | new_transaction = Transactions(
|
207 | 151 | hash=transaction_hash,
|
208 | 152 | from_address=from_address,
|
@@ -235,9 +179,6 @@ def insert_transaction(
|
235 | 179 |
|
236 | 180 | self.session.flush() # So that `created_at` gets set
|
237 | 181 |
|
238 |
| - if type != TransactionType.SEND.value: |
239 |
| - self.create_rollup_transaction(new_transaction.hash) |
240 |
| - |
241 | 182 | return new_transaction.hash
|
242 | 183 |
|
243 | 184 | def get_transaction_by_hash(self, transaction_hash: str) -> dict | None:
|
@@ -280,36 +221,40 @@ def create_rollup_transaction(self, transaction_hash: str):
|
280 | 221 | account = self.web3.eth.accounts[0]
|
281 | 222 | private_key = os.environ.get("HARDHAT_PRIVATE_KEY")
|
282 | 223 |
|
283 |
| - # gas_estimate = self.web3.eth.estimate_gas( |
284 |
| - # { |
285 |
| - # "from": account, |
286 |
| - # "to": transaction.ghost_contract_address, |
287 |
| - # "value": transaction.value, |
288 |
| - # "data": rollup_input_data, |
289 |
| - # } |
290 |
| - # ) |
291 |
| - |
292 |
| - # transaction = { |
293 |
| - # "from": account, |
294 |
| - # "to": transaction.ghost_contract_address, |
295 |
| - # "value": transaction.value, |
296 |
| - # "data": rollup_input_data, |
297 |
| - # "nonce": self.web3.eth.get_transaction_count(account), |
298 |
| - # "gas": gas_estimate, |
299 |
| - # "gasPrice": 0, |
300 |
| - # } |
301 |
| - |
302 |
| - # # Sign and send the transaction |
303 |
| - # signed_tx = self.web3.eth.account.sign_transaction( |
304 |
| - # transaction, private_key=private_key |
305 |
| - # ) |
306 |
| - # tx_hash = self.web3.eth.send_raw_transaction(signed_tx.raw_transaction) |
307 |
| - |
308 |
| - # # Wait for transaction to be actually mined and get the receipt |
309 |
| - # receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash) |
310 |
| - |
311 |
| - # # Get full transaction details including input data |
312 |
| - # transaction = self.web3.eth.get_transaction(tx_hash) |
| 224 | + try: |
| 225 | + gas_estimate = self.web3.eth.estimate_gas( |
| 226 | + { |
| 227 | + "from": account, |
| 228 | + "to": transaction.ghost_contract_address, |
| 229 | + "value": transaction.value, |
| 230 | + "data": rollup_input_data, |
| 231 | + } |
| 232 | + ) |
| 233 | + |
| 234 | + transaction = { |
| 235 | + "from": account, |
| 236 | + "to": transaction.ghost_contract_address, |
| 237 | + "value": transaction.value, |
| 238 | + "data": rollup_input_data, |
| 239 | + "nonce": self.web3.eth.get_transaction_count(account), |
| 240 | + "gas": gas_estimate, |
| 241 | + "gasPrice": 0, |
| 242 | + } |
| 243 | + |
| 244 | + # Sign and send the transaction |
| 245 | + signed_tx = self.web3.eth.account.sign_transaction( |
| 246 | + transaction, private_key=private_key |
| 247 | + ) |
| 248 | + tx_hash = self.web3.eth.send_raw_transaction(signed_tx.raw_transaction) |
| 249 | + |
| 250 | + # Wait for transaction to be actually mined and get the receipt |
| 251 | + receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash) |
| 252 | + |
| 253 | + # Get full transaction details including input data |
| 254 | + transaction = self.web3.eth.get_transaction(tx_hash) |
| 255 | + |
| 256 | + except Exception as e: |
| 257 | + print(f"Error creating rollup transaction: {e}") |
313 | 258 |
|
314 | 259 | def get_transaction_count(self, address: str) -> int:
|
315 | 260 | count = (
|
|
0 commit comments