# Buggy code
def modify_blockchain_account(
    self,
    blockchain: str,
    account: typing.BlockchainAddress,
    append_or_remove: str,
    add_or_sub: Callable[[FVal, FVal], FVal],
) -> BlockchainBalancesUpdate:
    if blockchain == S_BTC:
        if append_or_remove == "remove" and account not in self.accounts[S_BTC]:
            raise InputError("Tried to remove a non existing BTC account")
        self.modify_btc_account(account, append_or_remove, add_or_sub)

    elif blockchain == S_ETH:
        if append_or_remove == "remove" and account not in self.accounts[S_ETH]:
            raise InputError("Tried to remove a non existing ETH account")
        self.modify_eth_account(account, append_or_remove, add_or_sub)
    else:
        raise InputError(
            "Unsupported blockchain {} provided at remove_blockchain_account".format(
                blockchain
            )
        )

    return {"per_account": self.balances, "totals": self.totals}


# Traceback (zerorpc.exceptions.RemoteError)
Traceback (most recent call last):
File "/home/lefteris/.virtualenvs/rotkehlchen/bin/zerorpc", line 11, in <module>
load_entry_point('zerorpc==0.6.1', 'console_scripts', 'zerorpc')()
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/cli.py", line 310, in main
return run_client(args)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/cli.py", line 269, in run_client
results = client(args.command, *call_args)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/core.py", line 270, in __call__
return self._process_response(request_event, bufchan, timeout)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/core.py", line 238, in _process_response
reply_event, self._handle_remote_error)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/patterns.py", line 45, in process_answer
raise exception
zerorpc.exceptions.RemoteError: Traceback (most recent call last):
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/web3/contract.py", line 1214, in call_contract_function
output_data = decode_abi(output_types, return_data)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/eth_abi/abi.py", line 96, in decode_abi
return decoder(stream)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/eth_abi/decoding.py", line 118, in __call__
return self.decode(stream)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/eth_utils/functional.py", line 22, in inner
return callback(fn(*args, **kwargs))
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/eth_abi/decoding.py", line 164, in decode
yield decoder(stream)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/eth_abi/decoding.py", line 118, in __call__
return self.decode(stream)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/eth_abi/decoding.py", line 186, in decode
raw_data = self.read_data_from_stream(stream)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/eth_abi/decoding.py", line 279, in read_data_from_stream
len(data),
eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes.  Only got 0 bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/core.py", line 153, in _async_task
functor.pattern.process_call(self._context, bufchan, event, functor)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/patterns.py", line 30, in process_call
result = functor(*req_event.args)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/zerorpc/decorators.py", line 44, in __call__
return self._functor(*args, **kargs)
File "/home/lefteris/w/rotkehlchen/rotkehlchen/server.py", line 229, in query_balances
result = self.rotkehlchen.query_balances(save_data)
File "/home/lefteris/w/rotkehlchen/rotkehlchen/rotkehlchen.py", line 417, in query_balances
result = self.blockchain.query_balances()['totals']
File "/home/lefteris/w/rotkehlchen/rotkehlchen/utils.py", line 83, in wrapper
result = f(wrappingobj, *args)
File "/home/lefteris/w/rotkehlchen/rotkehlchen/blockchain.py", line 79, in query_balances
self.query_ethereum_balances()
File "/home/lefteris/w/rotkehlchen/rotkehlchen/blockchain.py", line 321, in query_ethereum_balances
self.query_ethereum_tokens(self.owned_eth_tokens, eth_balances)
File "/home/lefteris/w/rotkehlchen/rotkehlchen/blockchain.py", line 286, in query_ethereum_tokens
self.accounts[S_ETH],
File "/home/lefteris/w/rotkehlchen/rotkehlchen/ethchain.py", line 142, in get_multitoken_balance
token_amount = FVal(token_contract.functions.balanceOf(account).call())
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/web3/contract.py", line 979, in call
**self.kwargs)
File "/home/lefteris/.virtualenvs/rotkehlchen/lib/python3.6/site-packages/web3/contract.py", line 1236, in call_contract_function
raise BadFunctionCallOutput(msg) from e
web3.exceptions.BadFunctionCallOutput: Could not transact with/call contract function, is contract deployed correctly and chain synced?

# Fixed code
def modify_blockchain_account(
    self,
    blockchain: str,
    account: typing.BlockchainAddress,
    append_or_remove: str,
    add_or_sub: Callable[[FVal, FVal], FVal],
) -> BlockchainBalancesUpdate:
    if blockchain == S_BTC:
        if append_or_remove == "remove" and account not in self.accounts[S_BTC]:
            raise InputError("Tried to remove a non existing BTC account")
        self.modify_btc_account(account, append_or_remove, add_or_sub)

    elif blockchain == S_ETH:
        if append_or_remove == "remove" and account not in self.accounts[S_ETH]:
            raise InputError("Tried to remove a non existing ETH account")
        try:
            self.modify_eth_account(account, append_or_remove, add_or_sub)
        except BadFunctionCallOutput as e:
            logger.error(
                "Assuming unsynced chain. Got web3 BadFunctionCallOutput "
                "exception: {}".format(str(e))
            )
            raise EthSyncError(
                "Tried to use the ethereum chain of a local client to edit "
                "an eth account but the chain is not synced."
            )

    else:
        raise InputError(
            "Unsupported blockchain {} provided at remove_blockchain_account".format(
                blockchain
            )
        )

    return {"per_account": self.balances, "totals": self.totals}