Beispiel #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
Beispiel #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
Beispiel #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 []
Beispiel #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)
    }
Beispiel #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)
    }