def get_transaction_by_rid(cls, selector, rid=False, raw=False):
        from block import Block
        from transaction import Transaction
        from crypt import Crypt
        ds = Config.get_bulletin_secret()
        if not rid:
            selectors = [TU.hash(ds + selector), TU.hash(selector + ds)]
        else:
            if not isinstance(selector, list):
                selectors = [
                    selector,
                ]

        for block in Mongo.db.blocks.find(
            {"transactions": {
                "$elemMatch": {
                    "relationship": {
                        "$ne": ""
                    }
                }
            }}):
            for transaction in block.get('transactions'):
                if transaction.get('rid') in selectors:
                    if 'relationship' in transaction:
                        if not raw:
                            try:
                                cipher = Crypt(Config.wif)
                                decrypted = cipher.decrypt(
                                    transaction['relationship'])
                                relationship = json.loads(decrypted)
                                transaction['relationship'] = relationship
                            except:
                                continue
                    return transaction
    def get_transactions_by_rid(cls,
                                selector,
                                rid=False,
                                raw=False,
                                returnheight=True,
                                bulletin_secret=None):
        #selectors is old code before we got an RID by sorting the bulletin secrets
        from block import Block
        from transaction import Transaction
        from crypt import Crypt
        ds = Config.get_bulletin_secret()

        if not rid:
            selectors = [TU.hash(ds + selector), TU.hash(selector + ds)]
        else:
            if not isinstance(selector, list):
                selectors = [
                    selector,
                ]
            else:
                selectors = selector

        transactions_by_rid_cache = Mongo.db.transactions_by_rid_cache.find({
            'raw':
            raw,
            'rid':
            rid,
            'bulletin_secret':
            bulletin_secret,
            'returnheight':
            returnheight,
            'selector': {
                '$in': selectors
            }
        }).sort([('height', -1)])
        latest_block = cls.get_latest_block()
        if transactions_by_rid_cache.count():
            transactions_by_rid_cache = transactions_by_rid_cache[0]
            block_height = transactions_by_rid_cache['height']
        else:
            block_height = 0
        transactions = []
        blocks = Mongo.db.blocks.find({
            "transactions.rid": {
                "$in": selectors
            },
            "transactions": {
                "$elemMatch": {
                    "relationship": {
                        "$ne": ""
                    }
                }
            },
            'index': {
                '$gt': block_height
            }
        })
        for block in blocks:
            for transaction in block.get('transactions'):
                if 'relationship' in transaction and transaction[
                        'relationship']:
                    if returnheight:
                        transaction['height'] = block['index']
                    if not raw:
                        try:
                            cipher = Crypt(Config.wif)
                            decrypted = cipher.decrypt(
                                transaction['relationship'])
                            relationship = json.loads(decrypted)
                            transaction['relationship'] = relationship
                        except:
                            continue
                    for selector in selectors:
                        print 'caching transactions_by_rid at height:', block[
                            'index']
                        Mongo.db.transactions_by_rid_cache.insert({
                            'raw':
                            raw,
                            'rid':
                            rid,
                            'bulletin_secret':
                            bulletin_secret,
                            'returnheight':
                            returnheight,
                            'selector':
                            selector,
                            'txn':
                            transaction,
                            'height':
                            block['index']
                        })
                    transactions.append(transaction)
        if not transactions:
            for selector in selectors:
                Mongo.db.transactions_by_rid_cache.insert({
                    'raw':
                    raw,
                    'rid':
                    rid,
                    'bulletin_secret':
                    bulletin_secret,
                    'returnheight':
                    returnheight,
                    'selector':
                    selector,
                    'height':
                    latest_block['index']
                })
        for x in Mongo.db.transactions_by_rid_cache.find({
                'raw': raw,
                'rid': rid,
                'returnheight': returnheight,
                'selector': {
                    '$in': selectors
                }
        }):
            if 'txn' in x:
                yield x['txn']