def get_shell_balance(address):
    for group in rpc('listaddressgroupings', []):
        for bunch in group:
            shell_address, shell_balance = bunch[:2]
            if shell_address == address:
                return shell_balance
    return 0
def get_wallet_addresses():
    addresses = []
    for group in rpc('listaddressgroupings', []):
        for bunch in group:
            address, shell_balance = bunch[:2]
            addresses.append(address)
    return addresses
def is_locked():
    getinfo = rpc('getinfo', [])
    if 'unlocked_until' in getinfo:
        if getinfo['unlocked_until'] >= 10:
            return False # Wallet is unlocked for at least the next 10 seconds.
        else:
            return True # Wallet is locked
    else:
        False
def get_shell_balances():
    addresses = {}
    for output in rpc('listunspent', [0, 99999]):
        if output['address'] not in addresses:
            addresses[output['address']] = 0
        addresses[output['address']] += output['amount']

    for address in addresses:
        yield [address, addresses[address]]
def unlock(passphrase):
    return rpc('walletpassphrase', [passphrase, 60])
def get_pubkey(address):
    address_infos = rpc('validateaddress', [address])
    if address_infos['isvalid'] and address_infos['ismine']:
        return address_infos['pubkey']
    return None
def is_mine(address):
    return rpc('validateaddress', [address])['ismine']
def is_valid(address):
    return rpc('validateaddress', [address])['isvalid']
def list_unspent():
    return rpc('listunspent', [0, 99999])
def get_shell_balances():
    for group in rpc('listaddressgroupings', []):
        for bunch in group:
            yield bunch[:2]
def is_locked():
    return rpc('walletislocked', [])
def get_shell_balance(address):
    balance = 0
    for output in rpc('listunspent', [0, 99999]):
        if output['address'] == addresses:
            balance += output['amount']
    return balance
def is_mine(address):
    address_info = rpc('validateaddress', [address])
    if 'ismine' not in address_info:
        return False
    return address_info['ismine']
def is_valid(address):
    address_info = rpc('validateaddress', [address])
    # shellwallet return valid for pubkey
    if address_info['isvalid'] and address_info['address'] == address:
        return True
    return False
def send_raw_transaction(tx_hex):
    return rpc('sendrawtransaction', [tx_hex])
def sign_raw_transaction(tx_hex):
    return rpc('signrawtransaction', [tx_hex])['hex']
def wallet_last_block():
    getinfo = rpc('getinfo', [])
    return getinfo['blocks']
def get_wallet_addresses():
    addresses = []
    for output in rpc('listunspent', [0, 99999]):
        if output['address'] not in addresses:
            addresses.append(output['address'])
    return addresses