Skip to content

Commit b2b28c9

Browse files
authored
Merge pull request #203 from neonlabsorg/202_remove_account_creation_on_get_balance
Remove account creation on `getbalance` request #202
2 parents bf56943 + 1a9a57a commit b2b28c9

File tree

2 files changed

+85
-22
lines changed

2 files changed

+85
-22
lines changed

proxy/plugin/solana_rest_api_tools.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,23 +1099,7 @@ def getTokens(client, signer, evm_loader, eth_acc, base_account):
10991099
balance = client.get_token_account_balance(token_account, commitment=Confirmed)
11001100
if 'error' in balance:
11011101
if NEW_USER_AIRDROP_AMOUNT > 0:
1102-
trx = Transaction()
1103-
sender_sol_info = client.get_account_info(account, commitment=Confirmed)
1104-
if sender_sol_info['result']['value'] is None:
1105-
trx.add(createEtherAccountTrx(client, bytes(eth_acc).hex(), evm_loader_id, signer)[0])
1106-
trx.add(transfer2(Transfer2Params(
1107-
source=getTokenAddr(signer.public_key()),
1108-
owner=signer.public_key(),
1109-
dest=token_account,
1110-
amount=NEW_USER_AIRDROP_AMOUNT*1_000_000_000,
1111-
decimals=9,
1112-
mint=ETH_TOKEN_MINT_ID,
1113-
program_id=TOKEN_PROGRAM_ID,
1114-
)))
1115-
logger.debug("Token transfer to %s as ethereum 0x%s amount %s", token_account, bytes(eth_acc).hex(), str(NEW_USER_AIRDROP_AMOUNT))
1116-
send_transaction(client, trx, signer)
1117-
1118-
return getTokens(client, signer, evm_loader, eth_acc, base_account)
1102+
return NEW_USER_AIRDROP_AMOUNT * 1_000_000_000
11191103
else:
11201104
logger.debug("'error' in balance:")
11211105
return 0

