Ejemplo n.º 1
0
def get_transaction_by_txid(txid):
    if not validate_sha256_hash(txid):
        return "Invalid transaction ID", 400
    try:
        return TransactionSerializer.to_web(db.get_transaction_by_txid(txid))
    except KeyError:
        return "Transaction with given ID not found", 404
Ejemplo n.º 2
0
def get_block_by_hash(block_hash):
    if not validate_sha256_hash(block_hash):
        return "Invalid block hash", 400
    try:
        return BlockSerializer.to_web(db.get_block_by_hash(block_hash))
    except KeyError:
        return "Block with given hash doesn't exist", 404
Ejemplo n.º 3
0
def get_transactions_by_blockhash(blockhash):
    if not validate_sha256_hash(blockhash):
        return "Invalid block hash", 400
    try:
        return [
            TransactionSerializer.to_web(tr)
            for tr in db.get_transactions_by_blockhash(blockhash)
        ]
    except KeyError:
        return []
Ejemplo n.º 4
0
def get_block_confirmations(block_hash):
    if not validate_sha256_hash(block_hash):
        return "Invalid block hash", 400
    try:
        block = db.get_block_by_hash(block_hash)
    except KeyError:
        return "Block with given hash doesn't exist", 404

    return {
        "hash": block_hash,
        "confirmations": db.calculate_block_confirmations(block)
    }
Ejemplo n.º 5
0
def get_transaction_confirmations(txid):
    if not validate_sha256_hash(txid):
        return "Invalid transaction ID", 400
    try:
        tr = db.get_transaction_by_txid(txid)
    except KeyError:
        return "Transaction with given txid not found", 404

    block = db.get_block_by_hash(tr['blockhash'])
    return {
        "txid": txid,
        "confirmations": db.calculate_block_confirmations(block)
    }