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


import os
import sqlite3
import logging
import binascii
import hashlib
import ctypes
import ctypes.util
import sys
import utils
from bsddb.db import *
from pickle import dumps, loads
from bitcoin import script
from bitcoin.key import CKey
from bitcoin.core import COutPoint, CTxIn, CTxOut, CTransaction
from bitcoin.script import OP_VAULT_WITHDRAW, OP_VAULT_FAST_WITHDRAW, OP_VAULT_CONFIRM, OP_VAULT_OVERRIDE
from reversecoin import exceptions
            txin.scriptSig = scriptSig
        return amount, tx


    # create vault
    def createvault(self, toaddress, tomaster_address, timeout, maxfees):
        vault_address = utils.addresses_to_vault_address(toaddress,
            tomaster_address, timeout, maxfees)
        self.newvault(vault_address, toaddress, tomaster_address, timeout, maxfees)
        return vault_address

    # send to a vault
    def sendtovault(self, vault_address, amount):
        # select the input addresses
        funds = 0
        subaccounts = []
        accounts = self.getaccounts()
        for account in accounts:
            for address, subaccount in account.iteritems():
                if subaccount['balance'] == 0:
                    continue
                else:
                    subaccounts.append(subaccount)
                    funds = funds + subaccount['balance']
                    if funds >= amount + utils.calculate_fees(None):
                        break

        # incase of insufficient funds, return
        if funds < amount + utils.calculate_fees(None):
            self.logger.warning("Insufficient funds, exiting, return")

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


# Path: reversecoin/walletdb.py
import os
import sqlite3
import logging
import binascii
import hashlib
import ctypes
import ctypes.util
import sys
import utils
from bsddb.db import *
from pickle import dumps, loads
from bitcoin import script
from bitcoin.key import CKey
from bitcoin.core import COutPoint, CTxIn, CTxOut, CTransaction
from bitcoin.script import OP_VAULT_WITHDRAW, OP_VAULT_FAST_WITHDRAW, OP_VAULT_CONFIRM, OP_VAULT_OVERRIDE
from reversecoin import exceptions

            txin.scriptSig = scriptSig
        return amount, tx


    # create vault
    def createvault(self, toaddress, tomaster_address, timeout, maxfees):
        vault_address = utils.addresses_to_vault_address(toaddress,
            tomaster_address, timeout, maxfees)
        self.newvault(vault_address, toaddress, tomaster_address, timeout, maxfees)
        return vault_address

    # send to a vault
    def sendtovault(self, vault_address, amount):
        # select the input addresses
        funds = 0
        subaccounts = []
        accounts = self.getaccounts()
        for account in accounts:
            for address, subaccount in account.iteritems():
                if subaccount['balance'] == 0:
                    continue
                else:
                    subaccounts.append(subaccount)
                    funds = funds + subaccount['balance']
                    if funds >= amount + utils.calculate_fees(None):
                        break

        # incase of insufficient funds, return
        if funds < amount + utils.calculate_fees(None):
            self.logger.warning("Insufficient funds, exiting, return")

            raise exceptions.InsufficientBalanceException