44from solana ._layouts .system_instructions import SYSTEM_INSTRUCTIONS_LAYOUT , InstructionType
55from solana .publickey import PublicKey
66from solana .system_program import SYS_PROGRAM_ID
7- from solana .sysvar import SYSVAR_RENT_PUBKEY
7+ from solana .sysvar import SYSVAR_RENT_PUBKEY
88from solana .transaction import AccountMeta , TransactionInstruction , Transaction
99from spl .token .constants import TOKEN_PROGRAM_ID
10- from typing import Tuple , Optional
1110from logged_groups import logged_group
1211
1312from .address import accountWithSeed , ether2program , EthereumAddress
2423def create_account_with_seed_layout (base , seed , lamports , space ):
2524 return SYSTEM_INSTRUCTIONS_LAYOUT .build (
2625 dict (
27- instruction_type = InstructionType .CREATE_ACCOUNT_WITH_SEED ,
26+ instruction_type = InstructionType .CREATE_ACCOUNT_WITH_SEED ,
2827 args = dict (
2928 base = bytes (base ),
3029 seed = dict (length = len (seed ), chars = seed ),
@@ -44,15 +43,15 @@ def create_account_layout(ether, nonce):
4443
4544
4645def write_holder_layout (nonce , offset , data ):
47- return (bytes .fromhex ('12' )+
48- nonce .to_bytes (8 , byteorder = 'little' )+
49- offset .to_bytes (4 , byteorder = 'little' )+
50- len (data ).to_bytes (8 , byteorder = 'little' )+
46+ return (bytes .fromhex ('12' ) +
47+ nonce .to_bytes (8 , byteorder = 'little' ) +
48+ offset .to_bytes (4 , byteorder = 'little' ) +
49+ len (data ).to_bytes (8 , byteorder = 'little' ) +
5150 data )
5251
5352
5453def make_keccak_instruction_data (check_instruction_index , msg_len , data_start ):
55- if check_instruction_index > 255 and check_instruction_index < 0 :
54+ if check_instruction_index > 255 or check_instruction_index < 0 :
5655 raise Exception ("Invalid index for instruction - {}" .format (check_instruction_index ))
5756
5857 check_count = 1
@@ -76,9 +75,20 @@ def make_keccak_instruction_data(check_instruction_index, msg_len, data_start):
7675
7776@logged_group ("neon.Proxy" )
7877class NeonInstruction :
79- def __init__ (self , operator : PublicKey , operator_ether : Optional [ EthereumAddress ] = None ):
78+ def __init__ (self , operator : PublicKey ):
8079 self .operator_account = operator
81- self .operator_neon_address = ether2program (operator_ether )[0 ] if operator_ether else None
80+ self .operator_neon_address = None
81+ self .eth_accounts = []
82+ self .eth_trx = None
83+ self .msg = None
84+ self .collateral_pool_index_buf = None
85+ self .collateral_pool_address = None
86+ self .storage = None
87+ self .holder = None
88+ self .perm_accs_id = None
89+
90+ def init_operator_ether (self , operator_ether : EthereumAddress ):
91+ self .operator_neon_address = ether2program (operator_ether )[0 ]
8292
8393 def init_eth_trx (self , eth_trx , eth_accounts ):
8494 self .eth_accounts = eth_accounts
@@ -171,9 +181,9 @@ def createERC20TokenAccountTrx(self, token_info) -> Transaction:
171181
172182 def make_resize_instruction (self , account , code_account_old , code_account_new , seed ) -> TransactionInstruction :
173183 return TransactionInstruction (
174- program_id = EVM_LOADER_ID ,
175- data = bytearray .fromhex ("11" ) + bytes (seed ), # 17- ResizeStorageAccount
176- keys = [
184+ program_id = EVM_LOADER_ID ,
185+ data = bytearray .fromhex ("11" ) + bytes (seed ), # 17- ResizeStorageAccount
186+ keys = [
177187 AccountMeta (pubkey = PublicKey (account ), is_signer = False , is_writable = True ),
178188 (
179189 AccountMeta (pubkey = code_account_old , is_signer = False , is_writable = True )
@@ -195,7 +205,8 @@ def make_write_transaction(self, offset: int, data: bytes) -> Transaction:
195205 ]
196206 ))
197207
198- def make_keccak_instruction (self , check_instruction_index , msg_len , data_start ) -> TransactionInstruction :
208+ @staticmethod
209+ def make_keccak_instruction (check_instruction_index , msg_len , data_start ) -> TransactionInstruction :
199210 return TransactionInstruction (
200211 program_id = KECCAK_PROGRAM ,
201212 data = make_keccak_instruction_data (check_instruction_index , msg_len , data_start ),
@@ -206,9 +217,9 @@ def make_keccak_instruction(self, check_instruction_index, msg_len, data_start)
206217
207218 def make_05_call_instruction (self ) -> TransactionInstruction :
208219 return TransactionInstruction (
209- program_id = EVM_LOADER_ID ,
210- data = bytearray .fromhex ("05" ) + self .collateral_pool_index_buf + self .msg ,
211- keys = [
220+ program_id = EVM_LOADER_ID ,
221+ data = bytearray .fromhex ("05" ) + self .collateral_pool_index_buf + self .msg ,
222+ keys = [
212223 AccountMeta (pubkey = SYSVAR_INSTRUCTION_PUBKEY , is_signer = False , is_writable = False ),
213224 AccountMeta (pubkey = self .operator_account , is_signer = True , is_writable = True ),
214225 AccountMeta (pubkey = self .collateral_pool_address , is_signer = False , is_writable = True ),
@@ -224,17 +235,16 @@ def make_noniterative_call_transaction(self, length_before: int = 0) -> Transact
224235 trx .add (self .make_05_call_instruction ())
225236 return trx
226237
227- def make_cancel_transaction (self , cancel_keys = None ) -> Transaction :
228- append_keys = []
238+ def make_cancel_transaction (self , cancel_keys = None ) -> Transaction :
229239 if cancel_keys :
230240 append_keys = cancel_keys
231241 else :
232242 append_keys = self .eth_accounts
233243 append_keys += obligatory_accounts
234244 return Transaction ().add (TransactionInstruction (
235- program_id = EVM_LOADER_ID ,
236- data = bytearray .fromhex ("15" ) + self .eth_trx .nonce .to_bytes (8 , 'little' ),
237- keys = [
245+ program_id = EVM_LOADER_ID ,
246+ data = bytearray .fromhex ("15" ) + self .eth_trx .nonce .to_bytes (8 , 'little' ),
247+ keys = [
238248 AccountMeta (pubkey = self .storage , is_signer = False , is_writable = True ),
239249 AccountMeta (pubkey = self .operator_account , is_signer = True , is_writable = True ),
240250 AccountMeta (pubkey = INCINERATOR_PUBKEY , is_signer = False , is_writable = True ),
@@ -244,9 +254,9 @@ def make_cancel_transaction(self, cancel_keys = None) -> Transaction:
244254 def make_partial_call_or_continue_instruction (self , steps = 0 ) -> TransactionInstruction :
245255 data = bytearray .fromhex ("0D" ) + self .collateral_pool_index_buf + steps .to_bytes (8 , byteorder = "little" ) + self .msg
246256 return TransactionInstruction (
247- program_id = EVM_LOADER_ID ,
248- data = data ,
249- keys = [
257+ program_id = EVM_LOADER_ID ,
258+ data = data ,
259+ keys = [
250260 AccountMeta (pubkey = self .storage , is_signer = False , is_writable = True ),
251261
252262 AccountMeta (pubkey = SYSVAR_INSTRUCTION_PUBKEY , is_signer = False , is_writable = False ),
@@ -269,9 +279,9 @@ def make_partial_call_or_continue_from_account_data(self, steps, index=0) -> Tra
269279 if index :
270280 data = data + index .to_bytes (8 , byteorder = "little" )
271281 return Transaction ().add (TransactionInstruction (
272- program_id = EVM_LOADER_ID ,
273- data = data ,
274- keys = [
282+ program_id = EVM_LOADER_ID ,
283+ data = data ,
284+ keys = [
275285 AccountMeta (pubkey = self .holder , is_signer = False , is_writable = True ),
276286 AccountMeta (pubkey = self .storage , is_signer = False , is_writable = True ),
277287
0 commit comments