# Path: reversecoin/exceptions.py
# class BitcoinException(Exception):
# class InsufficientBalanceException(BitcoinException):
# class AmountTooLargeException(BitcoinException):
# class VaultAlreadyExistsException(BitcoinException):


import string
import cStringIO
import leveldb
import sqlite3
import io
import os
import time
import utils
import binascii
import shutil
import logging
from decimal import Decimal
from cache import Cache
from common import *
from bitcoin.serialize import *
from bitcoin.core import *
from bitcoin import core
from bitcoin.messages import msg_block, message_to_str, message_read
from bitcoin.coredefs import COIN
from bitcoin.scripteval import VerifySignature
from bitcoin import serialize
from bitcoin.script import OP_VAULT_WITHDRAW, OP_VAULT_FAST_WITHDRAW, OP_VAULT_CONFIRM, OP_VAULT_OVERRIDE
from reversecoin import exceptions

    def getbalance(self, address):
        balance = 0.0
        txouts = self.listreceivedbyaddress(address)
        for txout in txouts.itervalues():
            balance = balance + txout['value']
        return balance

    def sendtoaddress(self, toaddress, amount):
        amount, tx = self.wallet.sendtoaddress(toaddress, amount)
        if tx and self.mempool.add(tx):
            return amount
        return 0

    def createvault(self, toaddress, tomaster_address, timeout, maxfees):
        try:
            return self.wallet.createvault(toaddress, tomaster_address, timeout, maxfees)
        except exceptions.VaultAlreadyExistsException as e:
            return None

    # vault_address, amount
    def sendtovault(self, vault_address, amount):
        txouts = self.listallreceivedbyvault(vault_address)
        if txouts:
            return None
        if self.mempool.hasvault(vault_address):
            return None

        try:
            vault_address, tx = self.wallet.sendtovault(vault_address, amount)

# Path: reversecoin/exceptions.py
# class BitcoinException(Exception):
# class InsufficientBalanceException(BitcoinException):
# class AmountTooLargeException(BitcoinException):
# class VaultAlreadyExistsException(BitcoinException):


# Path: reversecoin/chaindb.py
import string
import cStringIO
import leveldb
import sqlite3
import io
import os
import time
import utils
import binascii
import shutil
import logging
from decimal import Decimal
from cache import Cache
from common import *
from bitcoin.serialize import *
from bitcoin.core import *
from bitcoin import core
from bitcoin.messages import msg_block, message_to_str, message_read
from bitcoin.coredefs import COIN
from bitcoin.scripteval import VerifySignature
from bitcoin import serialize
from bitcoin.script import OP_VAULT_WITHDRAW, OP_VAULT_FAST_WITHDRAW, OP_VAULT_CONFIRM, OP_VAULT_OVERRIDE
from reversecoin import exceptions


    def getbalance(self, address):
        balance = 0.0
        txouts = self.listreceivedbyaddress(address)
        for txout in txouts.itervalues():
            balance = balance + txout['value']
        return balance

    def sendtoaddress(self, toaddress, amount):
        amount, tx = self.wallet.sendtoaddress(toaddress, amount)
        if tx and self.mempool.add(tx):
            return amount
        return 0

    def createvault(self, toaddress, tomaster_address, timeout, maxfees):
        try:
            return self.wallet.createvault(toaddress, tomaster_address, timeout, maxfees)
        except exceptions.VaultAlreadyExistsException as e:
            return None

    # vault_address, amount
    def sendtovault(self, vault_address, amount):
        txouts = self.listallreceivedbyvault(vault_address)
        if txouts:
            return None
        if self.mempool.hasvault(vault_address):
            return None

        try:
            vault_address, tx = self.wallet.sendtovault(vault_address, amount)

        except exceptions.InsufficientBalanceException as e: