Exemplo n.º 1
0
    def blockstojson(self, raw_blocks: list):
        tx_list = []
        block = {}
        blocks = {}

        old = None
        for transaction_raw in raw_blocks:
            transaction = format_raw_tx(transaction_raw)
            height = transaction['block_height']
            hash = transaction['block_hash']

            del transaction['block_height']
            del transaction['block_hash']

            if old != height:  # if same block
                del tx_list[:]
                block.clear()

            tx_list.append(transaction)

            block['block_height'] = height
            block['block_hash'] = hash
            block['transactions'] = list(tx_list)
            blocks[height] = dict(block)

            old = height  # update

        return blocks
Exemplo n.º 2
0
def getbydata(data):
    print(dbhandler.limiter)
    if dbhandler.limiter:
        dbhandler.cursor.execute(
            "SELECT * FROM transactions WHERE ? in (address|recipient) AND openfield = ?  ORDER BY block_height DESC LIMIT ?",
            (
                dbhandler.limiter,
                data,
                dbhandler.limit,
            ))
        result = dbhandler.cursor.fetchall()

    else:
        dbhandler.cursor.execute(
            "SELECT * FROM transactions WHERE openfield = ? ORDER BY block_height DESC LIMIT ?",
            (
                data,
                dbhandler.limit,
            ))
        result = dbhandler.cursor.fetchall()

    if result:
        return_value = []
        for entry in result:
            return_value.append(essentials.format_raw_tx(entry))
        return return_value
Exemplo n.º 3
0
    def assign_preds(self, data):
        formatted = essentials.format_raw_tx(data)
        openfield = formatted["openfield"].split(";")
        assigned = {}
        try:
            for part in openfield:
                x = (part.split(":"))
                assigned[x[0]] = x[1]

            self.event = assigned["event"]
            self.result = assigned["result"]

            print(self.event, self.result)

        except:
            print(f"Problem assigning values for {openfield}")
Exemplo n.º 4
0
    def assign_init(self, data):
        formatted = essentials.format_raw_tx(data)
        openfield = formatted["openfield"].split(";")

        assigned = {}  #prevent misformatting
        try:
            for part in openfield:
                x = (part.split(":"))
                assigned[x[0]] = x[1]

            self.event = assigned["event"]
            self.until = assigned["until"]
            self.oracle = assigned["oracle"]
            self.results = assigned["results"].split(",")

            print(self.event, self.until, self.oracle, self.results)
        except:

            print(f"Problem assigning values for {openfield}")
Exemplo n.º 5
0
    def blocktojsondiffs(self, list_of_txs: list, list_of_diffs: list):
        i = 0
        blocks_dict = {}
        block_dict = {}
        normal_transactions = []

        old = None
        for transaction in list_of_txs:
            transaction_formatted = format_raw_tx(transaction)
            height = transaction_formatted["block_height"]

            del transaction_formatted["block_height"]

            #  del transaction_formatted["signature"]  # optional
            #  del transaction_formatted["pubkey"]  # optional

            if old != height:
                block_dict.clear()
                del normal_transactions[:]

            if transaction_formatted["reward"] == 0:  # if normal tx
                del transaction_formatted["block_hash"]
                del transaction_formatted["reward"]
                normal_transactions.append(transaction_formatted)

            else:
                del transaction_formatted["address"]
                del transaction_formatted["amount"]
                transaction_formatted['difficulty'] = list_of_diffs[i][0]
                block_dict['mining_tx'] = transaction_formatted

                block_dict['transactions'] = list(normal_transactions)

                blocks_dict[height] = dict(block_dict)
                i += 1
            old = height

        return blocks_dict
Exemplo n.º 6
0
 def block_max_ram(self):
     self.execute(self.c, 'SELECT * FROM transactions ORDER BY block_height DESC LIMIT 1')
     return essentials.format_raw_tx(self.c.fetchone())