orion-bcdb / orion-sdk-java

Apache License 2.0
1 stars 2 forks source link

Introduce Ledger Queries #17

Open tock-ibm opened 1 year ago

tock-ibm commented 1 year ago
interface ledger {
    // GetBlockHeader returns block header from ledger
    BlockHeader GetBlockHeader(uint64 blockNum) throws Exception;
    // GetLastBlockHeader returns last block from ledger
    BlockHeader GetLastBlockHeader() throws Exception;
    // GetLedgerPath returns cryptographically verifiable path between any block pairs in ledger skip list
    LedgerPath GetLedgerPath(uint64 startBlock, uint64 endBlock) throws Exception;
    // GetTransactionProof returns intermediate hashes from hash(tx, validating info) to root of
    // tx merkle tree stored in block header
    TxProof GetTransactionProof(uint64 blockNum, int txIndex) throws Exception;
    // GetTransactionReceipt return block header where tx is stored and tx index inside block
    TxReceipt GetTransactionReceipt(txId string) throws Exception;
    // GetDataProof returns proof of existence of value associated with key in block Merkle-Patricia Trie
    // Proof itself is a path from node that contains value to root node in MPTrie
    Proof GetDataProof(uint64 blockNum, String dbName, String key, boolean isDeleted) throws Exception;
    // GetFullTxProofAndVerify do full tx existence and validity proof by fetching and validating two ledger skip list paths and one Merkle tree path.
    // First, it fetches the Merkle tree path within the block with the transaction.
    // Next, the ledger path from the block with the transaction to the genesis block is fetched.
    // Then, the ledger path from the last know (a-priori) block to the block with the transaction is fetched.
    // Finally, these three proofs are validated.
    // Returns
    // TxProof - the Merkle tree path within the block with the transaction.
    // LedgerPath - two concatenated ledger paths [last... block... genesis]
    // error - in case if verification failed, nil otherwise
    TxProof GetFullTxProofAndVerify(TxReceipt txReceipt, BlockHeader lastKnownBlockHeader, Message tx) throws Exception;
    // NewBlockHeaderDeliveryService creates a delivery service to deliver block header
    // from a given starting block number present in the config to all the future block
    // till the service is stopped
    BlockHeaderDelivererService  NewBlockHeaderDeliveryService(BlockHeaderDeliveryConfig conf) throws Exception;
}