Ejemplo n.º 1
0
def call(keyfile, password):
    print("------------------------------------------------------------------")
    print("Trying {}".format(password))
    print("------------------------------------------------------------------")

    try:
        Account.load(keyfile, password=password)
    except ValueError as e:
        if str(e) == 'MAC mismatch. Password incorrect?':
            return False
        # else raise, as we got unexpected error
        raise e

    print("Found password: {}".format(password))
    return True
Ejemplo n.º 2
0
 def player_roll_dice(self, bet_size_ether, chances, wallet_path,
                      wallet_password):
     """
     Work in progress:
     https://github.com/AndreMiras/EtherollApp/issues/1
     """
     roll_under = chances
     value_wei = w3.toWei(bet_size_ether, 'ether')
     gas = 310000
     gas_price = w3.toWei(4, 'gwei')
     # since Account.load is hanging while decrypting the password
     # we set password to None and use `w3.eth.account.decrypt` instead
     account = Account.load(wallet_path, password=None)
     from_address_normalized = checksum_encode(account.address)
     nonce = self.web3.eth.getTransactionCount(from_address_normalized)
     transaction = {
         # 'chainId': ChainID.ROPSTEN.value,
         'chainId': int(self.web3.net.version),
         'gas': gas,
         'gasPrice': gas_price,
         'nonce': nonce,
         'value': value_wei,
     }
     transaction = self.contract.functions.playerRollDice(
         roll_under).buildTransaction(transaction)
     encrypted_key = open(wallet_path).read()
     private_key = w3.eth.account.decrypt(encrypted_key, wallet_password)
     signed_tx = self.web3.eth.account.signTransaction(
         transaction, private_key)
     tx_hash = self.web3.eth.sendRawTransaction(signed_tx.rawTransaction)
     print("tx_hash:", tx_hash.hex())
     return tx_hash
Ejemplo n.º 3
0
def test_store_absolute(app, account):
    s = app.services.accounts
    tmpdir = tempfile.mkdtemp()
    account.path = os.path.join(tmpdir, 'account1')
    assert os.path.isabs(account.path)
    s.add_account(account)
    assert os.path.exists(account.path)
    account_reloaded = Account.load(account.path)
    assert account_reloaded.address == account.address
    shutil.rmtree(tmpdir)
    account.path = None
Ejemplo n.º 4
0
def test_store_absolute(app, account):
    s = app.services.accounts
    tmpdir = tempfile.mkdtemp()
    account.path = os.path.join(tmpdir, "account1")
    assert os.path.isabs(account.path)
    s.add_account(account)
    assert os.path.exists(account.path)
    account_reloaded = Account.load(account.path)
    assert account_reloaded.address == account.address
    shutil.rmtree(tmpdir)
    account.path = None
Ejemplo n.º 5
0
def test_store_private(app, account, password):
    s = app.services.accounts
    account.path = os.path.join(app.config["accounts"]["keystore_dir"], "account1")
    s.add_account(account, include_id=False, include_address=False)
    account_reloaded = Account.load(account.path)
    assert account_reloaded.address is None
    assert account_reloaded.uuid is None
    account_reloaded.unlock(password)
    assert account_reloaded.address == account.address
    assert account_reloaded.uuid is None
    account.path = None
def test_store_private(app, account, password):
    s = app.services.accounts
    account.path = os.path.join(app.config['accounts']['keystore_dir'], 'account1')
    s.add_account(account, include_id=False, include_address=False)
    account_reloaded = Account.load(account.path)
    assert account_reloaded.address is None
    assert account_reloaded.uuid is None
    account_reloaded.unlock(password)
    assert account_reloaded.address == account.address
    assert account_reloaded.uuid is None
    account.path = None
Ejemplo n.º 7
0
def test_store(app, account):
    s = app.services.accounts
    account.path = os.path.join(app.config["accounts"]["keystore_dir"], "account1")
    s.add_account(account, include_id=True, include_address=True)
    assert os.path.exists(account.path)
    account_reloaded = Account.load(account.path)
    assert account_reloaded.uuid is not None
    assert account_reloaded.address is not None
    assert account_reloaded.uuid == account.uuid
    assert account_reloaded.address == account.address
    assert account_reloaded.privkey is None
    assert account_reloaded.path == account.path
    assert account.privkey is not None
    account.path = None
def test_store(app, account):
    s = app.services.accounts
    account.path = os.path.join(app.config['accounts']['keystore_dir'], 'account1')
    s.add_account(account, include_id=True, include_address=True)
    assert os.path.exists(account.path)
    account_reloaded = Account.load(account.path)
    assert account_reloaded.uuid is not None
    assert account_reloaded.address is not None
    assert account_reloaded.uuid == account.uuid
    assert account_reloaded.address == account.address
    assert account_reloaded.privkey is None
    assert account_reloaded.path == account.path
    assert account.privkey is not None
    account.path = None
Ejemplo n.º 9
0
 def player_roll_dice(self,
                      bet_size_ether,
                      chances,
                      wallet_path,
                      wallet_password,
                      gas_price_gwei=DEFAULT_GAS_PRICE_GWEI):
     """
     Signs and broadcasts `playerRollDice` transaction.
     Returns transaction hash.
     """
     roll_under = chances
     # `w3.toWei` one has some issues on Android, see:
     # https://github.com/AndreMiras/EtherollApp/issues/77
     # value_wei = w3.toWei(bet_size_ether, 'ether')
     value_wei = int(bet_size_ether * 1e18)
     gas = 310000
     gas_price = w3.toWei(gas_price_gwei, 'gwei')
     # since Account.load is hanging while decrypting the password
     # we set password to None and use `w3.eth.account.decrypt` instead
     account = Account.load(wallet_path, password=None)
     from_address_normalized = checksum_encode(account.address)
     nonce = self.web3.eth.getTransactionCount(from_address_normalized)
     transaction = {
         'chainId': self.chain_id.value,
         'gas': gas,
         'gasPrice': gas_price,
         'nonce': nonce,
         'value': value_wei,
     }
     transaction = self.contract.functions.playerRollDice(
         roll_under).buildTransaction(transaction)
     private_key = AccountUtils.get_private_key(wallet_path,
                                                wallet_password)
     signed_tx = self.web3.eth.account.signTransaction(
         transaction, private_key)
     tx_hash = self.web3.eth.sendRawTransaction(signed_tx.rawTransaction)
     return tx_hash