Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#272 manage starage and holder accounts #274

Merged
merged 13 commits into from
Nov 12, 2021
3 changes: 3 additions & 0 deletions proxy/core/acceptor/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
LOCK = multiprocessing.Lock()

proxy_id_glob = multiprocessing.Value('i', 0)
new_acc_id_glob = multiprocessing.Value('i', 0)
manager = multiprocessing.Manager()
acc_list_glob = manager.list()


class AcceptorPool:
Expand Down
29 changes: 3 additions & 26 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import base58
import traceback
import threading
from .solana_rest_api_tools import EthereumAddress, create_account_with_seed, getTokens, \
getAccountInfo, call_signed, call_emulated, \
Trx, EthereumError, create_collateral_pool_address, getTokenAddr, STORAGE_SIZE, neon_config_load, MINIMAL_GAS_PRICE
from .solana_rest_api_tools import EthereumAddress, getTokens, getAccountInfo, \
call_signed, call_emulated, EthereumError, neon_config_load, MINIMAL_GAS_PRICE
from solana.rpc.commitment import Commitment, Confirmed
from web3 import Web3
import logging
Expand All @@ -45,27 +44,6 @@

EXTRA_GAS = int(os.environ.get("EXTRA_GAS", "0"))

class PermanentAccounts:
def __init__(self, client, signer, proxy_id):
self.operator = signer.public_key()
self.operator_token = getTokenAddr(self.operator)
self.proxy_id = proxy_id

proxy_id_bytes = proxy_id.to_bytes((proxy_id.bit_length() + 7) // 8, 'big')

storage_seed = keccak_256(b"storage" + proxy_id_bytes).hexdigest()[:32]
storage_seed = bytes(storage_seed, 'utf8')
self.storage = create_account_with_seed(client, funding=signer, base=signer, seed=storage_seed, storage_size=STORAGE_SIZE)

holder_seed = keccak_256(b"holder" + proxy_id_bytes).hexdigest()[:32]
holder_seed = bytes(holder_seed, 'utf8')
self.holder = create_account_with_seed(client, funding=signer, base=signer, seed=holder_seed, storage_size=STORAGE_SIZE)

collateral_pool_index = proxy_id % 4
self.collateral_pool_index_buf = collateral_pool_index.to_bytes(4, 'little')
self.collateral_pool_address = create_collateral_pool_address(collateral_pool_index)


class EthereumModel:
def __init__(self):
# Initialize user account
Expand Down Expand Up @@ -98,7 +76,6 @@ def __init__(self):
proxy_id_glob.value += 1
logger.debug("worker id {}".format(self.proxy_id))

self.perm_accs = PermanentAccounts(self.client, self.signer, self.proxy_id)
neon_config_load(self)
pass

Expand Down Expand Up @@ -415,7 +392,7 @@ def eth_sendRawTransaction(self, rawTrx):
]
})
try:
signature = call_signed(self.signer, self.client, trx, self.perm_accs, steps=250)
signature = call_signed(self.signer, self.client, trx, steps=250)

logger.debug('Transaction signature: %s %s', signature, eth_signature)

Expand Down
Loading