proxy/test_eth_sendRawTransaction.py

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
function getKeccakOfEmptyString() public view returns (bytes32 variant) {
5050
variant = keccak256(emprty_string);
5151
}
52-
52+
5353
bytes32 constant neonlabsHash = keccak256("neonlabs");
5454
5555
function endlessCycle() public view returns (bytes32 variant) {
@@ -61,7 +61,7 @@
6161
}
6262
6363
bytes32 public value = "";
64-
64+
6565
function initValue(string memory s) public {
6666
value = keccak256(bytes(s));
6767
}
@@ -71,11 +71,11 @@
7171
value = keccak256(abi.encodePacked(value));
7272
}
7373
}
74-
74+
7575
function getValue() public view returns (bytes32) {
7676
return value;
7777
}
78-
78+
7979
}
8080
'''
8181

@@ -210,16 +210,55 @@ def test_04_execute_with_bad_nonce(self):
210210
# @unittest.skip("a.i.")
211211
def test_05_transfer_one_gwei(self):
212212
print("\ntest_05_transfer_one_gwei")
213+
214+
one_gwei = 1_000_000_000
215+
213216
eth_account_alice = proxy.eth.account.create('alice')
214217
eth_account_bob = proxy.eth.account.create('bob')
215218
print('eth_account_alice.address:', eth_account_alice.address)
216219
print('eth_account_bob.address:', eth_account_bob.address)
217220

221+
if True:
222+
print("add funds to alice and bob")
223+
224+
print("alice")
225+
trx_transfer = proxy.eth.account.sign_transaction(dict(
226+
nonce=proxy.eth.get_transaction_count(proxy.eth.default_account),
227+
chainId=proxy.eth.chain_id,
228+
gas=987654321,
229+
gasPrice=0,
230+
to=eth_account_alice.address,
231+
value=one_gwei),
232+
eth_account.key
233+
)
234+
235+
print('trx_transfer:', trx_transfer)
236+
trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction)
237+
print('trx_transfer_hash:', trx_transfer_hash.hex())
238+
trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash)
239+
print('trx_transfer_receipt:', trx_transfer_receipt)
240+
241+
print("bob")
242+
trx_transfer = proxy.eth.account.sign_transaction(dict(
243+
nonce=proxy.eth.get_transaction_count(proxy.eth.default_account),
244+
chainId=proxy.eth.chain_id,
245+
gas=987654321,
246+
gasPrice=0,
247+
to=eth_account_bob.address,
248+
value=one_gwei),
249+
eth_account.key
250+
)
251+
252+
print('trx_transfer:', trx_transfer)
253+
trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction)
254+
print('trx_transfer_hash:', trx_transfer_hash.hex())
255+
trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash)
256+
print('trx_transfer_receipt:', trx_transfer_receipt)
257+
218258
alice_balance_before_transfer = proxy.eth.get_balance(eth_account_alice.address)
219259
bob_balance_before_transfer = proxy.eth.get_balance(eth_account_bob.address)
220260
print('alice_balance_before_transfer:', alice_balance_before_transfer)
221261
print('bob_balance_before_transfer:', bob_balance_before_transfer)
222-
one_gwei = 1_000_000_000
223262
print('one_gwei:', one_gwei)
224263

225264
trx_transfer = proxy.eth.account.sign_transaction(dict(
@@ -248,11 +287,51 @@ def test_05_transfer_one_gwei(self):
248287
# @unittest.skip("a.i.")
249288
def test_06_transfer_one_and_a_half_gweis(self):
250289
print("\ntest_06_transfer_one_and_a_half_gweis")
290+
251291
eth_account_alice = proxy.eth.account.create('alice')
252292
eth_account_bob = proxy.eth.account.create('bob')
253293
print('eth_account_alice.address:', eth_account_alice.address)
254294
print('eth_account_bob.address:', eth_account_bob.address)
255295

296+
one_gwei = 1_000_000_000
297+
298+
if True:
299+
print("add funds to alice and bob")
300+
301+
print("alice")
302+
trx_transfer = proxy.eth.account.sign_transaction(dict(
303+
nonce=proxy.eth.get_transaction_count(proxy.eth.default_account),
304+
chainId=proxy.eth.chain_id,
305+
gas=987654321,
306+
gasPrice=0,
307+
to=eth_account_alice.address,
308+
value=one_gwei),
309+
eth_account.key
310+
)
311+
312+
print('trx_transfer:', trx_transfer)
313+
trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction)
314+
print('trx_transfer_hash:', trx_transfer_hash.hex())
315+
trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash)
316+
print('trx_transfer_receipt:', trx_transfer_receipt)
317+
318+
print("bob")
319+
trx_transfer = proxy.eth.account.sign_transaction(dict(
320+
nonce=proxy.eth.get_transaction_count(proxy.eth.default_account),
321+
chainId=proxy.eth.chain_id,
322+
gas=987654321,
323+
gasPrice=0,
324+
to=eth_account_bob.address,
325+
value=one_gwei),
326+
eth_account.key
327+
)
328+
329+
print('trx_transfer:', trx_transfer)
330+
trx_transfer_hash = proxy.eth.send_raw_transaction(trx_transfer.rawTransaction)
331+
print('trx_transfer_hash:', trx_transfer_hash.hex())
332+
trx_transfer_receipt = proxy.eth.wait_for_transaction_receipt(trx_transfer_hash)
333+
print('trx_transfer_receipt:', trx_transfer_receipt)
334+
256335
alice_balance_before_transfer = proxy.eth.get_balance(eth_account_alice.address)
257336
bob_balance_before_transfer = proxy.eth.get_balance(eth_account_bob.address)
258337
print('alice_balance_before_transfer:', alice_balance_before_transfer)

0 commit comments

Comments
 (0)