-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add stub for Bitcoin headers endpoint (#297)
As stated in [here](dfinity/interface-spec#298), candid interface should look as: ``` type bitcoin_block_header = blob; type get_block_headers_request = record { start_height : nat32; end_height: opt nat32; }; type get_block_headers_result = record { tip_height: nat32; block_headers: vec bitcoin_block_header; }; bitcoin_get_block_headers : (get_block_headers_request) -> (get_block_headers_response); ``` This PR will add no-op endpoint for returning the block headers in the [follow-up](#298) we will implement specified function.
- Loading branch information
1 parent
13a8853
commit 4d420e1
Showing
7 changed files
with
203 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use ic_btc_interface::{GetBlockHeadersError, GetBlockHeadersRequest, GetBlockHeadersResponse}; | ||
|
||
fn verify_get_block_headers_request( | ||
request: GetBlockHeadersRequest, | ||
) -> Result<(), GetBlockHeadersError> { | ||
if let Some(end_height) = request.end_height { | ||
if end_height < request.start_height { | ||
return Err(GetBlockHeadersError::StartHeightLagerThanEndHeight { | ||
start_height: request.start_height, | ||
end_height, | ||
}); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Given a start height and an optional end height from request, | ||
/// the function returns the block headers in the provided range. | ||
/// The range is inclusive, i.e., the block headers at the start | ||
/// and end heights are returned as well. | ||
/// If no end height is specified, all blocks until the tip height, | ||
/// i.e., the largest available height, are returned. However, if | ||
/// the range from the start height to the end height or the tip | ||
/// height is large, only a prefix of the requested block headers | ||
/// may be returned in order to bound the size of the response. | ||
pub fn get_block_headers( | ||
request: GetBlockHeadersRequest, | ||
) -> Result<GetBlockHeadersResponse, GetBlockHeadersError> { | ||
verify_get_block_headers_request(request)?; | ||
unimplemented!("get_block_headers is not implemented") | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use ic_btc_interface::{Config, GetBlockHeadersError, GetBlockHeadersRequest, Network}; | ||
|
||
use crate::api::get_block_headers; | ||
|
||
#[test] | ||
fn get_block_headers_malformed_heights() { | ||
crate::init(Config { | ||
stability_threshold: 1, | ||
network: Network::Mainnet, | ||
..Default::default() | ||
}); | ||
|
||
let start_height = 3; | ||
let end_height = 2; | ||
|
||
let err = get_block_headers(GetBlockHeadersRequest { | ||
start_height, | ||
end_height: Some(end_height), | ||
}) | ||
.unwrap_err(); | ||
|
||
assert_eq!( | ||
err, | ||
GetBlockHeadersError::StartHeightLagerThanEndHeight { | ||
start_height, | ||
end_height, | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters