Ejemplo n.º 1
0
def init_wallet(endpoint):
    if TM_URL:
        return RPCWallet(TM_URL)
    web3 = init_web3(endpoint)
    if LEDGER:
        return LedgerWallet(web3, debug=True)
    if ETH_PRIVATE_KEY:
        return Web3Wallet(ETH_PRIVATE_KEY, web3)

        raise Exception('You should provide TM_URL or ETH_PRIVATE_KEY or '
                        'set LEDGER=1 to init wallet')
    return Web3Wallet(ETH_PRIVATE_KEY, web3)
Ejemplo n.º 2
0
def create_account(skale, skale_amount, eth_amount, debug=True):
    base_wallet = Web3Wallet(ETH_PRIVATE_KEY, skale.web3)
    wallet_dict = generate_account(skale.web3)
    wallet = Web3Wallet(wallet_dict['private_key'], skale.web3)

    send_tokens(skale, base_wallet, wallet.address, skale_amount, debug)
    send_ether(skale.web3, base_wallet, wallet.address, eth_amount, debug)

    if debug:
        check_ether_balance(skale.web3, wallet.address)
        check_skale_balance(skale, wallet.address)
    return wallet, wallet_dict['private_key']
Ejemplo n.º 3
0
def test_lib_init():
    web3 = init_web3(ENDPOINT)
    wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    skale = Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet)

    lib_contracts_info = skale._Skale__contracts_info
    for contract_info in CONTRACTS_INFO:
        assert isinstance(lib_contracts_info[contract_info.name], ContractInfo)

    lib_contracts = skale._Skale__contracts
    assert len(lib_contracts) == len(CONTRACTS_INFO)

    for lib_contract in lib_contracts.values():
        assert issubclass(type(lib_contract), BaseContract)
        assert lib_contract.address is not None
        assert int(lib_contract.address, 16) != 0
        assert web3.eth.getCode(lib_contract.address)
        assert lib_contract.abi is not None

    assert skale.abi is not None

    provider = skale.web3.provider
    assert isinstance(provider, WebsocketProvider)

    http_endpoint = 'http://localhost:8080'
    with mock.patch.object(Skale, '_Skale__init_contracts'):
        skale = Skale(http_endpoint, TEST_ABI_FILEPATH, wallet)
        provider = skale.web3.provider
        assert isinstance(provider, HTTPProvider)

    file_endpoint = 'file://local_file:1001'
    with pytest.raises(Exception):
        Skale(file_endpoint, TEST_ABI_FILEPATH, wallet)
Ejemplo n.º 4
0
def init_skale(node_id=None):
    if node_id is None:
        wallet = RPCWallet(os.environ['TM_URL']) if ENV != 'DEV' else None
    else:
        ETH_PRIVATE_KEY = os.environ['ETH_PRIVATE_KEY']
        web3 = init_web3(ENDPOINT)
        wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    return Skale(ENDPOINT, ABI_FILEPATH, wallet)
Ejemplo n.º 5
0
def init_wallet(endpoint):
    if not TM_URL and not ETH_PRIVATE_KEY:
        raise Exception(
            'You should provide TM_URL or ETH_PRIVATE_KEY to init wallet')
    if TM_URL:
        return RPCWallet(TM_URL)
    web3 = init_web3(endpoint)
    return Web3Wallet(ETH_PRIVATE_KEY, web3)
Ejemplo n.º 6
0
def init_skale_w_wallet(endpoint, wallet_type, pk_file=None, spin=True):
    """Init instance of SKALE library with wallet"""
    web3 = init_web3(endpoint)
    if wallet_type == 'hardware':
        wallet = LedgerWallet(web3)
    else:
        with open(pk_file, 'r') as f:
            pk = str(f.read()).strip()
        wallet = Web3Wallet(pk, web3)
    return init_skale(endpoint, wallet, spin)
Ejemplo n.º 7
0
def init_local_wallet(web3):
    """
    Inits Web3Wallet object with private key name from local wallet.

    :param Web3 web3: web3 object connected to some network

    :returns Web3Wallet: Inited Web3Wallet object
    """
    private_key = get_local_wallet_private_key()
    return Web3Wallet(private_key, web3)
Ejemplo n.º 8
0
def init_skale_w_wallet(endpoint,
                        wallet_type,
                        pk_file=None,
                        disable_spin=DISABLE_SPIN):
    """Init instance of SKALE library with wallet"""
    web3 = init_web3(endpoint)
    if wallet_type == 'ledger':
        wallet = LedgerWallet(web3)
    elif wallet_type == 'sgx':
        info = get_sgx_info()
        wallet = SgxWallet(info['server_url'],
                           web3,
                           key_name=info['key'],
                           path_to_cert=SGX_SSL_CERTS_PATH)
    else:
        with open(pk_file, 'r') as f:
            pk = str(f.read()).strip()
        wallet = Web3Wallet(pk, web3)
    return init_skale(endpoint, wallet, disable_spin)
Ejemplo n.º 9
0
def skale():
    web3 = init_web3(ENDPOINT)
    wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    return Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet)
Ejemplo n.º 10
0
def skale():
    '''Returns a SKALE instance with provider from config'''
    web3 = init_web3(ENDPOINT)
    wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    return Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet)
from skale.utils.account_tools import generate_accounts

logger = logging.getLogger(__name__)
init_default_logger()

CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
ENDPOINT = os.environ['ENDPOINT']
ABI_FILEPATH = os.path.join(CURRENT_DIR, 'manager.json')
ETH_PRIVATE_KEY = os.environ['ETH_PRIVATE_KEY']

N_WALLETS = os.environ['N_WALLETS']
SKALE_AMOUNT = os.environ['SKALE_AMOUNT']
ETH_AMOUNT = os.environ['ETH_AMOUNT']

web3 = init_web3(ENDPOINT)
wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
skale = Skale(ENDPOINT, ABI_FILEPATH, wallet)


def save_wallet_info(i, account):
    filename = f'wallet-{i}.txt'
    filepath = os.path.join(CURRENT_DIR, 'wallets', filename)
    with open(filepath, 'w') as outfile:
        logger.info(f'Saving info to {filename}')
        outfile.write(account["private_key"])


def prepare_wallets():
    accounts = generate_accounts(skale, skale.wallet, N_WALLETS, SKALE_AMOUNT,
                                 ETH_AMOUNT, True)
    for i, account in enumerate(accounts):