# Path: coloredcoinlib/store.py
# class PersistentDictStore(DictMixin, DataStore):
#     """ Persistent dict object """
# 
#     def __init__(self, conn, dictname):
#         super(PersistentDictStore, self).__init__(conn)
#         conn.text_factory = str
#         self.tablename = dictname + "_dict"
#         if not self.table_exists(self.tablename):
#             self.execute("CREATE TABLE {0} (key NOT NULL PRIMARY KEY "
#                          "UNIQUE, value BLOB)".format(self.tablename))
# 
#     def deserialize(self, svalue):
#         return pickle.loads(svalue)
# 
#     def serialize(self, value):
#         return pickle.dumps(value)
# 
#     def __getitem__(self, key):
#         svalue = self.execute(
#             "SELECT value FROM {0} WHERE key = ?".format(self.tablename),
#             (key,)).fetchone()
#         if svalue:
#             return self.deserialize(unwrap1(svalue))
#         else:
#             raise KeyError()
# 
#     def __setitem__(self, key, value):
#         self.execute(
#             "INSERT OR REPLACE INTO {0} VALUES (?, ?)".format(self.tablename),
#             (key, self.serialize(value)))
# 
#     def __contains__(self, key):
#         svalue = self.execute(
#             "SELECT value FROM {0} WHERE key = ?".format(self.tablename),
#             (key,)).fetchone()
#         return svalue is not None
# 
#     def __delitem__(self, key):
#         if self.__contains__(key):
#             self.execute(
#                 "DELETE FROM {0} WHERE key = ?".format(self.tablename),
#                 (key,))
#         else:
#             raise KeyError()
# 
#     def keys(self):
#         return map(
#             unwrap1,
#             self.execute(
#                 "SELECT key FROM {0}".format(self.tablename)).fetchall())
# 
# Path: ngcccbase/address.py
# class AddressRecord(object):
#     """Object that holds both address and color information
#     Note this is now an Abstract Class.
#     """
#     def __init__(self, **kwargs):
#         self.color_set = kwargs.get('color_set')
#         self.testnet = kwargs.get('testnet')
#         self.prefix = self.testnet and b'\x6f' or b"\0"
# 
#     def rawPubkey(self):
#         return public_pair_to_hash160_sec(self.publicPoint.pair(), False)
# 
#     def get_color_set(self):
#         """Access method for the color set associated
#         with this address record
#         """
#         return self.color_set
# 
#     def get_data(self):
#         """Get this object as a JSON/Storage compatible dict.
#         Useful for storage and persistence.
#         """
#         raw = self.prefix + to_bytes_32(self.rawPrivKey)
#         return {"color_set": self.color_set.get_data(),
#                 "address_data": b2a_hashed_base58(raw)}
# 
#     def get_private_key(self):
#         return secret_exponent_to_wif(self.rawPrivKey, False, self.prefix)
# 
#     def get_address(self):
#         """Get the actual bitcoin address
#         """
#         return self.address
# 
#     def get_color_address(self):
#         """This is the address that can be used for sending/receiving
#         colored coins
#         """
#         if self.color_set.uncolored_only():
#             return self.get_address()
#         return "%s@%s" % (self.get_color_set().get_color_hash(),
#                           self.get_address())


import time
from coloredcoinlib.store import PersistentDictStore
from asset import AdditiveAssetValue, AssetTarget
from txcons import RawTxSpec
from ngcccbase.address import AddressRecord

def asset_value_to_data(av):
    return (av.get_asset().get_id(),
            av.get_value())

class TxHistoryEntry(object):
    def __init__(self, model, data):
        self.txhash = data['txhash']
        self.txtime = data['txtime']
        self.txtype = data['txtype']
        self.data = data
        self.model = model

    @classmethod
    def from_data(cls, model, data):
        txtype = data['txtype']

# Path: coloredcoinlib/store.py
# class PersistentDictStore(DictMixin, DataStore):
#     """ Persistent dict object """
# 
#     def __init__(self, conn, dictname):
#         super(PersistentDictStore, self).__init__(conn)
#         conn.text_factory = str
#         self.tablename = dictname + "_dict"
#         if not self.table_exists(self.tablename):
#             self.execute("CREATE TABLE {0} (key NOT NULL PRIMARY KEY "
#                          "UNIQUE, value BLOB)".format(self.tablename))
# 
#     def deserialize(self, svalue):
#         return pickle.loads(svalue)
# 
#     def serialize(self, value):
#         return pickle.dumps(value)
# 
#     def __getitem__(self, key):
#         svalue = self.execute(
#             "SELECT value FROM {0} WHERE key = ?".format(self.tablename),
#             (key,)).fetchone()
#         if svalue:
#             return self.deserialize(unwrap1(svalue))
#         else:
#             raise KeyError()
# 
#     def __setitem__(self, key, value):
#         self.execute(
#             "INSERT OR REPLACE INTO {0} VALUES (?, ?)".format(self.tablename),
#             (key, self.serialize(value)))
# 
#     def __contains__(self, key):
#         svalue = self.execute(
#             "SELECT value FROM {0} WHERE key = ?".format(self.tablename),
#             (key,)).fetchone()
#         return svalue is not None
# 
#     def __delitem__(self, key):
#         if self.__contains__(key):
#             self.execute(
#                 "DELETE FROM {0} WHERE key = ?".format(self.tablename),
#                 (key,))
#         else:
#             raise KeyError()
# 
#     def keys(self):
#         return map(
#             unwrap1,
#             self.execute(
#                 "SELECT key FROM {0}".format(self.tablename)).fetchall())
# 
# Path: ngcccbase/address.py
# class AddressRecord(object):
#     """Object that holds both address and color information
#     Note this is now an Abstract Class.
#     """
#     def __init__(self, **kwargs):
#         self.color_set = kwargs.get('color_set')
#         self.testnet = kwargs.get('testnet')
#         self.prefix = self.testnet and b'\x6f' or b"\0"
# 
#     def rawPubkey(self):
#         return public_pair_to_hash160_sec(self.publicPoint.pair(), False)
# 
#     def get_color_set(self):
#         """Access method for the color set associated
#         with this address record
#         """
#         return self.color_set
# 
#     def get_data(self):
#         """Get this object as a JSON/Storage compatible dict.
#         Useful for storage and persistence.
#         """
#         raw = self.prefix + to_bytes_32(self.rawPrivKey)
#         return {"color_set": self.color_set.get_data(),
#                 "address_data": b2a_hashed_base58(raw)}
# 
#     def get_private_key(self):
#         return secret_exponent_to_wif(self.rawPrivKey, False, self.prefix)
# 
#     def get_address(self):
#         """Get the actual bitcoin address
#         """
#         return self.address
# 
#     def get_color_address(self):
#         """This is the address that can be used for sending/receiving
#         colored coins
#         """
#         if self.color_set.uncolored_only():
#             return self.get_address()
#         return "%s@%s" % (self.get_color_set().get_color_hash(),
#                           self.get_address())


# Path: ngcccbase/txhistory.py
import time
from coloredcoinlib.store import PersistentDictStore
from asset import AdditiveAssetValue, AssetTarget
from txcons import RawTxSpec
from ngcccbase.address import AddressRecord


def asset_value_to_data(av):
    return (av.get_asset().get_id(),
            av.get_value())

class TxHistoryEntry(object):
    def __init__(self, model, data):
        self.txhash = data['txhash']
        self.txtime = data['txtime']
        self.txtype = data['txtype']
        self.data = data
        self.model = model

    @classmethod
    def from_data(cls, model, data):
        txtype = data['txtype']

        if txtype == 'send':