# Path: database.py
# def txn_required(func):
#     @functools.wraps(func)
#     def _func(*args, **kwargs):
#         txn = current_txn()
#         if txn:
#             return func(*args, **kwargs)
#         else:
#             return run_in_transaction(func, txn_name=func.__name__, *args, **kwargs)
#     return _func


import database
import ec
import jserialize as js
import bserialize as bs
from database import txn_required
from utils import *
        if self._key.get_compressed():
            secret += "\x01"
        secret = secret+doublesha(secret)[:4]
        return b58encode(secret)
        
    @classmethod    
    def fromsecret(cls, secret):
        self = cls()
        secret = b58decode(secret, None)
        secret, cksum = secret[:-4], secret[-4:]
        if doublesha(secret)[:4] != cksum:
            return None
        valid, secret, compressed = secret[0]=="\x80", secret[1:33], secret[33:] == "\x01" 
        if not valid:
            return None
        self._key = ec.Key.generate(secret, compressed)
        self.privatkey = self._key.get_privkey()
        self.publickey = self._key.get_pubkey() 
        self.txs = []
        return self
        
    @classmethod
    def generate(cls):
        self = cls()
        self._key = ec.Key.generate()
        self.privatkey = self._key.get_privkey()
        self.publickey = self._key.get_pubkey() 
        self.txs = []
        return self
        

# Path: database.py
# def txn_required(func):
#     @functools.wraps(func)
#     def _func(*args, **kwargs):
#         txn = current_txn()
#         if txn:
#             return func(*args, **kwargs)
#         else:
#             return run_in_transaction(func, txn_name=func.__name__, *args, **kwargs)
#     return _func


# Path: keychain.py
import database
import ec
import jserialize as js
import bserialize as bs
from database import txn_required
from utils import *

        if self._key.get_compressed():
            secret += "\x01"
        secret = secret+doublesha(secret)[:4]
        return b58encode(secret)
        
    @classmethod    
    def fromsecret(cls, secret):
        self = cls()
        secret = b58decode(secret, None)
        secret, cksum = secret[:-4], secret[-4:]
        if doublesha(secret)[:4] != cksum:
            return None
        valid, secret, compressed = secret[0]=="\x80", secret[1:33], secret[33:] == "\x01" 
        if not valid:
            return None
        self._key = ec.Key.generate(secret, compressed)
        self.privatkey = self._key.get_privkey()
        self.publickey = self._key.get_pubkey() 
        self.txs = []
        return self
        
    @classmethod
    def generate(cls):
        self = cls()
        self._key = ec.Key.generate()
        self.privatkey = self._key.get_privkey()
        self.publickey = self._key.get_pubkey() 
        self.txs = []
        return self
        

    @txn_required