from ether_sql.models import Receipts import sys from sqlalchemy.sql.expression import func sys.path.append('../') from sessions import Session ss = Session() session = ss.connect_to_psql() Receipt = ss.get_table_object('receipts') class ApiReceipts(Receipts): @staticmethod def get_receipt(transaction_hash): results = [] receipts = session.query(Receipt).filter_by( transaction_hash=transaction_hash).all() columns = Receipt.columns.keys() for row in receipts: results.append(dict(zip(columns, row))) return results
from ether_sql.models import Transactions import sys from sqlalchemy.sql.expression import func from .api_blocks import ApiBlocks sys.path.append('../') from sessions import Session ss = Session() session = ss.connect_to_psql() Transaction = ss.get_table_object('transactions') class ApiTransactions(Transactions): @staticmethod def get_all_transactions(): results = [] blocks = session.query(Transaction).limit(10).all() columns = Transaction.columns.keys() for row in blocks: results.append(dict(zip(columns, row))) return results @staticmethod def get_transaction_by_hash(transaction_hash): results = [] transactions = session.query(Transaction).filter_by( transaction_hash=transaction_hash).all() columns = Transaction.columns.keys() for row in transactions: results.append(dict(zip(columns, row))) return results
from ether_sql.models import Blocks import sys from sqlalchemy.sql.expression import func sys.path.append('../') from sessions import Session ss = Session() session = ss.connect_to_psql() Block = ss.get_table_object('blocks') class ApiBlocks(Blocks): @staticmethod def get_all_blocks(): results = [] blocks = session.query(Block).limit(10).all() columns = Block.columns.keys() for row in blocks: results.append(dict(zip(columns, row))) return results @staticmethod def get_current_block_number(): results = [] blocks = session.query( func.max(Block.columns.block_number).label('block_number')) column_names = [c["name"] for c in blocks.column_descriptions] results = [dict(zip(column_names, row)) for row in blocks.all()] return results @staticmethod
from ether_sql.models import Uncles import sys from sqlalchemy.sql.expression import func sys.path.append('../') from sessions import Session ss = Session() session = ss.connect_to_psql() Uncle = ss.get_table_object('uncles') class ApiUncles(Uncles): @staticmethod def get_uncle_by_uncle_hash(uncle_hash): results = [] uncles = session.query(Uncle).filter_by(uncle_hash=uncle_hash).all() columns = Uncle.columns.keys() for row in uncles: results.append(dict(zip(columns, row))) return results