2
2
from enum import Enum
3
3
import rlp
4
4
5
- from .models import Transactions
5
+ from .models import Transactions , RollupTransactions
6
6
from sqlalchemy .orm import Session
7
7
from sqlalchemy import or_ , and_
8
8
11
11
import json
12
12
import base64
13
13
import time
14
- from backend .domain .types import TransactionType
15
- from web3 import Web3
16
- from backend .database_handler .contract_snapshot import ContractSnapshot
17
- import os
18
14
19
15
20
16
class TransactionAddressFilter (Enum ):
@@ -30,12 +26,6 @@ def __init__(
30
26
):
31
27
self .session = session
32
28
33
- # Connect to Hardhat Network
34
- port = os .environ .get ("HARDHAT_PORT" )
35
- url = os .environ .get ("HARDHAT_URL" )
36
- hardhat_url = f"{ url } :{ port } "
37
- self .web3 = Web3 (Web3 .HTTPProvider (hardhat_url ))
38
-
39
29
@staticmethod
40
30
def _parse_transaction_data (transaction_data : Transactions ) -> dict :
41
31
return {
@@ -59,7 +49,6 @@ def _parse_transaction_data(transaction_data: Transactions) -> dict:
59
49
transaction .hash
60
50
for transaction in transaction_data .triggered_transactions
61
51
],
62
- "ghost_contract_address" : transaction_data .ghost_contract_address ,
63
52
"appealed" : transaction_data .appealed ,
64
53
"timestamp_accepted" : transaction_data .timestamp_accepted ,
65
54
}
@@ -141,64 +130,6 @@ def insert_transaction(
141
130
from_address , to_address , data , value , type , nonce
142
131
)
143
132
144
- if type == TransactionType .DEPLOY_CONTRACT .value :
145
- # Hardhat account
146
- account = self .web3 .eth .accounts [0 ]
147
- private_key = os .environ .get ("HARDHAT_PRIVATE_KEY" )
148
-
149
- # Ghost contract
150
- # Read contract ABI and bytecode from compiled contract
151
- contract_file = os .path .join (
152
- os .getcwd (),
153
- "hardhat/artifacts/contracts/GhostContract.sol/GhostContract.json" ,
154
- )
155
-
156
- with open (contract_file , "r" ) as f :
157
- contract_json = json .loads (f .read ())
158
- abi = contract_json ["abi" ]
159
- bytecode = contract_json ["bytecode" ]
160
-
161
- # Create the contract instance
162
- contract = self .web3 .eth .contract (abi = abi , bytecode = bytecode )
163
-
164
- # Build the transaction
165
- gas_estimate = self .web3 .eth .estimate_gas (
166
- contract .constructor ().build_transaction (
167
- {
168
- "from" : account ,
169
- "nonce" : self .web3 .eth .get_transaction_count (account ),
170
- "gasPrice" : 0 ,
171
- }
172
- )
173
- )
174
- transaction = contract .constructor ().build_transaction (
175
- {
176
- "from" : account ,
177
- "nonce" : self .web3 .eth .get_transaction_count (account ),
178
- "gas" : gas_estimate ,
179
- "gasPrice" : 0 ,
180
- }
181
- )
182
-
183
- # Sign the transaction
184
- signed_tx = self .web3 .eth .account .sign_transaction (
185
- transaction , private_key = private_key
186
- )
187
-
188
- # Send the transaction
189
- tx_hash = self .web3 .eth .send_raw_transaction (signed_tx .raw_transaction )
190
-
191
- # Wait for the transaction receipt
192
- receipt = self .web3 .eth .wait_for_transaction_receipt (tx_hash )
193
- ghost_contract_address = receipt .contractAddress
194
-
195
- elif type == TransactionType .RUN_CONTRACT .value :
196
- genlayer_contract_address = to_address
197
- contract_snapshot = ContractSnapshot (
198
- genlayer_contract_address , self .session
199
- )
200
- ghost_contract_address = contract_snapshot .ghost_contract_address
201
-
202
133
new_transaction = Transactions (
203
134
hash = transaction_hash ,
204
135
from_address = from_address ,
@@ -221,7 +152,6 @@ def insert_transaction(
221
152
if triggered_by_hash
222
153
else None
223
154
),
224
- ghost_contract_address = ghost_contract_address ,
225
155
appealed = False ,
226
156
timestamp_accepted = None ,
227
157
)
@@ -265,44 +195,29 @@ def create_rollup_transaction(self, transaction_hash: str):
265
195
transaction = (
266
196
self .session .query (Transactions ).filter_by (hash = transaction_hash ).one ()
267
197
)
268
- rollup_input_data = json . dumps (
198
+ rollup_input_data = self . _transaction_data_to_str (
269
199
self ._parse_transaction_data (transaction )
270
- ).encode ("utf-8" )
271
-
272
- # Hardhat transaction
273
- account = self .web3 .eth .accounts [0 ]
274
- private_key = os .environ .get ("HARDHAT_PRIVATE_KEY" )
275
-
276
- gas_estimate = self .web3 .eth .estimate_gas (
277
- {
278
- "from" : account ,
279
- "to" : transaction .ghost_contract_address ,
280
- "value" : transaction .value ,
281
- "data" : rollup_input_data ,
282
- }
283
200
)
284
-
285
- transaction = {
286
- "from" : account ,
287
- "to" : transaction .ghost_contract_address ,
288
- "value" : transaction .value ,
289
- "data" : rollup_input_data ,
290
- "nonce" : self .web3 .eth .get_transaction_count (account ),
291
- "gas" : gas_estimate ,
292
- "gasPrice" : 0 ,
293
- }
294
-
295
- # Sign and send the transaction
296
- signed_tx = self .web3 .eth .account .sign_transaction (
297
- transaction , private_key = private_key
201
+ rollup_nonce = int (time .time () * 1000 )
202
+ rollup_transaction_hash = self ._generate_transaction_hash (
203
+ transaction .from_address ,
204
+ transaction .to_address ,
205
+ rollup_input_data ,
206
+ transaction .value ,
207
+ 0 ,
208
+ rollup_nonce ,
298
209
)
299
- tx_hash = self .web3 .eth .send_raw_transaction (signed_tx .raw_transaction )
300
-
301
- # Wait for transaction to be actually mined and get the receipt
302
- receipt = self .web3 .eth .wait_for_transaction_receipt (tx_hash )
303
-
304
- # Get full transaction details including input data
305
- transaction = self .web3 .eth .get_transaction (tx_hash )
210
+ rollup_transaction_record = RollupTransactions (
211
+ transaction_hash = rollup_transaction_hash ,
212
+ from_ = transaction .from_address ,
213
+ to_ = transaction .to_address ,
214
+ gas = 0 ,
215
+ gas_price = 0 ,
216
+ value = transaction .value ,
217
+ input = rollup_input_data ,
218
+ nonce = rollup_nonce ,
219
+ )
220
+ self .session .add (rollup_transaction_record )
306
221
307
222
def get_transaction_count (self , address : str ) -> int :
308
223
count = (
0 commit comments