Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Extend get_block_header API and get_block_header_batch API to optionally return witness signatures #2652

Merged
merged 3 commits into from
Oct 7, 2022

Conversation

abitmore
Copy link
Member

@abitmore abitmore commented Oct 5, 2022

Follow-up of #2641, for issue #2588.

Instead of always returning witness signatures (as in #2641), this PR adds an optional with_witness_signature parameter to the get_block_header API, and add an optional with_witness_signatures parameter to the get_block_header_batch API, to indicate whether to return witness signatures.

This PR also updates the return types of these 2 APIs so that witness signature can optionally be returned. The new type maybe_signed_block_header is derived from block_header with an optional witness_signature field.

   struct maybe_signed_block_header : block_header
   {
      optional<signature_type> witness_signature;
   };

Updated APIs:

  • get_block_header( block_num, with_witness_signature )
      /** 
       * @brief Retrieve a block header
       * @param block_num Height of the block whose header should be returned
       * @param with_witness_signature Whether to return witness signature. Optional.
       *                               If omitted or is @a false, will not return witness signature.
       * @return header of the referenced block, or null if no matching block was found
       */
      optional<maybe_signed_block_header> get_block_header(
            uint32_t block_num,
            const optional<bool>& with_witness_signature = optional<bool>() )const;
  • get_block_header_batch( block_nums, with_witness_signatures )
      /** 
       * @brief Retrieve multiple block headers by block numbers
       * @param block_nums vector containing heights of the blocks whose headers should be returned
       * @param with_witness_signatures Whether to return witness signatures. Optional.
       *                                If omitted or is @a false, will not return witness signatures.
       * @return array of headers of the referenced blocks, or null if no matching block was found
       */
      map<uint32_t, optional<maybe_signed_block_header>> get_block_header_batch(
            const vector<uint32_t>& block_nums,
            const optional<bool>& with_witness_signatures = optional<bool>() )const;

... to indicate whether to return signatures.
Including 2 database APIs:
- get_block_header
- get_block_header_batch
@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 6, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

86.7% 86.7% Coverage
0.0% 0.0% Duplication

@abitmore abitmore merged commit 0883cad into develop Oct 7, 2022
@abitmore abitmore deleted the pr-2588-optional-sigs branch October 7, 2022 20:27
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a new database API to get signed block header
1 participant